test(P22PROD1-5): 差旅支付与对账E2E补齐及稳态修复
这个提交包含在:
@@ -0,0 +1,49 @@
|
||||
import type { APIRequestContext } from "@playwright/test";
|
||||
import { apiGetData, apiPostData } from "./auth";
|
||||
|
||||
type WorkflowTaskSummary = {
|
||||
id: string;
|
||||
workflowInstance: {
|
||||
entityType: string;
|
||||
entityId: string;
|
||||
} | null;
|
||||
};
|
||||
|
||||
type WorkflowTaskListResponse = {
|
||||
items: WorkflowTaskSummary[];
|
||||
};
|
||||
|
||||
function sleep(ms: number) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
export async function waitForWorkflowTask(api: APIRequestContext, input: {
|
||||
entityId: string;
|
||||
entityType: string;
|
||||
attempts?: number;
|
||||
intervalMs?: number;
|
||||
}) {
|
||||
const attempts = input.attempts ?? 20;
|
||||
const intervalMs = input.intervalMs ?? 1000;
|
||||
|
||||
for (let index = 0; index < attempts; index += 1) {
|
||||
const response = await apiGetData<WorkflowTaskListResponse>(api, "/api/workflow/tasks?status=pending&page=1&pageSize=50");
|
||||
const matched = response.items.find(
|
||||
(item) => item.workflowInstance?.entityType === input.entityType && item.workflowInstance.entityId === input.entityId,
|
||||
);
|
||||
if (matched) {
|
||||
return matched;
|
||||
}
|
||||
await sleep(intervalMs);
|
||||
}
|
||||
|
||||
throw new Error(`未在待办列表中找到 ${input.entityType}:${input.entityId}`);
|
||||
}
|
||||
|
||||
export async function approveWorkflowTaskViaApi(api: APIRequestContext, taskId: string) {
|
||||
return apiPostData<Record<string, unknown>>(api, `/api/workflow/tasks/${taskId}/approve`, {});
|
||||
}
|
||||
|
||||
export async function rejectWorkflowTaskViaApi(api: APIRequestContext, taskId: string, comment: string) {
|
||||
return apiPostData<Record<string, unknown>>(api, `/api/workflow/tasks/${taskId}/reject`, { comment });
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户