refactor: centralize frontend auth query gating

This commit is contained in:
2026-08-25 14:29:41 +03:00
parent fff36f252a
commit 268acdf2e1
24 changed files with 352 additions and 82 deletions
+14 -5
View File
@@ -5,13 +5,10 @@ import { HttpResponse, http } from "msw";
import { MemoryRouter } from "react-router";
import { afterEach, describe, expect, it, vi } from "vitest";
import { brokerageAccountsQueryKey } from "@/entities/brokerage-account";
import { configureAuthClient } from "@/shared/api";
import { server } from "@/test/server";
import { AccountsPage } from "./AccountsPage";
vi.mock("@/features/auth", () => ({
useAuth: () => ({ accessToken: "test-token" }),
}));
const account = {
id: "account-1",
name: "Основной",
@@ -19,7 +16,16 @@ const account = {
openedOn: "2026-01-01",
} as const;
function configureTestAuth() {
configureAuthClient({
accessToken: () => "test-token",
refresh: async () => true,
clear: vi.fn(),
});
}
function renderPage(queryClient: QueryClient) {
configureTestAuth();
return render(
<QueryClientProvider client={queryClient}>
<MantineProvider>
@@ -32,7 +38,10 @@ function renderPage(queryClient: QueryClient) {
}
describe("AccountsPage", () => {
afterEach(cleanup);
afterEach(() => {
configureAuthClient(null);
cleanup();
});
it("keeps the cached account list visible during a background refresh", async () => {
let requestCount = 0;
+1 -3
View File
@@ -1,9 +1,7 @@
import { errorCode, useBrokerageAccounts } from "@/entities/brokerage-account";
import { useAuth } from "@/features/auth";
export function useAccountsPageViewModel() {
const { accessToken } = useAuth();
const accounts = useBrokerageAccounts(accessToken);
const accounts = useBrokerageAccounts();
if (!accounts.data) {
if (accounts.isFetching) return { state: "loading" as const };
if (accounts.isError)