feat: add portfolio

This commit is contained in:
2026-08-13 22:45:00 +03:00
parent 6e89c1a8f7
commit 9156f29707
11 changed files with 594 additions and 12 deletions
@@ -0,0 +1,45 @@
import { MantineProvider } from "@mantine/core";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { renderHook, waitFor } from "@testing-library/react";
import type { ReactNode } from "react";
import { describe, expect, it, vi } from "vitest";
const { get } = vi.hoisted(() => ({ get: vi.fn() }));
vi.mock("../../../shared/api", () => ({ apiClient: { GET: get } }));
import { portfolioQueryPolicy, usePortfolio } from "./usePortfolio";
describe("usePortfolio", () => {
it("uses the account endpoint with a 30 second cache and no retry", async () => {
const client = new QueryClient();
get.mockResolvedValueOnce({
data: {
lastSuccessfulAt: "2026-08-13T10:00:00Z",
isStale: false,
totalsByCurrency: [],
positions: [],
cashBalances: [],
},
});
const wrapper = ({ children }: { children: ReactNode }) => (
<MantineProvider>
<QueryClientProvider client={client}>{children}</QueryClientProvider>
</MantineProvider>
);
const { result } = renderHook(() => usePortfolio("account-1", "token"), {
wrapper,
});
await waitFor(() => expect(result.current.isSuccess).toBe(true));
expect(get).toHaveBeenCalledWith(
"/api/v1/brokerage-accounts/{accountId}/portfolio",
{
params: { path: { accountId: "account-1" } },
headers: { Authorization: "Bearer token" },
},
);
expect(portfolioQueryPolicy).toEqual({ staleTime: 30_000, retry: false });
});
});