|
1 | 1 | import { environment } from "../../fixtures/config"; |
2 | | -import * as DiscordGroups from "../../../src/utils/fetchDiscordGroups"; |
| 2 | +import * as DiscordGroups from "../../../src/utils/fetchDiscordGroupById"; |
3 | 3 | import JSONResponse from "../../../src/utils/JsonResponse"; |
4 | 4 | import { groupInvite } from "../../../src/controllers/groupInvite"; |
5 | | -import { groups } from "../../fixtures/groups"; |
| 5 | +import { group, invalidGroup } from "../../fixtures/groups"; |
6 | 6 | import { discordTextResponse } from "../../../src/utils/discordResponse"; |
7 | 7 |
|
8 | 8 | describe("Test /group-invite command", () => { |
9 | | - beforeEach(() => { |
10 | | - jest |
11 | | - .spyOn(DiscordGroups, "fetchDiscordGroups") |
12 | | - .mockImplementation(() => Promise.resolve(groups)); |
13 | | - }); |
14 | | - |
15 | 9 | afterEach(() => { |
16 | 10 | jest.resetAllMocks(); |
17 | 11 | jest.restoreAllMocks(); |
18 | 12 | }); |
19 | 13 |
|
20 | 14 | it("Should be an instance of JSONResponse", async () => { |
21 | | - const response = await groupInvite( |
22 | | - "1", |
23 | | - groups.groups[0].roleid, |
24 | | - environment[0] |
25 | | - ); |
| 15 | + jest |
| 16 | + .spyOn(DiscordGroups, "fetchDiscordGroupById") |
| 17 | + .mockImplementation(() => Promise.resolve(group)); |
| 18 | + |
| 19 | + const response = await groupInvite("1", group.id, environment[0]); |
26 | 20 |
|
27 | 21 | expect(response).toBeInstanceOf(JSONResponse); |
28 | 22 | }); |
29 | 23 |
|
30 | 24 | it("Should return a discordTextResponse if group is not found", async () => { |
31 | | - const invalidRoleId = "invalidRoleId"; |
| 25 | + jest |
| 26 | + .spyOn(DiscordGroups, "fetchDiscordGroupById") |
| 27 | + .mockImplementation(() => Promise.resolve(invalidGroup)); |
| 28 | + |
32 | 29 | const expectedResponse = discordTextResponse( |
33 | | - `<@&${invalidRoleId}> is not a valid group.` |
| 30 | + `<@&${invalidGroup.id}> is not a valid group.` |
34 | 31 | ); |
35 | 32 |
|
36 | | - const response = await groupInvite("1", invalidRoleId, environment[0]); |
| 33 | + const response = await groupInvite("1", invalidGroup.id, environment[0]); |
37 | 34 |
|
38 | 35 | expect(await response.json()).toEqual(await expectedResponse.json()); |
39 | 36 | }); |
|
0 commit comments