From a7bdf14a4e267a132b1155ed067615fc7cf71f78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 10 Sep 2026 04:17:45 +0200 Subject: [PATCH] test(api): pin the pagination tiebreaker in the two route tests Both asserted the single-column `orderBy` the offset lists used to build, so they held the defect in place: a test that pins the shape a fix has to change is not evidence, it is a lock. Turned round to assert the total order, with the reason at the call site. --- .../illness/episodes/[id]/day-logs/__tests__/route.test.ts | 7 +++++-- .../[id]/__tests__/skip-snooze-history.test.ts | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/app/api/illness/episodes/[id]/day-logs/__tests__/route.test.ts b/src/app/api/illness/episodes/[id]/day-logs/__tests__/route.test.ts index 659d66159..6c2ae4d52 100644 --- a/src/app/api/illness/episodes/[id]/day-logs/__tests__/route.test.ts +++ b/src/app/api/illness/episodes/[id]/day-logs/__tests__/route.test.ts @@ -105,7 +105,10 @@ describe("GET /api/illness/episodes/{id}/day-logs — date-less list", () => { const findArgs = vi.mocked(prisma.illnessDayLog.findMany).mock.calls[0][0]; expect(findArgs).toMatchObject({ where: { episodeId: "ep-1", deletedAt: null }, - orderBy: { date: "desc" }, + // `date` is a calendar day and repeats within an episode, so the + // unique tiebreaker is what keeps `skip`-based paging from repeating + // one row and dropping another between pages. + orderBy: [{ date: "desc" }, { id: "desc" }], take: 60, skip: 0, }); @@ -126,7 +129,7 @@ describe("GET /api/illness/episodes/{id}/day-logs — date-less list", () => { const findArgs = vi.mocked(prisma.illnessDayLog.findMany).mock.calls[0][0]; expect(findArgs).toMatchObject({ - orderBy: { date: "asc" }, + orderBy: [{ date: "asc" }, { id: "asc" }], take: 10, skip: 20, }); diff --git a/src/app/api/measurement-reminders/[id]/__tests__/skip-snooze-history.test.ts b/src/app/api/measurement-reminders/[id]/__tests__/skip-snooze-history.test.ts index 8483ec1f6..ecafa0b85 100644 --- a/src/app/api/measurement-reminders/[id]/__tests__/skip-snooze-history.test.ts +++ b/src/app/api/measurement-reminders/[id]/__tests__/skip-snooze-history.test.ts @@ -303,7 +303,10 @@ describe("GET /api/measurement-reminders/[id]/history", () => { }); expect(body.data.meta).toEqual({ total: 2, limit: 10, offset: 0 }); const query = eventFindManyMock.mock.calls[0][0]; - expect(query.orderBy).toEqual({ occurredAt: "desc" }); + // The trailing `id` is the unique tiebreaker: several reminder events + // can share one `occurredAt`, and offset paging over a tied key repeats + // and drops rows between pages. + expect(query.orderBy).toEqual([{ occurredAt: "desc" }, { id: "desc" }]); expect(query.where).toEqual({ reminderId: "r1", userId: "u1" }); });