mock-flow-api.ts 1.68 KB
import type { Page } from '@playwright/test'

export async function mockFlowBootstrap(page: Page) {
  await page.route('**/admin/**', async (route) => {
    const url = route.request().url()

    if (url.includes('a=flow_version') && url.includes('m=mod')) {
      await route.fulfill({
        status: 200,
        contentType: 'application/json',
        body: JSON.stringify({
          code: 1,
          data: [
            {
              id: 1,
              code: 1,
              status: '1',
              note: '基线版本',
            },
          ],
        }),
      })
      return
    }

    if (url.includes('a=flow_nodes') && url.includes('m=srv')) {
      await route.fulfill({
        status: 200,
        contentType: 'application/json',
        body: JSON.stringify({
          code: 1,
          data: {
            nodes: [
              {
                id: 'start',
                text: '开始节点',
                shape: 'start',
                x: 120,
                y: 180,
              },
              {
                id: 'approve',
                text: '审批节点',
                activity: 'approval',
                shape: 'activity',
                x: 320,
                y: 180,
              },
            ],
            edges: [
              {
                source: 'start',
                target: 'approve',
                shape: 'flow-polyline-round',
                text: '提交审批',
              },
            ],
          },
        }),
      })
      return
    }

    await route.fulfill({
      status: 200,
      contentType: 'application/json',
      body: JSON.stringify({
        code: 1,
        data: {},
      }),
    })
  })
}