From 3132da4b325bb8a3fa63ef57013a885d11ba1e0a Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Fri, 15 Mar 2024 20:34:23 -0400 Subject: [PATCH] USe msw test data overrides --- .../application-assessment-status.test.tsx | 77 ++++++++++--------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/client/src/app/pages/applications/components/application-assessment-status/tests/application-assessment-status.test.tsx b/client/src/app/pages/applications/components/application-assessment-status/tests/application-assessment-status.test.tsx index b8c7599e51..bf5cd511a0 100644 --- a/client/src/app/pages/applications/components/application-assessment-status/tests/application-assessment-status.test.tsx +++ b/client/src/app/pages/applications/components/application-assessment-status/tests/application-assessment-status.test.tsx @@ -6,50 +6,55 @@ import { createMockAssessment, renderHook, } from "@app/test-config/test-utils"; +import { server } from "../../../../../../mocks/server"; +import { rest } from "msw"; describe("useAssessmentStatus", () => { beforeEach(() => { jest.clearAllMocks(); }); - it("Correctly calculates status given one started assessment and one complete assessment for an application", async () => { - // jest.mock("@app/queries/assessments", () => ({ - // useFetchAssessments: () => ({ - // assessments: [ - // createMockAssessment({ - // id: 1, - // application: { id: 1, name: "app1" }, - // questionnaire: { id: 1, name: "questionnaire1" }, - // status: "started", - // }), - - // createMockAssessment({ - // id: 2, - // application: { id: 1, name: "app1" }, - // questionnaire: { id: 2, name: "questionnaire2" }, - // status: "complete", - // }), - // ], - // isFetching: false, - // fetchError: false, - // }), - // })); + // // Dynamically change the handler response for a specific test + beforeEach(() => { + server.use( + // Override the handler for fetching assessments for this test only + rest.get("/hub/assessments", (req, res, ctx) => { + return res( + ctx.json([ + { + id: 1, + application: { id: 1, name: "app1" }, + questionnaire: { id: 1, name: "questionnaire1" }, + status: "started", + sections: [], + }, + { + id: 2, + application: { id: 1, name: "app1" }, + questionnaire: { id: 2, name: "questionnaire2" }, + status: "complete", + sections: [], + }, + ]) + ); + }), - // jest.mock("@app/queries/archetypes", () => ({ - // useFetchArchetypes: () => ({ - // archetypes: [ - // createMockArchetype({ - // id: 1, - // name: "archetype1", - // applications: [{ id: 1, name: "app1" }], - // }), - // ], - // isFetching: false, - // error: false, - // }), - // })); + // Override the handler for fetching archetypes for this test only + rest.get("/hub/archetypes", (req, res, ctx) => { + return res( + ctx.json([ + { + id: 1, + name: "archetype1", + applications: [{ id: 1, name: "app1" }], + }, + ]) + ); + }) + ); + }); - // Assuming useAssessmentStatus makes two axios.get calls + it("Correctly calculates status given one started assessment and one complete assessment for an application", async () => { const { result, waitForNextUpdate } = renderHook(() => useAssessmentStatus(createMockApplication({ id: 1, name: "app1" })) );