Skip to content

Commit

Permalink
USe msw test data overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 committed Mar 16, 2024
1 parent cb8d815 commit 3132da4
Showing 1 changed file with 41 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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" }))
);
Expand Down

0 comments on commit 3132da4

Please sign in to comment.