Skip to content

Commit 60aa74e

Browse files
authored
test: unit test for user util - getUsernamesFromPRs (#1123)
* feat: unit test for user util - getUsernamesFromPRs * move constanst to fixtures
1 parent 2555dcb commit 60aa74e

File tree

3 files changed

+145
-4
lines changed

3 files changed

+145
-4
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
const filteredPRs = [
2+
{
3+
title: "Redesign the discord linking page",
4+
username: "RitikJaiswal75",
5+
state: "closed",
6+
createdAt: "2023-05-19T06:35:41Z",
7+
updatedAt: "2023-05-28T19:29:08Z",
8+
repository: "website-my",
9+
url: "https://github.com/Real-Dev-Squad/website-my/pull/407",
10+
labels: ["UX", "UI"],
11+
assignees: ["RitikJaiswal75"],
12+
},
13+
{
14+
title: "Added a link on logo ",
15+
username: "kushvahasumit",
16+
state: "closed",
17+
createdAt: "2023-04-29T18:01:24Z",
18+
updatedAt: "2023-05-28T17:58:53Z",
19+
repository: "website-www",
20+
url: "https://github.com/Real-Dev-Squad/website-www/pull/465",
21+
labels: [],
22+
assignees: [],
23+
},
24+
{
25+
title: "nuke: links to crypto site",
26+
username: "vvaibhavdesai",
27+
state: "closed",
28+
createdAt: "2023-05-07T06:18:28Z",
29+
updatedAt: "2023-05-28T15:37:54Z",
30+
repository: "website-www",
31+
url: "https://github.com/Real-Dev-Squad/website-www/pull/473",
32+
labels: [],
33+
assignees: [],
34+
},
35+
{
36+
title: "[Ember-Migration] Embroider Setup",
37+
username: "rohan09-raj",
38+
state: "closed",
39+
createdAt: "2023-05-27T15:55:18Z",
40+
updatedAt: "2023-05-28T07:56:38Z",
41+
repository: "website-www",
42+
url: "https://github.com/Real-Dev-Squad/website-www/pull/490",
43+
labels: ["ember-migration", "config"],
44+
assignees: ["rohan09-raj"],
45+
},
46+
{
47+
title: "Added task-dependency data model",
48+
username: "vinit717",
49+
state: "closed",
50+
createdAt: "2023-05-24T00:50:02Z",
51+
updatedAt: "2023-05-28T06:15:22Z",
52+
repository: "website-data-models",
53+
url: "https://github.com/Real-Dev-Squad/website-data-models/pull/46",
54+
labels: ["documentation"],
55+
assignees: ["vinit717"],
56+
},
57+
{
58+
title: "[Live-Site] create a modal for joining the live session",
59+
username: "SanketDhabarde",
60+
state: "closed",
61+
createdAt: "2023-05-10T10:01:21Z",
62+
updatedAt: "2023-05-28T05:01:01Z",
63+
repository: "website-www",
64+
url: "https://github.com/Real-Dev-Squad/website-www/pull/477",
65+
labels: ["live-site"],
66+
assignees: ["SanketDhabarde"],
67+
},
68+
{
69+
title: "Set github actions timeout to 5 mins",
70+
username: "prakashchoudhary07",
71+
state: "closed",
72+
createdAt: "2023-05-26T11:36:07Z",
73+
updatedAt: "2023-05-27T09:21:38Z",
74+
repository: "website-backend",
75+
url: "https://github.com/Real-Dev-Squad/website-backend/pull/1117",
76+
labels: [],
77+
assignees: [],
78+
},
79+
{
80+
title: "create a social share image for realdevsquad.com/join",
81+
username: "Pratiyushkumar",
82+
state: "closed",
83+
createdAt: "2023-05-26T15:22:52Z",
84+
updatedAt: "2023-05-27T08:21:17Z",
85+
repository: "website-www",
86+
url: "https://github.com/Real-Dev-Squad/website-www/pull/487",
87+
labels: [],
88+
assignees: ["Pratiyushkumar"],
89+
},
90+
{
91+
title: "Sync dev to main",
92+
username: "RitikJaiswal75",
93+
state: "closed",
94+
createdAt: "2023-05-27T06:01:41Z",
95+
updatedAt: "2023-05-27T07:59:45Z",
96+
repository: "website-status",
97+
url: "https://github.com/Real-Dev-Squad/website-status/pull/586",
98+
labels: [],
99+
assignees: [],
100+
},
101+
{
102+
title: "Task details page",
103+
username: "YashJain24-chief",
104+
state: "closed",
105+
createdAt: "2022-11-07T14:43:28Z",
106+
updatedAt: "2023-05-27T07:35:50Z",
107+
repository: "website-status",
108+
url: "https://github.com/Real-Dev-Squad/website-status/pull/341",
109+
labels: ["feature task"],
110+
assignees: ["kotesh-arya"],
111+
},
112+
];
113+
114+
module.exports = {
115+
filteredPRs,
116+
};

test/unit/utils/users.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { expect } = chai;
44
const usersUtils = require("../../../utils/users");
55
const cleanDb = require("../../utils/cleanDb");
66
const addUser = require("../../utils/addUser");
7+
const { filteredPRs } = require("../../fixtures/pullrequests/pullrequests");
78
const userData = require("../../fixtures/user/user")()[0];
89
/**
910
* Test the utils functions and validate the data returned
@@ -65,4 +66,31 @@ describe("users", function () {
6566
expect(participantUserId).to.include(userId);
6667
});
6768
});
69+
70+
describe("getUsernamesFromPRs", function () {
71+
it("returns an array of unique usernames from the filtered PRs/Issues response", function () {
72+
// Mock the allPRs data
73+
const allPRs = filteredPRs;
74+
75+
// Execute the function and store the result
76+
const usernames = usersUtils.getUsernamesFromPRs(allPRs);
77+
78+
// Assert that the returned value is an array
79+
expect(usernames).to.be.an("array");
80+
81+
// Assert that the returned array contains the correct usernames
82+
const expectedUsernames = [
83+
"RitikJaiswal75",
84+
"kushvahasumit",
85+
"vvaibhavdesai",
86+
"rohan09-raj",
87+
"vinit717",
88+
"SanketDhabarde",
89+
"prakashchoudhary07",
90+
"Pratiyushkumar",
91+
"YashJain24-chief",
92+
];
93+
expect(usernames).to.have.members(expectedUsernames);
94+
});
95+
});
6896
});

utils/users.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,8 @@ function getPaginationLink(query, cursor, documentId) {
122122
}
123123

124124
/**
125-
* Returns an array of unique users from the filtered PRs/Issues response
126-
*
125+
* @desc Returns an array of unique users from the filtered PRs/Issues response
127126
* @param allPRs {Array} - list of all PRs/Issues from the respective github service
128-
* @param allUsers {Array} - list of total users from firebase
129-
*
130127
*/
131128
function getUsernamesFromPRs(allPRs) {
132129
const uniqueUsernamesSet = new Set();

0 commit comments

Comments
 (0)