From 7683e84a840312a25f181202fb5643e03e920d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 12 Nov 2026 15:17:50 +0100 Subject: [PATCH] test(medications): fail the dose history test on a read of every intake The case with a year of earlier takes proved the ledger stays the same, which the old read of every intake satisfied as well, so a revert of the bounded read passed every test. It now also counts the rows the route read and expects only the window's. --- tests/integration/dose-history-window.test.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/integration/dose-history-window.test.ts b/tests/integration/dose-history-window.test.ts index 5068770d3..846b7ed0a 100644 --- a/tests/integration/dose-history-window.test.ts +++ b/tests/integration/dose-history-window.test.ts @@ -8,7 +8,7 @@ * a rolling medication last taken before the window shows the dose that fell * due inside it. All data invented. */ -import { beforeEach, describe, expect, it } from "vitest"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import { GET as getDoseHistory } from "@/app/api/medications/[id]/dose-history/route"; @@ -112,6 +112,15 @@ describe("the dose history of a window", () => { expect(shortLedger.filter((r) => r[2] === "taken_on_time")).toEqual( inWindow.map((day) => [day, "slot", "taken_on_time"]), ); - expect(await ledger(auth, long.id)).toEqual(shortLedger); + // The same ledger from the window's rows alone: reading every intake + // also answers it, after a year of rows. + const read = vi.spyOn(prisma.medicationIntakeEvent, "findMany"); + try { + expect(await ledger(auth, long.id)).toEqual(shortLedger); + const rows = await Promise.all(read.mock.results.map((r) => r.value)); + expect(rows.flat()).toHaveLength(inWindow.length); + } finally { + read.mockRestore(); + } }); });