From fbf9ad39276269ecf686a66626ba97dc7e8a4375 Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Fri, 9 Aug 2024 09:48:51 +0200 Subject: [PATCH] Refactor JobInformation test to use server mock --- .../JobInformation/JobInformation.test.js | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/client/src/components/JobInformation/JobInformation.test.js b/client/src/components/JobInformation/JobInformation.test.js index df8448c4d1dd..0508a6485825 100644 --- a/client/src/components/JobInformation/JobInformation.test.js +++ b/client/src/components/JobInformation/JobInformation.test.js @@ -1,32 +1,37 @@ import { mount } from "@vue/test-utils"; -import axios from "axios"; -import MockAdapter from "axios-mock-adapter"; import flushPromises from "flush-promises"; import { getLocalVue } from "tests/jest/helpers"; -import JobInformation from "./JobInformation"; +import { useServerMock } from "@/api/client/__mocks__"; + import jobResponse from "./testData/jobInformationResponse.json"; +import JobInformation from "./JobInformation.vue"; + jest.mock("app"); const JOB_ID = "test_id"; const localVue = getLocalVue(); +const { server, http } = useServerMock(); + describe("JobInformation/JobInformation.vue", () => { let wrapper; let jobInfoTable; - let axiosMock; beforeEach(() => { - axiosMock = new MockAdapter(axios); - axiosMock.onGet(new RegExp(`api/configuration/decode/*`)).reply(200, { decoded_id: 123 }); - axiosMock.onGet("/api/jobs/test_id?full=True").reply(200, jobResponse); - axiosMock.onGet("/api/invocations?job_id=test_id").reply(200, []); - }); - - afterEach(() => { - axiosMock.restore(); + server.use( + http.get("/api/configuration/decode/{encoded_id}", ({ response }) => { + return response(200).json({ decoded_id: 123 }); + }), + http.get("/api/jobs/{job_id}", ({ response }) => { + return response(200).json(jobResponse); + }), + http.get("/api/invocations", ({ response }) => { + return response(200).json([]); + }) + ); }); const verifyValues = (rendered_entries, infoTable, backendResponse) => {