From 9d82b25c6f39486df75e6f28be8ab39ac712d904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Fri, 31 Jul 2026 11:15:38 +0200 Subject: [PATCH] Type the cycle route's locale probe instead of ignoring its argument The stand-in for the discovery engine took an argument it never read, so the lint run flagged it. Give the mock a function type instead: the argument stays inspectable, which is the whole point of the probe, and nothing is declared and then dropped. --- .../insights/__tests__/route-locale.test.ts | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/app/api/cycle/insights/__tests__/route-locale.test.ts b/src/app/api/cycle/insights/__tests__/route-locale.test.ts index 9cac955dc..a55be82e6 100644 --- a/src/app/api/cycle/insights/__tests__/route-locale.test.ts +++ b/src/app/api/cycle/insights/__tests__/route-locale.test.ts @@ -17,7 +17,15 @@ import { describe, it, expect, vi, beforeEach } from "vitest"; * notice. */ -const discoverPhaseCorrelations = vi.fn(() => ({ +/** Stands in for the discovery engine so the ARGUMENTS are what is inspected. */ +const discoverPhaseCorrelations = vi.fn< + (args: { locale?: unknown }) => { + discovered: never[]; + pairsTested: number; + fdrQ: number; + minPairs: number; + } +>(() => ({ discovered: [], pairsTested: 0, fdrQ: 0.1, @@ -25,7 +33,8 @@ const discoverPhaseCorrelations = vi.fn(() => ({ })); vi.mock("@/lib/cycle/phase-crosstab", async (importOriginal) => ({ ...(await importOriginal()), - discoverPhaseCorrelations: (args: unknown) => discoverPhaseCorrelations(args), + discoverPhaseCorrelations: (args: { locale?: unknown }) => + discoverPhaseCorrelations(args), })); vi.mock("@/lib/db", () => ({ @@ -101,16 +110,14 @@ beforeEach(() => { /** The locale the route handed the discovery engine on the last call. */ function passedLocale(): unknown { - const args = discoverPhaseCorrelations.mock.calls.at(-1)?.[0] as - { locale?: unknown } | undefined; - return args?.locale; + return discoverPhaseCorrelations.mock.calls.at(-1)?.[0]?.locale; } describe("GET /api/cycle/insights — the reader's language", () => { it("passes the language the switcher's cookie names", async () => { localeCookie.mockReturnValue("de"); - const res = await GET(new Request("http://localhost/api/cycle/insights")); + const res = await GET(); expect(res.status).toBe(200); expect(passedLocale()).toBe("de"); @@ -123,7 +130,7 @@ describe("GET /api/cycle/insights — the reader's language", () => { >, ); - await GET(new Request("http://localhost/api/cycle/insights")); + await GET(); expect(passedLocale()).toBe("pl"); }); @@ -132,10 +139,10 @@ describe("GET /api/cycle/insights — the reader's language", () => { // Two readers, two languages, from the same handler. A route that named // one outright would pass this only by accident. localeCookie.mockReturnValue("it"); - await GET(new Request("http://localhost/api/cycle/insights")); + await GET(); const first = passedLocale(); localeCookie.mockReturnValue("fr"); - await GET(new Request("http://localhost/api/cycle/insights")); + await GET(); expect([first, passedLocale()]).toEqual(["it", "fr"]); });