import { describe, expect, it, vi } from "vitest"; import { fetchCollection } from "../src/client/api-client.js"; describe("API response validation", () => { it("rejects a successful HTTP response with an unknown schema", async () => { vi.stubGlobal( "fetch", vi.fn(() => Promise.resolve( new Response(JSON.stringify({ schema_version: 2 }), { status: 200, headers: { "Content-Type": "application/json" }, }), ), ), ); await expect(fetchCollection()).rejects.toMatchObject({ code: "invalid_response" }); }); it("uses the server error instead of guessing a partial schema", async () => { vi.stubGlobal( "fetch", vi.fn(() => Promise.resolve( new Response( JSON.stringify({ error: { code: "unsupported_review_schema", message: "reviewer 与 JSON schema 不匹配。", }, }), { status: 409, headers: { "Content-Type": "application/json" } }, ), ), ), ); await expect(fetchCollection()).rejects.toMatchObject({ code: "unsupported_review_schema", message: "reviewer 与 JSON schema 不匹配。", }); }); });