test(personal-records): coverage for limit clamp + default value

Update existing call-shape assertions to include the new `take: 100`
default and add three cases for the W10 pagination contract:
  - explicit `?limit=25` passes through verbatim
  - `?limit=999999` clamps to the project-wide ceiling (500)
  - garbage `?limit=abc` falls back to the default without 400-ing
This commit is contained in:
Marc-André Bombeck committed 2026-05-14 16:54:35 +02:00
1 parent a2bcbe90ba
commit 3dff9345d2
1 file changed
+38
@@ -65,6 +65,7 @@ describe("GET /api/personal-records", () => {
expect(prisma.personalRecord.findMany).toHaveBeenCalledWith({
where: { userId: "user-1" },
orderBy: { achievedAt: "desc" },
take: 100,
});
});
@@ -77,6 +78,7 @@ describe("GET /api/personal-records", () => {
expect(prisma.personalRecord.findMany).toHaveBeenCalledWith({
where: { userId: "user-1", metricType: "VO2_MAX" },
orderBy: { achievedAt: "desc" },
take: 100,
});
});
@@ -89,6 +91,42 @@ describe("GET /api/personal-records", () => {
expect(prisma.personalRecord.findMany).toHaveBeenCalledWith({
where: { userId: "user-1" },
orderBy: { achievedAt: "desc" },
take: 100,
});
});
it("honours an explicit ?limit param", async () => {
vi.mocked(getSession).mockResolvedValue(SESSION_OK as never);
const res = await GET(req("http://localhost/api/personal-records?limit=25"));
expect(res.status).toBe(200);
expect(prisma.personalRecord.findMany).toHaveBeenCalledWith({
where: { userId: "user-1" },
orderBy: { achievedAt: "desc" },
take: 25,
});
});
it("clamps ?limit to the project-wide ceiling of 500", async () => {
vi.mocked(getSession).mockResolvedValue(SESSION_OK as never);
const res = await GET(
req("http://localhost/api/personal-records?limit=999999"),
);
expect(res.status).toBe(200);
expect(prisma.personalRecord.findMany).toHaveBeenCalledWith({
where: { userId: "user-1" },
orderBy: { achievedAt: "desc" },
take: 500,
});
});
it("falls back to default on garbage ?limit (defence-in-depth)", async () => {
vi.mocked(getSession).mockResolvedValue(SESSION_OK as never);
const res = await GET(req("http://localhost/api/personal-records?limit=abc"));
expect(res.status).toBe(200);
expect(prisma.personalRecord.findMany).toHaveBeenCalledWith({
where: { userId: "user-1" },
orderBy: { achievedAt: "desc" },
take: 100,
});
});