Skip to content

Commit ba94af4

Browse files
committed
feat: add test cases
1 parent 0363e9f commit ba94af4

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

src/controllers/verifyCommand.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ export async function verifyCommand(
2929
discordJoinedAt,
3030
env
3131
);
32-
3332
if (response?.status === 201 || response?.status === 200) {
3433
let verificationSiteURL = "";
3534
let message = "";
36-
if (dev) {
35+
if (dev?.value) {
3736
verificationSiteURL = config(env).MAIN_SITE_URL;
3837
message = `${VERIFICATION_STRING}\n${verificationSiteURL}/discord?dev=true&token=${token}\n${VERIFICATION_SUBSTRING}`;
3938
} else {

tests/unit/handlers/verifyCommand.test.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
env,
1111
mockDateNow,
1212
} from "../../fixtures/fixture";
13+
import { DevFlag } from "../../../src/typeDefinitions/verify.types";
1314

1415
describe("verifyCommand", () => {
1516
beforeEach(() => {
@@ -24,6 +25,68 @@ describe("verifyCommand", () => {
2425
jest.spyOn(Date, "now").mockRestore();
2526
});
2627

28+
test("should return message with verification site url when dev is false", async () => {
29+
jest.spyOn(global, "fetch").mockResolvedValueOnce({
30+
ok: true,
31+
status: 200,
32+
json: jest.fn().mockResolvedValueOnce(discordUserData),
33+
} as unknown as Response);
34+
35+
const { verifyCommand } = await import(
36+
"../../../src/controllers/verifyCommand"
37+
);
38+
39+
const result = await verifyCommand(
40+
1,
41+
"userAvatarHash",
42+
"userName",
43+
"discriminator",
44+
"2021-07-25T19:25:16.172000+00:00",
45+
env,
46+
{
47+
value: false,
48+
type: 5,
49+
name: "dev",
50+
} as DevFlag
51+
);
52+
53+
const resultText = await result.text();
54+
const resultData = JSON.parse(resultText);
55+
56+
const verificationSiteURL = config(env).VERIFICATION_SITE_URL;
57+
const message = `${VERIFICATION_STRING}\n${verificationSiteURL}/discord?token=${UNIQUE_TOKEN}\n${VERIFICATION_SUBSTRING}`;
58+
expect(resultData.data.content).toEqual(message);
59+
});
60+
61+
test("should return message with verification site url when dev is true", async () => {
62+
jest.spyOn(global, "fetch").mockResolvedValueOnce({
63+
ok: true,
64+
status: 200,
65+
json: jest.fn().mockResolvedValueOnce(discordUserData),
66+
} as unknown as Response);
67+
68+
const { verifyCommand } = await import(
69+
"../../../src/controllers/verifyCommand"
70+
);
71+
72+
const result = await verifyCommand(
73+
1,
74+
"userAvatarHash",
75+
"userName",
76+
"discriminator",
77+
"2021-07-25T19:25:16.172000+00:00",
78+
env,
79+
{ value: true, type: 5, name: "dev" } as DevFlag
80+
);
81+
82+
const resultText = await result.text();
83+
const resultData = JSON.parse(resultText);
84+
85+
const verificationSiteURL = config(env).MAIN_SITE_URL;
86+
const message = `${VERIFICATION_STRING}\n${verificationSiteURL}/discord?dev=true&token=${UNIQUE_TOKEN}\n${VERIFICATION_SUBSTRING}`;
87+
expect(resultData.data.content).toEqual(message);
88+
});
89+
2790
test("should return JSON response when response is ok", async () => {
2891
jest.spyOn(global, "fetch").mockResolvedValueOnce({
2992
ok: true,

0 commit comments

Comments
 (0)