Skip to content

Commit 9576666

Browse files
committed
add test for group invite
1 parent faea616 commit 9576666

File tree

4 files changed

+83
-4
lines changed

4 files changed

+83
-4
lines changed

src/controllers/groupInvite.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import config from "../../config/config";
22
import { env } from "../typeDefinitions/default.types";
33
import { discordTextResponse } from "../utils/discordResponse";
4-
import { fetchDiscordGroups } from "../utils/fetchDiscordGroups";
4+
import * as DiscordGroups from "../utils/fetchDiscordGroups";
5+
import JSONResponse from "../utils/JsonResponse";
56

6-
export async function groupInvite(userId: string, roleId: string, env: env) {
7-
const response = await fetchDiscordGroups(env);
7+
export async function groupInvite(
8+
userId: string,
9+
roleId: string,
10+
env: env
11+
): Promise<JSONResponse> {
12+
const response = await DiscordGroups.fetchDiscordGroups(env);
813
const group = response.groups.find((group) => group.roleid === roleId);
914

1015
if (!group) {

src/typeDefinitions/group.types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ export type GroupType = {
1313
};
1414

1515
export type GroupResponseType = {
16-
message?: string;
16+
message: string;
1717
groups: GroupType[];
1818
};

tests/fixtures/groups.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { GroupResponseType } from "../../src/typeDefinitions/group.types";
2+
3+
export const groups: GroupResponseType = {
4+
message: "Roles fetched successfully!",
5+
groups: [
6+
{
7+
id: "27EdauP9UmxCTgAMDPpl",
8+
date: {
9+
_seconds: 1719334613,
10+
_nanoseconds: 934000000,
11+
},
12+
createdBy: "zXQpimWaGWOFF2sLyrFt",
13+
rolename: "group-testing 3",
14+
roleid: "1255205109340573782",
15+
description: "for testing",
16+
memberCount: 0,
17+
isMember: false,
18+
},
19+
{
20+
id: "ELjCeNZxhHupn8qU5pWI",
21+
date: {
22+
_seconds: 1718771669,
23+
_nanoseconds: 27000000,
24+
},
25+
createdBy: "zXQpimWaGWOFF2sLyrFt",
26+
rolename: "group-testing",
27+
roleid: "1252843931306164298",
28+
description: "for testing",
29+
memberCount: 0,
30+
isMember: false,
31+
},
32+
{
33+
id: "tO4vZe5CC690yOb9Txlh",
34+
date: {
35+
_seconds: 1718771969,
36+
_nanoseconds: 680000000,
37+
},
38+
createdBy: "zXQpimWaGWOFF2sLyrFt",
39+
rolename: "group-testinge",
40+
roleid: "1252845191472087050",
41+
description: "",
42+
memberCount: 0,
43+
isMember: false,
44+
},
45+
],
46+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { environment } from "../../fixtures/config";
2+
import * as DiscordGroups from "../../../src/utils/fetchDiscordGroups";
3+
import JSONResponse from "../../../src/utils/JsonResponse";
4+
import { groupInvite } from "../../../src/controllers/groupInvite";
5+
import { groups } from "../../fixtures/groups";
6+
7+
describe("Test /group-invite command", () => {
8+
beforeEach(() => {
9+
jest
10+
.spyOn(DiscordGroups, "fetchDiscordGroups")
11+
.mockImplementation(() => Promise.resolve(groups));
12+
});
13+
14+
afterEach(() => {
15+
jest.resetAllMocks();
16+
jest.restoreAllMocks();
17+
});
18+
19+
it("Should be an instance of JSONResponse", async () => {
20+
const response = await groupInvite(
21+
"1",
22+
groups.groups[0].roleid,
23+
environment[0]
24+
);
25+
26+
expect(response).toBeInstanceOf(JSONResponse);
27+
});
28+
});

0 commit comments

Comments
 (0)