Skip to content

Commit c6a5e12

Browse files
committed
feat: create unit test for UserService
1 parent 9ab37c9 commit c6a5e12

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { UserService } from "@src/items/services/UserService";
2+
3+
jest.mock("../../../data/githubDiscordMap.json", () => ({
4+
alice: {
5+
githubUsername: "alice",
6+
githubId: "ghid-alice",
7+
discordId: "discord-alice",
8+
},
9+
bob: {
10+
githubUsername: "bob",
11+
githubId: "ghid-bob",
12+
discordId: "discord-bob",
13+
},
14+
}));
15+
16+
describe("UserService", () => {
17+
it("finds user by Discord ID", async () => {
18+
const result = await UserService.findUserByDiscordID("discord-bob");
19+
expect(result.ok).toBe(true);
20+
21+
if (result.ok) {
22+
expect(result.val.githubUsername).toBe("bob");
23+
}
24+
});
25+
26+
it("will return error for unknown Discord ID", async () => {
27+
const result = await UserService.findUserByDiscordID("unknown");
28+
expect(result.err).toBe(true);
29+
});
30+
31+
it("finds user by GitHub username", async () => {
32+
const result = await UserService.findUserByGithubUsername("alice");
33+
expect(result.ok).toBe(true);
34+
35+
if (result.ok) {
36+
expect(result.val.discordId).toBe("discord-alice");
37+
}
38+
});
39+
40+
it("will return error for unknown GitHub username", async () => {
41+
const result = await UserService.findUserByGithubUsername("charlie");
42+
expect(result.err).toBe(true);
43+
});
44+
});

0 commit comments

Comments
 (0)