import { afterEach, expect, test, vi } from "vitest"; import { GET } from "../../../app/api/dashboard/workflow-lookup/route"; afterEach(() => { vi.unstubAllEnvs(); vi.unstubAllGlobals(); }); test("proxies workflow lookup items from the backend workflows list api", async () => { vi.stubEnv("BACKEND_BASE_URL", "http://backend.test/api/v1"); const fetchMock = vi.fn().mockResolvedValue( new Response( JSON.stringify({ page: 2, limit: 4, total: 7, total_pages: 2, items: [ { order_id: 3, workflow_id: "order-3", workflow_type: "MidEndPipelineWorkflow", workflow_status: "waiting_review", current_step: "review", updated_at: "2026-03-27T14:00:03Z", failure_count: 0, review_task_status: "revision_uploaded", latest_revision_asset_id: 8, latest_revision_version: 1, revision_count: 1, pending_manual_confirm: true, }, ], }), { status: 200, headers: { "content-type": "application/json", }, }, ), ); vi.stubGlobal("fetch", fetchMock); const response = await GET( new Request("http://frontend.test/api/dashboard/workflow-lookup?page=2&limit=4&status=waiting_review&query=4201"), ); const payload = await response.json(); expect(response.status).toBe(200); expect(payload).toEqual({ mode: "proxy", data: { page: 2, limit: 4, total: 7, totalPages: 2, items: [ { orderId: 3, workflowId: "order-3", workflowType: "MidEndPipelineWorkflow", status: "waiting_review", statusMeta: { label: "待审核", tone: "warning", }, currentStep: "review", currentStepLabel: "人工审核", updatedAt: "2026-03-27T14:00:03Z", }, ], }, message: "流程追踪首页当前显示真实后端最近流程。", }); expect(fetchMock).toHaveBeenCalledWith( "http://backend.test/api/v1/workflows?page=2&limit=4&status=waiting_review&query=4201", expect.any(Object), ); });