Skip to content

Commit 65ff578

Browse files
committed
fix: change field and expectation message and test name as it was failing
1 parent a614514 commit 65ff578

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

tests/unit/handlers/onboardingExtension.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe("onboardingExtensionCommand", () => {
1515
jest.restoreAllMocks();
1616
});
1717
const discordId =
18-
transformedArgsForOnboardingExtension.member.user.id.toString();
18+
transformedArgsForOnboardingExtension.memberObj.user.id.toString();
1919

2020
it("should return Feature not implemented", async () => {
2121
const expectedRes = await onboardingExtensionCommand(
@@ -32,7 +32,7 @@ describe("onboardingExtensionCommand", () => {
3232
});
3333

3434
it("should return initial response", async () => {
35-
transformedArgsForOnboardingExtension.dev.value = true;
35+
transformedArgsForOnboardingExtension.devObj.value = true;
3636
const expectedRes = await onboardingExtensionCommand(
3737
transformedArgsForOnboardingExtension,
3838
guildEnv,
@@ -48,7 +48,7 @@ describe("onboardingExtensionCommand", () => {
4848

4949
it("should call fetch", async () => {
5050
jest.spyOn(utils, "createOnboardingExtension");
51-
transformedArgsForOnboardingExtension.dev.value = true;
51+
transformedArgsForOnboardingExtension.devObj.value = true;
5252
await onboardingExtensionCommand(
5353
transformedArgsForOnboardingExtension,
5454
guildEnv,

tests/unit/utils/onboardingExtension.test.ts

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import config from "../../../config/config";
2+
import { UNAUTHORIZED_TO_CREATE_ONBOARDING_EXTENSION_REQUEST } from "../../../src/constants/responses";
23
import { DISCORD_BASE_URL } from "../../../src/constants/urls";
34
import { generateDiscordAuthToken } from "../../../src/utils/authTokenGenerator";
45
import {
@@ -18,7 +19,6 @@ describe("createOnboaringExtension", () => {
1819
};
1920
const discordReplyUrl = `${DISCORD_BASE_URL}/channels/${args.channelId}/messages`;
2021
const base_url = config(env).RDS_BASE_API_URL;
21-
const errorContent = `<@${args.discordId}> Error occurred while creating onboarding extension request.`;
2222
const createOnboardingExtensionUrl = `${base_url}/requests?dev=true`;
2323
let fetchSpy: jest.SpyInstance;
2424
let authToken: string;
@@ -27,7 +27,6 @@ describe("createOnboaringExtension", () => {
2727
userId: args.userId,
2828
type: "ONBOARDING",
2929
numberOfDays: args.numberOfDays,
30-
requestedBy: args.discordId,
3130
reason: args.reason,
3231
};
3332

@@ -47,33 +46,21 @@ describe("createOnboaringExtension", () => {
4746
jest.restoreAllMocks();
4847
});
4948

50-
it("should call fetch with error response", async () => {
51-
fetchSpy.mockImplementation(() => {
52-
throw new Error();
53-
});
54-
try {
55-
await createOnboardingExtension(args, guildEnv);
56-
} catch (err) {
57-
expect(global.fetch).toHaveBeenCalledTimes(2);
58-
expect(global.fetch).toHaveBeenCalledWith(createOnboardingExtensionUrl, {
59-
method: "POST",
60-
headers: {
61-
"Content-Type": "application/json",
62-
Authorization: `Bearer ${authToken}`,
63-
},
64-
body: JSON.stringify(requestData),
65-
});
66-
expect(utils.sendReplyInDiscordChannel).toHaveBeenCalledTimes(1);
67-
expect(utils.sendReplyInDiscordChannel).toHaveBeenCalledWith(
68-
discordReplyUrl,
69-
errorContent,
70-
guildEnv
71-
);
72-
}
49+
it("should call sendReplyInDiscordChannel with error content", async () => {
50+
await createOnboardingExtension(args, guildEnv);
51+
expect(utils.sendReplyInDiscordChannel).toHaveBeenCalledTimes(1);
52+
expect(utils.sendReplyInDiscordChannel).toHaveBeenCalledWith(
53+
discordReplyUrl,
54+
`<@${args.discordId}> ${UNAUTHORIZED_TO_CREATE_ONBOARDING_EXTENSION_REQUEST}`,
55+
guildEnv
56+
);
7357
});
7458

7559
it("should call fetch with success response", async () => {
60+
args.userId = undefined;
61+
requestData.userId = args.discordId;
7662
await createOnboardingExtension(args, guildEnv);
63+
7764
expect(global.fetch).toHaveBeenCalledTimes(2);
7865
expect(global.fetch).toHaveBeenCalledWith(createOnboardingExtensionUrl, {
7966
method: "POST",
@@ -83,6 +70,5 @@ describe("createOnboaringExtension", () => {
8370
},
8471
body: JSON.stringify(requestData),
8572
});
86-
expect(utils.sendReplyInDiscordChannel).toHaveBeenCalledTimes(1);
8773
});
8874
});

0 commit comments

Comments
 (0)