fix: return arrays for list endpoints in test fetch mock

Prevents "agentList is not iterable" warnings in test output.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Dave
2026-03-19 16:09:02 +00:00
parent 3ced187aaa
commit 932325744c

View File

@@ -7,8 +7,14 @@ import { beforeEach, vi } from "vitest";
beforeEach(() => {
vi.stubGlobal(
"fetch",
vi.fn(() =>
Promise.resolve(new Response(JSON.stringify({}), { status: 200 })),
),
vi.fn((input: string | URL | Request) => {
const url = typeof input === "string" ? input : input.toString();
// Endpoints that return arrays need [] not {} to avoid "not iterable" errors.
const arrayEndpoints = ["/agents", "/agents/config"];
const body = arrayEndpoints.some((ep) => url.endsWith(ep))
? JSON.stringify([])
: JSON.stringify({});
return Promise.resolve(new Response(body, { status: 200 }));
}),
);
});