test(medications): make compliance and analytics tests timezone-stable

These tests passed in Europe/Berlin but failed under UTC (or against the
shipped engine) because they leant on the host clock:

- intake route test: the mocked user had no timezone, so slot resolution
  fell back to the host TZ and the 07:00 schedule slot only matched in
  Berlin. Pin the user to Europe/Berlin.
- health-score: 30 daily takes seeded at an unaligned now-i*DAY shifted
  their Berlin hour with the runner TZ, dropping them out of the
  08:00-10:00 on-time band. Anchor each take to a fixed 07:30 UTC.
- sleep-stages: the night sat on the trailing-30-day window edge for a
  fixed calendar instant. Anchor it to now-5d.
- weekly-compliance: not a timezone issue. The dose-window engine treats
  a weekly dose inside the 4-day overdue tail as still-takeable, not
  missed, so skipping the most-recent Monday no longer lowers the rate.
  Skip an older, settled-miss Monday instead; the gap assertion stands.
This commit is contained in:
Marc-André Bombeck committed 2026-06-08 20:09:17 +02:00
1 parent dfb6a7f298
commit 050ddbecb2
4 files changed
+32 -6

No files matched your search

@@ -96,7 +96,14 @@ import { getSession } from "@/lib/auth/session";
const SESSION_OK = {
session: { id: "sess-1", expiresAt: new Date(Date.now() + 3_600_000) },
user: { id: "user-1", username: "marc", role: "USER" as const },
user: {
id: "user-1",
username: "marc",
role: "USER" as const,
// Pin the user timezone so slot-instant resolution is deterministic
// regardless of the host TZ (CI runs in UTC, local in Europe/Berlin).
timezone: "Europe/Berlin",
},
};
const MED_OK = { id: "med-1", userId: "user-1" };