refactor: centralize frontend auth query gating
This commit is contained in:
@@ -3,15 +3,12 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { HttpResponse, http } from "msw";
|
||||
import { MemoryRouter, Route, Routes } from "react-router";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { BrokerageOperation } from "@/entities/broker-operation";
|
||||
import { configureAuthClient } from "@/shared/api";
|
||||
import { server } from "@/test/server";
|
||||
import { AccountOperationsPage, OperationRow } from "./AccountOperationsPage";
|
||||
|
||||
vi.mock("@/features/auth", () => ({
|
||||
useAuth: () => ({ accessToken: "token" }),
|
||||
}));
|
||||
|
||||
const operation: BrokerageOperation = {
|
||||
id: "operation-1",
|
||||
occurredAt: "2026-08-14T10:00:00Z",
|
||||
@@ -29,6 +26,14 @@ const operation: BrokerageOperation = {
|
||||
commission: { currency: "RUB", value: "1" },
|
||||
};
|
||||
|
||||
function configureTestAuth() {
|
||||
configureAuthClient({
|
||||
accessToken: () => "token",
|
||||
refresh: async () => true,
|
||||
clear: vi.fn(),
|
||||
});
|
||||
}
|
||||
|
||||
describe("OperationRow", () => {
|
||||
it("marks cashless operations without rendering operation details", () => {
|
||||
render(
|
||||
@@ -49,7 +54,10 @@ describe("OperationRow", () => {
|
||||
});
|
||||
|
||||
describe("AccountOperationsPage", () => {
|
||||
afterEach(() => configureAuthClient(null));
|
||||
|
||||
it("resets cursor pagination when filters change", async () => {
|
||||
configureTestAuth();
|
||||
const searches: string[] = [];
|
||||
server.use(
|
||||
http.get(
|
||||
@@ -96,6 +104,7 @@ describe("AccountOperationsPage", () => {
|
||||
});
|
||||
|
||||
it("renders an error state", async () => {
|
||||
configureTestAuth();
|
||||
server.use(
|
||||
http.get("*/api/v1/brokerage-accounts/:accountId/operations", () =>
|
||||
HttpResponse.json({ code: "TBANK_UNAVAILABLE" }, { status: 503 }),
|
||||
|
||||
@@ -18,7 +18,6 @@ import {
|
||||
useBrokerageOperations,
|
||||
} from "@/entities/broker-operation";
|
||||
import { formatMoney, formatSnapshotTime } from "@/entities/portfolio";
|
||||
import { useAuth } from "@/features/auth";
|
||||
import { StateView } from "@/shared/ui";
|
||||
|
||||
function dateStart(value: string) {
|
||||
@@ -31,14 +30,13 @@ function dateEnd(value: string) {
|
||||
|
||||
export function AccountOperationsPage() {
|
||||
const { accountId } = useParams();
|
||||
const { accessToken } = useAuth();
|
||||
const { t } = useTranslation();
|
||||
const [from, setFrom] = useState("");
|
||||
const [to, setTo] = useState("");
|
||||
const [categories, setCategories] = useState<OperationCategory[]>([]);
|
||||
const [cursors, setCursors] = useState<string[]>([]);
|
||||
const cursor = cursors.at(-1);
|
||||
const operations = useBrokerageOperations(accountId, accessToken, {
|
||||
const operations = useBrokerageOperations(accountId, {
|
||||
from: dateStart(from),
|
||||
to: dateEnd(to),
|
||||
...(categories.length ? { categories } : {}),
|
||||
|
||||
Reference in New Issue
Block a user