chore: finish frontend ESLint migration #18
Enable every plugin recommended preset and replace Biome with ESLint formatting. Preserve API contracts and JSX whitespace; verify source, tests, builds and tooling.
This commit is contained in:
@@ -1,41 +1,41 @@
|
||||
import { act, renderHook, waitFor } from "@testing-library/react";
|
||||
import { HttpResponse, http } from "msw";
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { useBrokerageAccounts } from "@/entities/brokerage-account";
|
||||
import { useStockQuote } from "@/entities/stock";
|
||||
import { configureAuthClient, invalidateResourceAccess } from "@/shared/api";
|
||||
import { createQueryWrapper } from "@/test/query";
|
||||
import { resource } from "@/test/resource";
|
||||
import { server } from "@/test/server";
|
||||
|
||||
import { useScreenSync } from "../index";
|
||||
import { commitTbankConnectionBoundary } from "./connection-boundary";
|
||||
|
||||
function auth() {
|
||||
configureAuthClient({
|
||||
accessToken: () => "synthetic",
|
||||
refresh: async () => true,
|
||||
clear: vi.fn(),
|
||||
refresh: () => Promise.resolve(true),
|
||||
});
|
||||
}
|
||||
describe("page-owned screen synchronization", () => {
|
||||
it("ignores a late sync acceptance after the account scope changes", async () => {
|
||||
auth();
|
||||
let release!: () => void;
|
||||
const blocked = new Promise<void>((resolve) => {
|
||||
release = resolve;
|
||||
});
|
||||
|
||||
const { promise: blocked, resolve: release } = Promise.withResolvers<void>();
|
||||
const posted: string[] = [];
|
||||
const polled: string[] = [];
|
||||
server.use(
|
||||
http.post("*/api/v1/tbank-sync", async ({ request }) => {
|
||||
const scope = (await request.json()) as {
|
||||
screen: "account";
|
||||
accountId: string;
|
||||
screen: "account";
|
||||
};
|
||||
posted.push(scope.accountId);
|
||||
await blocked;
|
||||
return HttpResponse.json(
|
||||
{ id: scope.accountId, scope, now: "2026-09-25T00:00:00Z" },
|
||||
{ id: scope.accountId, now: "2026-09-25T00:00:00Z", scope },
|
||||
{ status: 202 },
|
||||
);
|
||||
}),
|
||||
@@ -43,13 +43,13 @@ describe("page-owned screen synchronization", () => {
|
||||
polled.push(String(params.id));
|
||||
return HttpResponse.json({
|
||||
id: params.id,
|
||||
state: "succeeded",
|
||||
resources: [],
|
||||
state: "succeeded",
|
||||
});
|
||||
}),
|
||||
);
|
||||
const { result, rerender } = renderHook(
|
||||
({ accountId }) => useScreenSync({ screen: "account", accountId }, []),
|
||||
const { rerender, result } = renderHook(
|
||||
({ accountId }) => useScreenSync({ accountId, screen: "account" }, []),
|
||||
{
|
||||
initialProps: { accountId: "old" },
|
||||
wrapper: createQueryWrapper().wrapper,
|
||||
@@ -73,13 +73,13 @@ describe("page-owned screen synchronization", () => {
|
||||
"retries a failed GET without forcing the source (cached=%s)",
|
||||
async (cached) => {
|
||||
auth();
|
||||
const modes: (string | null)[] = [];
|
||||
let unavailable = !cached;
|
||||
const modes: (null | string)[] = [];
|
||||
let isUnavailable = !cached;
|
||||
let posts = 0;
|
||||
server.use(
|
||||
http.get("*/api/v1/brokerage-accounts", ({ request }) => {
|
||||
modes.push(new URL(request.url).searchParams.get("sync"));
|
||||
return unavailable
|
||||
return isUnavailable
|
||||
? HttpResponse.json({ code: "UNAVAILABLE" }, { status: 503 })
|
||||
: HttpResponse.json(
|
||||
resource([], { stateVersion: String(modes.length) }),
|
||||
@@ -90,7 +90,7 @@ describe("page-owned screen synchronization", () => {
|
||||
return new HttpResponse(null, { status: 500 });
|
||||
}),
|
||||
);
|
||||
const { wrapper, queryClient } = createQueryWrapper();
|
||||
const { queryClient, wrapper } = createQueryWrapper();
|
||||
const { result } = renderHook(
|
||||
() => {
|
||||
const accounts = useBrokerageAccounts();
|
||||
@@ -105,20 +105,21 @@ describe("page-owned screen synchronization", () => {
|
||||
);
|
||||
if (cached) {
|
||||
await waitFor(() =>
|
||||
// eslint-disable-next-line vitest/no-conditional-expect -- The fixed table case selects the expected outcome; every case asserts its own branch.
|
||||
expect(result.current.accounts.isSuccess).toBe(true),
|
||||
);
|
||||
unavailable = true;
|
||||
isUnavailable = true;
|
||||
await act(() => result.current.accounts.refetch());
|
||||
}
|
||||
await waitFor(() => expect(result.current.accounts.isError).toBe(true));
|
||||
unavailable = false;
|
||||
isUnavailable = false;
|
||||
await act(() => result.current.sync.retry());
|
||||
await waitFor(() => expect(result.current.accounts.isSuccess).toBe(true));
|
||||
expect(result.current.accounts.meta?.stateVersion).toBe(
|
||||
cached ? "3" : "2",
|
||||
);
|
||||
expect(modes).toEqual(
|
||||
cached ? [null, null, "observe"] : [null, "observe"],
|
||||
cached ? [null, /* eslint-disable-line unicorn/no-null -- Exercise the explicit null returned by the production API/DOM contract. */ null, "observe"] : [null, "observe"],
|
||||
);
|
||||
expect(posts).toBe(0);
|
||||
expect(result.current.disabled.data).toBeUndefined();
|
||||
@@ -139,26 +140,24 @@ describe("page-owned screen synchronization", () => {
|
||||
"discards recovery after %s changes (HTTP already pending=%s)",
|
||||
async (boundary, pending) => {
|
||||
auth();
|
||||
let release!: () => void;
|
||||
const blocked = new Promise<void>((resolve) => {
|
||||
release = resolve;
|
||||
});
|
||||
let recovering = false;
|
||||
let changed = false;
|
||||
|
||||
const { promise: blocked, resolve: release } = Promise.withResolvers<void>();
|
||||
let isRecovering = false;
|
||||
let isChanged = false;
|
||||
server.use(
|
||||
http.get("*/api/v1/brokerage-accounts", async ({ request }) => {
|
||||
if (boundary === "connection" && changed && !request.signal.aborted)
|
||||
if (boundary === "connection" && isChanged && !request.signal.aborted)
|
||||
return HttpResponse.json(resource([], { stateVersion: "current" }));
|
||||
if (!new URL(request.url).searchParams.has("sync"))
|
||||
return changed
|
||||
return isChanged
|
||||
? HttpResponse.json(resource([], { stateVersion: "current" }))
|
||||
: HttpResponse.json({ code: "UNAVAILABLE" }, { status: 503 });
|
||||
recovering = true;
|
||||
isRecovering = true;
|
||||
await blocked;
|
||||
return HttpResponse.json(resource([], { stateVersion: "old" }));
|
||||
}),
|
||||
);
|
||||
const { wrapper, queryClient } = createQueryWrapper();
|
||||
const { queryClient, wrapper } = createQueryWrapper();
|
||||
const published: unknown[] = [];
|
||||
const unsubscribe = queryClient.getQueryCache().subscribe((event) => {
|
||||
if (event.type === "updated" && event.action.type === "success")
|
||||
@@ -179,29 +178,42 @@ describe("page-owned screen synchronization", () => {
|
||||
act(() => {
|
||||
recovery = result.current.sync.retry();
|
||||
});
|
||||
if (pending) await waitFor(() => expect(recovering).toBe(true));
|
||||
// eslint-disable-next-line vitest/no-conditional-expect -- The fixed table case selects the expected outcome; every case asserts its own branch.
|
||||
if (pending) await waitFor(() => expect(isRecovering).toBe(true));
|
||||
await act(async () => {
|
||||
changed = true;
|
||||
if (boundary === "logout") {
|
||||
configureAuthClient(null);
|
||||
queryClient.clear();
|
||||
} else if (boundary === "session") {
|
||||
auth();
|
||||
queryClient.clear();
|
||||
} else if (boundary === "access") {
|
||||
invalidateResourceAccess(queryClient, "brokerage", {
|
||||
code: "FORBIDDEN",
|
||||
});
|
||||
} else
|
||||
commitTbankConnectionBoundary(queryClient, {
|
||||
isChanged = true;
|
||||
switch (boundary) {
|
||||
case "access": {
|
||||
invalidateResourceAccess(queryClient, "brokerage", {
|
||||
code: "FORBIDDEN",
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
case "logout": {
|
||||
configureAuthClient();
|
||||
queryClient.clear();
|
||||
|
||||
break;
|
||||
}
|
||||
case "session": {
|
||||
auth();
|
||||
queryClient.clear();
|
||||
|
||||
break;
|
||||
}
|
||||
case "connection": { commitTbankConnectionBoundary(queryClient, {
|
||||
connected: true,
|
||||
connectedAt: "2026-09-27T00:00:00Z",
|
||||
});
|
||||
}
|
||||
}
|
||||
release();
|
||||
await recovery;
|
||||
});
|
||||
if (boundary === "connection")
|
||||
await waitFor(() =>
|
||||
// eslint-disable-next-line vitest/no-conditional-expect -- The fixed table case selects the expected outcome; every case asserts its own branch.
|
||||
expect(result.current.accounts.meta?.stateVersion).toBe("current"),
|
||||
);
|
||||
expect(published).not.toContainEqual(
|
||||
@@ -216,7 +228,7 @@ describe("page-owned screen synchronization", () => {
|
||||
"recovers an initial GET failure after forced sync without metadata (status retry=%s)",
|
||||
async (retryStatus) => {
|
||||
auth();
|
||||
const modes: (string | null)[] = [];
|
||||
const modes: (null | string)[] = [];
|
||||
let polls = 0;
|
||||
server.use(
|
||||
http.get("*/api/v1/brokerage-accounts", ({ request }) => {
|
||||
@@ -234,12 +246,12 @@ describe("page-owned screen synchronization", () => {
|
||||
? HttpResponse.json({ code: "UNAVAILABLE" }, { status: 503 })
|
||||
: HttpResponse.json({
|
||||
id: "recover",
|
||||
state: "succeeded",
|
||||
resources: [resource([]).meta],
|
||||
state: "succeeded",
|
||||
});
|
||||
}),
|
||||
);
|
||||
const { wrapper, queryClient } = createQueryWrapper();
|
||||
const { queryClient, wrapper } = createQueryWrapper();
|
||||
const { result } = renderHook(
|
||||
() => {
|
||||
const accounts = useBrokerageAccounts();
|
||||
@@ -256,12 +268,14 @@ describe("page-owned screen synchronization", () => {
|
||||
await act(() => result.current.sync.refresh());
|
||||
if (retryStatus) {
|
||||
await waitFor(() =>
|
||||
// eslint-disable-next-line vitest/no-conditional-expect -- The fixed table case selects the expected outcome; every case asserts its own branch.
|
||||
expect(result.current.sync.transportError).toBe(true),
|
||||
);
|
||||
await act(() => result.current.sync.retry());
|
||||
}
|
||||
await waitFor(() => expect(result.current.accounts.isSuccess).toBe(true));
|
||||
expect(result.current.accounts.data).toEqual([]);
|
||||
// eslint-disable-next-line unicorn/no-null -- Preserve the API/DOM null sentinel in the expected response.
|
||||
expect(modes).toEqual([null, "observe"]);
|
||||
expect(
|
||||
queryClient
|
||||
@@ -272,12 +286,12 @@ describe("page-owned screen synchronization", () => {
|
||||
);
|
||||
it("posts only its scope once and observes completion without importing again", async () => {
|
||||
auth();
|
||||
const modes: (string | null)[] = [];
|
||||
const modes: (null | string)[] = [];
|
||||
const bodies: unknown[] = [];
|
||||
let completed = false;
|
||||
let isCompleted = false;
|
||||
let polls = 0;
|
||||
const meta = () =>
|
||||
resource([], { stateVersion: completed ? "2" : "1" }).meta;
|
||||
resource([], { stateVersion: isCompleted ? "2" : "1" }).meta;
|
||||
server.use(
|
||||
http.get("*/api/v1/brokerage-accounts", ({ request }) => {
|
||||
modes.push(new URL(request.url).searchParams.get("sync"));
|
||||
@@ -285,27 +299,29 @@ describe("page-owned screen synchronization", () => {
|
||||
}),
|
||||
http.post("*/api/v1/tbank-sync", async ({ request }) => {
|
||||
bodies.push(await request.json());
|
||||
completed = true;
|
||||
isCompleted = true;
|
||||
return HttpResponse.json(
|
||||
{
|
||||
id: "screen",
|
||||
scope: { screen: "accounts" },
|
||||
now: "2026-09-25T00:00:00Z",
|
||||
scope: { screen: "accounts" },
|
||||
},
|
||||
{ status: 202 },
|
||||
);
|
||||
}),
|
||||
http.get("*/api/v1/tbank-sync/:id", () => {
|
||||
polls++;
|
||||
return HttpResponse.json({
|
||||
id: "screen",
|
||||
scope: { screen: "accounts" },
|
||||
now: "2026-09-25T00:00:00Z",
|
||||
state: "succeeded",
|
||||
errorCode: null,
|
||||
progress: { total: 1, completed: 1, discovering: false },
|
||||
resources: [meta()],
|
||||
});
|
||||
return HttpResponse.json((/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
|
||||
{
|
||||
errorCode: null,
|
||||
id: "screen",
|
||||
now: "2026-09-25T00:00:00Z",
|
||||
progress: { completed: 1, discovering: false, total: 1 },
|
||||
resources: [meta()],
|
||||
scope: { screen: "accounts" },
|
||||
state: "succeeded",
|
||||
}
|
||||
/* eslint-enable unicorn/no-null */));
|
||||
}),
|
||||
);
|
||||
const { result, unmount } = renderHook(
|
||||
@@ -329,16 +345,19 @@ describe("page-owned screen synchronization", () => {
|
||||
expect(result.current.accounts.meta?.stateVersion).toBe("2"),
|
||||
);
|
||||
expect(bodies).toEqual([{ screen: "accounts" }]);
|
||||
// eslint-disable-next-line unicorn/no-null -- Preserve the API/DOM null sentinel in the expected response.
|
||||
expect(modes).toEqual([null, "observe"]);
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
await act(() => vi.advanceTimersByTimeAsync(120000));
|
||||
await act(() => vi.advanceTimersByTimeAsync(120_000));
|
||||
expect(polls).toBe(1);
|
||||
// eslint-disable-next-line unicorn/no-null -- Preserve the API/DOM null sentinel in the expected response.
|
||||
expect(modes).toEqual([null, "observe"]);
|
||||
unmount();
|
||||
await vi.advanceTimersByTimeAsync(120000);
|
||||
await vi.advanceTimersByTimeAsync(120_000);
|
||||
expect(polls).toBe(1);
|
||||
} finally {
|
||||
}
|
||||
finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
@@ -348,14 +367,16 @@ describe("page-owned screen synchronization", () => {
|
||||
vi.useFakeTimers({ toFake: ["Date"] });
|
||||
try {
|
||||
auth();
|
||||
let completed = false;
|
||||
let isCompleted = false;
|
||||
let polls = 0;
|
||||
const modes: (string | null)[] = [];
|
||||
const modes: (null | string)[] = [];
|
||||
const snapshot = () =>
|
||||
resource(completed ? [] : null, {
|
||||
stateVersion: completed ? "covered" : "initial",
|
||||
sync: { id: "history", state: "running", errorCode: null },
|
||||
});
|
||||
resource(isCompleted ? [] : /* eslint-disable-line unicorn/no-null -- Exercise the explicit null returned by the production API/DOM contract. */ null, (/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
|
||||
{
|
||||
stateVersion: isCompleted ? "covered" : "initial",
|
||||
sync: { errorCode: null, id: "history", state: "running" },
|
||||
}
|
||||
/* eslint-enable unicorn/no-null */));
|
||||
server.use(
|
||||
http.get("*/api/v1/brokerage-accounts", ({ request }) => {
|
||||
modes.push(new URL(request.url).searchParams.get("sync"));
|
||||
@@ -363,19 +384,21 @@ describe("page-owned screen synchronization", () => {
|
||||
}),
|
||||
http.get("*/api/v1/tbank-sync/:id", () => {
|
||||
polls++;
|
||||
return HttpResponse.json({
|
||||
id: "history",
|
||||
scope: null,
|
||||
now: "2026-09-25T00:00:00Z",
|
||||
state: "running",
|
||||
errorCode: null,
|
||||
progress: {
|
||||
total: 2,
|
||||
completed: completed ? 1 : 0,
|
||||
discovering: true,
|
||||
},
|
||||
resources: [snapshot().meta],
|
||||
});
|
||||
return HttpResponse.json((/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
|
||||
{
|
||||
errorCode: null,
|
||||
id: "history",
|
||||
now: "2026-09-25T00:00:00Z",
|
||||
progress: {
|
||||
completed: isCompleted ? 1 : 0,
|
||||
discovering: true,
|
||||
total: 2,
|
||||
},
|
||||
resources: [snapshot().meta],
|
||||
scope: null,
|
||||
state: "running",
|
||||
}
|
||||
/* eslint-enable unicorn/no-null */));
|
||||
}),
|
||||
);
|
||||
const { result, unmount } = renderHook(
|
||||
@@ -394,24 +417,26 @@ describe("page-owned screen synchronization", () => {
|
||||
await waitFor(() => expect(polls).toBeGreaterThan(0));
|
||||
expect(result.current.sync.refreshing).toBe(true);
|
||||
expect(result.current.accounts.data).toBeUndefined();
|
||||
completed = true;
|
||||
vi.setSystemTime(Date.now() + 61000);
|
||||
isCompleted = true;
|
||||
vi.setSystemTime(Date.now() + 61_000);
|
||||
await waitFor(() => expect(result.current.accounts.data).toEqual([]), {
|
||||
timeout: 3000,
|
||||
});
|
||||
expect(result.current.sync.refreshing).toBe(true);
|
||||
await act(async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1100));
|
||||
await new Promise(resolve => setTimeout(resolve, 1100));
|
||||
});
|
||||
// eslint-disable-next-line unicorn/no-null -- Preserve the API/DOM null sentinel in the expected response.
|
||||
expect(modes).toEqual([null, "observe"]);
|
||||
if (boundary === "leave") unmount();
|
||||
else act(() => configureAuthClient(null));
|
||||
else act(() => configureAuthClient());
|
||||
const stopped = polls;
|
||||
await act(async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1100));
|
||||
await new Promise(resolve => setTimeout(resolve, 1100));
|
||||
});
|
||||
expect(polls).toBe(stopped);
|
||||
} finally {
|
||||
}
|
||||
finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
},
|
||||
@@ -422,9 +447,11 @@ describe("page-owned screen synchronization", () => {
|
||||
server.use(
|
||||
http.get("*/api/v1/brokerage-accounts", () =>
|
||||
HttpResponse.json(
|
||||
resource([], {
|
||||
sync: { id: "revoked", state: "running", errorCode: null },
|
||||
}),
|
||||
resource([], (/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
|
||||
{
|
||||
sync: { errorCode: null, id: "revoked", state: "running" },
|
||||
}
|
||||
/* eslint-enable unicorn/no-null */)),
|
||||
),
|
||||
),
|
||||
http.get("*/api/v1/tbank-sync/:id", () =>
|
||||
@@ -446,41 +473,45 @@ describe("page-owned screen synchronization", () => {
|
||||
});
|
||||
it("observes a projection when only its dependency reports new coverage", async () => {
|
||||
auth();
|
||||
let observed = false;
|
||||
const modes: (string | null)[] = [];
|
||||
const dependency = resource([], {
|
||||
resourceKey: "operations",
|
||||
stateVersion: observed ? "covered" : "initial",
|
||||
sync: {
|
||||
id: "dependency",
|
||||
state: observed ? "idle" : "running",
|
||||
errorCode: null,
|
||||
},
|
||||
}).meta;
|
||||
let isObserved = false;
|
||||
const modes: (null | string)[] = [];
|
||||
const dependency = resource([], (/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
|
||||
{
|
||||
resourceKey: "operations",
|
||||
stateVersion: isObserved ? "covered" : "initial",
|
||||
sync: {
|
||||
errorCode: null,
|
||||
id: "dependency",
|
||||
state: isObserved ? "idle" : "running",
|
||||
},
|
||||
}
|
||||
/* eslint-enable unicorn/no-null */)).meta;
|
||||
server.use(
|
||||
http.get("*/api/v1/brokerage-accounts", ({ request }) => {
|
||||
const mode = new URL(request.url).searchParams.get("sync");
|
||||
modes.push(mode);
|
||||
if (mode) observed = true;
|
||||
if (mode) isObserved = true;
|
||||
return HttpResponse.json(
|
||||
resource(observed ? [] : null, {
|
||||
resourceKey: "projection",
|
||||
resource(isObserved ? [] : /* eslint-disable-line unicorn/no-null -- Exercise the explicit null returned by the production API/DOM contract. */ null, {
|
||||
dependencies: [
|
||||
{ ...dependency, stateVersion: observed ? "covered" : "initial" },
|
||||
{ ...dependency, stateVersion: isObserved ? "covered" : "initial" },
|
||||
],
|
||||
resourceKey: "projection",
|
||||
}),
|
||||
);
|
||||
}),
|
||||
http.get("*/api/v1/tbank-sync/:id", () =>
|
||||
HttpResponse.json({
|
||||
id: "dependency",
|
||||
scope: null,
|
||||
now: "2026-09-25T00:00:00Z",
|
||||
state: "succeeded",
|
||||
errorCode: null,
|
||||
progress: { total: 1, completed: 1, discovering: false },
|
||||
resources: [{ ...dependency, stateVersion: "covered" }],
|
||||
}),
|
||||
HttpResponse.json((/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
|
||||
{
|
||||
errorCode: null,
|
||||
id: "dependency",
|
||||
now: "2026-09-25T00:00:00Z",
|
||||
progress: { completed: 1, discovering: false, total: 1 },
|
||||
resources: [{ ...dependency, stateVersion: "covered" }],
|
||||
scope: null,
|
||||
state: "succeeded",
|
||||
}
|
||||
/* eslint-enable unicorn/no-null */)),
|
||||
),
|
||||
);
|
||||
const { result } = renderHook(
|
||||
@@ -492,6 +523,7 @@ describe("page-owned screen synchronization", () => {
|
||||
{ wrapper: createQueryWrapper().wrapper },
|
||||
);
|
||||
await waitFor(() => expect(result.current.data).toEqual([]));
|
||||
// eslint-disable-next-line unicorn/no-null -- Preserve the API/DOM null sentinel in the expected response.
|
||||
expect(modes).toEqual([null, "observe"]);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user