diff --git a/src/lib/jobs/__tests__/measurement-reminder.test.ts b/src/lib/jobs/__tests__/measurement-reminder.test.ts index f2176d8b8..ab30f3fdf 100644 --- a/src/lib/jobs/__tests__/measurement-reminder.test.ts +++ b/src/lib/jobs/__tests__/measurement-reminder.test.ts @@ -548,28 +548,32 @@ describe("runMeasurementReminderTick", () => { ); }); - it("v1.18.0 — skips a glucose reminder when the Glucose module is off, and advances", async () => { - const { prisma, updates } = makePrisma({ - reminders: [reminder({ measurementType: "BLOOD_GLUCOSE" })], - measurementMatch: null, - }); - const dispatch = vi.fn(async () => OK); - const isModuleEnabled = vi.fn(async () => false); + // Ketones come off the glucose meter and follow the same module. + it.each(["BLOOD_GLUCOSE", "BLOOD_KETONES"] as const)( + "skips a %s reminder when the Glucose module is off, and advances", + async (measurementType) => { + const { prisma, updates } = makePrisma({ + reminders: [reminder({ measurementType })], + measurementMatch: null, + }); + const dispatch = vi.fn(async () => OK); + const isModuleEnabled = vi.fn(async () => false); - const summary = await runMeasurementReminderTick( - prisma as never, - NINE_LOCAL, - { dispatch, isModuleEnabled }, - ); + const summary = await runMeasurementReminderTick( + prisma as never, + NINE_LOCAL, + { dispatch, isModuleEnabled }, + ); - expect(summary.skippedModuleDisabled).toBe(1); - expect(summary.dispatched).toBe(0); - expect(dispatch).not.toHaveBeenCalled(); - expect(isModuleEnabled).toHaveBeenCalledWith("u1", "glucose"); - // Advances past the cycle so it does not re-evaluate every tick. - expect(updates).toHaveLength(1); - expect(updates[0].data.nextDueAt).toBeInstanceOf(Date); - }); + expect(summary.skippedModuleDisabled).toBe(1); + expect(summary.dispatched).toBe(0); + expect(dispatch).not.toHaveBeenCalled(); + expect(isModuleEnabled).toHaveBeenCalledWith("u1", "glucose"); + // Advances past the cycle so it does not re-evaluate every tick. + expect(updates).toHaveLength(1); + expect(updates[0].data.nextDueAt).toBeInstanceOf(Date); + }, + ); it("v1.18.0 — still dispatches a glucose reminder when the Glucose module is on", async () => { const { prisma } = makePrisma({ @@ -590,25 +594,6 @@ describe("runMeasurementReminderTick", () => { expect(isModuleEnabled).toHaveBeenCalledWith("u1", "glucose"); }); - it("skips a ketone checkup when the Glucose module is off, like glucose", async () => { - const { prisma } = makePrisma({ - reminders: [reminder({ measurementType: "BLOOD_KETONES" })], - measurementMatch: null, - }); - const dispatch = vi.fn(async () => OK); - const isModuleEnabled = vi.fn(async () => false); - - const summary = await runMeasurementReminderTick( - prisma as never, - NINE_LOCAL, - { dispatch, isModuleEnabled }, - ); - - expect(summary.skippedModuleDisabled).toBe(1); - expect(dispatch).not.toHaveBeenCalled(); - expect(isModuleEnabled).toHaveBeenCalledWith("u1", "glucose"); - }); - it("v1.18.0 — a core-vital (BP) reminder never consults the module gate and dispatches", async () => { const { prisma } = makePrisma({ reminders: [reminder({ measurementType: "BLOOD_PRESSURE_SYS" })], diff --git a/src/lib/jobs/__tests__/reminder-satisfy.test.ts b/src/lib/jobs/__tests__/reminder-satisfy.test.ts index b16b7f8f3..90ed1a39a 100644 --- a/src/lib/jobs/__tests__/reminder-satisfy.test.ts +++ b/src/lib/jobs/__tests__/reminder-satisfy.test.ts @@ -164,46 +164,30 @@ describe("runReminderSatisfyForUser", () => { expect(updates[0].data.lastSatisfiedAt).toEqual(takenAt); }); - it("produces no engine activity for a disabled module", async () => { - const { prisma, updates } = makePrisma({ - reminders: [reminderRow({ measurementType: "BLOOD_GLUCOSE" })], - measurement: { measuredAt: new Date("2026-06-14T18:00:00Z") }, - }); - const isModuleEnabled = vi.fn(async () => false); + it.each(["BLOOD_GLUCOSE", "BLOOD_KETONES"] as const)( + "produces no engine activity for a %s reminder while Glucose is off", + async (measurementType) => { + const { prisma, updates } = makePrisma({ + reminders: [reminderRow({ measurementType })], + measurement: { measuredAt: new Date("2026-06-14T18:00:00Z") }, + }); + const isModuleEnabled = vi.fn(async () => false); - const summary = await runReminderSatisfyForUser( - prisma as never, - "u1", - new Date(), - { isModuleEnabled }, - ); + const summary = await runReminderSatisfyForUser( + prisma as never, + "u1", + new Date(), + { isModuleEnabled }, + ); - expect(summary.skippedModuleDisabled).toBe(1); - expect(summary.satisfied).toBe(0); - expect(isModuleEnabled).toHaveBeenCalledWith("u1", "glucose"); - expect(updates).toHaveLength(0); - // The matcher never runs for a gated reminder. - expect(prisma.measurement.findFirst).not.toHaveBeenCalled(); - }); - - it("leaves a ketone checkup alone while the Glucose module is off", async () => { - const { prisma, updates } = makePrisma({ - reminders: [reminderRow({ measurementType: "BLOOD_KETONES" })], - measurement: { measuredAt: new Date("2026-06-14T18:00:00Z") }, - }); - const isModuleEnabled = vi.fn(async () => false); - - const summary = await runReminderSatisfyForUser( - prisma as never, - "u1", - new Date(), - { isModuleEnabled }, - ); - - expect(summary.skippedModuleDisabled).toBe(1); - expect(isModuleEnabled).toHaveBeenCalledWith("u1", "glucose"); - expect(updates).toHaveLength(0); - }); + expect(summary.skippedModuleDisabled).toBe(1); + expect(summary.satisfied).toBe(0); + expect(isModuleEnabled).toHaveBeenCalledWith("u1", "glucose"); + expect(updates).toHaveLength(0); + // The matcher never runs for a gated reminder. + expect(prisma.measurement.findFirst).not.toHaveBeenCalled(); + }, + ); it("satisfies a screening reminder from the server-written score row (v1.27.6)", async () => { // A completed PHQ-9 check-in writes a COMPUTED PHQ9_SCORE measurement;