mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 20:42:43 +00:00
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.
This commit is contained in:
1 parent
4993352cc9
commit
a7bdf14a4e
2 files changed
+9
-3
No files matched your search
@@ -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,
|
||||
});
|
||||
|
||||
@@ -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" });
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user