|
| 1 | +import { sendTaskUpdatesHandler } from "../../../src/controllers/taskUpdatesHandler"; |
| 2 | +import JSONResponse from "../../../src/utils/JsonResponse"; |
| 3 | +import * as response from "../../../src/constants/responses"; |
| 4 | +import { sendTaskUpdate } from "../../../src/utils/sendTaskUpdates"; |
| 5 | + |
| 6 | +import { generateDummyRequestObject } from "../../fixtures/fixture"; |
| 7 | + |
| 8 | +jest.mock("../../../src/utils/verifyAuthToken", () => ({ |
| 9 | + verifyNodejsBackendAuthToken: jest.fn().mockResolvedValue(true), |
| 10 | +})); |
| 11 | +jest.mock("../../../src/utils/sendTaskUpdates", () => ({ |
| 12 | + sendTaskUpdate: jest.fn().mockResolvedValue(undefined), |
| 13 | +})); |
| 14 | + |
| 15 | +describe("sendTaskUpdatesHandler", () => { |
| 16 | + const mockEnv = { DISCORD_TOKEN: "mockToken" }; |
| 17 | + const mockData = { |
| 18 | + content: { |
| 19 | + completed: "Wrote test cases", |
| 20 | + planned: "Will test the feature at staging.", |
| 21 | + blockers: "NA", |
| 22 | + }, |
| 23 | + }; |
| 24 | + afterEach(() => { |
| 25 | + jest.clearAllMocks(); |
| 26 | + }); |
| 27 | + |
| 28 | + it("sendTaskUpdate function should return undefined after successfully sending the message", async () => { |
| 29 | + const { completed, planned, blockers } = mockData.content; |
| 30 | + const response = await sendTaskUpdate( |
| 31 | + completed, |
| 32 | + planned, |
| 33 | + blockers, |
| 34 | + mockEnv |
| 35 | + ); |
| 36 | + expect(response).toBe(undefined); |
| 37 | + }); |
| 38 | + |
| 39 | + it("should return Bad Signature object if no auth headers provided", async () => { |
| 40 | + const mockRequest = generateDummyRequestObject({ url: "/task/update" }); |
| 41 | + const result: JSONResponse = await sendTaskUpdatesHandler( |
| 42 | + mockRequest, |
| 43 | + mockEnv |
| 44 | + ); |
| 45 | + const jsonResponse: { error: string } = await result.json(); |
| 46 | + expect(result.status).toBe(401); |
| 47 | + expect(jsonResponse).toEqual(response.UNAUTHORIZED); |
| 48 | + }); |
| 49 | +}); |
0 commit comments