Skip to content

Commit

Permalink
Refactor JobInformation test to use server mock
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Aug 9, 2024
1 parent 72fc76c commit fbf9ad3
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions client/src/components/JobInformation/JobInformation.test.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down

0 comments on commit fbf9ad3

Please sign in to comment.