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,15 +1,17 @@
|
||||
import { HttpResponse, http } from "msw";
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { resource } from "@/test/resource";
|
||||
import { server } from "@/test/server";
|
||||
|
||||
import { apiClient, configureAuthClient } from "./client";
|
||||
|
||||
describe("apiClient authentication", () => {
|
||||
it("refreshes once and retries an unauthorized protected request", async () => {
|
||||
let token = "expired";
|
||||
const refresh = vi.fn(async () => {
|
||||
const refresh = vi.fn(() => {
|
||||
token = "fresh";
|
||||
return true;
|
||||
return Promise.resolve(true);
|
||||
});
|
||||
const authorization: string[] = [];
|
||||
server.use(
|
||||
@@ -20,7 +22,7 @@ describe("apiClient authentication", () => {
|
||||
: HttpResponse.json(resource([]));
|
||||
}),
|
||||
);
|
||||
configureAuthClient({ accessToken: () => token, refresh, clear: vi.fn() });
|
||||
configureAuthClient({ accessToken: () => token, clear: vi.fn(), refresh });
|
||||
|
||||
const { data } = await apiClient.GET("/api/v1/brokerage-accounts");
|
||||
|
||||
@@ -38,8 +40,8 @@ describe("apiClient authentication", () => {
|
||||
);
|
||||
configureAuthClient({
|
||||
accessToken: () => "expired",
|
||||
refresh: async () => false,
|
||||
clear,
|
||||
refresh: () => Promise.resolve(false),
|
||||
});
|
||||
|
||||
await apiClient.GET("/api/v1/brokerage-accounts");
|
||||
@@ -48,7 +50,7 @@ describe("apiClient authentication", () => {
|
||||
});
|
||||
|
||||
it("does not attach Bearer auth to authentication endpoints", async () => {
|
||||
let authorization: string | null = null;
|
||||
let authorization: null | string = /* eslint-disable-line unicorn/no-null -- Exercise the explicit null returned by the production API/DOM contract. */ null;
|
||||
server.use(
|
||||
http.post("*/api/v1/auth/refresh", ({ request }) => {
|
||||
authorization = request.headers.get("Authorization");
|
||||
@@ -57,8 +59,8 @@ describe("apiClient authentication", () => {
|
||||
);
|
||||
configureAuthClient({
|
||||
accessToken: () => "token",
|
||||
refresh: vi.fn(),
|
||||
clear: vi.fn(),
|
||||
refresh: vi.fn(),
|
||||
});
|
||||
|
||||
await apiClient.POST("/api/v1/auth/refresh");
|
||||
@@ -68,10 +70,8 @@ describe("apiClient authentication", () => {
|
||||
it("discards a retried request response after another session takes over", async () => {
|
||||
let generation = 0;
|
||||
let calls = 0;
|
||||
let release!: () => void;
|
||||
const pending = new Promise<void>((resolve) => {
|
||||
release = resolve;
|
||||
});
|
||||
|
||||
const { promise: pending, resolve: release } = Promise.withResolvers<void>();
|
||||
server.use(
|
||||
http.get("*/api/v1/brokerage-accounts", async () => {
|
||||
if (++calls === 1)
|
||||
@@ -82,9 +82,9 @@ describe("apiClient authentication", () => {
|
||||
);
|
||||
configureAuthClient({
|
||||
accessToken: () => "synthetic",
|
||||
generation: () => generation,
|
||||
refresh: async () => true,
|
||||
clear: vi.fn(),
|
||||
generation: () => generation,
|
||||
refresh: () => Promise.resolve(true),
|
||||
});
|
||||
// eslint-disable-next-line vitest/valid-expect -- Attach rejection handling before releasing the request; the assertion is awaited below.
|
||||
const response = expect(
|
||||
|
||||
Reference in New Issue
Block a user