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.
This commit is contained in:
Marc-André Bombeck committed 2026-11-12 13:03:51 +01:00
1 parent 315c89d229
commit 2af0751b69
10 files changed
+31 -23

No files matched your search

+2 -2
View File
@@ -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,
@@ -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,
@@ -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"] }));
@@ -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<ReturnType<typeof getSession>>);
// 14 May picked at 00:30 in Berlin.
const res = await POST(req({ dateOfBirth: "1960-05-13T23:30:00Z" }));
expect(res.status).toBe(200);
@@ -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({
@@ -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 }),
});
+1 -1
View File
@@ -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<ReturnType<typeof prisma.user.findUnique>>);
const provider = await resolveProviderForTest("user-123", {});
expect(provider.type).toBe("none");
+5 -4
View File
@@ -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<string, unknown>;
}) =>
const read = async (args: { select?: Record<string, unknown> }) =>
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);
}
@@ -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<ReturnType<typeof requireCookieAuth>>);
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");
@@ -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<ReturnType<typeof prisma.user.findUnique>>);
await applyProfileUpdate("user-tonga", {
dateOfBirth: "2012-05-13T20:30:00Z",
});