fix(frontend): complete audit remediation
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { QueryClientProvider, useQueryClient } from "@tanstack/react-query";
|
||||
import { act, renderHook, waitFor } from "@testing-library/react";
|
||||
import { HttpResponse, http } from "msw";
|
||||
import type { FC, PropsWithChildren } from "react";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { apiClient, apiQueryClient } from "@/shared/api";
|
||||
import { createTestQueryClient } from "@/test/query";
|
||||
import { server } from "@/test/server";
|
||||
import { AuthProvider, useAuth } from "./auth";
|
||||
|
||||
@@ -22,26 +23,36 @@ describe("AuthProvider", () => {
|
||||
return HttpResponse.json([]);
|
||||
}),
|
||||
);
|
||||
const queryClient = createTestQueryClient();
|
||||
const wrapper: FC<PropsWithChildren> = (props) => {
|
||||
const { children } = props;
|
||||
|
||||
return (
|
||||
<QueryClientProvider client={new QueryClient()}>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<AuthProvider>{children}</AuthProvider>
|
||||
</QueryClientProvider>
|
||||
);
|
||||
};
|
||||
const { result } = renderHook(() => useAuth(), { wrapper });
|
||||
const { result, rerender } = renderHook(
|
||||
() => ({ ...useAuth(), queryClient: useQueryClient() }),
|
||||
{ wrapper },
|
||||
);
|
||||
|
||||
await waitFor(() => expect(result.current.ready).toBe(true));
|
||||
await apiClient.GET("/api/v1/brokerage-accounts");
|
||||
|
||||
expect(authorization).toBe("Bearer restored-token");
|
||||
queryClient.setQueryData(["rerender-proof"], { value: "preserved" });
|
||||
rerender();
|
||||
expect(result.current.queryClient).toBe(queryClient);
|
||||
expect(result.current.queryClient.getQueryData(["rerender-proof"])).toEqual(
|
||||
{ value: "preserved" },
|
||||
);
|
||||
});
|
||||
|
||||
it("settles unauthenticated and clears cached data when cold-start refresh has a transport error", async () => {
|
||||
server.use(http.post("*/api/v1/auth/refresh", () => HttpResponse.error()));
|
||||
const queryClient = new QueryClient();
|
||||
const queryClient = createTestQueryClient();
|
||||
queryClient.setQueryData(["cached-query"], { value: "stale" });
|
||||
const wrapper: FC<PropsWithChildren> = (props) => {
|
||||
const { children } = props;
|
||||
@@ -77,7 +88,7 @@ describe("AuthProvider", () => {
|
||||
HttpResponse.json({ code: "UNAUTHORIZED" }, { status: 401 }),
|
||||
),
|
||||
);
|
||||
const queryClient = new QueryClient();
|
||||
const queryClient = createTestQueryClient();
|
||||
queryClient.setQueryData(["cached-query"], { value: "stale" });
|
||||
const wrapper: FC<PropsWithChildren> = (props) => {
|
||||
const { children } = props;
|
||||
@@ -110,7 +121,7 @@ describe("AuthProvider", () => {
|
||||
}),
|
||||
),
|
||||
);
|
||||
const queryClient = new QueryClient();
|
||||
const queryClient = createTestQueryClient();
|
||||
const statusKey = apiQueryClient.queryOptions(
|
||||
"get",
|
||||
"/api/v1/tbank-connection",
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { MantineProvider } from "@mantine/core";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { type QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { HttpResponse, http } from "msw";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { apiQueryClient, configureAuthClient } from "@/shared/api";
|
||||
import { createTestQueryClient } from "@/test/query";
|
||||
import { server } from "@/test/server";
|
||||
import { TbankConnectionSection } from "./TbankConnectionSection";
|
||||
|
||||
@@ -42,9 +43,7 @@ function renderSection(client: QueryClient) {
|
||||
}
|
||||
|
||||
function seededClient() {
|
||||
const client = new QueryClient({
|
||||
defaultOptions: { queries: { retry: false } },
|
||||
});
|
||||
const client = createTestQueryClient();
|
||||
client.setQueryData(brokerageAccountsQueryKey, [
|
||||
{
|
||||
id: "account-1",
|
||||
|
||||
Reference in New Issue
Block a user