refactor: align frontend ownership boundaries
Close audit gaps across API drift, query policy, UI, and tests.
This commit is contained in:
@@ -1,31 +1,12 @@
|
||||
import { MantineProvider } from "@mantine/core";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { renderHook, waitFor } from "@testing-library/react";
|
||||
import { HttpResponse, http } from "msw";
|
||||
import type { FC, PropsWithChildren } from "react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { createQueryWrapper } from "@/test/query";
|
||||
import { server } from "@/test/server";
|
||||
import { useAuthenticatedQuery } from "./authenticated-query";
|
||||
import { apiQueryClient, configureAuthClient } from "./client";
|
||||
|
||||
function createWrapper() {
|
||||
const client = new QueryClient();
|
||||
const TestWrapper: FC<PropsWithChildren> = (props) => {
|
||||
const { children } = props;
|
||||
|
||||
return (
|
||||
<MantineProvider>
|
||||
<QueryClientProvider client={client}>{children}</QueryClientProvider>
|
||||
</MantineProvider>
|
||||
);
|
||||
};
|
||||
|
||||
return TestWrapper;
|
||||
}
|
||||
|
||||
describe("useAuthenticatedQuery", () => {
|
||||
afterEach(() => configureAuthClient(null));
|
||||
|
||||
it("keeps protected queries idle without a session and loads after session configuration", async () => {
|
||||
const requests = vi.fn();
|
||||
server.use(
|
||||
@@ -47,7 +28,7 @@ describe("useAuthenticatedQuery", () => {
|
||||
useAuthenticatedQuery(
|
||||
apiQueryClient.queryOptions("get", "/api/v1/brokerage-accounts"),
|
||||
),
|
||||
{ wrapper: createWrapper() },
|
||||
{ wrapper: createQueryWrapper().wrapper },
|
||||
);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { HttpResponse, http } from "msw";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { server } from "@/test/server";
|
||||
import { apiClient, configureAuthClient } from "./client";
|
||||
|
||||
describe("apiClient authentication", () => {
|
||||
afterEach(() => configureAuthClient(null));
|
||||
|
||||
it("refreshes once and retries an unauthorized protected request", async () => {
|
||||
let token = "expired";
|
||||
const refresh = vi.fn(async () => {
|
||||
|
||||
Vendored
+1
-1
@@ -232,7 +232,7 @@ export interface components {
|
||||
TbankConnectionStatusDto: {
|
||||
connected: boolean;
|
||||
/** Format: date-time */
|
||||
connectedAt: Record<string, never> | null;
|
||||
connectedAt: string | null;
|
||||
};
|
||||
PutTbankConnectionDto: {
|
||||
token: string;
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
export { useAuthenticatedQuery } from "./authenticated-query";
|
||||
export { apiClient, apiQueryClient, configureAuthClient } from "./client";
|
||||
export type { paths } from "./generated/schema";
|
||||
export { apiErrorCode } from "./problem-details";
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
function apiErrorCode(error: unknown): string | undefined {
|
||||
return typeof error === "object" && error !== null && "code" in error
|
||||
? String(error.code)
|
||||
: undefined;
|
||||
}
|
||||
|
||||
export { apiErrorCode };
|
||||
@@ -1275,7 +1275,7 @@
|
||||
"type": "boolean"
|
||||
},
|
||||
"connectedAt": {
|
||||
"type": "object",
|
||||
"type": "string",
|
||||
"nullable": true,
|
||||
"format": "date-time"
|
||||
}
|
||||
@@ -1960,4 +1960,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user