diff --git a/modules/gitea/test/pages.test.ts b/modules/gitea/test/pages.test.ts new file mode 100644 index 0000000..6e6d964 --- /dev/null +++ b/modules/gitea/test/pages.test.ts @@ -0,0 +1,24 @@ +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { createServer } from "node:http"; +import { GiteaClient } from "../client.ts"; + +test("every page of a pull request's files is read, though the forge caps a page at fifty", async () => { + const total = 59; + const server = createServer((req, res) => { + const url = new URL(req.url ?? "", "http://x"); + const page = Number(url.searchParams.get("page") ?? "1"); + const start = (page - 1) * 50; + const files = Array.from({ length: Math.max(0, Math.min(50, total - start)) }, (_, i) => ({ filename: `modules/m${start + i}/x` })); + res.setHeader("content-type", "application/json"); + res.end(JSON.stringify(files)); + }); + await new Promise((r) => server.listen(0, r)); + const port = (server.address() as any).port; + const client = new GiteaClient(`http://127.0.0.1:${port}`, "t"); + const got = await client.listPullFiles("novox", "mesh-catalog", 60); + server.close(); + assert.equal(got.paths.length, total); + assert.equal(got.truncated, false); + assert.equal(new Set(got.paths).size, total); +});