refactor: align frontend ownership boundaries
Close audit gaps across API drift, query policy, UI, and tests.
This commit is contained in:
@@ -1,17 +1,13 @@
|
||||
import { MantineProvider } from "@mantine/core";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { renderHook, waitFor } from "@testing-library/react";
|
||||
import type { FC, PropsWithChildren } from "react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { configureAuthClient } from "@/shared/api";
|
||||
import { createQueryWrapper } from "@/test/query";
|
||||
import {
|
||||
brokerageOperationsQueryParams,
|
||||
useBrokerageOperations,
|
||||
} from "./useBrokerageOperations";
|
||||
|
||||
describe("useBrokerageOperations", () => {
|
||||
afterEach(() => configureAuthClient(null));
|
||||
|
||||
it("normalizes query parameters and loads a page without retries", async () => {
|
||||
configureAuthClient({
|
||||
accessToken: () => "token",
|
||||
@@ -24,20 +20,9 @@ describe("useBrokerageOperations", () => {
|
||||
cursor: "next",
|
||||
}),
|
||||
).toEqual({ categories: ["income", "tax"], cursor: "next" });
|
||||
const client = new QueryClient();
|
||||
const wrapper: FC<PropsWithChildren> = (props) => {
|
||||
const { children } = props;
|
||||
|
||||
return (
|
||||
<MantineProvider>
|
||||
<QueryClientProvider client={client}>{children}</QueryClientProvider>
|
||||
</MantineProvider>
|
||||
);
|
||||
};
|
||||
|
||||
const { result } = renderHook(
|
||||
() => useBrokerageOperations("account-1", { limit: 5 }),
|
||||
{ wrapper },
|
||||
{ wrapper: createQueryWrapper().wrapper },
|
||||
);
|
||||
|
||||
await waitFor(() => expect(result.current.isSuccess).toBe(true));
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { apiQueryClient, useAuthenticatedQuery } from "@/shared/api";
|
||||
import type { paths } from "@/shared/api/generated/schema";
|
||||
import {
|
||||
apiQueryClient,
|
||||
type paths,
|
||||
useAuthenticatedQuery,
|
||||
} from "@/shared/api";
|
||||
|
||||
type OperationsEndpoint =
|
||||
paths["/api/v1/brokerage-accounts/{accountId}/operations"]["get"];
|
||||
@@ -32,25 +35,36 @@ function brokerageOperationsQueryParams(query: BrokerageOperationsQuery) {
|
||||
};
|
||||
}
|
||||
|
||||
function brokerageOperationsQueryOptions(
|
||||
accountId: string | undefined,
|
||||
query: BrokerageOperationsQuery = {},
|
||||
) {
|
||||
return apiQueryClient.queryOptions(
|
||||
"get",
|
||||
"/api/v1/brokerage-accounts/{accountId}/operations",
|
||||
{
|
||||
params: {
|
||||
path: { accountId: accountId ?? "" },
|
||||
query: brokerageOperationsQueryParams(query),
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function useBrokerageOperations(
|
||||
accountId: string | undefined,
|
||||
query: BrokerageOperationsQuery = {},
|
||||
) {
|
||||
const params = brokerageOperationsQueryParams(query);
|
||||
return useAuthenticatedQuery({
|
||||
...apiQueryClient.queryOptions(
|
||||
"get",
|
||||
"/api/v1/brokerage-accounts/{accountId}/operations",
|
||||
{ params: { path: { accountId: accountId ?? "" }, query: params } },
|
||||
),
|
||||
...brokerageOperationsQueryOptions(accountId, query),
|
||||
enabled: Boolean(accountId),
|
||||
staleTime: 30_000,
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
type BrokerageOperation,
|
||||
brokerageOperationsQueryOptions,
|
||||
brokerageOperationsQueryParams,
|
||||
type OperationCategory,
|
||||
operationCategories,
|
||||
|
||||
Reference in New Issue
Block a user