From e73661fef67464b1dce49a11cb798aeacc37405b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 21 May 2026 09:02:06 +0200 Subject: [PATCH] test(medications-intake-route): anchor seed row on runtime today The v1.4.39 W-MED route test hard-coded a `2026-05-18` rollup row and expected it to land at `body.data[body.data.length - 1]` (today). The test ran green on the day the marathon shipped, then started failing on every subsequent day because the trailing-7-day window drifted off the seed. Deriving the seed key from `new Date()` keeps the assertion date-stable across the calendar without weakening the parity check. --- .../api/medications/intake/__tests__/route.test.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/app/api/medications/intake/__tests__/route.test.ts b/src/app/api/medications/intake/__tests__/route.test.ts index 9542c8977..3c99a7b7f 100644 --- a/src/app/api/medications/intake/__tests__/route.test.ts +++ b/src/app/api/medications/intake/__tests__/route.test.ts @@ -208,8 +208,20 @@ describe("v1.4.39 W-MED — compliance rollup read swap", () => { vi.mocked(prisma.$queryRaw).mockResolvedValue([ { rolled_days: BigInt(7), event_days: BigInt(7) }, ] as never); + // v1.4.39.1 — anchor the seed row on the runtime's "today" so the + // test stays green across the calendar regardless of when it + // runs. The pre-fix shape hard-coded `2026-05-18`, which fell out + // of the trailing-7-day window on every subsequent wall-clock + // day and silently shifted the body.data tail off the seed. + const todayKey = (() => { + const now = new Date(); + const y = now.getUTCFullYear(); + const m = String(now.getUTCMonth() + 1).padStart(2, "0"); + const d = String(now.getUTCDate()).padStart(2, "0"); + return `${y}-${m}-${d}`; + })(); vi.mocked(prisma.medicationComplianceRollup.findMany).mockResolvedValue([ - { day: "2026-05-18", scheduled: 3, taken: 2, skipped: 1 }, + { day: todayKey, scheduled: 3, taken: 2, skipped: 1 }, ] as never); const res = await GET(