mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-12 06:06:10 +00:00
fix: preserve legacy compliance response contract
This commit is contained in:
1 parent
41d47c3184
commit
24ff031f7a
9 files changed
+119
-44
No files matched your search
@@ -175,8 +175,22 @@ describe("GET /api/medications/[id]/compliance - applicability", () => {
|
||||
expect(data).toEqual({
|
||||
applicable: false,
|
||||
notApplicableReason: "NO_LOCAL_SCHEDULE",
|
||||
compliance7: null,
|
||||
compliance30: null,
|
||||
compliance7: {
|
||||
totalExpected: 0,
|
||||
taken: 0,
|
||||
skipped: 0,
|
||||
missed: 0,
|
||||
rate: 0,
|
||||
streak: 0,
|
||||
},
|
||||
compliance30: {
|
||||
totalExpected: 0,
|
||||
taken: 0,
|
||||
skipped: 0,
|
||||
missed: 0,
|
||||
rate: 0,
|
||||
streak: 0,
|
||||
},
|
||||
dailyCompliance: {},
|
||||
complianceDisplay: null,
|
||||
});
|
||||
|
||||
@@ -59,6 +59,15 @@ import { checkRateLimit } from "@/lib/rate-limit";
|
||||
|
||||
const TZ = "UTC";
|
||||
|
||||
const LEGACY_EMPTY_COMPLIANCE = {
|
||||
totalExpected: 0,
|
||||
taken: 0,
|
||||
skipped: 0,
|
||||
missed: 0,
|
||||
rate: 0,
|
||||
streak: 0,
|
||||
};
|
||||
|
||||
const SESSION_OK = {
|
||||
session: { id: "sess-1", expiresAt: new Date(Date.now() + 3_600_000) },
|
||||
user: {
|
||||
@@ -165,14 +174,46 @@ describe("GET /api/medications/compliance", () => {
|
||||
medicationId: "mirror-1",
|
||||
applicable: false,
|
||||
notApplicableReason: "NO_LOCAL_SCHEDULE",
|
||||
compliance7: null,
|
||||
compliance30: null,
|
||||
compliance7: LEGACY_EMPTY_COMPLIANCE,
|
||||
compliance30: LEGACY_EMPTY_COMPLIANCE,
|
||||
complianceDisplay: null,
|
||||
},
|
||||
]);
|
||||
expect(prisma.medicationIntakeEvent.findMany).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps a mixed scheduled/mirror batch decodable by the legacy non-null contract", async () => {
|
||||
vi.mocked(prisma.medication.findMany).mockResolvedValue([
|
||||
medication("med-1"),
|
||||
{
|
||||
...medication("mirror-1"),
|
||||
externalSource: "APPLE_HEALTH",
|
||||
externalId: "hk-concept-1",
|
||||
schedules: [],
|
||||
},
|
||||
] as never);
|
||||
|
||||
const res = await (GET as (req: Request) => Promise<Response>)(
|
||||
new Request("http://localhost"),
|
||||
);
|
||||
expect(res.status).toBe(200);
|
||||
const body = await res.json();
|
||||
const items = body.data as Array<Record<string, unknown>>;
|
||||
|
||||
expect(items).toHaveLength(2);
|
||||
expect(items[0]?.applicable).toBe(true);
|
||||
expect(items[0]?.compliance7).toBeTruthy();
|
||||
expect(items[0]?.compliance30).toBeTruthy();
|
||||
expect(items[1]).toMatchObject({
|
||||
medicationId: "mirror-1",
|
||||
applicable: false,
|
||||
notApplicableReason: "NO_LOCAL_SCHEDULE",
|
||||
compliance7: LEGACY_EMPTY_COMPLIANCE,
|
||||
compliance30: LEGACY_EMPTY_COMPLIANCE,
|
||||
complianceDisplay: null,
|
||||
});
|
||||
});
|
||||
|
||||
it("reads each medication through the shared per-medication cache cell", async () => {
|
||||
vi.mocked(prisma.medication.findMany).mockResolvedValue([
|
||||
medication("med-1"),
|
||||
|
||||
Reference in new issue
Block a user