From 1e760df3e36854a0c933f280836b250333c99bac Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Tue, 29 Oct 2024 18:57:24 +0530 Subject: [PATCH 01/13] draft PR --- tests/dashboard/build-dashboard.test.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/dashboard/build-dashboard.test.js diff --git a/tests/dashboard/build-dashboard.test.js b/tests/dashboard/build-dashboard.test.js new file mode 100644 index 000000000000..e69de29bb2d1 From d447661881c459de84f6e416957e5faf64d3b7e7 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Fri, 1 Nov 2024 16:29:00 +0530 Subject: [PATCH 02/13] initial test setup --- scripts/dashboard/build-dashboard.js | 19 +++-- tests/dashboard/build-dashboard.test.js | 100 ++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 8 deletions(-) diff --git a/scripts/dashboard/build-dashboard.js b/scripts/dashboard/build-dashboard.js index 5b0a34bee17b..20a768c70fda 100644 --- a/scripts/dashboard/build-dashboard.js +++ b/scripts/dashboard/build-dashboard.js @@ -83,8 +83,8 @@ async function processHotDiscussions(batch) { const finalInteractionsCount = isPR ? interactionsCount + - discussion.reviews.totalCount + - discussion.reviews.nodes.reduce((acc, curr) => acc + curr.comments.totalCount, 0) + discussion.reviews.totalCount + + discussion.reviews.nodes.reduce((acc, curr) => acc + curr.comments.totalCount, 0) : interactionsCount; return { id: discussion.id, @@ -123,8 +123,8 @@ async function getHotDiscussions(discussions) { const filteredResult = result.filter((issue) => issue.author !== 'asyncapi-bot'); return filteredResult.slice(0, 12); } -async function writeToFile(content) { - writeFileSync(resolve(__dirname, '..', '..', 'dashboard.json'), JSON.stringify(content, null, ' ')); +async function writeToFile(content, writePath) { + writeFileSync(writePath, JSON.stringify(content, null, ' ')); } async function mapGoodFirstIssues(issues) { return issues.map((issue) => ({ @@ -153,7 +153,7 @@ function monthsSince(date) { return Math.floor(months); } -async function start() { +async function start(writePath) { try { const issues = await getDiscussions(Queries.hotDiscussionsIssues, 20); const PRs = await getDiscussions(Queries.hotDiscussionsPullRequests, 20); @@ -163,12 +163,15 @@ async function start() { getHotDiscussions(discussions), mapGoodFirstIssues(rawGoodFirstIssues) ]); - writeToFile({ hotDiscussions, goodFirstIssues }); + writeToFile(writePath, { hotDiscussions, goodFirstIssues }); } catch (e) { console.log('There were some issues parsing data from github.'); console.log(e); } } -start(); -module.exports = { getLabel, monthsSince, mapGoodFirstIssues, getHotDiscussions, getDiscussionByID }; +if (require.main === module) { + start(resolve(__dirname, '..', '..', 'dashboard.json')); +} + +module.exports = { getLabel, monthsSince, mapGoodFirstIssues, getHotDiscussions, getDiscussionByID, writeToFile }; diff --git a/tests/dashboard/build-dashboard.test.js b/tests/dashboard/build-dashboard.test.js index e69de29bb2d1..e41d26f0abf1 100644 --- a/tests/dashboard/build-dashboard.test.js +++ b/tests/dashboard/build-dashboard.test.js @@ -0,0 +1,100 @@ +const { graphql } = require('@octokit/graphql'); +const { promises: fs, mkdirSync, rmSync } = require('fs'); +const { resolve } = require('path'); +const { getLabel, monthsSince, mapGoodFirstIssues, getHotDiscussions, getDiscussionByID, writeToFile } = require('../../scripts/dashboard/build-dashboard'); +const os = require('os'); + +jest.mock('@octokit/graphql'); + +describe('GitHub Discussions and Issues Processing Module', () => { + let tempDir; + + beforeAll(() => { + tempDir = resolve(os.tmpdir(), 'test-config'); + mkdirSync(tempDir); + }); + + afterAll(() => { + rmSync(tempDir, { recursive: true, force: true }); + }); + + beforeEach(() => { + jest.clearAllMocks(); + }); + + it('should return the correct label based on a filter prefix', () => { + const issue = { + labels: { nodes: [{ name: 'area/bug' }, { name: 'good first issue' }] }, + }; + const label = getLabel(issue, 'area/'); + expect(label).toBe('bug'); + }); + + it('should return undefined if no matching label is found', () => { + const issue = { + labels: { nodes: [{ name: 'type/enhancement' }] }, + }; + const label = getLabel(issue, 'area/'); + expect(label).toBeUndefined(); + }); + + it('should correctly calculate months since a given date', () => { + const date = new Date(); + date.setMonth(date.getMonth() - 3); + expect(monthsSince(date)).toBe(3); + }); + + it('should correctly map issues and filter labels', async () => { + const issues = [ + { + id: '1', + title: 'Test issue', + assignees: { totalCount: 1 }, + resourcePath: '/path/to/issue', + repository: { name: 'repo' }, + author: { login: 'author' }, + labels: { nodes: [{ name: 'area/documentation' }, { name: 'good first issue' }] }, + }, + ]; + + const result = await mapGoodFirstIssues(issues); + expect(result).toEqual([ + { + id: '1', + title: 'Test issue', + isAssigned: true, + resourcePath: '/path/to/issue', + repo: 'asyncapi/repo', + author: 'author', + area: 'documentation', + labels: [], + }, + ]); + }); + + it('should fetch discussion by ID and type', async () => { + const mockResponse = { node: { id: 'test-id', title: 'Test title' } }; + graphql.mockResolvedValue(mockResponse); + + const result = await getDiscussionByID(true, 'test-id'); + expect(result).toEqual(mockResponse); + expect(graphql).toHaveBeenCalledWith(expect.any(String), { + id: 'test-id', + headers: { authorization: `token ${process.env.GITHUB_TOKEN}` }, + }); + }); + + it('should handle errors gracefully', async () => { + graphql.mockRejectedValue(new Error('API error')); + await expect(getDiscussionByID(true, 'test-id')).rejects.toThrow('API error'); + }); + + it('should write JSON content to a file in the temporary directory', async () => { + const content = { test: 'data' }; + const filePath = resolve(tempDir, 'dashboard.json'); + await writeToFile(content, filePath); + + const fileContent = JSON.parse(await fs.readFile(filePath, 'utf-8')); + expect(fileContent).toEqual(content); + }); +}); From 045150d0290096d17b1e7d0706aff0fe15cd1861 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Fri, 1 Nov 2024 16:40:21 +0530 Subject: [PATCH 03/13] tests added --- tests/dashboard/build-dashboard.test.js | 172 +++++++++++++----------- 1 file changed, 92 insertions(+), 80 deletions(-) diff --git a/tests/dashboard/build-dashboard.test.js b/tests/dashboard/build-dashboard.test.js index e41d26f0abf1..40cee3c2166d 100644 --- a/tests/dashboard/build-dashboard.test.js +++ b/tests/dashboard/build-dashboard.test.js @@ -1,100 +1,112 @@ const { graphql } = require('@octokit/graphql'); const { promises: fs, mkdirSync, rmSync } = require('fs'); const { resolve } = require('path'); -const { getLabel, monthsSince, mapGoodFirstIssues, getHotDiscussions, getDiscussionByID, writeToFile } = require('../../scripts/dashboard/build-dashboard'); +const { + getLabel, + monthsSince, + mapGoodFirstIssues, + getHotDiscussions, + getDiscussionByID, + writeToFile, +} = require('../../scripts/dashboard/build-dashboard'); const os = require('os'); jest.mock('@octokit/graphql'); -describe('GitHub Discussions and Issues Processing Module', () => { - let tempDir; +const mockDiscussion = { + id: 'test-id', + __typename: 'Issue', + title: 'Test', + author: { login: 'author' }, + resourcePath: '/path', + repository: { name: 'repo' }, + assignees: { totalCount: 0 }, + reactions: { totalCount: 5 }, + comments: { + totalCount: 2, + nodes: [{ reactions: { totalCount: 1 } }], + pageInfo: { hasNextPage: false } + }, + labels: { nodes: [] }, + timelineItems: { updatedAt: new Date().toISOString() } +}; - beforeAll(() => { - tempDir = resolve(os.tmpdir(), 'test-config'); - mkdirSync(tempDir); - }); +describe('GitHub Discussions Processing', () => { + let tempDir; - afterAll(() => { - rmSync(tempDir, { recursive: true, force: true }); - }); + beforeAll(() => { + tempDir = resolve(os.tmpdir(), 'test-config'); + mkdirSync(tempDir); + }); - beforeEach(() => { - jest.clearAllMocks(); - }); + afterAll(() => { + rmSync(tempDir, { recursive: true, force: true }); + }); - it('should return the correct label based on a filter prefix', () => { - const issue = { - labels: { nodes: [{ name: 'area/bug' }, { name: 'good first issue' }] }, - }; - const label = getLabel(issue, 'area/'); - expect(label).toBe('bug'); - }); + beforeEach(() => { + jest.clearAllMocks(); + }); - it('should return undefined if no matching label is found', () => { - const issue = { - labels: { nodes: [{ name: 'type/enhancement' }] }, - }; - const label = getLabel(issue, 'area/'); - expect(label).toBeUndefined(); - }); + it('should get labels correctly', () => { + const issue = { + labels: { nodes: [{ name: 'area/bug' }, { name: 'good first issue' }] } + }; + expect(getLabel(issue, 'area/')).toBe('bug'); + expect(getLabel(issue, 'nonexistent/')).toBeUndefined(); + }); - it('should correctly calculate months since a given date', () => { - const date = new Date(); - date.setMonth(date.getMonth() - 3); - expect(monthsSince(date)).toBe(3); - }); + it('should calculate months since date', () => { + const date = new Date(); + date.setMonth(date.getMonth() - 2); + expect(monthsSince(date)).toBe(2); + }); - it('should correctly map issues and filter labels', async () => { - const issues = [ - { - id: '1', - title: 'Test issue', - assignees: { totalCount: 1 }, - resourcePath: '/path/to/issue', - repository: { name: 'repo' }, - author: { login: 'author' }, - labels: { nodes: [{ name: 'area/documentation' }, { name: 'good first issue' }] }, - }, - ]; - - const result = await mapGoodFirstIssues(issues); - expect(result).toEqual([ - { - id: '1', - title: 'Test issue', - isAssigned: true, - resourcePath: '/path/to/issue', - repo: 'asyncapi/repo', - author: 'author', - area: 'documentation', - labels: [], - }, - ]); + it('should map good first issues', async () => { + const issues = [{ + id: '1', + title: 'Test', + assignees: { totalCount: 1 }, + resourcePath: '/path', + repository: { name: 'repo' }, + author: { login: 'author' }, + labels: { nodes: [{ name: 'area/docs' }] } + }]; + + const result = await mapGoodFirstIssues(issues); + expect(result[0]).toMatchObject({ + id: '1', + area: 'docs' }); + }); - it('should fetch discussion by ID and type', async () => { - const mockResponse = { node: { id: 'test-id', title: 'Test title' } }; - graphql.mockResolvedValue(mockResponse); + it('should handle discussion retrieval', async () => { + graphql.mockResolvedValueOnce({ node: mockDiscussion }); + const result = await getDiscussionByID(false, 'test-id'); + expect(result.node).toBeDefined(); - const result = await getDiscussionByID(true, 'test-id'); - expect(result).toEqual(mockResponse); - expect(graphql).toHaveBeenCalledWith(expect.any(String), { - id: 'test-id', - headers: { authorization: `token ${process.env.GITHUB_TOKEN}` }, - }); - }); + graphql.mockRejectedValueOnce(new Error('API error')); + await expect(getDiscussionByID(true, 'test-id')).rejects.toThrow(); + }); - it('should handle errors gracefully', async () => { - graphql.mockRejectedValue(new Error('API error')); - await expect(getDiscussionByID(true, 'test-id')).rejects.toThrow('API error'); - }); + it('should process hot discussions', async () => { + const prDiscussion = { + ...mockDiscussion, + __typename: 'PullRequest', + reviews: { + totalCount: 1, + nodes: [{ comments: { totalCount: 1 } }] + } + }; - it('should write JSON content to a file in the temporary directory', async () => { - const content = { test: 'data' }; - const filePath = resolve(tempDir, 'dashboard.json'); - await writeToFile(content, filePath); + const result = await getHotDiscussions([mockDiscussion, prDiscussion]); + expect(result.length).toBeLessThanOrEqual(12); + }); - const fileContent = JSON.parse(await fs.readFile(filePath, 'utf-8')); - expect(fileContent).toEqual(content); - }); -}); + it('should write to file', async () => { + const filePath = resolve(tempDir, 'test.json'); + await writeToFile({ test: true }, filePath); + const content = JSON.parse(await fs.readFile(filePath, 'utf-8')); + expect(content).toEqual({ test: true }); + }); + +}); \ No newline at end of file From 1bf30ea83d9925f66148d17d3b40d7659291b7ed Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Fri, 1 Nov 2024 17:09:48 +0530 Subject: [PATCH 04/13] feqg --- scripts/dashboard/build-dashboard.js | 20 +++---- tests/dashboard/build-dashboard.test.js | 74 ++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 14 deletions(-) diff --git a/scripts/dashboard/build-dashboard.js b/scripts/dashboard/build-dashboard.js index 20a768c70fda..74b93e9c2e70 100644 --- a/scripts/dashboard/build-dashboard.js +++ b/scripts/dashboard/build-dashboard.js @@ -1,4 +1,4 @@ -const { writeFileSync } = require('fs'); +const { writeFile } = require('fs-extra'); const { resolve } = require('path'); const { graphql } = require('@octokit/graphql'); const { Queries } = require('./issue-queries'); @@ -44,10 +44,10 @@ async function getDiscussions(query, pageSize, endCursor = null) { return result.search.nodes.concat(await getDiscussions(query, pageSize, result.search.pageInfo.endCursor)); } catch (e) { console.error(e); - return Promise.reject(e); } } + async function getDiscussionByID(isPR, id) { try { const result = await graphql(isPR ? Queries.pullRequestById : Queries.issueById, { @@ -60,7 +60,6 @@ async function getDiscussionByID(isPR, id) { return result; } catch (e) { console.error(e); - return Promise.reject(e); } } @@ -69,7 +68,6 @@ async function processHotDiscussions(batch) { return Promise.all( batch.map(async (discussion) => { try { - // eslint-disable-next-line no-underscore-dangle const isPR = discussion.__typename === 'PullRequest'; if (discussion.comments.pageInfo.hasNextPage) { const fetchedDiscussion = await getDiscussionByID(isPR, discussion.id); @@ -86,6 +84,7 @@ async function processHotDiscussions(batch) { discussion.reviews.totalCount + discussion.reviews.nodes.reduce((acc, curr) => acc + curr.comments.totalCount, 0) : interactionsCount; + return { id: discussion.id, isPR, @@ -111,21 +110,20 @@ async function getHotDiscussions(discussions) { for (let i = 0; i < discussions.length; i += batchSize) { const batch = discussions.slice(i, i + batchSize); - // eslint-disable-next-line no-await-in-loop const batchResults = await processHotDiscussions(batch); - - // eslint-disable-next-line no-await-in-loop await pause(1000); - result.push(...batchResults); } + result.sort((ElemA, ElemB) => ElemB.score - ElemA.score); const filteredResult = result.filter((issue) => issue.author !== 'asyncapi-bot'); return filteredResult.slice(0, 12); } + async function writeToFile(content, writePath) { - writeFileSync(writePath, JSON.stringify(content, null, ' ')); + await writeFile(writePath, JSON.stringify(content, null, ' ')); } + async function mapGoodFirstIssues(issues) { return issues.map((issue) => ({ id: issue.id, @@ -163,7 +161,7 @@ async function start(writePath) { getHotDiscussions(discussions), mapGoodFirstIssues(rawGoodFirstIssues) ]); - writeToFile(writePath, { hotDiscussions, goodFirstIssues }); + return await writeToFile({ hotDiscussions, goodFirstIssues }, writePath); } catch (e) { console.log('There were some issues parsing data from github.'); console.log(e); @@ -174,4 +172,4 @@ if (require.main === module) { start(resolve(__dirname, '..', '..', 'dashboard.json')); } -module.exports = { getLabel, monthsSince, mapGoodFirstIssues, getHotDiscussions, getDiscussionByID, writeToFile }; +module.exports = { getLabel, monthsSince, mapGoodFirstIssues, getHotDiscussions, getDiscussionByID, writeToFile, start }; diff --git a/tests/dashboard/build-dashboard.test.js b/tests/dashboard/build-dashboard.test.js index 40cee3c2166d..d79433c5e1b4 100644 --- a/tests/dashboard/build-dashboard.test.js +++ b/tests/dashboard/build-dashboard.test.js @@ -1,6 +1,7 @@ const { graphql } = require('@octokit/graphql'); -const { promises: fs, mkdirSync, rmSync } = require('fs'); +const { promises: fs, mkdirSync, rmSync } = require('fs-extra'); const { resolve } = require('path'); +const os = require('os'); const { getLabel, monthsSince, @@ -8,8 +9,8 @@ const { getHotDiscussions, getDiscussionByID, writeToFile, + start } = require('../../scripts/dashboard/build-dashboard'); -const os = require('os'); jest.mock('@octokit/graphql'); @@ -109,4 +110,71 @@ describe('GitHub Discussions Processing', () => { expect(content).toEqual({ test: true }); }); -}); \ No newline at end of file + it('should process and write hot discussions and good first issues to a file', async () => { + const mockIssue = { + id: 'issue1', + __typename: 'Issue', + title: 'Test Issue', + author: { login: 'author1' }, + resourcePath: '/path/to/issue', + repository: { name: 'repo' }, + assignees: { totalCount: 1 }, + reactions: { totalCount: 5 }, + comments: { + totalCount: 2, + nodes: [{ reactions: { totalCount: 1 } }], + pageInfo: { hasNextPage: false } + }, + labels: { nodes: [{ name: 'area/docs' }] }, + timelineItems: { updatedAt: new Date().toISOString() } + }; + + const mockPR = { + id: 'pr1', + __typename: 'PullRequest', + title: 'Test PR', + author: { login: 'author2' }, + resourcePath: '/path/to/pr', + repository: { name: 'repo' }, + assignees: { totalCount: 0 }, + reactions: { totalCount: 3 }, + comments: { + totalCount: 1, + nodes: [{ reactions: { totalCount: 1 } }], + pageInfo: { hasNextPage: false } + }, + reviews: { + totalCount: 1, + nodes: [{ comments: { totalCount: 1 } }] + }, + labels: { nodes: [{ name: 'good first issue' }] }, + timelineItems: { updatedAt: new Date().toISOString() } + }; + + const tempFilePath = resolve(tempDir, 'dashboard.json'); + + graphql.mockResolvedValueOnce({ search: { nodes: [mockIssue], pageInfo: { hasNextPage: false } } }); + graphql.mockResolvedValueOnce({ search: { nodes: [mockPR], pageInfo: { hasNextPage: false } } }); + graphql.mockResolvedValueOnce({ search: { nodes: [mockIssue], pageInfo: { hasNextPage: false } } }); + + await start(tempFilePath); + + const content = JSON.parse(await fs.readFile(tempFilePath, 'utf-8')); + expect(content.hotDiscussions).toBeDefined(); + expect(content.goodFirstIssues).toBeDefined(); + expect(content.hotDiscussions).toHaveLength(1); + expect(content.goodFirstIssues).toHaveLength(1); + expect(content.hotDiscussions[0]).toMatchObject({ + id: 'issue1', + title: 'Test Issue', + author: 'author1', + repo: 'asyncapi/repo' + }); + expect(content.goodFirstIssues[0]).toMatchObject({ + id: 'issue1', + title: 'Test Issue', + area: 'docs', + author: 'author1' + }); + }); +}); From d1fbc8b7f376f24b4bd7aee943570ece7520cab2 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Tue, 5 Nov 2024 15:27:59 +0530 Subject: [PATCH 05/13] 95% coverage --- scripts/dashboard/build-dashboard.js | 1 + tests/dashboard/build-dashboard.test.js | 207 ++++++++++++++++-------- 2 files changed, 143 insertions(+), 65 deletions(-) diff --git a/scripts/dashboard/build-dashboard.js b/scripts/dashboard/build-dashboard.js index 74b93e9c2e70..072e1ce7a745 100644 --- a/scripts/dashboard/build-dashboard.js +++ b/scripts/dashboard/build-dashboard.js @@ -168,6 +168,7 @@ async function start(writePath) { } } +/* istanbul ignore next */ if (require.main === module) { start(resolve(__dirname, '..', '..', 'dashboard.json')); } diff --git a/tests/dashboard/build-dashboard.test.js b/tests/dashboard/build-dashboard.test.js index d79433c5e1b4..8c0f29439fde 100644 --- a/tests/dashboard/build-dashboard.test.js +++ b/tests/dashboard/build-dashboard.test.js @@ -34,6 +34,8 @@ const mockDiscussion = { describe('GitHub Discussions Processing', () => { let tempDir; + let consoleErrorSpy; + let consoleLogSpy; beforeAll(() => { tempDir = resolve(os.tmpdir(), 'test-config'); @@ -46,8 +48,127 @@ describe('GitHub Discussions Processing', () => { beforeEach(() => { jest.clearAllMocks(); + consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => {}); }); + afterEach(() => { + consoleErrorSpy.mockRestore(); + consoleLogSpy.mockRestore(); + }); + + // Existing tests remain the same... + + describe('getDiscussions function', () => { + it('should handle rate limit warnings', async () => { + const mockResponse = { + search: { + nodes: [mockDiscussion], + pageInfo: { hasNextPage: false } + }, + rateLimit: { + cost: 1, + limit: 5000, + remaining: 50, + resetAt: new Date().toISOString() + } + }; + + graphql.mockResolvedValueOnce(mockResponse); + + await getDiscussions('test-query', 10); + + expect(consoleLogSpy).toHaveBeenCalledWith( + '[WARNING] GitHub GraphQL rateLimit', + 'cost = 1', + 'limit = 5000', + 'remaining = 50', + expect.any(String) + ); + }); + + it('should handle pagination', async () => { + const mockFirstResponse = { + search: { + nodes: [mockDiscussion], + pageInfo: { hasNextPage: true, endCursor: 'cursor1' } + }, + rateLimit: { remaining: 1000 } + }; + + const mockSecondResponse = { + search: { + nodes: [{ ...mockDiscussion, id: 'test-id-2' }], + pageInfo: { hasNextPage: false } + }, + rateLimit: { remaining: 1000 } + }; + + graphql + .mockResolvedValueOnce(mockFirstResponse) + .mockResolvedValueOnce(mockSecondResponse); + + const result = await getDiscussions('test-query', 10); + expect(result).toHaveLength(2); + }); + + it('should handle API errors', async () => { + graphql.mockRejectedValueOnce(new Error('API Error')); + await expect(getDiscussions('test-query', 10)).rejects.toThrow('API Error'); + }); + }); + + describe('processHotDiscussions', () => { + it('should handle parsing errors', async () => { + const invalidDiscussion = { + ...mockDiscussion, + comments: null // This will cause a parsing error + }; + + await expect(processHotDiscussions([invalidDiscussion])).rejects.toThrow(); + expect(consoleErrorSpy).toHaveBeenCalled(); + }); + + it('should handle missing author', async () => { + const noAuthorDiscussion = { + ...mockDiscussion, + author: null + }; + + const result = await processHotDiscussions([noAuthorDiscussion]); + expect(result[0].author).toBe(''); + }); + }); + + describe('start function', () => { + it('should handle complete failure', async () => { + graphql.mockRejectedValue(new Error('Complete API failure')); + + const filePath = resolve(tempDir, 'error-output.json'); + await start(filePath); + + expect(consoleLogSpy).toHaveBeenCalledWith('There were some issues parsing data from github.'); + }); + + it('should successfully process and write data', async () => { + const mockResponse = { + search: { + nodes: [mockDiscussion], + pageInfo: { hasNextPage: false } + }, + rateLimit: { remaining: 1000 } + }; + + graphql.mockResolvedValue(mockResponse); + + const filePath = resolve(tempDir, 'success-output.json'); + await start(filePath); + + const content = JSON.parse(await fs.readFile(filePath, 'utf-8')); + expect(content).toHaveProperty('hotDiscussions'); + expect(content).toHaveProperty('goodFirstIssues'); + }); + }); it('should get labels correctly', () => { const issue = { labels: { nodes: [{ name: 'area/bug' }, { name: 'good first issue' }] } @@ -110,71 +231,27 @@ describe('GitHub Discussions Processing', () => { expect(content).toEqual({ test: true }); }); - it('should process and write hot discussions and good first issues to a file', async () => { - const mockIssue = { - id: 'issue1', - __typename: 'Issue', - title: 'Test Issue', - author: { login: 'author1' }, - resourcePath: '/path/to/issue', - repository: { name: 'repo' }, - assignees: { totalCount: 1 }, - reactions: { totalCount: 5 }, - comments: { - totalCount: 2, - nodes: [{ reactions: { totalCount: 1 } }], - pageInfo: { hasNextPage: false } - }, - labels: { nodes: [{ name: 'area/docs' }] }, - timelineItems: { updatedAt: new Date().toISOString() } - }; - - const mockPR = { - id: 'pr1', - __typename: 'PullRequest', - title: 'Test PR', - author: { login: 'author2' }, - resourcePath: '/path/to/pr', - repository: { name: 'repo' }, - assignees: { totalCount: 0 }, - reactions: { totalCount: 3 }, - comments: { - totalCount: 1, - nodes: [{ reactions: { totalCount: 1 } }], - pageInfo: { hasNextPage: false } - }, - reviews: { - totalCount: 1, - nodes: [{ comments: { totalCount: 1 } }] - }, - labels: { nodes: [{ name: 'good first issue' }] }, - timelineItems: { updatedAt: new Date().toISOString() } - }; - - const tempFilePath = resolve(tempDir, 'dashboard.json'); - - graphql.mockResolvedValueOnce({ search: { nodes: [mockIssue], pageInfo: { hasNextPage: false } } }); - graphql.mockResolvedValueOnce({ search: { nodes: [mockPR], pageInfo: { hasNextPage: false } } }); - graphql.mockResolvedValueOnce({ search: { nodes: [mockIssue], pageInfo: { hasNextPage: false } } }); - - await start(tempFilePath); - - const content = JSON.parse(await fs.readFile(tempFilePath, 'utf-8')); + it('should run the start function and write output to a file', async () => { + const mockIssues = [mockDiscussion]; + const mockPRs = [{ ...mockDiscussion, __typename: 'PullRequest' }]; + const mockGoodFirstIssues = [{ ...mockDiscussion, id: 'good-first-issue' }]; + + graphql.mockImplementation((query) => { + if (query === Queries.hotDiscussionsIssues) return { search: { nodes: mockIssues, pageInfo: { hasNextPage: false } } }; + if (query === Queries.hotDiscussionsPullRequests) return { search: { nodes: mockPRs, pageInfo: { hasNextPage: false } } }; + if (query === Queries.goodFirstIssues) return { search: { nodes: mockGoodFirstIssues, pageInfo: { hasNextPage: false } } }; + return null; + }); + + const filePath = resolve(tempDir, 'start-output.json'); + + await start(filePath); + + const content = JSON.parse(await fs.readFile(filePath, 'utf-8')); + expect(content.hotDiscussions).toBeDefined(); expect(content.goodFirstIssues).toBeDefined(); - expect(content.hotDiscussions).toHaveLength(1); - expect(content.goodFirstIssues).toHaveLength(1); - expect(content.hotDiscussions[0]).toMatchObject({ - id: 'issue1', - title: 'Test Issue', - author: 'author1', - repo: 'asyncapi/repo' - }); - expect(content.goodFirstIssues[0]).toMatchObject({ - id: 'issue1', - title: 'Test Issue', - area: 'docs', - author: 'author1' - }); + expect(content.hotDiscussions.length).toBeGreaterThan(0); + expect(content.goodFirstIssues.length).toBeGreaterThan(0); }); -}); +}); \ No newline at end of file From a97ce4fc1089680a68e914d750fbf7f07d7a4410 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Tue, 5 Nov 2024 15:39:28 +0530 Subject: [PATCH 06/13] tests updated --- tests/dashboard/build-dashboard.test.js | 188 +++++++++--------------- 1 file changed, 66 insertions(+), 122 deletions(-) diff --git a/tests/dashboard/build-dashboard.test.js b/tests/dashboard/build-dashboard.test.js index 8c0f29439fde..8b4cf800a91c 100644 --- a/tests/dashboard/build-dashboard.test.js +++ b/tests/dashboard/build-dashboard.test.js @@ -48,8 +48,8 @@ describe('GitHub Discussions Processing', () => { beforeEach(() => { jest.clearAllMocks(); - consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); - consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => {}); + consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => { }); + consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => { }); }); afterEach(() => { @@ -57,118 +57,86 @@ describe('GitHub Discussions Processing', () => { consoleLogSpy.mockRestore(); }); - // Existing tests remain the same... + it('should handle rate limit warnings', async () => { + const mockResponse = { + search: { + nodes: [mockDiscussion], + pageInfo: { hasNextPage: false } + }, + rateLimit: { + cost: 1, + limit: 5000, + remaining: 50, + resetAt: new Date().toISOString() + } + }; - describe('getDiscussions function', () => { - it('should handle rate limit warnings', async () => { - const mockResponse = { - search: { - nodes: [mockDiscussion], - pageInfo: { hasNextPage: false } - }, - rateLimit: { - cost: 1, - limit: 5000, - remaining: 50, - resetAt: new Date().toISOString() - } - }; + graphql.mockResolvedValueOnce(mockResponse); - graphql.mockResolvedValueOnce(mockResponse); - - await getDiscussions('test-query', 10); - - expect(consoleLogSpy).toHaveBeenCalledWith( - '[WARNING] GitHub GraphQL rateLimit', - 'cost = 1', - 'limit = 5000', - 'remaining = 50', - expect.any(String) - ); - }); + await getDiscussions('test-query', 10); - it('should handle pagination', async () => { - const mockFirstResponse = { - search: { - nodes: [mockDiscussion], - pageInfo: { hasNextPage: true, endCursor: 'cursor1' } - }, - rateLimit: { remaining: 1000 } - }; + expect(consoleLogSpy).toHaveBeenCalledWith( + '[WARNING] GitHub GraphQL rateLimit', + 'cost = 1', + 'limit = 5000', + 'remaining = 50', + expect.any(String) + ); + }); - const mockSecondResponse = { - search: { - nodes: [{ ...mockDiscussion, id: 'test-id-2' }], - pageInfo: { hasNextPage: false } - }, - rateLimit: { remaining: 1000 } - }; + it('should handle pagination', async () => { + const mockFirstResponse = { + search: { + nodes: [mockDiscussion], + pageInfo: { hasNextPage: true, endCursor: 'cursor1' } + }, + rateLimit: { remaining: 1000 } + }; - graphql - .mockResolvedValueOnce(mockFirstResponse) - .mockResolvedValueOnce(mockSecondResponse); + const mockSecondResponse = { + search: { + nodes: [{ ...mockDiscussion, id: 'test-id-2' }], + pageInfo: { hasNextPage: false } + }, + rateLimit: { remaining: 1000 } + }; - const result = await getDiscussions('test-query', 10); - expect(result).toHaveLength(2); - }); + graphql + .mockResolvedValueOnce(mockFirstResponse) + .mockResolvedValueOnce(mockSecondResponse); - it('should handle API errors', async () => { - graphql.mockRejectedValueOnce(new Error('API Error')); - await expect(getDiscussions('test-query', 10)).rejects.toThrow('API Error'); - }); + const result = await getDiscussions('test-query', 10); + expect(result).toHaveLength(2); }); - describe('processHotDiscussions', () => { - it('should handle parsing errors', async () => { - const invalidDiscussion = { - ...mockDiscussion, - comments: null // This will cause a parsing error - }; - - await expect(processHotDiscussions([invalidDiscussion])).rejects.toThrow(); - expect(consoleErrorSpy).toHaveBeenCalled(); - }); + it('should handle complete failure', async () => { + graphql.mockRejectedValue(new Error('Complete API failure')); - it('should handle missing author', async () => { - const noAuthorDiscussion = { - ...mockDiscussion, - author: null - }; + const filePath = resolve(tempDir, 'error-output.json'); + await start(filePath); - const result = await processHotDiscussions([noAuthorDiscussion]); - expect(result[0].author).toBe(''); - }); + expect(consoleLogSpy).toHaveBeenCalledWith('There were some issues parsing data from github.'); }); - describe('start function', () => { - it('should handle complete failure', async () => { - graphql.mockRejectedValue(new Error('Complete API failure')); - - const filePath = resolve(tempDir, 'error-output.json'); - await start(filePath); - - expect(consoleLogSpy).toHaveBeenCalledWith('There were some issues parsing data from github.'); - }); - - it('should successfully process and write data', async () => { - const mockResponse = { - search: { - nodes: [mockDiscussion], - pageInfo: { hasNextPage: false } - }, - rateLimit: { remaining: 1000 } - }; + it('should successfully process and write data', async () => { + const mockResponse = { + search: { + nodes: [mockDiscussion], + pageInfo: { hasNextPage: false } + }, + rateLimit: { remaining: 1000 } + }; - graphql.mockResolvedValue(mockResponse); + graphql.mockResolvedValue(mockResponse); - const filePath = resolve(tempDir, 'success-output.json'); - await start(filePath); + const filePath = resolve(tempDir, 'success-output.json'); + await start(filePath); - const content = JSON.parse(await fs.readFile(filePath, 'utf-8')); - expect(content).toHaveProperty('hotDiscussions'); - expect(content).toHaveProperty('goodFirstIssues'); - }); + const content = JSON.parse(await fs.readFile(filePath, 'utf-8')); + expect(content).toHaveProperty('hotDiscussions'); + expect(content).toHaveProperty('goodFirstIssues'); }); + it('should get labels correctly', () => { const issue = { labels: { nodes: [{ name: 'area/bug' }, { name: 'good first issue' }] } @@ -230,28 +198,4 @@ describe('GitHub Discussions Processing', () => { const content = JSON.parse(await fs.readFile(filePath, 'utf-8')); expect(content).toEqual({ test: true }); }); - - it('should run the start function and write output to a file', async () => { - const mockIssues = [mockDiscussion]; - const mockPRs = [{ ...mockDiscussion, __typename: 'PullRequest' }]; - const mockGoodFirstIssues = [{ ...mockDiscussion, id: 'good-first-issue' }]; - - graphql.mockImplementation((query) => { - if (query === Queries.hotDiscussionsIssues) return { search: { nodes: mockIssues, pageInfo: { hasNextPage: false } } }; - if (query === Queries.hotDiscussionsPullRequests) return { search: { nodes: mockPRs, pageInfo: { hasNextPage: false } } }; - if (query === Queries.goodFirstIssues) return { search: { nodes: mockGoodFirstIssues, pageInfo: { hasNextPage: false } } }; - return null; - }); - - const filePath = resolve(tempDir, 'start-output.json'); - - await start(filePath); - - const content = JSON.parse(await fs.readFile(filePath, 'utf-8')); - - expect(content.hotDiscussions).toBeDefined(); - expect(content.goodFirstIssues).toBeDefined(); - expect(content.hotDiscussions.length).toBeGreaterThan(0); - expect(content.goodFirstIssues.length).toBeGreaterThan(0); - }); -}); \ No newline at end of file +}); From 9b6d95da61fc4a84ebf7fbf0a58e4eac236cfaad Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Tue, 5 Nov 2024 15:50:29 +0530 Subject: [PATCH 07/13] coverage 97% --- scripts/dashboard/build-dashboard.js | 2 +- tests/dashboard/build-dashboard.test.js | 57 +++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/scripts/dashboard/build-dashboard.js b/scripts/dashboard/build-dashboard.js index 072e1ce7a745..b305857684c0 100644 --- a/scripts/dashboard/build-dashboard.js +++ b/scripts/dashboard/build-dashboard.js @@ -173,4 +173,4 @@ if (require.main === module) { start(resolve(__dirname, '..', '..', 'dashboard.json')); } -module.exports = { getLabel, monthsSince, mapGoodFirstIssues, getHotDiscussions, getDiscussionByID, writeToFile, start }; +module.exports = { getLabel, monthsSince, mapGoodFirstIssues, getHotDiscussions, getDiscussionByID, getDiscussions, writeToFile, start }; diff --git a/tests/dashboard/build-dashboard.test.js b/tests/dashboard/build-dashboard.test.js index 8b4cf800a91c..2937001ecc44 100644 --- a/tests/dashboard/build-dashboard.test.js +++ b/tests/dashboard/build-dashboard.test.js @@ -9,6 +9,7 @@ const { getHotDiscussions, getDiscussionByID, writeToFile, + getDiscussions, start } = require('../../scripts/dashboard/build-dashboard'); @@ -57,6 +58,62 @@ describe('GitHub Discussions Processing', () => { consoleLogSpy.mockRestore(); }); + it('should fetch additional discussion details when comments have next page', async () => { + const discussionWithMoreComments = { + id: 'paginated-discussion', + __typename: 'Issue', + title: 'Test with Pagination', + author: { login: 'author' }, + resourcePath: '/path', + repository: { name: 'repo' }, + assignees: { totalCount: 0 }, + reactions: { totalCount: 5 }, + comments: { + totalCount: 5, + nodes: [{ reactions: { totalCount: 1 } }], + pageInfo: { hasNextPage: true } + }, + labels: { nodes: [] }, + timelineItems: { updatedAt: new Date().toISOString() } + }; + + const fullDiscussionDetails = { + node: { + ...discussionWithMoreComments, + comments: { + totalCount: 5, + nodes: [ + { reactions: { totalCount: 1 } }, + { reactions: { totalCount: 2 } }, + { reactions: { totalCount: 3 } } + ], + pageInfo: { hasNextPage: false } + } + } + }; + + graphql.mockResolvedValueOnce(fullDiscussionDetails); + + const result = await getHotDiscussions([discussionWithMoreComments]); + + expect(graphql).toHaveBeenCalledWith( + expect.any(String), + expect.objectContaining({ + id: 'paginated-discussion', + headers: expect.any(Object) + }) + ); + + expect(result[0]).toMatchObject({ + id: 'paginated-discussion', + isPR: false, + title: 'Test with Pagination' + }); + + const firstResult = result[0]; + expect(firstResult.score).toBeGreaterThan(0); + }); + it('should handle rate limit warnings', async () => { const mockResponse = { search: { From eeb8b79f2d4aeb2a219c92639bf4bbd475bc8bcf Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Tue, 5 Nov 2024 15:55:03 +0530 Subject: [PATCH 08/13] coverage 100% --- scripts/dashboard/build-dashboard.js | 2 +- tests/dashboard/build-dashboard.test.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/scripts/dashboard/build-dashboard.js b/scripts/dashboard/build-dashboard.js index b305857684c0..4452ba0b9b52 100644 --- a/scripts/dashboard/build-dashboard.js +++ b/scripts/dashboard/build-dashboard.js @@ -173,4 +173,4 @@ if (require.main === module) { start(resolve(__dirname, '..', '..', 'dashboard.json')); } -module.exports = { getLabel, monthsSince, mapGoodFirstIssues, getHotDiscussions, getDiscussionByID, getDiscussions, writeToFile, start }; +module.exports = { getLabel, monthsSince, mapGoodFirstIssues, getHotDiscussions, getDiscussionByID, getDiscussions, writeToFile, start, processHotDiscussions }; diff --git a/tests/dashboard/build-dashboard.test.js b/tests/dashboard/build-dashboard.test.js index 2937001ecc44..5b07efed5455 100644 --- a/tests/dashboard/build-dashboard.test.js +++ b/tests/dashboard/build-dashboard.test.js @@ -10,6 +10,7 @@ const { getDiscussionByID, writeToFile, getDiscussions, + processHotDiscussions, start } = require('../../scripts/dashboard/build-dashboard'); @@ -255,4 +256,17 @@ describe('GitHub Discussions Processing', () => { const content = JSON.parse(await fs.readFile(filePath, 'utf-8')); expect(content).toEqual({ test: true }); }); + + it('should handle parsing errors in processHotDiscussions', async () => { + const consoleErrorSpy = jest.spyOn(console, 'error'); + + await expect(getHotDiscussions([undefined])).rejects.toThrow(); + + expect(consoleErrorSpy).toHaveBeenCalledWith( + 'there was some issues while parsing this item: undefined' + ); + + consoleErrorSpy.mockRestore(); + }); + }); From 08ba356b96883cc35bb0a2daba6ac79743854922 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Tue, 5 Nov 2024 16:06:46 +0530 Subject: [PATCH 09/13] fixtures updated --- tests/dashboard/build-dashboard.test.js | 84 +++---------------------- tests/fixtures/dashboardData.js | 70 +++++++++++++++++++++ 2 files changed, 78 insertions(+), 76 deletions(-) create mode 100644 tests/fixtures/dashboardData.js diff --git a/tests/dashboard/build-dashboard.test.js b/tests/dashboard/build-dashboard.test.js index 5b07efed5455..4da968b7aa59 100644 --- a/tests/dashboard/build-dashboard.test.js +++ b/tests/dashboard/build-dashboard.test.js @@ -10,30 +10,17 @@ const { getDiscussionByID, writeToFile, getDiscussions, - processHotDiscussions, start } = require('../../scripts/dashboard/build-dashboard'); +const { + mockDiscussion, + discussionWithMoreComments, + fullDiscussionDetails, + mockRateLimitResponse +} = require("../fixtures/dashboardData") jest.mock('@octokit/graphql'); -const mockDiscussion = { - id: 'test-id', - __typename: 'Issue', - title: 'Test', - author: { login: 'author' }, - resourcePath: '/path', - repository: { name: 'repo' }, - assignees: { totalCount: 0 }, - reactions: { totalCount: 5 }, - comments: { - totalCount: 2, - nodes: [{ reactions: { totalCount: 1 } }], - pageInfo: { hasNextPage: false } - }, - labels: { nodes: [] }, - timelineItems: { updatedAt: new Date().toISOString() } -}; - describe('GitHub Discussions Processing', () => { let tempDir; let consoleErrorSpy; @@ -60,39 +47,6 @@ describe('GitHub Discussions Processing', () => { }); it('should fetch additional discussion details when comments have next page', async () => { - const discussionWithMoreComments = { - id: 'paginated-discussion', - __typename: 'Issue', - title: 'Test with Pagination', - author: { login: 'author' }, - resourcePath: '/path', - repository: { name: 'repo' }, - assignees: { totalCount: 0 }, - reactions: { totalCount: 5 }, - comments: { - totalCount: 5, - nodes: [{ reactions: { totalCount: 1 } }], - pageInfo: { hasNextPage: true } - }, - labels: { nodes: [] }, - timelineItems: { updatedAt: new Date().toISOString() } - }; - - const fullDiscussionDetails = { - node: { - ...discussionWithMoreComments, - comments: { - totalCount: 5, - nodes: [ - { reactions: { totalCount: 1 } }, - { reactions: { totalCount: 2 } }, - { reactions: { totalCount: 3 } } - ], - pageInfo: { hasNextPage: false } - } - } - }; - graphql.mockResolvedValueOnce(fullDiscussionDetails); const result = await getHotDiscussions([discussionWithMoreComments]); @@ -116,20 +70,7 @@ describe('GitHub Discussions Processing', () => { }); it('should handle rate limit warnings', async () => { - const mockResponse = { - search: { - nodes: [mockDiscussion], - pageInfo: { hasNextPage: false } - }, - rateLimit: { - cost: 1, - limit: 5000, - remaining: 50, - resetAt: new Date().toISOString() - } - }; - - graphql.mockResolvedValueOnce(mockResponse); + graphql.mockResolvedValueOnce(mockRateLimitResponse); await getDiscussions('test-query', 10); @@ -177,15 +118,7 @@ describe('GitHub Discussions Processing', () => { }); it('should successfully process and write data', async () => { - const mockResponse = { - search: { - nodes: [mockDiscussion], - pageInfo: { hasNextPage: false } - }, - rateLimit: { remaining: 1000 } - }; - - graphql.mockResolvedValue(mockResponse); + graphql.mockResolvedValue(mockRateLimitResponse); const filePath = resolve(tempDir, 'success-output.json'); await start(filePath); @@ -268,5 +201,4 @@ describe('GitHub Discussions Processing', () => { consoleErrorSpy.mockRestore(); }); - }); diff --git a/tests/fixtures/dashboardData.js b/tests/fixtures/dashboardData.js new file mode 100644 index 000000000000..45ab9424189b --- /dev/null +++ b/tests/fixtures/dashboardData.js @@ -0,0 +1,70 @@ +const mockDiscussion = { + id: 'test-id', + __typename: 'Issue', + title: 'Test', + author: { login: 'author' }, + resourcePath: '/path', + repository: { name: 'repo' }, + assignees: { totalCount: 0 }, + reactions: { totalCount: 5 }, + comments: { + totalCount: 2, + nodes: [{ reactions: { totalCount: 1 } }], + pageInfo: { hasNextPage: false } + }, + labels: { nodes: [] }, + timelineItems: { updatedAt: new Date().toISOString() } +}; + +const discussionWithMoreComments = { + id: 'paginated-discussion', + __typename: 'Issue', + title: 'Test with Pagination', + author: { login: 'author' }, + resourcePath: '/path', + repository: { name: 'repo' }, + assignees: { totalCount: 0 }, + reactions: { totalCount: 5 }, + comments: { + totalCount: 5, + nodes: [{ reactions: { totalCount: 1 } }], + pageInfo: { hasNextPage: true } + }, + labels: { nodes: [] }, + timelineItems: { updatedAt: new Date().toISOString() } +}; + +const fullDiscussionDetails = { + node: { + ...discussionWithMoreComments, + comments: { + totalCount: 5, + nodes: [ + { reactions: { totalCount: 1 } }, + { reactions: { totalCount: 2 } }, + { reactions: { totalCount: 3 } } + ], + pageInfo: { hasNextPage: false } + } + } +}; + +const mockRateLimitResponse = { + search: { + nodes: [mockDiscussion], + pageInfo: { hasNextPage: false } + }, + rateLimit: { + cost: 1, + limit: 5000, + remaining: 50, + resetAt: new Date().toISOString() + } +}; + +module.exports = { + mockDiscussion, + discussionWithMoreComments, + fullDiscussionDetails, + mockRateLimitResponse +}; From 972e0a1581f3f10e837afb5f399171bb443307cc Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Tue, 5 Nov 2024 16:08:46 +0530 Subject: [PATCH 10/13] wfgfefg --- tests/dashboard/build-dashboard.test.js | 11 ++--------- tests/fixtures/dashboardData.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/dashboard/build-dashboard.test.js b/tests/dashboard/build-dashboard.test.js index 4da968b7aa59..645a0c01c7bb 100644 --- a/tests/dashboard/build-dashboard.test.js +++ b/tests/dashboard/build-dashboard.test.js @@ -12,7 +12,9 @@ const { getDiscussions, start } = require('../../scripts/dashboard/build-dashboard'); + const { + issues, mockDiscussion, discussionWithMoreComments, fullDiscussionDetails, @@ -143,15 +145,6 @@ describe('GitHub Discussions Processing', () => { }); it('should map good first issues', async () => { - const issues = [{ - id: '1', - title: 'Test', - assignees: { totalCount: 1 }, - resourcePath: '/path', - repository: { name: 'repo' }, - author: { login: 'author' }, - labels: { nodes: [{ name: 'area/docs' }] } - }]; const result = await mapGoodFirstIssues(issues); expect(result[0]).toMatchObject({ diff --git a/tests/fixtures/dashboardData.js b/tests/fixtures/dashboardData.js index 45ab9424189b..fa0618c299a9 100644 --- a/tests/fixtures/dashboardData.js +++ b/tests/fixtures/dashboardData.js @@ -62,7 +62,18 @@ const mockRateLimitResponse = { } }; +const issues = [{ + id: '1', + title: 'Test', + assignees: { totalCount: 1 }, + resourcePath: '/path', + repository: { name: 'repo' }, + author: { login: 'author' }, + labels: { nodes: [{ name: 'area/docs' }] } +}]; + module.exports = { + issues, mockDiscussion, discussionWithMoreComments, fullDiscussionDetails, From 6ff849e33913ed20caaf2f3ae12436e27fbaa571 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Tue, 5 Nov 2024 21:27:41 +0530 Subject: [PATCH 11/13] feewg --- tests/dashboard/build-dashboard.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/dashboard/build-dashboard.test.js b/tests/dashboard/build-dashboard.test.js index 645a0c01c7bb..d68d44e37d81 100644 --- a/tests/dashboard/build-dashboard.test.js +++ b/tests/dashboard/build-dashboard.test.js @@ -194,4 +194,5 @@ describe('GitHub Discussions Processing', () => { consoleErrorSpy.mockRestore(); }); + }); From abccd7f1ff372a4ea8f784c3213c2e338dce14e4 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Thu, 7 Nov 2024 09:03:26 +0530 Subject: [PATCH 12/13] fix tests --- scripts/dashboard/build-dashboard.js | 2 +- tests/dashboard/build-dashboard.test.js | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/dashboard/build-dashboard.js b/scripts/dashboard/build-dashboard.js index 4452ba0b9b52..b3974f3ab833 100644 --- a/scripts/dashboard/build-dashboard.js +++ b/scripts/dashboard/build-dashboard.js @@ -97,7 +97,7 @@ async function processHotDiscussions(batch) { score: finalInteractionsCount / (monthsSince(discussion.timelineItems.updatedAt) + 2) ** 1.8 }; } catch (e) { - console.error(`there was some issues while parsing this item: ${JSON.stringify(discussion)}`); + console.error(`there were some issues while parsing this item: ${JSON.stringify(discussion)}`); throw e; } }) diff --git a/tests/dashboard/build-dashboard.test.js b/tests/dashboard/build-dashboard.test.js index d68d44e37d81..e7861c36dc65 100644 --- a/tests/dashboard/build-dashboard.test.js +++ b/tests/dashboard/build-dashboard.test.js @@ -184,15 +184,15 @@ describe('GitHub Discussions Processing', () => { }); it('should handle parsing errors in processHotDiscussions', async () => { - const consoleErrorSpy = jest.spyOn(console, 'error'); - + const localConsoleErrorSpy = jest.spyOn(console, 'error'); + await expect(getHotDiscussions([undefined])).rejects.toThrow(); - + expect(consoleErrorSpy).toHaveBeenCalledWith( - 'there was some issues while parsing this item: undefined' + 'there were some issues while parsing this item: undefined' ); - - consoleErrorSpy.mockRestore(); + + localConsoleErrorSpy.mockRestore(); }); - + }); From ed642053ddf01247752dc1f30f7c3a9b45275020 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Thu, 7 Nov 2024 09:13:04 +0530 Subject: [PATCH 13/13] add error catch --- scripts/dashboard/build-dashboard.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/dashboard/build-dashboard.js b/scripts/dashboard/build-dashboard.js index b3974f3ab833..c20be204e87b 100644 --- a/scripts/dashboard/build-dashboard.js +++ b/scripts/dashboard/build-dashboard.js @@ -121,7 +121,15 @@ async function getHotDiscussions(discussions) { } async function writeToFile(content, writePath) { - await writeFile(writePath, JSON.stringify(content, null, ' ')); + try { + await writeFile(writePath, JSON.stringify(content, null, ' ')); + } catch (error) { + console.error('Failed to write dashboard data:', { + error: error.message, + writePath + }); + throw error; + } } async function mapGoodFirstIssues(issues) {