From 2af0751b69a845572ae8ec2ebb47cf65f798082a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 12 Nov 2026 13:03:51 +0100 Subject: [PATCH] test: type the new fixtures instead of casting them to never The fixtures added with these fixes switched the type checker off with `as never`, which the realism ratchet refuses to see grow. They now carry their types, three webhook mocks needed no cast at all, and the lowered counts, with the targets route's one fewer version stamp, are written back. --- src/__tests__/baselines/test-as-never.json | 4 ++-- src/__tests__/baselines/version-stamp-comments.json | 4 ++-- .../measurements/bulk-delete/__tests__/route.test.ts | 6 ++---- .../api/onboarding/complete/__tests__/route.test.ts | 2 +- src/app/api/telegram/webhook/__tests__/route.test.ts | 8 ++++---- .../__tests__/measurement-list-glucose-unit.test.tsx | 12 ++++++++++-- src/lib/ai/__tests__/provider.test.ts | 2 +- src/lib/ai/__tests__/resolve-chain.test.ts | 9 +++++---- .../__tests__/enrollment-proof-second-factor.test.ts | 5 +++-- src/lib/auth/__tests__/profile-update.test.ts | 2 +- 10 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/__tests__/baselines/test-as-never.json b/src/__tests__/baselines/test-as-never.json index ef945bea3..4786f3b8b 100644 --- a/src/__tests__/baselines/test-as-never.json +++ b/src/__tests__/baselines/test-as-never.json @@ -1,7 +1,7 @@ { "$comment": "as never casts in tests, per test file under src/. Maintained by src/__tests__/test-realism-ratchet.test.ts.", "count": 523, - "total": 5459, + "total": 5457, "entries": { "__tests__/api/auth/login/mfa-branch.test.ts": 10, "__tests__/api/auth/mfa/verify.test.ts": 9, @@ -236,7 +236,7 @@ "app/api/sleep/rhythm/__tests__/route.test.ts": 6, "app/api/sync/changes/__tests__/module-gate.test.ts": 7, "app/api/sync/state/__tests__/route.test.ts": 8, - "app/api/telegram/webhook/__tests__/route.test.ts": 43, + "app/api/telegram/webhook/__tests__/route.test.ts": 41, "app/api/tokens/documents/__tests__/route.test.ts": 25, "app/api/tokens/measurements/__tests__/route.test.ts": 25, "app/api/tokens/workouts/__tests__/route.test.ts": 25, diff --git a/src/__tests__/baselines/version-stamp-comments.json b/src/__tests__/baselines/version-stamp-comments.json index 642303b6b..85cd2c071 100644 --- a/src/__tests__/baselines/version-stamp-comments.json +++ b/src/__tests__/baselines/version-stamp-comments.json @@ -1,7 +1,7 @@ { "$comment": "Comment lines that open with a release version, per file under src/. Maintained by src/__tests__/version-stamp-ratchet.test.ts.", "count": 2884, - "total": 9191, + "total": 9190, "entries": { "__tests__/account-payload-consumer-guard.test.ts": 2, "__tests__/acting-account-boundary-guard.test.ts": 7, @@ -355,7 +355,7 @@ "app/api/insights/rhythm-events/route.ts": 2, "app/api/insights/settings/route.ts": 1, "app/api/insights/targets/__tests__/route.test.ts": 1, - "app/api/insights/targets/route.ts": 2, + "app/api/insights/targets/route.ts": 1, "app/api/insights/weight-status/route.ts": 2, "app/api/integrations/healthkit/__tests__/route.test.ts": 4, "app/api/integrations/healthkit/route.ts": 3, diff --git a/src/app/api/measurements/bulk-delete/__tests__/route.test.ts b/src/app/api/measurements/bulk-delete/__tests__/route.test.ts index cadf4b3e0..839656912 100644 --- a/src/app/api/measurements/bulk-delete/__tests__/route.test.ts +++ b/src/app/api/measurements/bulk-delete/__tests__/route.test.ts @@ -158,10 +158,8 @@ describe("POST /api/measurements/bulk-delete", () => { it("leaves a computed score out of the selection it deletes", async () => { // The read is scoped like the write, so a computed row never reaches it. - vi.mocked(prisma.measurement.findMany).mockResolvedValue([] as never); - vi.mocked(prisma.measurement.updateMany).mockResolvedValue({ - count: 0, - } as never); + vi.mocked(prisma.measurement.findMany).mockResolvedValue([]); + vi.mocked(prisma.measurement.updateMany).mockResolvedValue({ count: 0 }); await POST(postReq({ ids: ["score-1"] })); diff --git a/src/app/api/onboarding/complete/__tests__/route.test.ts b/src/app/api/onboarding/complete/__tests__/route.test.ts index 1c1f36b18..164f97dd2 100644 --- a/src/app/api/onboarding/complete/__tests__/route.test.ts +++ b/src/app/api/onboarding/complete/__tests__/route.test.ts @@ -94,7 +94,7 @@ describe("POST /api/onboarding/complete", () => { vi.mocked(getSession).mockResolvedValue({ ...SESSION_OK, user: { ...SESSION_OK.user, timezone: "Europe/Berlin" }, - } as never); + } as unknown as Awaited>); // 14 May picked at 00:30 in Berlin. const res = await POST(req({ dateOfBirth: "1960-05-13T23:30:00Z" })); expect(res.status).toBe(200); diff --git a/src/app/api/telegram/webhook/__tests__/route.test.ts b/src/app/api/telegram/webhook/__tests__/route.test.ts index f9fa42f50..9a92baadf 100644 --- a/src/app/api/telegram/webhook/__tests__/route.test.ts +++ b/src/app/api/telegram/webhook/__tests__/route.test.ts @@ -479,7 +479,7 @@ describe("Telegram webhook — callback dispatch", () => { }); it("rejects 'taken' for an inactive medication and acks with the localised error", async () => { - vi.mocked(prisma.medication.findMany).mockResolvedValueOnce([] as never); + vi.mocked(prisma.medication.findMany).mockResolvedValueOnce([]); const res = await POST(tgRequest(callbackUpdate("taken:med-1"))); expect(res.status).toBe(200); @@ -497,7 +497,7 @@ describe("Telegram webhook — callback dispatch", () => { }); it("'snooze' for a missing medication acks with medicationNotFound (no update)", async () => { - vi.mocked(prisma.medication.findMany).mockResolvedValueOnce([] as never); + vi.mocked(prisma.medication.findMany).mockResolvedValueOnce([]); const res = await POST(tgRequest(callbackUpdate("snooze:med-X:60"))); expect(res.status).toBe(200); expect(prisma.medication.update).not.toHaveBeenCalled(); @@ -652,7 +652,7 @@ describe("Telegram webhook — text-message dispatch", () => { }); it("/add with no active medications replies with the 'no active' message", async () => { - vi.mocked(prisma.medication.findMany).mockResolvedValueOnce([] as never); + vi.mocked(prisma.medication.findMany).mockResolvedValueOnce([]); const res = await POST( tgRequest({ update_id: 203, @@ -769,7 +769,7 @@ describe("Telegram webhook — text-message dispatch", () => { it("'taken UnknownMed' replies with the medication-not-found message and writes nothing", async () => { // The lookup by name finds nothing. - vi.mocked(prisma.medication.findMany).mockResolvedValueOnce([] as never); + vi.mocked(prisma.medication.findMany).mockResolvedValueOnce([]); const res = await POST( tgRequest({ diff --git a/src/components/measurements/__tests__/measurement-list-glucose-unit.test.tsx b/src/components/measurements/__tests__/measurement-list-glucose-unit.test.tsx index a42afdca6..0eec0f5f2 100644 --- a/src/components/measurements/__tests__/measurement-list-glucose-unit.test.tsx +++ b/src/components/measurements/__tests__/measurement-list-glucose-unit.test.tsx @@ -61,6 +61,7 @@ vi.mock("@/hooks/use-auth", () => ({ import { I18nProvider } from "@/lib/i18n/context"; import { MeasurementList } from "../measurement-list"; +import type { Measurement } from "../list/list-model"; import type { UnitDisplay } from "@/hooks/use-unit-display"; import { convertGlucose, toCanonicalMgdl } from "@/lib/glucose"; import { getUnitForType } from "@/lib/measurements/unit-map"; @@ -150,8 +151,15 @@ describe("the out-of-range sentence", () => { `${key} ${JSON.stringify(params)}`) as unknown as Parameters< typeof outOfRangeMessage >[2]; - const reading = (type: string, unit: string) => - ({ id: "m1", type, value: 1, unit, source: "MANUAL" }) as never; + const reading = (type: string, unit: string): Measurement => ({ + id: "m1", + type, + value: 1, + unit, + source: "MANUAL", + measuredAt: "2026-11-10T12:00:00.000Z", + notes: null, + }); const shows = (unit: string) => ({ rowDisplay: (m: { value: number }) => ({ value: m.value, unit }), }); diff --git a/src/lib/ai/__tests__/provider.test.ts b/src/lib/ai/__tests__/provider.test.ts index 46a0ad60e..ea5ff3e40 100644 --- a/src/lib/ai/__tests__/provider.test.ts +++ b/src/lib/ai/__tests__/provider.test.ts @@ -362,7 +362,7 @@ describe("resolveProviderForTest — empty override resolves via the chain", () aiLocalKeyEncrypted: null, aiOpenaiKeyEncrypted: null, aiProviderChain: [{ providerType: "openai", priority: 1, enabled: true }], - } as never); + } as unknown as Awaited>); const provider = await resolveProviderForTest("user-123", {}); expect(provider.type).toBe("none"); diff --git a/src/lib/ai/__tests__/resolve-chain.test.ts b/src/lib/ai/__tests__/resolve-chain.test.ts index 183d72c71..57ed76485 100644 --- a/src/lib/ai/__tests__/resolve-chain.test.ts +++ b/src/lib/ai/__tests__/resolve-chain.test.ts @@ -230,9 +230,7 @@ describe("resolveProviderChain and the picked gateway", () => { /** Serve `chain` as the record's saved chain; Codex is not connected. */ async function resolveWith(chain: unknown) { - vi.mocked(prisma.user.findUnique).mockImplementation((async (args: { - select?: Record; - }) => + const read = async (args: { select?: Record }) => args.select?.codexAccessTokenEncrypted ? { codexAccessTokenEncrypted: null, @@ -240,7 +238,10 @@ describe("resolveProviderChain and the picked gateway", () => { codexTokenExpiresAt: null, codexConnectionStatus: "disconnected", } - : { ...gatewayRow, aiProviderChain: chain }) as never); + : { ...gatewayRow, aiProviderChain: chain }; + vi.mocked(prisma.user.findUnique).mockImplementation( + read as unknown as typeof prisma.user.findUnique, + ); operator({ adminAiKeyEncrypted: null }); return (await resolveProviderChain("user-1")).map((c) => c.providerType); } diff --git a/src/lib/auth/__tests__/enrollment-proof-second-factor.test.ts b/src/lib/auth/__tests__/enrollment-proof-second-factor.test.ts index 20ca150e3..c68778ded 100644 --- a/src/lib/auth/__tests__/enrollment-proof-second-factor.test.ts +++ b/src/lib/auth/__tests__/enrollment-proof-second-factor.test.ts @@ -9,6 +9,7 @@ * account only possession of a factor counts now; the account without one is * unchanged. */ +import type { NextRequest } from "next/server"; import { describe, it, expect, vi, beforeEach } from "vitest"; vi.mock("@/lib/db", () => ({ @@ -252,10 +253,10 @@ describe("POST /api/auth/passkey/register-options", () => { vi.mocked(requireCookieAuth).mockResolvedValue({ user: stored(PLAIN), session: { id: "sess-1" }, - } as never); + } as unknown as Awaited>); vi.mocked(verifyPassword).mockResolvedValue(false); const res = await PASSKEY_REGISTER_OPTIONS( - passkeyReq({ method: "password", password: "typo" }) as never, + passkeyReq({ method: "password", password: "typo" }) as NextRequest, ); expect(res.status).toBe(401); expect((await res.json()).meta.errorCode).toBe("auth.reproof.failed"); diff --git a/src/lib/auth/__tests__/profile-update.test.ts b/src/lib/auth/__tests__/profile-update.test.ts index 9b5d83497..ad78f1475 100644 --- a/src/lib/auth/__tests__/profile-update.test.ts +++ b/src/lib/auth/__tests__/profile-update.test.ts @@ -102,7 +102,7 @@ describe("applyProfileUpdate date of birth", () => { // the zone resolver caches per account. vi.mocked(prisma.user.findUnique).mockResolvedValue({ timezone: "Pacific/Tongatapu", - } as never); + } as unknown as Awaited>); await applyProfileUpdate("user-tonga", { dateOfBirth: "2012-05-13T20:30:00Z", });