refactor: improve test isolation for Axios API logic (#13125)

* wip: commit progress on code split-up

* wip: commit more progress

* wip: finish initial version of class implementation

* chore: update all import paths to go through client instance

* fix: remove temp comments

* refactor: smoooooooosh the API

* refactor: update import setup for tests
This commit is contained in:
Michael Smith
2024-05-12 19:05:22 +00:00
committed by GitHub
parent 5ddbeddf85
commit f13b1c9af6
95 changed files with 1964 additions and 1896 deletions
+6 -5
View File
@@ -8,7 +8,7 @@ import {
useState,
} from "react";
import { useQuery } from "react-query";
import { getWorkspaceProxies, getWorkspaceProxyRegions } from "api/api";
import { API } from "api/api";
import { cachedQuery } from "api/queries/util";
import type { Region, WorkspaceProxy } from "api/typesGenerated";
import { useAuthenticated } from "contexts/auth/RequireAuth";
@@ -108,10 +108,11 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => {
metadata: metadata.regions,
queryKey: ["get-proxies"],
queryFn: async (): Promise<readonly Region[]> => {
const endpoint = permissions.editWorkspaceProxies
? getWorkspaceProxies
: getWorkspaceProxyRegions;
const resp = await endpoint();
const apiCall = permissions.editWorkspaceProxies
? API.getWorkspaceProxies
: API.getWorkspaceProxyRegions;
const resp = await apiCall();
return resp.regions;
},
}),
+2 -1
View File
@@ -1,6 +1,6 @@
import { type FC, useEffect } from "react";
import { Outlet, Navigate, useLocation } from "react-router-dom";
import { axiosInstance } from "api/api";
import { API } from "api/api";
import { isApiError } from "api/errors";
import { Loader } from "components/Loader/Loader";
import { ProxyProvider } from "contexts/ProxyContext";
@@ -18,6 +18,7 @@ export const RequireAuth: FC = () => {
return;
}
const axiosInstance = API.getAxiosInstance();
const interceptorHandle = axiosInstance.interceptors.response.use(
(okResponse) => okResponse,
(error: unknown) => {
+2 -1
View File
@@ -1,6 +1,6 @@
import PerformanceObserver from "@fastly/performance-observer-polyfill";
import { useEffect, useReducer, useState } from "react";
import { axiosInstance } from "api/api";
import { API } from "api/api";
import type { Region } from "api/typesGenerated";
import { generateRandomString } from "utils/random";
@@ -197,6 +197,7 @@ export const useProxyLatency = (
// The resource requests include xmlhttp requests.
observer.observe({ entryTypes: ["resource"] });
const axiosInstance = API.getAxiosInstance();
const proxyRequests = Object.keys(proxyChecks).map((latencyURL) => {
return axiosInstance.get(latencyURL, {
withCredentials: false,