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.
This commit is contained in:
Marc-André Bombeck committed 2026-11-12 15:17:50 +01:00
1 parent 8d2ba7cd4b
commit 7683e84a84
1 file changed
+11 -2
+11 -2
View File
@@ -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();
}
});
});