fix(vaccinations): re-anchor a booster on the logged dose's own day

Logging the next dose satisfies a matching booster reminder with the
dose date, a calendar date stored at UTC midnight. The reminder engine
reads that instant in the person's zone, where west of UTC it is the
evening before, so the next booster came due a day early. The first
booster's anchor was already counted from the start of the dose day in
the person's zone; the satisfy path now hands the engine the same
instant.
This commit is contained in:
Marc-André Bombeck committed 2026-11-11 22:55:59 +01:00
1 parent f76e5cdafd
commit 46906916d8
4 files changed
+81 -3

No files matched your search

@@ -18,6 +18,8 @@ process.env.ENCRYPTION_KEY ??=
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
import { POST as createVaccination } from "@/app/api/vaccinations/route";
import { dateOnlyKey } from "@/lib/tz/date-only";
import { startOfLocalDayKey } from "@/lib/tz/local-day";
import { POST as mintBooster } from "@/app/api/vaccinations/[id]/booster/route";
import { GET as listReminders } from "@/app/api/measurement-reminders/route";
@@ -221,7 +223,10 @@ describe("the whole activity-aware loop, through real routes", () => {
const after = await prisma.measurementReminder.findUniqueOrThrow({
where: { id: reminderId },
});
expect(after.lastSatisfiedAt?.toISOString()).toBe(occurredAt.toISOString());
// The start of the dose's calendar day in the person's zone.
expect(after.lastSatisfiedAt).toEqual(
startOfLocalDayKey(dateOnlyKey(occurredAt), "Europe/Berlin"),
);
expect(after.nextDueAt!.getTime()).toBeGreaterThan(
before.nextDueAt!.getTime(),
);
@@ -24,6 +24,8 @@ process.env.ENCRYPTION_KEY ??=
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
import { POST as createVaccination } from "@/app/api/vaccinations/route";
import { dateOnlyKey } from "@/lib/tz/date-only";
import { startOfLocalDayKey } from "@/lib/tz/local-day";
import { cookieJar, headerJar } from "./mock-next-headers";
import { getPrismaClient, truncateAllTables } from "./setup";
@@ -132,7 +134,10 @@ describe("a dose satisfies the boosters it answers", () => {
expect(res.status, JSON.stringify(await res.clone().json())).toBe(201);
const after = await reminderById(reminder.id);
expect(after.lastSatisfiedAt?.toISOString()).toBe(occurredAt.toISOString());
// The start of the dose's calendar day in the person's zone.
expect(after.lastSatisfiedAt).toEqual(
startOfLocalDayKey(dateOnlyKey(occurredAt), "Europe/Berlin"),
);
// Re-anchored from the satisfy instant, so the next one lands roughly ten
// years out rather than staying on the date it was already overdue on.
expect(after.nextDueAt).not.toBeNull();