Skip to content

Commit cf520e1

Browse files
committed
write test for brew install redis
1 parent 6b013d7 commit cf520e1

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

models/users.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,19 +428,19 @@ const getUsersBasedOnFilter = async (query) => {
428428
});
429429
});
430430

431-
return filteredUsers;
431+
return filteredUsers.filter((user) => !user.roles?.archived);
432432
}
433-
if (verifiedQuery) {
433+
if (verifiedQuery === "true") {
434434
const filteredUsers = [];
435-
const snapshot = await userModel.orderBy("discordId").get();
435+
const snapshot = await userModel.where("discordId", "!=", null).get();
436436
snapshot.forEach((doc) => {
437437
filteredUsers.push({
438438
id: doc.id,
439439
...doc.data(),
440440
});
441441
});
442442

443-
return filteredUsers;
443+
return filteredUsers.filter((user) => !user.roles?.archived);
444444
}
445445
return [];
446446
};

test/fixtures/user/user.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ module.exports = () => {
2121
isMember: true,
2222
phone: "1234567890",
2323
24+
joined_discord: "2023-01-13T18:21:09.278000+00:00",
2425
roles: {
2526
member: true,
27+
in_discord: true,
2628
},
2729
tokens: {
2830
githubAccessToken: "githubAccessToken",
@@ -105,13 +107,15 @@ module.exports = () => {
105107
github_display_name: "Ankush Dharkar",
106108
phone: "1234567890",
107109
110+
joined_discord: "2023-01-13T18:21:09.278000+00:00",
108111
status: "idle",
109112
tokens: {
110113
githubAccessToken: "githubAccessToken",
111114
},
112115
roles: {
113116
super_user: true,
114117
archived: false,
118+
in_discord: true,
115119
},
116120
picture: {
117121
publicId: "profile/mtS4DhUvNYsKqI7oCWVB/aenklfhtjldc5ytei3ar",

test/unit/models/users.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,16 @@ describe("users", function () {
8888
expect(userExists).to.equal(true);
8989
});
9090
});
91+
92+
describe("brew install redis", function () {
93+
it("should return an empty array if no query is provided", async function () {
94+
const result = await users.getUsersBasedOnFilter({});
95+
expect(result).to.deep.equal([]);
96+
});
97+
98+
it("should return an array of verified users", async function () {
99+
const result = await users.getUsersBasedOnFilter({ verified: "true" });
100+
expect(result).to.deep.equal(userDataArray.filter((user) => user.discordId));
101+
});
102+
});
91103
});

0 commit comments

Comments
 (0)