fix(suggestions): preserve one-item archived pagination
CI / validate (push) Successful in 8m20s
Release / release (push) Successful in 10m52s

This commit is contained in:
dmg
2026-09-10 16:00:02 -04:00
parent 47782b3ccc
commit eb8ef18688
4 changed files with 111 additions and 10 deletions
@@ -20,7 +20,17 @@ beforeEach(() => {
vi.stubGlobal("fetch", fetcher);
fetcher.mockImplementation(async (url: string) => {
if (url.endsWith(`/channels/${forum}`)) return Response.json({ id: forum, guild_id: guild, type: 15, available_tags: [] });
if (url.includes("/threads/archived/public")) return Response.json({ threads: [thread], has_more: true });
if (url.includes("/threads/archived/public")) {
const params = new URL(url).searchParams;
if (Number(params.get("limit")) < 2) return Response.json({ code: 50035, message: "Invalid Form Body", errors: { limit: { _errors: [{ code: "NUMBER_TYPE_MIN", message: "int value should be greater than or equal to 2." }] } } }, { status: 400 });
const newest = { ...thread, thread_metadata: { ...thread.thread_metadata, archived: true } };
const older = { ...newest, id: "100000000000000008", thread_metadata: { ...newest.thread_metadata, archive_timestamp: "2026-09-10T00:00:00.123455+00:00" } };
if (params.has("before")) {
expect(params.get("before")).toBe("2026-09-10T00:00:00.123456Z");
return Response.json({ threads: [older], has_more: false });
}
return Response.json({ threads: [newest, older], has_more: false });
}
if (url.includes("/threads/active")) return Response.json({ threads: [thread] });
if (url.endsWith(`/channels/${id}`)) return Response.json(thread);
if (url.endsWith(`/messages/${id}`)) return Response.json(message);
@@ -48,7 +58,16 @@ it("documents the nullable deleted starter and precise archived cursor", async (
expect((await response.json()).originalPost).toBeNull();
const archived = await list.GET(new Request("https://portal.example/api/suggestions?status=archived&limit=1"));
await assertResponse("/api/suggestions", "get", archived);
expect((await archived.json()).nextCursor).toBe("2026-09-10T00:00:00.123456Z");
expect(archived.status).toBe(200);
const first = await archived.json();
expect(first.items.map((item: { id: string }) => item.id)).toEqual([id]);
expect(first.nextCursor).toBe("2026-09-10T00:00:00.123456Z");
const terminal = await list.GET(new Request(`https://portal.example/api/suggestions?status=archived&limit=1&cursor=${encodeURIComponent(first.nextCursor)}`));
expect(terminal.status).toBe(200);
await assertResponse("/api/suggestions", "get", terminal);
const last = await terminal.json();
expect(last.items.map((item: { id: string }) => item.id)).toEqual(["100000000000000008"]);
expect(last.nextCursor).toBeNull();
});
it.each(routes)("documents Retry-After on $path upstream rate limits", async ({ path, route }) => {
fetcher.mockImplementation(async () => Response.json({ retry_after: 2.1 }, { status: 429 }));