diff --git a/src/components/medications/__tests__/intake-history-list-v2.test.tsx b/src/components/medications/__tests__/intake-history-list-v2.test.tsx index 315bb11fd..f42ebc513 100644 --- a/src/components/medications/__tests__/intake-history-list-v2.test.tsx +++ b/src/components/medications/__tests__/intake-history-list-v2.test.tsx @@ -4,6 +4,7 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { I18nProvider } from "@/lib/i18n/context"; import { IntakeHistoryListV2 } from "@/components/medications/intake-history-list-v2"; +import { queryKeys } from "@/lib/query-keys"; /** * v1.4.36 W4a — IntakeHistoryListV2 SSR smoke tests. @@ -62,16 +63,17 @@ function seedIntake( const limit = opts.limit ?? 25; const offset = opts.offset ?? 0; // v1.4.37 W3 — the component pins `status:"completed"` on the - // server-side query and threads it through the cache key, so the - // seed mirrors that shape verbatim. + // server-side query and threads it through the cache key. The seed + // routes through the canonical factory so the params shape stays in + // lockstep with the component's read. client.setQueryData( - [ - "medications", - medId, - "intake", - "list", - { sortBy, sortDir, limit, offset, status: "completed" }, - ], + queryKeys.medicationIntakeList(medId, { + sortBy, + sortDir, + limit, + offset, + status: "completed", + }), { events: rows, meta: { total, limit, offset } }, ); } diff --git a/src/lib/__tests__/query-keys.test.ts b/src/lib/__tests__/query-keys.test.ts index 4011311b8..ce4c9e630 100644 --- a/src/lib/__tests__/query-keys.test.ts +++ b/src/lib/__tests__/query-keys.test.ts @@ -137,10 +137,17 @@ describe("queryKeys factory", () => { offset: 0, status: "completed", }); - expect(listKey[0]).toBe("medications"); - expect(listKey[1]).toBe("med1"); - expect(listKey[2]).toBe("intake"); - expect(listKey[3]).toBe("list"); + expect(listKey).toEqual([ + "medications", + "med1", + "intake", + "list", + "takenAt", + "desc", + 25, + 0, + "completed", + ]); }); it("exposes withingsStatus under the withings prefix", () => { diff --git a/src/lib/query-keys.ts b/src/lib/query-keys.ts index b761cb484..d838f0455 100644 --- a/src/lib/query-keys.ts +++ b/src/lib/query-keys.ts @@ -104,7 +104,18 @@ export const queryKeys = { offset: number; status: string; }, - ) => ["medications", medicationId, "intake", "list", params] as const, + ) => + [ + "medications", + medicationId, + "intake", + "list", + params.sortBy, + params.sortDir, + params.limit, + params.offset, + params.status, + ] as const, /** * v1.4.40 W-RSC — the dashboard-level compliance chart (aggregate * across every scheduled medication) was a bare `["medication-