18 lines
698 B
TypeScript
18 lines
698 B
TypeScript
import { expect, test } from "bun:test";
|
|
import { createContext } from "../src/index.ts";
|
|
|
|
test("context pagination applies defaults, bounds and cursor parsing", () => {
|
|
const request = new Request("https://example.test/items?limit=500&cursor=next-1");
|
|
const ctx = createContext(request, new URL(request.url));
|
|
expect(ctx.pagination({ defaultLimit: 25, maxLimit: 100 })).toEqual({
|
|
limit: 100,
|
|
cursor: "next-1",
|
|
});
|
|
});
|
|
|
|
test("context pagination rejects invalid limits", () => {
|
|
const request = new Request("https://example.test/items?limit=-2");
|
|
const ctx = createContext(request, new URL(request.url));
|
|
expect(ctx.pagination()).toEqual({ limit: 25, cursor: undefined });
|
|
});
|