diff --git a/tests/unit/handlers/onboardingExtension.test.ts b/tests/unit/handlers/onboardingExtension.test.ts index d45d85d..d1851a8 100644 --- a/tests/unit/handlers/onboardingExtension.test.ts +++ b/tests/unit/handlers/onboardingExtension.test.ts @@ -15,7 +15,7 @@ describe("onboardingExtensionCommand", () => { jest.restoreAllMocks(); }); const discordId = - transformedArgsForOnboardingExtension.member.user.id.toString(); + transformedArgsForOnboardingExtension.memberObj.user.id.toString(); it("should return Feature not implemented", async () => { const expectedRes = await onboardingExtensionCommand( @@ -32,7 +32,7 @@ describe("onboardingExtensionCommand", () => { }); it("should return initial response", async () => { - transformedArgsForOnboardingExtension.dev.value = true; + transformedArgsForOnboardingExtension.devObj.value = true; const expectedRes = await onboardingExtensionCommand( transformedArgsForOnboardingExtension, guildEnv, @@ -48,7 +48,7 @@ describe("onboardingExtensionCommand", () => { it("should call fetch", async () => { jest.spyOn(utils, "createOnboardingExtension"); - transformedArgsForOnboardingExtension.dev.value = true; + transformedArgsForOnboardingExtension.devObj.value = true; await onboardingExtensionCommand( transformedArgsForOnboardingExtension, guildEnv, diff --git a/tests/unit/utils/onboardingExtension.test.ts b/tests/unit/utils/onboardingExtension.test.ts index fb07ca4..4981af7 100644 --- a/tests/unit/utils/onboardingExtension.test.ts +++ b/tests/unit/utils/onboardingExtension.test.ts @@ -1,4 +1,5 @@ import config from "../../../config/config"; +import { UNAUTHORIZED_TO_CREATE_ONBOARDING_EXTENSION_REQUEST } from "../../../src/constants/responses"; import { DISCORD_BASE_URL } from "../../../src/constants/urls"; import { generateDiscordAuthToken } from "../../../src/utils/authTokenGenerator"; import { @@ -18,7 +19,6 @@ describe("createOnboaringExtension", () => { }; const discordReplyUrl = `${DISCORD_BASE_URL}/channels/${args.channelId}/messages`; const base_url = config(env).RDS_BASE_API_URL; - const errorContent = `<@${args.discordId}> Error occurred while creating onboarding extension request.`; const createOnboardingExtensionUrl = `${base_url}/requests?dev=true`; let fetchSpy: jest.SpyInstance; let authToken: string; @@ -27,7 +27,6 @@ describe("createOnboaringExtension", () => { userId: args.userId, type: "ONBOARDING", numberOfDays: args.numberOfDays, - requestedBy: args.discordId, reason: args.reason, }; @@ -47,33 +46,21 @@ describe("createOnboaringExtension", () => { jest.restoreAllMocks(); }); - it("should call fetch with error response", async () => { - fetchSpy.mockImplementation(() => { - throw new Error(); - }); - try { - await createOnboardingExtension(args, guildEnv); - } catch (err) { - expect(global.fetch).toHaveBeenCalledTimes(2); - expect(global.fetch).toHaveBeenCalledWith(createOnboardingExtensionUrl, { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${authToken}`, - }, - body: JSON.stringify(requestData), - }); - expect(utils.sendReplyInDiscordChannel).toHaveBeenCalledTimes(1); - expect(utils.sendReplyInDiscordChannel).toHaveBeenCalledWith( - discordReplyUrl, - errorContent, - guildEnv - ); - } + it("should call sendReplyInDiscordChannel with error content", async () => { + await createOnboardingExtension(args, guildEnv); + expect(utils.sendReplyInDiscordChannel).toHaveBeenCalledTimes(1); + expect(utils.sendReplyInDiscordChannel).toHaveBeenCalledWith( + discordReplyUrl, + `<@${args.discordId}> ${UNAUTHORIZED_TO_CREATE_ONBOARDING_EXTENSION_REQUEST}`, + guildEnv + ); }); it("should call fetch with success response", async () => { + args.userId = undefined; + requestData.userId = args.discordId; await createOnboardingExtension(args, guildEnv); + expect(global.fetch).toHaveBeenCalledTimes(2); expect(global.fetch).toHaveBeenCalledWith(createOnboardingExtensionUrl, { method: "POST", @@ -83,6 +70,5 @@ describe("createOnboaringExtension", () => { }, body: JSON.stringify(requestData), }); - expect(utils.sendReplyInDiscordChannel).toHaveBeenCalledTimes(1); }); });