mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-13 06:32:03 +00:00
test(reminders): run the ketone checkup cases beside the glucose ones
The two ketone cases repeated the glucose cases with one type changed; they are now one parametrized case each, which keeps the mocked client casts at their count.
This commit is contained in:
1 parent
352a170313
commit
159f40c0fc
2 files changed
+46
-77
No files matched your search
@@ -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<DispatchFn>(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<DispatchFn>(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<DispatchFn>(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" })],
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user