修正 OALAUNCH1 登录与业务流回归(05-28-oalaunch1-parallel-closeout)

这个提交包含在:
2026-05-28 16:23:56 +08:00
父节点 c8b41a4056
当前提交 c30e2b1348
共修改 9 个文件,包含 162 行新增和 53 行删除
@@ -1,8 +1,50 @@
import { devices, expect, test } from "@playwright/test";
import { createAuthenticatedApiClient, MANAGER, type E2EUser } from "./helpers/auth";
import { createSubmittedTravelRequestViaApi } from "./helpers/travel";
import { apiGetData, apiPostData, createAuthenticatedApiClient, EMPLOYEE, MANAGER, type E2EUser } from "./helpers/auth";
import { approveWorkflowTaskViaApi, waitForWorkflowTask } from "./helpers/workflow";
type LeaveTypeListResponse = {
items: Array<{ id: string; requiresAttachment: boolean }>;
};
type WorkflowSubmitResponse = {
workflowInstanceId: string;
};
function formatDate(offsetDays: number) {
const value = new Date();
value.setUTCDate(value.getUTCDate() + offsetDays);
return value.toISOString().slice(0, 10);
}
async function createSubmittedLeaveViaApi(input: { reasonPrefix: string }) {
const client = await createAuthenticatedApiClient(EMPLOYEE);
const leaveTypes = await apiGetData<LeaveTypeListResponse>(client.api, "/api/leave-types?enabled=true");
const leaveType = leaveTypes.items.find((item) => !item.requiresAttachment) ?? leaveTypes.items[0];
if (!leaveType) {
throw new Error("缺少可用于移动审批离线测试的请假类型");
}
const offset = 3600 + (Date.now() % 1200);
const startDate = formatDate(offset);
const created = await apiPostData<{ id: string }>(client.api, "/api/leave-requests", {
leaveTypeId: leaveType.id,
startDate,
endDate: startDate,
startSession: "am",
endSession: "pm",
reason: `${input.reasonPrefix}-${Date.now()}`,
});
await apiPostData<WorkflowSubmitResponse>(client.api, `/api/leave-requests/${created.id}/submit`, {});
return {
client,
leaveRequest: {
requestId: created.id,
startDate,
},
};
}
async function loginMobile(page: import("@playwright/test").Page, user: E2EUser) {
await page.goto("/login");
await page.getByTestId("login-identifier").fill(user.identifier);
@@ -62,23 +104,22 @@ test.use({
});
test("E2E 移动审批:deep link 分流 + 离线草稿重放", async ({ page }) => {
const created = await createSubmittedTravelRequestViaApi({
purposePrefix: "Playwright移动审批通过",
amount: "999.00",
const created = await createSubmittedLeaveViaApi({
reasonPrefix: "Playwright移动审批通过",
});
const managerApi = await createAuthenticatedApiClient(MANAGER);
try {
const task = await waitForWorkflowTask(managerApi.api, {
entityId: created.travelRequest.requestId,
entityType: "travel_request",
entityId: created.leaveRequest.requestId,
entityType: "leave",
});
await loginMobile(page, MANAGER);
await page.goto(`/workflow/tasks/${task.id}`);
await expectMobileApprovalDetailUrl(page, task.id);
await expect(page.getByTestId("mobile-approvals-detail")).toBeVisible({ timeout: 30_000 });
await expect(page.getByTestId("mobile-approvals-detail")).toContainText(created.travelRequest.requestNo);
await expect(page.getByTestId("mobile-approvals-detail")).toContainText("请假");
await waitForWorkflowTaskCache(page, task.id);
await page.context().setOffline(true);
@@ -98,23 +139,22 @@ test("E2E 移动审批:deep link 分流 + 离线草稿重放", async ({ page }
});
test("E2E 移动审批:离线草稿冲突态可见", async ({ page }) => {
const created = await createSubmittedTravelRequestViaApi({
purposePrefix: "Playwright移动审批冲突",
amount: "1099.00",
const created = await createSubmittedLeaveViaApi({
reasonPrefix: "Playwright移动审批冲突",
});
const managerApi = await createAuthenticatedApiClient(MANAGER);
try {
const task = await waitForWorkflowTask(managerApi.api, {
entityId: created.travelRequest.requestId,
entityType: "travel_request",
entityId: created.leaveRequest.requestId,
entityType: "leave",
});
await loginMobile(page, MANAGER);
await page.goto(`/workflow/tasks/${task.id}`);
await expectMobileApprovalDetailUrl(page, task.id);
await expect(page.getByTestId("mobile-approvals-detail")).toBeVisible({ timeout: 30_000 });
await expect(page.getByTestId("mobile-approvals-detail")).toContainText(created.travelRequest.requestNo);
await expect(page.getByTestId("mobile-approvals-detail")).toContainText("请假");
await waitForWorkflowTaskCache(page, task.id);
await page.context().setOffline(true);
@@ -523,7 +523,7 @@ test.describe("R3 权限直连审计", () => {
await expectApiStatus({ role: "employee", api: employee.api, path: "/api/notifications/deliveries", statuses: [403], note: "员工不得查看通知投递审计" });
await expectApiMutationStatus({ role: "employee", api: employee.api, path: "/api/exports/ap-operations", method: "post", data: { format: "csv" }, statuses: [403, 409], note: "员工不得导出 AP 运营数据;409 表示功能门禁关闭且未泄露数据" });
await expectApiStatus({ role: "employee", api: employee.api, path: "/api/contracts-registry", statuses: [200, 409], note: "员工合同台账只能走范围过滤或功能门禁" });
await expectApiStatus({ role: "employee", api: employee.api, path: "/api/travel-requests?mine=0&pageSize=50", statuses: [200], note: "员工差旅列表强制本人范围" });
await expectApiStatus({ role: "employee", api: employee.api, path: "/api/travel-requests?mine=0&pageSize=50", statuses: [403], note: "差旅冻结期员工不得直连差旅列表" });
const employeeInvoices = await expectApiStatus({
role: "employee",
@@ -535,22 +535,6 @@ test.describe("R3 权限直连审计", () => {
expect((employeeInvoices.body?.data as JsonObject)?.ownerScope).toBe("own");
expectArray((employeeInvoices.body?.data as JsonObject)?.items, "employee invoice items");
const employeeTravel = await expectApiStatus({
role: "employee",
api: employee.api,
path: "/api/travel-requests?mine=0&pageSize=50",
statuses: [200],
note: "员工差旅 mine=0 被服务端收敛为 mine=true",
});
const travelData = employeeTravel.body?.data as JsonObject;
expect(travelData.mine).toBe(true);
for (const item of expectArray(travelData.items, "employee travel items")) {
expect(
item.applicantEmployeeId === employee.me.id || item.submitterId === employee.me.id,
`travel request ${String(item.id)} must belong to employee scope`,
).toBe(true);
}
await expectApiStatus({ role: "manager", api: manager.api, path: "/api/ap-operations", statuses: [403, 409], note: "主管不得直连 AP" });
await expectApiStatus({ role: "manager", api: manager.api, path: "/api/ap-operations/reimbursement-ledger", statuses: [403, 409], note: "主管不得直连财务台账" });
await expectApiStatus({ role: "manager", api: manager.api, path: "/api/payment-batches", statuses: [403, 409], note: "主管不得直连付款批次" });
@@ -364,7 +364,7 @@ test.describe("R102 reimbursement main flow", () => {
await page.setViewportSize({ width: 390, height: 844 });
await page.goto("/mobile/reimbursements");
await expect(page.getByRole("heading", { name: "报销" })).toBeVisible();
await expect(page.getByRole("heading", { name: "移动报销", exact: true })).toBeVisible();
await expect(page.getByTestId("mobile-reimbursement-card")).toBeVisible();
await expect(page.getByText(formNumber)).toBeVisible();
await expect(page.getByText(reimbursementId)).toHaveCount(0);
@@ -134,6 +134,15 @@ async function mockR89Apis(page: Page) {
return;
}
if (path === "/api/auth/capabilities") {
await fulfillJson(route, {
emailDelivery: { ready: true, statusReasons: [] },
emailLoginCode: { enabled: true },
passwordReset: { enabled: true },
});
return;
}
if (path === "/api/auth/sso/providers") {
await fulfillJson(route, []);
return;
@@ -136,17 +136,17 @@ test("E2E 报销支付批次主链路:提交 -> 审批 -> 创建批次 -> 复
await page.goto("/payment-batches");
await expect(page).toHaveURL(/\/payment-batches/);
const createCard = page.locator(".card-std").filter({ hasText: "新建批次" }).first();
const createCard = page.getByTestId("payment-batch-create-panel");
const createBatchResponsePromise = page.waitForResponse((response) => {
const url = new URL(response.url());
return response.request().method() === "POST" && url.pathname === "/api/payment-batches" && response.ok();
});
await createCard.locator("select").nth(0).selectOption("reimbursement");
await createCard.getByPlaceholder("例如:2026Q2-财务付款批次-01").fill(batchName);
await createCard.getByPlaceholder("用逗号或换行分隔 reimbursement / travel_order ID").fill(reimbursementId);
await createCard.locator('input[type="date"]').fill(paymentDate);
await createCard.locator("select").nth(1).selectOption("bank");
await createCard.getByPlaceholder("例如 PBX").fill("R78PB");
await createCard.getByTestId("payment-batch-create-entity-type").selectOption("reimbursement");
await createCard.getByTestId("payment-batch-create-name").fill(batchName);
await createCard.getByTestId("payment-batch-create-entity-ids").fill(reimbursementId);
await createCard.getByTestId("payment-batch-create-payment-date").fill(paymentDate);
await createCard.getByTestId("payment-batch-create-payment-channel").selectOption("bank");
await createCard.getByTestId("payment-batch-create-voucher-prefix").fill("R78PB");
await createCard.getByRole("button", { name: "创建批次" }).click();
const createBatchPayload = (await (await createBatchResponsePromise).json()) as {
@@ -157,10 +157,10 @@ test("E2E 报销支付批次主链路:提交 -> 审批 -> 创建批次 -> 复
throw new Error(`创建支付批次后未返回 id: ${JSON.stringify(createBatchPayload)}`);
}
await page.goto(`/payment-batches?id=${batchId}`);
const batchDetailCard = page.locator(".card-std").filter({ hasText: batchName }).filter({ hasText: "复核进度:" }).last();
const batchDetailCard = page.getByTestId("payment-batch-detail-panel").filter({ hasText: batchName });
await expect(batchDetailCard).toBeVisible();
await expect(batchDetailCard).toContainText("状态:草稿");
await expect(batchDetailCard).toContainText("复核进度:0/1");
await expect(batchDetailCard).toContainText("草稿");
await expect(batchDetailCard).toContainText("0/1");
await logout(page, FINANCE.name);
@@ -179,12 +179,12 @@ test("E2E 报销支付批次主链路:提交 -> 审批 -> 创建批次 -> 复
await login(page, FINANCE);
await page.goto(`/payment-batches?id=${batchId}`);
const executedBatchDetailCard = page.locator(".card-std").filter({ hasText: batchName }).filter({ hasText: "复核进度:" }).last();
const executedBatchDetailCard = page.getByTestId("payment-batch-detail-panel").filter({ hasText: batchName });
await expect(executedBatchDetailCard).toBeVisible();
await expect(executedBatchDetailCard).toContainText("复核进度:1/1");
const receiptCard = page.locator(".card-std").filter({ hasText: "银行回单附件" }).first();
await expect(executedBatchDetailCard).toContainText("1/1");
const receiptCard = page.getByTestId("payment-batch-receipt-panel");
await expect(receiptCard).toBeVisible();
await receiptCard.locator('input[type="file"]').setInputFiles({
await receiptCard.getByTestId("payment-batch-receipt-file-input").setInputFiles({
name: "r78-bank-receipt.pdf",
mimeType: "application/pdf",
buffer: Buffer.from(`%PDF-1.4\npayment receipt ${marker}\n%%EOF\n`, "utf8"),
@@ -209,7 +209,7 @@ test("E2E 报销支付批次主链路:提交 -> 审批 -> 创建批次 -> 复
await expect(page.getByTestId("action-confirm-dialog")).toContainText("确认后将执行付款批次");
await page.getByTestId("action-confirm-submit").click();
await executeBatchResponsePromise;
await expect(executedBatchDetailCard).toContainText("状态:已执行", { timeout: 30_000 });
await expect(executedBatchDetailCard).toContainText("已执行", { timeout: 30_000 });
await page.goto(`/reimbursements/${reimbursementId}`);
await reimbursementDetail.assertLoaded();
@@ -243,7 +243,7 @@ test("E2E 报销支付批次主链路:提交 -> 审批 -> 创建批次 -> 复
).toBe(true);
await page.goto("/ap-operations");
await expect(page.getByRole("tab", { name: /财务台账/ })).toBeVisible();
await page.getByRole("tab", { name: /财务台账/ }).click();
await expect(page.getByTestId("finance-ledger-table")).toContainText(reimbursementDisplayCode);
await expect(page.getByTestId("finance-ledger-table")).toContainText("已付款");
await expect(page.getByRole("tab", { name: /待付款/ })).toBeVisible();