mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 12:32:43 +00:00
fix: allow scheduled Apple Health mirrors
This commit is contained in:
1 parent
c183d1862e
commit
30e454fb83
2 files changed
+26
-1
No files matched your search
@@ -526,6 +526,28 @@ describe("POST /api/medications — Apple Health mirror (v1.28)", () => {
|
||||
.data;
|
||||
}
|
||||
|
||||
it("admits a scheduled Apple Health mirror without a HealthLog-owned schedule", async () => {
|
||||
vi.mocked(prisma.medication.findFirst).mockResolvedValue(null as never);
|
||||
vi.mocked(prisma.medication.count).mockResolvedValue(0 as never);
|
||||
|
||||
const res = await POST(
|
||||
postReq({
|
||||
name: "Telmisartan",
|
||||
dose: "1 count",
|
||||
externalSource: "APPLE_HEALTH",
|
||||
externalId: "hk-concept-scheduled",
|
||||
asNeeded: false,
|
||||
}),
|
||||
);
|
||||
|
||||
expect(res.status).toBe(201);
|
||||
const data = lastCreateData();
|
||||
expect(data.externalSource).toBe("APPLE_HEALTH");
|
||||
expect(data.externalId).toBe("hk-concept-scheduled");
|
||||
expect(data.asNeeded).toBe(false);
|
||||
expect(data.schedules).toEqual({ create: [] });
|
||||
});
|
||||
|
||||
it("persists externalSource + externalId field-by-field on create", async () => {
|
||||
vi.mocked(prisma.medication.findFirst).mockResolvedValue(null as never);
|
||||
const res = await POST(postReq(MIRROR_BODY));
|
||||
|
||||
@@ -228,7 +228,10 @@ export const createMedicationSchema = z
|
||||
path: ["asNeeded"],
|
||||
})
|
||||
.refine(
|
||||
(b) => b.asNeeded === true || (!!b.schedules && b.schedules.length >= 1),
|
||||
(b) =>
|
||||
b.externalSource === "APPLE_HEALTH" ||
|
||||
b.asNeeded === true ||
|
||||
(!!b.schedules && b.schedules.length >= 1),
|
||||
{
|
||||
message: "Mindestens ein Zeitfenster",
|
||||
path: ["schedules"],
|
||||
|
||||
Reference in new issue
Block a user