-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5cfbbb7
commit 60d7950
Showing
36 changed files
with
594 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const mergeStats = require('../mergeStats'); | ||
const { VALID_STATS } = require('../../config/stats'); | ||
Check failure on line 2 in src/interactors/__tests__/mergeStats.test.js GitHub Actions / lint
|
||
const { authors, reviewStats, pullRequestStats } = require('../../../tests/mocks'); | ||
|
||
describe('Interactors | .mergeStats', () => { | ||
const baseParams = { | ||
authors, | ||
reviewStats, | ||
pullRequestStats, | ||
}; | ||
|
||
it('returns an array with all the stats for each author', async () => { | ||
const results = mergeStats(baseParams); | ||
expect(results.length).toEqual(authors.length); | ||
|
||
results.forEach((result) => { | ||
expect(result).toHaveProperty('author'); | ||
expect(result.author).toHaveProperty('login'); | ||
expect(result).toHaveProperty('stats'); | ||
VALID_STATS.forEach((stat) => { | ||
expect(result.stats).toHaveProperty(stat); | ||
}); | ||
}); | ||
}); | ||
|
||
it('returns all the stats for authors with data', async () => { | ||
const results = mergeStats(baseParams) | ||
.find(({ author }) => author.login === 'user1'); | ||
|
||
expect(results.stats).toEqual({ | ||
totalReviews: 4, | ||
totalComments: 1, | ||
timeToReview: 2052500, | ||
commentsPerReview: 0.25, | ||
openedPullRequests: 17, | ||
}); | ||
}); | ||
|
||
it('returns empty stats for authors with no data', async () => { | ||
const results = mergeStats(baseParams) | ||
.find(({ author }) => author.login === 'user4'); | ||
|
||
expect(results.stats).toEqual({ | ||
timeToReview: null, | ||
totalReviews: null, | ||
totalComments: null, | ||
commentsPerReview: null, | ||
openedPullRequests: null, | ||
}); | ||
}); | ||
|
||
it('returns empty array when no authors passed', async () => { | ||
const results = mergeStats({ ...baseParams, authors: [] }); | ||
expect(results).toEqual([]); | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
src/interactors/getPullRequestStats/__tests__/calculateReviewsStats.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { reviews: input } = require('../../../../tests/mocks'); | ||
const calculatePullRequestStats = require('../calculatePullRequestStats'); | ||
|
||
describe('Interactors | getPullRequestStats | .calculatePullRequestStats', () => { | ||
const result = calculatePullRequestStats(input); | ||
|
||
it('calculates the openedPullRequests', () => { | ||
expect(result.openedPullRequests).toBe(3); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
src/interactors/getPullRequestStats/__tests__/groupPullRequests.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { pullRequests: input } = require('../../../../tests/mocks'); | ||
const groupPullRequests = require('../groupPullRequests'); | ||
|
||
const getPRsByAuthorId = (data, authorId) => { | ||
const { pullRequests } = data.find((review) => review.authorId === authorId); | ||
return pullRequests.map(({ id }) => id); | ||
}; | ||
|
||
describe('Interactors | getPullRequestStats | .groupPullRequests', () => { | ||
it('groups pull requests by author', () => { | ||
const result = groupPullRequests(input); | ||
expect(result.length).toEqual(2); | ||
const authorIds = result.map((pr) => pr.authorId); | ||
expect(authorIds).toContain('1031639', '2009676'); | ||
expect(getPRsByAuthorId(result, '1031639')).toEqual([12345]); | ||
expect(getPRsByAuthorId(result, '2009676').sort()).toEqual([12346].sort()); | ||
}); | ||
|
||
it('keeps only the required properties', () => { | ||
const result = groupPullRequests(input); | ||
result.forEach(({ pullRequests }) => pullRequests.forEach((pullRequest) => { | ||
expect(pullRequest).toHaveProperty('id'); | ||
expect(pullRequest).toHaveProperty('submittedAt'); | ||
expect(pullRequest).not.toHaveProperty('cursor'); | ||
expect(pullRequest).not.toHaveProperty('reviews'); | ||
})); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
src/interactors/getPullRequestStats/__tests__/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { pullRequests: input } = require('../../../../tests/mocks'); | ||
const getPullRequestStats = require('../index'); | ||
|
||
const getAuthorIds = (reviewers) => reviewers.map((r) => r.authorId); | ||
|
||
describe('Interactors | getPullRequestStats', () => { | ||
it('groups pull requests by author and calculate its stats', () => { | ||
const result = getPullRequestStats(input); | ||
expect(result.length).toEqual(2); | ||
expect(getAuthorIds(result)).toContain('1031639', '8755542'); | ||
|
||
result.forEach((author) => { | ||
expect(author).toHaveProperty('authorId'); | ||
|
||
expect(author).toHaveProperty('stats'); | ||
expect(author.stats).toHaveProperty('openedPullRequests'); | ||
}); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
src/interactors/getPullRequestStats/calculatePullRequestStats.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = (pulls) => { | ||
const openedPullRequests = pulls.length; | ||
|
||
return { | ||
openedPullRequests, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = (pulls) => { | ||
const byAuthor = pulls.reduce((acc, pull) => { | ||
const authorId = pull.author.id; | ||
|
||
if (!acc[authorId]) acc[authorId] = { authorId, pullRequests: [] }; | ||
|
||
acc[authorId].pullRequests.push({ | ||
id: pull.id, | ||
submittedAt: pull.submittedAt, | ||
}); | ||
return acc; | ||
}, {}); | ||
|
||
return Object.values(byAuthor); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const calculatePullRequestStats = require('./calculatePullRequestStats'); | ||
const groupPullRequests = require('./groupPullRequests'); | ||
|
||
module.exports = (pulls) => groupPullRequests(pulls) | ||
.map(({ authorId, pullRequests }) => { | ||
const stats = calculatePullRequestStats(pullRequests); | ||
return { authorId, pullRequests, stats }; | ||
}); |
4 changes: 2 additions & 2 deletions
4
...s/__tests__/calculateReviewsStats.test.js → ...s/__tests__/calculateReviewsStats.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 9 additions & 9 deletions
18
...tReviewers/__tests__/groupReviews.test.js → ...eviewStats/__tests__/groupReviews.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const { pullRequests: input } = require('../../../../tests/mocks'); | ||
const getReviewers = require('../index'); | ||
|
||
const getAuthorIds = (reviewers) => reviewers.map((r) => r.authorId); | ||
|
||
describe('Interactors | getReviewStats', () => { | ||
it('groups reviews by author and calculate its stats', () => { | ||
const result = getReviewers(input); | ||
expect(result.length).toEqual(2); | ||
expect(getAuthorIds(result)).toContain('1031639', '8755542'); | ||
|
||
result.forEach((reviewer) => { | ||
expect(reviewer).toHaveProperty('authorId'); | ||
|
||
expect(reviewer).toHaveProperty('reviews'); | ||
expect(reviewer.reviews.length > 0).toBe(true); | ||
|
||
expect(reviewer).toHaveProperty('stats'); | ||
expect(reviewer.stats).toHaveProperty('timeToReview'); | ||
}); | ||
}); | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const calculateReviewsStats = require('./calculateReviewsStats'); | ||
const groupReviews = require('./groupReviews'); | ||
|
||
module.exports = (pulls) => groupReviews(pulls) | ||
.map(({ authorId, reviews }) => { | ||
const stats = calculateReviewsStats(reviews); | ||
return { authorId, reviews, stats }; | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.