Skip to content

Commit

Permalink
Remove axios-mock package
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 committed Apr 23, 2024
1 parent 0d877ab commit eba3308
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 120 deletions.
1 change: 0 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"@types/react-measure": "^2.0.12",
"@types/react-router-dom": "^5.1.7",
"@types/tinycolor2": "^1.4.6",
"axios-mock-adapter": "^1.22.0",
"browserslist": "^4.19.1",
"case-sensitive-paths-webpack-plugin": "^2.4.0",
"copy-webpack-plugin": "^12.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import React from "react";
import "@testing-library/jest-dom";
import { render, screen, waitFor } from "@app/test-config/test-utils";
import { AnalysisWizard } from "../analysis-wizard";
import { TASKGROUPS } from "@app/api/rest";
import userEvent from "@testing-library/user-event";
import MockAdapter from "axios-mock-adapter";
import { mockApi } from "@app/test-config/mockInstance";

mockApi.onAny().reply(200, []);
import { server } from "@mocks/server";
import { rest } from "msw";

const applicationData1 = {
id: 1,
Expand Down Expand Up @@ -54,6 +51,13 @@ const taskgroupData = {
};

describe("<AnalysisWizard />", () => {
beforeEach(() => {
jest.clearAllMocks();
});
afterEach(() => {
server.resetHandlers();
});

let isAnalyzeModalOpen = true;
const setAnalyzeModalOpen = (toggle: boolean) =>
(isAnalyzeModalOpen = toggle);
Expand Down Expand Up @@ -158,7 +162,11 @@ describe("<AnalysisWizard />", () => {
},
];

mock.onPost(`${TASKGROUPS}`).reply(200, taskgroupData);
server.use(
rest.get("/hub/taskgroups", (req, res, ctx) => {
return res(ctx.json([taskgroupData]));
})
);

render(
<AnalysisWizard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,30 @@ import {
fireEvent,
} from "@app/test-config/test-utils";

import { BUSINESS_SERVICES } from "@app/api/rest";
import mock from "@app/test-config/mockInstance";
import userEvent from "@testing-library/user-event";

import "@testing-library/jest-dom";
import { BusinessService } from "@app/api/models";
import { ApplicationFormModal } from "../application-form-modal";
import { server } from "@mocks/server";
import { rest } from "msw";

describe("Component: application-form", () => {
const mockChangeValue = jest.fn();
beforeAll(() => server.listen({ onUnhandledRequest: "warn" }));

beforeEach(() => {
jest.clearAllMocks();
});
afterEach(() => {
server.resetHandlers();
});
server.use(
rest.get("/hub/businessservices", (req, res, ctx) => {
return res(ctx.status(200), ctx.json([{ id: 1, name: "service" }]));
})
);

it("Validation tests", async () => {
const businessServices: BusinessService[] = [{ id: 1, name: "service" }];

mock
.onGet(`${BUSINESS_SERVICES}`)
.reply(200, businessServices)
.onAny()
.reply(200, []);

render(
<ApplicationFormModal application={null} onClose={mockChangeValue} />
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ import {
fireEvent,
} from "@app/test-config/test-utils";

import { IDENTITIES } from "@app/api/rest";
import mock from "@app/test-config/mockInstance";

import { IdentityForm } from "..";
import "@testing-library/jest-dom";
import { server } from "@mocks/server";

const data: any[] = [];
describe("Component: identity-form", () => {
beforeAll(() => server.listen({ onUnhandledRequest: "bypass" }));

mock.onGet(`${IDENTITIES}`).reply(200, data);
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

describe("Component: identity-form", () => {
const mockChangeValue = jest.fn();

it("Display form on initial load", async () => {
Expand Down Expand Up @@ -176,7 +175,7 @@ describe("Component: identity-form", () => {
expect(createButton).toBeDisabled();
});

it.skip("Identity form validation test - source - key upload", async () => {
it("Identity form validation test - source - key upload", async () => {
render(<IdentityForm onClose={mockChangeValue} />);

const identityNameInput = await screen.findByLabelText("Name *");
Expand Down Expand Up @@ -231,7 +230,7 @@ describe("Component: identity-form", () => {
expect(createButton).toBeEnabled();
});

it.skip("Identity form validation test - maven", async () => {
it("Identity form validation test - maven", async () => {
render(<IdentityForm onClose={mockChangeValue} xmlValidator={jest.fn()} />);

const identityNameInput = await screen.findByLabelText("Name *");
Expand Down
98 changes: 49 additions & 49 deletions client/src/app/pages/proxies/__tests__/proxy-form.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,38 @@ import {
} from "@app/test-config/test-utils";

import { Proxies } from "../proxies";
import MockAdapter from "axios-mock-adapter";
import { IDENTITIES, PROXIES } from "@app/api/rest";
import axios from "axios";
import { Proxy, Identity } from "@app/api/models";
import userEvent from "@testing-library/user-event";
import { ProxyForm } from "../proxy-form";
import mock from "@app/test-config/mockInstance";

const identitiesData: Identity[] = [];
mock.onGet(`${IDENTITIES}`).reply(200, identitiesData);

const proxiesData = [
{
host: "",
kind: "http",
port: 0,
excluded: [],
identity: null,
id: 1,
enabled: false,
},
{
host: "",
kind: "https",
port: 0,
excluded: [],
identity: null,
id: 1,
enabled: false,
},
];
mock.onGet(`${PROXIES}`).reply(200, proxiesData);
import { server } from "@mocks/server";
import { rest } from "msw";

describe("Component: proxy-form", () => {
beforeEach(() => {
jest.clearAllMocks();
});
afterEach(() => {
server.resetHandlers();
});
server.use(
rest.get("/hub/identities", (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json([
{ id: 0, name: "proxy-cred", kind: "proxy" },
{ id: 1, name: "maven-cred", kind: "maven" },
{ id: 2, name: "source-cred", kind: "source" },
])
);
})
);

it("Display switch statements on initial load", async () => {
render(<Proxies />);
await screen.findByLabelText("HTTP proxy");

await screen.findByLabelText("HTTPS proxy");
});

it.skip("Show HTTP proxy form when switch button clicked", async () => {
it("Show HTTP proxy form when switch button clicked", async () => {
render(<Proxies />);
const httpProxySwitch = await screen.findByLabelText("HTTP proxy");

Expand All @@ -62,7 +52,7 @@ describe("Component: proxy-form", () => {
);
});

it.skip("Show HTTPS proxy form when switch button clicked", async () => {
it("Show HTTPS proxy form when switch button clicked", async () => {
render(<Proxies />);
const httpsProxySwitch = await screen.findByLabelText("HTTPS proxy");

Expand All @@ -75,14 +65,19 @@ describe("Component: proxy-form", () => {
);
});

it.skip("Select http proxy identity", async () => {
const identitiesData: Identity[] = [
{ id: 0, name: "proxy-cred", kind: "proxy" },
{ id: 1, name: "maven-cred", kind: "maven" },
{ id: 2, name: "source-cred", kind: "source" },
];

mock.onGet(`${IDENTITIES}`).reply(200, identitiesData);
it("Select http proxy identity", async () => {
server.use(
rest.get("/hub/identities", (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json([
{ id: 0, name: "proxy-cred", kind: "proxy" },
{ id: 1, name: "maven-cred", kind: "maven" },
{ id: 2, name: "source-cred", kind: "source" },
])
);
})
);

render(<Proxies />);
const httpProxySwitch = await screen.findByLabelText("HTTP proxy");
Expand Down Expand Up @@ -112,14 +107,19 @@ describe("Component: proxy-form", () => {
expect(sourceCred).toBeNull(); // it doesn't exist
});

it.skip("Select https proxy identity", async () => {
const identitiesData: Identity[] = [
{ id: 0, name: "proxy-cred", kind: "proxy" },
{ id: 1, name: "maven-cred", kind: "maven" },
{ id: 2, name: "source-cred", kind: "source" },
];

mock.onGet(`${IDENTITIES}`).reply(200, identitiesData);
it("Select https proxy identity", async () => {
server.use(
rest.get("/hub/identities", (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json([
{ id: 0, name: "proxy-cred", kind: "proxy" },
{ id: 1, name: "maven-cred", kind: "maven" },
{ id: 2, name: "source-cred", kind: "source" },
])
);
})
);

render(<Proxies />);
const httpsProxySwitch = await screen.findByLabelText("HTTPS proxy");
Expand Down
20 changes: 0 additions & 20 deletions client/src/app/test-config/mockInstance.ts

This file was deleted.

25 changes: 0 additions & 25 deletions client/src/app/utils/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,6 @@ describe("utils", () => {
expect(errorMessage).toBe(errorMsg);
});

it("getAxiosErrorMessage: should pick body message", () => {
const errorMsg = "Internal server error";

const mockAxiosError: AxiosError = {
isAxiosError: true,
name: "error",
message: "Network error",
response: {
data: {
errorMessage: errorMsg,
},
status: 400,
statusText: "",
headers: {},
config: {} as any,
},
toJSON: () => ({}),
};

const errorMessage = getAxiosErrorMessage(mockAxiosError);
expect(errorMessage).toBe(errorMsg);
});

// getValidatedFromError

it("getValidatedFromError: given value should return 'error'", () => {
const error = "Any value";

Expand Down

0 comments on commit eba3308

Please sign in to comment.