mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
@@ -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;
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user