From 51b5a6d3ef283d07dec163aa54d194b582ec2023 Mon Sep 17 00:00:00 2001 From: Ethan Kaplan Date: Wed, 26 Jun 2024 09:42:09 -0700 Subject: [PATCH 1/3] MAT-7204a axiosInstance added for Intercept --- src/api/useCqlLibraryServiceApi.tsx | 2 +- src/components/config/useGetServiceConfig.ts | 2 +- src/components/editCqlLibrary/EditCqlLibrary.test.tsx | 3 +++ src/types/madie-madie-util.d.ts | 2 ++ src/utils/axios-insatnce.ts | 7 +++++++ 5 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 src/utils/axios-insatnce.ts diff --git a/src/api/useCqlLibraryServiceApi.tsx b/src/api/useCqlLibraryServiceApi.tsx index b011950..9283d44 100644 --- a/src/api/useCqlLibraryServiceApi.tsx +++ b/src/api/useCqlLibraryServiceApi.tsx @@ -1,4 +1,4 @@ -import axios from "axios"; +import { axiosInstance as axios } from "../utils/axios-insatnce"; import useServiceConfig from "./useServiceConfig"; import { ServiceConfig } from "./ServiceContext"; import { CqlLibrary } from "@madie/madie-models"; diff --git a/src/components/config/useGetServiceConfig.ts b/src/components/config/useGetServiceConfig.ts index f0e5154..ad4ece9 100644 --- a/src/components/config/useGetServiceConfig.ts +++ b/src/components/config/useGetServiceConfig.ts @@ -1,4 +1,4 @@ -import axios from "axios"; +import { axiosInstance as axios } from "../../utils/axios-insatnce"; import { useEffect, useState } from "react"; export interface OktaConfig { diff --git a/src/components/editCqlLibrary/EditCqlLibrary.test.tsx b/src/components/editCqlLibrary/EditCqlLibrary.test.tsx index 0187807..5e82b8c 100644 --- a/src/components/editCqlLibrary/EditCqlLibrary.test.tsx +++ b/src/components/editCqlLibrary/EditCqlLibrary.test.tsx @@ -79,6 +79,9 @@ const organizations = [ jest.mock("axios"); const mockedAxios = axios as jest.Mocked; +mockedAxios.interceptors = axios.interceptors as jest.Mocked< + typeof axios.interceptors +>; // mocking useHistory const mockPush = jest.fn(); diff --git a/src/types/madie-madie-util.d.ts b/src/types/madie-madie-util.d.ts index 8fde3c9..ecc5fa2 100644 --- a/src/types/madie-madie-util.d.ts +++ b/src/types/madie-madie-util.d.ts @@ -87,6 +87,8 @@ declare module "@madie/madie-util" { draft?: boolean ): boolean; + export function wafIntercept(): void; + export const bootstrap: LifeCycleFn; export const mount: LifeCycleFn; export const unmount: LifeCycleFn; diff --git a/src/utils/axios-insatnce.ts b/src/utils/axios-insatnce.ts new file mode 100644 index 0000000..f19f22c --- /dev/null +++ b/src/utils/axios-insatnce.ts @@ -0,0 +1,7 @@ +import axios from "axios"; +import { wafIntercept } from "@madie/madie-util"; + +export const axiosInstance = axios.create(); +axiosInstance.interceptors.response.use((response) => { + return response; +}, wafIntercept); From 486459817506515a1f5b2c493b4f637c38433a1f Mon Sep 17 00:00:00 2001 From: Ethan Kaplan Date: Wed, 26 Jun 2024 10:44:34 -0700 Subject: [PATCH 2/3] MAT-7204a axiosInstance added for Intercept --- src/components/editCqlLibrary/EditCqlLibrary.test.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/components/editCqlLibrary/EditCqlLibrary.test.tsx b/src/components/editCqlLibrary/EditCqlLibrary.test.tsx index 5e82b8c..0187807 100644 --- a/src/components/editCqlLibrary/EditCqlLibrary.test.tsx +++ b/src/components/editCqlLibrary/EditCqlLibrary.test.tsx @@ -79,9 +79,6 @@ const organizations = [ jest.mock("axios"); const mockedAxios = axios as jest.Mocked; -mockedAxios.interceptors = axios.interceptors as jest.Mocked< - typeof axios.interceptors ->; // mocking useHistory const mockPush = jest.fn(); From 709b2b11871114fdaa3124035803a5ae96d10b57 Mon Sep 17 00:00:00 2001 From: Ethan Kaplan Date: Thu, 27 Jun 2024 14:46:41 -0700 Subject: [PATCH 3/3] MAT-7204 change axios import --- src/api/axios-instance.ts | 9 +++++++++ src/api/useCqlLibraryServiceApi.tsx | 2 +- src/components/config/useGetServiceConfig.ts | 2 +- src/components/editCqlLibrary/EditCqlLibrary.test.tsx | 4 ++-- src/utils/axios-insatnce.ts | 7 ------- 5 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 src/api/axios-instance.ts delete mode 100644 src/utils/axios-insatnce.ts diff --git a/src/api/axios-instance.ts b/src/api/axios-instance.ts new file mode 100644 index 0000000..dd908ff --- /dev/null +++ b/src/api/axios-instance.ts @@ -0,0 +1,9 @@ +import axiosReal from "axios"; +import { wafIntercept } from "@madie/madie-util"; + +const axios = axiosReal.create(); +axios.interceptors.response.use((response) => { + return response; +}, wafIntercept); + +export default axios; diff --git a/src/api/useCqlLibraryServiceApi.tsx b/src/api/useCqlLibraryServiceApi.tsx index 9283d44..7585c18 100644 --- a/src/api/useCqlLibraryServiceApi.tsx +++ b/src/api/useCqlLibraryServiceApi.tsx @@ -1,4 +1,4 @@ -import { axiosInstance as axios } from "../utils/axios-insatnce"; +import axios from "./axios-instance"; import useServiceConfig from "./useServiceConfig"; import { ServiceConfig } from "./ServiceContext"; import { CqlLibrary } from "@madie/madie-models"; diff --git a/src/components/config/useGetServiceConfig.ts b/src/components/config/useGetServiceConfig.ts index ad4ece9..133c4bc 100644 --- a/src/components/config/useGetServiceConfig.ts +++ b/src/components/config/useGetServiceConfig.ts @@ -1,4 +1,4 @@ -import { axiosInstance as axios } from "../../utils/axios-insatnce"; +import axios from "../../api/axios-instance"; import { useEffect, useState } from "react"; export interface OktaConfig { diff --git a/src/components/editCqlLibrary/EditCqlLibrary.test.tsx b/src/components/editCqlLibrary/EditCqlLibrary.test.tsx index 0187807..5873d79 100644 --- a/src/components/editCqlLibrary/EditCqlLibrary.test.tsx +++ b/src/components/editCqlLibrary/EditCqlLibrary.test.tsx @@ -6,7 +6,7 @@ import { MemoryRouter, Route } from "react-router"; import userEvent from "@testing-library/user-event"; import { ApiContextProvider, ServiceConfig } from "../../api/ServiceContext"; import { Simulate } from "react-dom/test-utils"; -import axios from "axios"; +import axios from "../../api/axios-instance"; import { ElmTranslationExternalError, isUsingEmpty, @@ -77,7 +77,7 @@ const organizations = [ }, ]; -jest.mock("axios"); +jest.mock("../../api/axios-instance"); const mockedAxios = axios as jest.Mocked; // mocking useHistory diff --git a/src/utils/axios-insatnce.ts b/src/utils/axios-insatnce.ts deleted file mode 100644 index f19f22c..0000000 --- a/src/utils/axios-insatnce.ts +++ /dev/null @@ -1,7 +0,0 @@ -import axios from "axios"; -import { wafIntercept } from "@madie/madie-util"; - -export const axiosInstance = axios.create(); -axiosInstance.interceptors.response.use((response) => { - return response; -}, wafIntercept);