mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 20:42:43 +00:00
test(intake): pin wall-clock on idempotency tests
Both 'is idempotent on a second pass' and 'does not double-mint when today's rows already exist' hard-coded the scheduledFor to 2026-05-21T05:00Z while the route's projection uses new Date(). On 2026-05-22 the projected day diverged from the existence-row date and createMany fired, breaking the regression guard. vi.setSystemTime pins both ends to the same calendar day.
This commit is contained in:
1 parent
690cfaf0a2
commit
3e0eb77b4d
2 files changed
+15
No files matched your search
@@ -604,6 +604,13 @@ describe("GET /api/dashboard/summary", () => {
|
||||
// slot (e.g. the intake route or the reminder worker minted it
|
||||
// first), the dashboard route's backfill `createMany` must not
|
||||
// fire — the route simply re-reads + returns.
|
||||
//
|
||||
// v1.4.47 — pin the wall-clock so the projected scheduledFor and
|
||||
// the mocked existence row land on the same day regardless of
|
||||
// when the suite runs (previously hard-coded 2026-05-21 — broke
|
||||
// on 2026-05-22).
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(new Date("2026-05-21T08:00:00.000Z"));
|
||||
vi.mocked(getSession).mockResolvedValue(SESSION_OK as never);
|
||||
const scheduledFor = new Date("2026-05-21T05:00:00.000Z");
|
||||
vi.mocked(prisma.medication.findMany).mockResolvedValue([
|
||||
@@ -646,6 +653,7 @@ describe("GET /api/dashboard/summary", () => {
|
||||
data: { compliance: { scheduledToday: number; takenToday: number } };
|
||||
};
|
||||
expect(body.data.compliance.scheduledToday).toBe(1);
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("computes intake compliance for today", async () => {
|
||||
|
||||
@@ -218,6 +218,12 @@ describe("GET /api/medications/intake", () => {
|
||||
});
|
||||
|
||||
it("does not double-mint when today's rows already exist", async () => {
|
||||
// v1.4.47 — pin the wall-clock so the projected scheduledFor and
|
||||
// the mocked existence row land on the same day regardless of
|
||||
// when the suite runs (previously hard-coded 2026-05-21 — broke
|
||||
// on 2026-05-22).
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(new Date("2026-05-21T08:00:00.000Z"));
|
||||
vi.mocked(getSession).mockResolvedValue(SESSION_OK as never);
|
||||
const scheduledFor = new Date("2026-05-21T05:00:00.000Z");
|
||||
vi.mocked(prisma.medication.findMany).mockResolvedValue([
|
||||
@@ -256,6 +262,7 @@ describe("GET /api/medications/intake", () => {
|
||||
);
|
||||
expect(res.status).toBe(200);
|
||||
expect(prisma.medicationIntakeEvent.createMany).not.toHaveBeenCalled();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("returns compliance buckets for the last N days", async () => {
|
||||
|
||||
Reference in new issue
Block a user