fix: scope Apple Health schedule exemption

This commit is contained in:
muhdusama committed 2026-09-20 20:46:47 +10:00
1 parent 30e454fb83
commit c223b6d77d
2 files changed
+23 -1

No files matched your search

@@ -625,6 +625,28 @@ describe("PUT /api/medications/[id] — as-needed (v1.16.11, #316)", () => {
expect(prisma.medication.update).not.toHaveBeenCalled();
});
it("allows a normal update on an existing zero-schedule scheduled mirror when schedules are omitted", async () => {
mockExisting({ asNeeded: false, scheduleCount: 0 });
vi.mocked(getMedicationCategories).mockResolvedValue({} as never);
vi.mocked(auditLog).mockResolvedValue(undefined);
vi.mocked(prisma.medication.update).mockResolvedValue({
id: "m1",
userId: "user-1",
dose: "10 mg",
asNeeded: false,
schedules: [],
} as never);
const res = await PUT(putReq({ dose: "10 mg" }), ROUTE_CTX);
expect(res.status).toBe(200);
const updateData = vi.mocked(prisma.medication.update).mock.calls[0][0] as {
data: Record<string, unknown>;
};
expect(updateData.data.dose).toBe("10 mg");
expect(updateData.data.schedules).toBeUndefined();
});
it("flips to as-needed with schedules:[] — old rows deleted, none recreated", async () => {
mockExisting({ scheduleCount: 1 });
// Re-stub deps the outer beforeEach's resetAllMocks cleared.
@@ -229,7 +229,7 @@ export const createMedicationSchema = z
})
.refine(
(b) =>
b.externalSource === "APPLE_HEALTH" ||
(b.externalSource === "APPLE_HEALTH" && b.externalId !== undefined) ||
b.asNeeded === true ||
(!!b.schedules && b.schedules.length >= 1),
{