Skip to content

Commit 6997e7c

Browse files
committed
fix tests
1 parent 1925a61 commit 6997e7c

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

tests/fixtures/groups.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ export const group: DiscordGuildRole = {
44
id: "1",
55
name: "group-frontend",
66
};
7+
8+
export const invalidGroup: DiscordGuildRole = {
9+
id: "2",
10+
name: "invalidRole",
11+
};

tests/unit/handlers/groupInvite.test.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,35 @@ import { environment } from "../../fixtures/config";
22
import * as DiscordGroups from "../../../src/utils/fetchDiscordGroupById";
33
import JSONResponse from "../../../src/utils/JsonResponse";
44
import { groupInvite } from "../../../src/controllers/groupInvite";
5-
import { group } from "../../fixtures/groups";
5+
import { group, invalidGroup } from "../../fixtures/groups";
66
import { discordTextResponse } from "../../../src/utils/discordResponse";
77

88
describe("Test /group-invite command", () => {
9-
beforeEach(() => {
10-
jest
11-
.spyOn(DiscordGroups, "fetchDiscordGroupById")
12-
.mockImplementation(() => Promise.resolve(group));
13-
});
14-
159
afterEach(() => {
1610
jest.resetAllMocks();
1711
jest.restoreAllMocks();
1812
});
1913

2014
it("Should be an instance of JSONResponse", async () => {
15+
jest
16+
.spyOn(DiscordGroups, "fetchDiscordGroupById")
17+
.mockImplementation(() => Promise.resolve(group));
18+
2119
const response = await groupInvite("1", group.id, environment[0]);
2220

2321
expect(response).toBeInstanceOf(JSONResponse);
2422
});
2523

2624
it("Should return a discordTextResponse if group is not found", async () => {
27-
const invalidRoleId = "invalidRoleId";
25+
jest
26+
.spyOn(DiscordGroups, "fetchDiscordGroupById")
27+
.mockImplementation(() => Promise.resolve(invalidGroup));
28+
2829
const expectedResponse = discordTextResponse(
29-
`<@&${invalidRoleId}> is not a valid group.`
30+
`<@&${invalidGroup.id}> is not a valid group.`
3031
);
3132

32-
const response = await groupInvite("1", invalidRoleId, environment[0]);
33+
const response = await groupInvite("1", invalidGroup.id, environment[0]);
3334

3435
expect(await response.json()).toEqual(await expectedResponse.json());
3536
});

0 commit comments

Comments
 (0)