Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/mcp/src/pagination.test.ts
T
2026-07-08 16:15:37 +02:00

20 lines
759 B
TypeScript

import { describe, expect, it } from "vitest";
import { clampLimit, decodeCursor, encodeCursor } from "./pagination.js";
describe("MCP pagination", () => {
it("clamps limits to a safe page size", () => {
expect(clampLimit(undefined)).toBe(20);
expect(clampLimit(-1)).toBe(20);
expect(clampLimit(500)).toBe(50);
expect(clampLimit(12)).toBe(12);
});
it("round-trips opaque cursors and rejects invalid values", () => {
const cursor = { id: "lead_1", createdAt: "2026-07-03T10:00:00.000Z" };
expect(decodeCursor(encodeCursor(cursor))).toEqual(cursor);
expect(decodeCursor("not-a-cursor")).toBeNull();
expect(decodeCursor(Buffer.from(JSON.stringify({ id: 1, createdAt: "x" })).toString("base64url"))).toBeNull();
});
});