feat: centralize application framework primitives
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
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 });
|
||||
});
|
||||
Reference in New Issue
Block a user