From 4c5dbf00ec4b040c290bedfc60e2ad6be9f1dfeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sat, 13 Jun 2026 16:08:53 +0200 Subject: [PATCH] test(medications): anchor inventory first-use date relative to now MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The markAsFirstUseAt case hardcoded 2026-05-14, whose 30-day in-use window lapses at noon UTC on 2026-06-13 — past that the expected state flips to EXPIRED and the assertion fails. Anchor first-use to one day ago so the window is always open relative to the run. --- .../api/medications/[id]/inventory/__tests__/route.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/api/medications/[id]/inventory/__tests__/route.test.ts b/src/app/api/medications/[id]/inventory/__tests__/route.test.ts index 16617b3fd..d27144f42 100644 --- a/src/app/api/medications/[id]/inventory/__tests__/route.test.ts +++ b/src/app/api/medications/[id]/inventory/__tests__/route.test.ts @@ -220,7 +220,11 @@ describe("PATCH /api/medications/[id]/inventory/[itemId]", () => { state: "IN_USE", } as never); - const intake = "2026-05-14T12:00:00Z"; + // Anchor first-use to one day ago so the 30-day in-use window is + // always open relative to "now" — a previously hardcoded date + // (2026-05-14) silently aged past its window and flipped the expected + // state to EXPIRED once the wall clock crossed firstUseAt + 30 days. + const intake = new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(); const res = await PATCH( jsonReq( "http://localhost/api/medications/med-1/inventory/inv-1",