|
| 1 | +import { onboardingExtensionCommand } from "../../../src/controllers/onboardingExtensionCommand"; |
| 2 | +import { discordTextResponse } from "../../../src/utils/discordResponse"; |
| 3 | +import { |
| 4 | + ctx, |
| 5 | + guildEnv, |
| 6 | + transformedArgsForOnboardingExtension, |
| 7 | +} from "../../fixtures/fixture"; |
| 8 | +import * as utils from "../../../src/utils/onboardingExtension"; |
| 9 | + |
| 10 | +describe("onboardingExtensionCommand", () => { |
| 11 | + beforeEach(() => { |
| 12 | + jest.clearAllMocks(); |
| 13 | + }); |
| 14 | + afterEach(() => { |
| 15 | + jest.restoreAllMocks(); |
| 16 | + }); |
| 17 | + const discordId = |
| 18 | + transformedArgsForOnboardingExtension.memberObj.user.id.toString(); |
| 19 | + |
| 20 | + it("should return Feature not implemented", async () => { |
| 21 | + const expectedRes = await onboardingExtensionCommand( |
| 22 | + transformedArgsForOnboardingExtension, |
| 23 | + guildEnv, |
| 24 | + ctx |
| 25 | + ); |
| 26 | + const jsonResponse = await expectedRes.json(); |
| 27 | + const mockResponse = discordTextResponse( |
| 28 | + `<@${discordId}> Feature not implemented` |
| 29 | + ); |
| 30 | + const mockJsonResponse = await mockResponse.json(); |
| 31 | + expect(jsonResponse).toStrictEqual(mockJsonResponse); |
| 32 | + }); |
| 33 | + |
| 34 | + it("should return initial response", async () => { |
| 35 | + transformedArgsForOnboardingExtension.devObj.value = true; |
| 36 | + const expectedRes = await onboardingExtensionCommand( |
| 37 | + transformedArgsForOnboardingExtension, |
| 38 | + guildEnv, |
| 39 | + ctx |
| 40 | + ); |
| 41 | + const jsonResponse = await expectedRes.json(); |
| 42 | + const mockResponse = discordTextResponse( |
| 43 | + `<@${discordId}> Processing your request for onboarding extension` |
| 44 | + ); |
| 45 | + const mockJsonResponse = await mockResponse.json(); |
| 46 | + expect(jsonResponse).toStrictEqual(mockJsonResponse); |
| 47 | + }); |
| 48 | + |
| 49 | + it("should call createOnboardingExtension", async () => { |
| 50 | + jest.spyOn(utils, "createOnboardingExtension"); |
| 51 | + transformedArgsForOnboardingExtension.devObj.value = true; |
| 52 | + await onboardingExtensionCommand( |
| 53 | + transformedArgsForOnboardingExtension, |
| 54 | + guildEnv, |
| 55 | + ctx |
| 56 | + ); |
| 57 | + expect(utils.createOnboardingExtension).toHaveBeenCalledTimes(1); |
| 58 | + expect(utils.createOnboardingExtension).toHaveBeenCalledWith( |
| 59 | + { |
| 60 | + channelId: transformedArgsForOnboardingExtension.channelId, |
| 61 | + userId: transformedArgsForOnboardingExtension.userIdObj?.value, |
| 62 | + numberOfDays: Number( |
| 63 | + transformedArgsForOnboardingExtension.numberOfDaysObj.value |
| 64 | + ), |
| 65 | + reason: transformedArgsForOnboardingExtension.reasonObj.value, |
| 66 | + discordId: discordId, |
| 67 | + }, |
| 68 | + guildEnv |
| 69 | + ); |
| 70 | + }); |
| 71 | +}); |
0 commit comments