import { afterEach, expect, test, vi } from "vitest"; import { POST } from "../../../app/api/reviews/[orderId]/confirm-revision/route"; afterEach(() => { vi.unstubAllEnvs(); vi.unstubAllGlobals(); }); test("proxies revision confirmation and normalizes response data", async () => { vi.stubEnv("BACKEND_BASE_URL", "http://backend.test/api/v1"); const fetchMock = vi.fn().mockResolvedValue( new Response( JSON.stringify({ order_id: 101, workflow_id: "wf-101", revision_asset_id: 501, decision: "approve", status: "submitted", }), { status: 200, headers: { "content-type": "application/json", }, }, ), ); vi.stubGlobal("fetch", fetchMock); const request = new Request("http://localhost/api/reviews/101/confirm-revision", { method: "POST", headers: { "content-type": "application/json", }, body: JSON.stringify({ reviewer_id: 88, comment: "确认继续流水线", }), }); const response = await POST(request, { params: Promise.resolve({ orderId: "101" }), }); const payload = await response.json(); expect(response.status).toBe(200); expect(payload).toEqual({ mode: "proxy", data: { orderId: 101, workflowId: "wf-101", revisionAssetId: 501, decision: "approve", decisionMeta: { label: "通过", tone: "success", }, status: "submitted", }, }); });