Skip to content

Commit

Permalink
Your commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 committed Apr 23, 2024
1 parent 1420868 commit 0d877ab
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 43 deletions.
4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@react-keycloak/web": "^3.4.0",
"@tanstack/react-query": "^4.22.0",
"@tanstack/react-query-devtools": "^4.22.0",
"axios": "^0.21.2",
"axios": "^1.6.8",
"dayjs": "^1.11.7",
"ejs": "^3.1.7",
"fast-xml-parser": "^4.0.3",
Expand Down Expand Up @@ -71,7 +71,7 @@
"@types/react-measure": "^2.0.12",
"@types/react-router-dom": "^5.1.7",
"@types/tinycolor2": "^1.4.6",
"axios-mock-adapter": "^1.19.0",
"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
43 changes: 24 additions & 19 deletions client/src/app/api/rest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// hub OpenAPI definition: https://github.com/konveyor/tackle2-hub/blob/main/docs/openapi3.json

import axios, { AxiosPromise } from "axios";
import axios, {
AxiosHeaders,
AxiosPromise,
RawAxiosRequestHeaders,
} from "axios";

import {
AnalysisDependency,
Expand Down Expand Up @@ -107,14 +109,18 @@ export const QUESTIONNAIRES = HUB + "/questionnaires";

export const ARCHETYPES = HUB + "/archetypes";

// PATHFINDER
export const PATHFINDER = "/hub/pathfinder";
export const ASSESSMENTS = HUB + "/assessments";

const jsonHeaders = { headers: { Accept: "application/json" } };
const formHeaders = { headers: { Accept: "multipart/form-data" } };
const fileHeaders = { headers: { Accept: "application/json" } };
const yamlHeaders = { headers: { Accept: "application/x-yaml" } };
const jsonHeaders: RawAxiosRequestHeaders = {
Accept: "application/json",
};
const formHeaders: RawAxiosRequestHeaders = {
Accept: "multipart/form-data",
};
const fileHeaders: RawAxiosRequestHeaders = { Accept: "application/json" };
const yamlHeaders: RawAxiosRequestHeaders = {
Accept: "application/x-yaml",
};

type Direction = "asc" | "desc";

Expand All @@ -137,7 +143,7 @@ export const getApplicationDependencies = (
return axios
.get(`${APPLICATION_DEPENDENCY}`, {
params,
headers: jsonHeaders.headers,
headers: jsonHeaders,
})
.then((response) => response.data);
};
Expand Down Expand Up @@ -243,7 +249,7 @@ export const deleteAssessment = (id: number) => {
};

export const getIdentities = () => {
return axios.get<Identity[]>(`${IDENTITIES}`, jsonHeaders);
return axios.get<Identity[]>(`${IDENTITIES}`, { headers: jsonHeaders });
};

export const createIdentity = (obj: New<Identity>) => {
Expand Down Expand Up @@ -322,8 +328,7 @@ export function getTaskById(
format: string,
merged: boolean = false
): Promise<Task | string> {
const headers =
format === "yaml" ? { ...yamlHeaders.headers } : { ...jsonHeaders.headers };
const headers = format === "yaml" ? { ...yamlHeaders } : { ...jsonHeaders };
const responseType = format === "yaml" ? "text" : "json";

let url = `${TASKS}/${id}`;
Expand Down Expand Up @@ -371,11 +376,9 @@ export const uploadFileTaskgroup = ({
formData: any;
file: any;
}) => {
return axios.post<Taskgroup>(
`${TASKGROUPS}/${id}/bucket/${path}`,
formData,
formHeaders
);
return axios.post<Taskgroup>(`${TASKGROUPS}/${id}/bucket/${path}`, formData, {
headers: formHeaders,
});
};

export const removeFileTaskgroup = ({
Expand Down Expand Up @@ -430,7 +433,9 @@ export const createFile = ({
file: IReadFile;
}) =>
axios
.post<HubFile>(`${FILES}/${file.fileName}`, formData, fileHeaders)
.post<HubFile>(`${FILES}/${file.fileName}`, formData, {
headers: fileHeaders,
})
.then((response) => {
return response.data;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ 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 mock from "@app/test-config/mockInstance";
import userEvent from "@testing-library/user-event";
import MockAdapter from "axios-mock-adapter";
import { mockApi } from "@app/test-config/mockInstance";

mock.onAny().reply(200, []);
mockApi.onAny().reply(200, []);

const applicationData1 = {
id: 1,
Expand Down
4 changes: 2 additions & 2 deletions client/src/app/pages/controls/tags/tags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const Tags: React.FC = () => {
const onDeleteTagError = (error: AxiosError) => {
if (
error.response?.status === 500 &&
error.response?.data.error === "FOREIGN KEY constraint failed"
error.message === "FOREIGN KEY constraint failed"
) {
pushNotification({
title: "Cannot delete a used tag",
Expand Down Expand Up @@ -121,7 +121,7 @@ export const Tags: React.FC = () => {
const onDeleteTagCategoryError = (error: AxiosError) => {
if (
error.response?.status === 500 &&
error.response?.data.error === "FOREIGN KEY constraint failed"
error.message === "FOREIGN KEY constraint failed"
) {
pushNotification({
title: "Cannot delete a used tag",
Expand Down
20 changes: 18 additions & 2 deletions client/src/app/test-config/mockInstance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
// import axios, { AxiosInstance } from "axios";
// import MockAdapter from "axios-mock-adapter";
// export const mockApi = axios.create();

// export default new MockAdapter(axios as AxiosInstance, { delayResponse: 1000 });

import axios, { AxiosInstance, Method } from "axios";
import MockAdapter from "axios-mock-adapter";
import axios from "axios";

export default new MockAdapter(axios);
const axiosInstance = axios.create({
baseURL: "http://localhost:3000",
method: "GET" as Method,
});

export function createAxiosInstance() {
return axiosInstance as AxiosInstance;
}

const mock = new MockAdapter(createAxiosInstance());
export default mock;
4 changes: 1 addition & 3 deletions client/src/app/utils/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe("utils", () => {
isAxiosError: true,
name: "error",
message: errorMsg,
config: {},
toJSON: () => ({}),
};

Expand All @@ -37,15 +36,14 @@ describe("utils", () => {
isAxiosError: true,
name: "error",
message: "Network error",
config: {},
response: {
data: {
errorMessage: errorMsg,
},
status: 400,
statusText: "",
headers: {},
config: {},
config: {} as any,
},
toJSON: () => ({}),
};
Expand Down
15 changes: 3 additions & 12 deletions client/src/app/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,10 @@ import { Paths } from "@app/Paths";
// Axios error

export const getAxiosErrorMessage = (axiosError: AxiosError) => {
if (
axiosError.response &&
axiosError.response.data &&
axiosError.response.data.errorMessage
) {
return axiosError.response.data.errorMessage;
} else if (
axiosError.response?.data?.error &&
typeof axiosError?.response?.data?.error === "string"
) {
return axiosError?.response?.data?.error;
} else {
if (axiosError.response && axiosError.response.data && axiosError.message) {
return axiosError.message;
} else {
return "Network error";
}
};

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"typescript": "^5.1.6"
},
"overrides": {
"follow-redirects": "^1.15.6"
"follow-redirects": "^1.15.6",
"axios": "^1.6.8"
}
}

0 comments on commit 0d877ab

Please sign in to comment.