Skip to content

Commit 6321376

Browse files
resolved the comments
1 parent b117aea commit 6321376

File tree

2 files changed

+25
-33
lines changed

2 files changed

+25
-33
lines changed

tests/fixtures/fixture.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,22 @@ export const rolesMock = [
135135
mentionable: true,
136136
},
137137
];
138+
export const mockDateNow = 1626512345678;
139+
export const UNIQUE_TOKEN = "UNIQUE_TOKEN";
140+
export const env = {
141+
BOT_PUBLIC_KEY: "BOT_PUBLIC_KEY",
142+
DISCORD_GUILD_ID: "DISCORD_GUILD_ID",
143+
DISCORD_TOKEN: "SIGNED_JWT",
144+
};
145+
146+
export const discordUserData = {
147+
type: "discord",
148+
token: UNIQUE_TOKEN,
149+
attributes: {
150+
discordId: 1,
151+
userAvatar: "https://cdn.discordapp.com/avatars/1/userAvatarHash.jpg",
152+
userName: "userName",
153+
discriminator: "discriminator",
154+
expiry: mockDateNow + 1000 * 60 * 2,
155+
},
156+
};

tests/unit/handlers/verifyCommand.test.ts

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@ import {
33
VERIFICATION_STRING,
44
} from "../../../src/constants/responses";
55
import config from "../../../config/config";
6+
import { UNIQUE_TOKEN, discordUserData, env, mockDateNow } from "../../fixtures/fixture";
7+
68

7-
const mockDateNow = 1626512345678;
8-
const UNIQUE_TOKEN = "UNIQUE_TOKEN";
9-
const env = {
10-
BOT_PUBLIC_KEY: "BOT_PUBLIC_KEY",
11-
DISCORD_GUILD_ID: "DISCORD_GUILD_ID",
12-
DISCORD_TOKEN: "SIGNED_JWT",
13-
};
149

1510
describe("verifyCommand", () => {
1611
beforeEach(() => {
@@ -26,22 +21,11 @@ describe("verifyCommand", () => {
2621
});
2722

2823
test("should return JSON response when response is ok", async () => {
29-
const data = {
30-
type: "discord",
31-
token: UNIQUE_TOKEN,
32-
attributes: {
33-
discordId: 1,
34-
userAvatar: "https://cdn.discordapp.com/avatars/1/userAvatarHash.jpg",
35-
userName: "userName",
36-
discriminator: "discriminator",
37-
expiry: mockDateNow + 1000 * 60 * 2,
38-
},
39-
};
4024

4125
jest.spyOn(global, "fetch").mockResolvedValueOnce({
4226
ok: true,
4327
status: 200,
44-
json: jest.fn().mockResolvedValueOnce(data),
28+
json: jest.fn().mockResolvedValueOnce(discordUserData),
4529
} as unknown as Response);
4630

4731
const { verifyCommand } = await import(
@@ -64,7 +48,7 @@ describe("verifyCommand", () => {
6448
"Content-Type": "application/json",
6549
Authorization: `Bearer ${env.DISCORD_TOKEN}`,
6650
},
67-
body: JSON.stringify(data),
51+
body: JSON.stringify(discordUserData),
6852
}
6953
);
7054
const resultText = await result.text();
@@ -79,22 +63,11 @@ describe("verifyCommand", () => {
7963
});
8064

8165
test("should return INTERNAL_SERVER_ERROR when response is not ok", async () => {
82-
const data = {
83-
type: "discord",
84-
token: UNIQUE_TOKEN,
85-
attributes: {
86-
discordId: 1,
87-
userAvatar: "https://cdn.discordapp.com/avatars/1/userAvatarHash.jpg",
88-
userName: "userName",
89-
discriminator: "discriminator",
90-
expiry: mockDateNow + 1000 * 60 * 2,
91-
},
92-
};
9366

9467
jest.spyOn(global, "fetch").mockResolvedValueOnce({
9568
ok: true,
9669
status: 400, // ERROR STATUS
97-
json: jest.fn().mockResolvedValueOnce(data),
70+
json: jest.fn().mockResolvedValueOnce(discordUserData),
9871
} as unknown as Response);
9972

10073
const { verifyCommand } = await import(
@@ -116,7 +89,7 @@ describe("verifyCommand", () => {
11689
"Content-Type": "application/json",
11790
Authorization: `Bearer ${env.DISCORD_TOKEN}`,
11891
},
119-
body: JSON.stringify(data),
92+
body: JSON.stringify(discordUserData),
12093
}
12194
);
12295
const resultText = await result.text();

0 commit comments

Comments
 (0)