完善报销通知与付款进度(08-01-reimbursement-notification-progress-clarity)
ci-e2e / e2e (push) Canceled after 0s
ci-minimal / check-minimal (push) Canceled after 0s

这个提交包含在:
2026-08-01 21:06:31 +08:00
父节点 ca24479a44
当前提交 aa6b9bc373
共修改 23 个文件,包含 730 行新增和 88 行删除
@@ -211,6 +211,10 @@ function buildPrisma(options = {}) {
},
receiptAttachments: options.receiptAttachments ?? defaultReceiptAttachments,
reservedEntityIds: options.reservedEntityIds ?? [],
employees: options.employees ?? [
{ id: MAKER_ID, employee_no: "FIN001", status: "active", roles: [{ role_code: "finance" }] },
{ id: REVIEWER_ID, employee_no: "MGR001", status: "active", roles: [{ role_code: "manager" }] },
],
invoice: {
linked_reimbursement_id: REIMBURSEMENT_ID,
status: "bound",
@@ -421,6 +425,9 @@ function buildPrisma(options = {}) {
auditLog: {
create: vi.fn(async () => ({ id: "audit-1" })),
},
employee: {
findMany: vi.fn(async () => state.employees.map((employee) => ({ ...employee }))),
},
$queryRaw: vi.fn(async () => [{ id: BATCH_ID }]),
};
@@ -657,6 +664,33 @@ describe("payment batch reimbursement routes", () => {
expect(response.statusCode).toBe(409);
expect(response.json().error.details.review).toBe("maker_checker_conflict");
expect(createNotificationsWithRecordsMock).not.toHaveBeenCalled();
expect(flushNotificationDispatchTasksMock).not.toHaveBeenCalled();
await app.close();
});
it("rejects repeated payment review without creating another responsibility notification", async () => {
const { app } = await buildApp({
actor: {
id: REVIEWER_ID,
department_id: "dept-1",
permissionCodes: ["payment.batch.review"],
roleCodes: ["manager"],
},
});
const response = await app.inject({
method: "POST",
url: `/api/payment-batches/${BATCH_ID}/review`,
headers: { authorization: "Bearer test" },
payload: {},
});
expect(response.statusCode).toBe(409);
expect(response.json().error.details.review).toBe("batch_not_reviewable");
expect(createNotificationsWithRecordsMock).not.toHaveBeenCalled();
expect(flushNotificationDispatchTasksMock).not.toHaveBeenCalled();
await app.close();
});
@@ -756,6 +790,9 @@ describe("payment batch reimbursement routes", () => {
});
it("allows one manager review for a high-amount batch and does not require a second reviewer", async () => {
createNotificationsWithRecordsMock.mockResolvedValueOnce([
{ id: "notif-execute-1", recipient_employee_id: MAKER_ID },
]);
const { app } = await buildApp({
actor: {
id: REVIEWER_ID,
@@ -783,7 +820,7 @@ describe("payment batch reimbursement routes", () => {
payload: { comment: "已核对高额付款对象和金额" },
});
expect(response.statusCode).toBe(200);
expect(response.statusCode, response.body).toBe(200);
expect(response.json().data.item).toMatchObject({
status: "reviewed",
highRisk: true,
@@ -794,6 +831,65 @@ describe("payment batch reimbursement routes", () => {
reviewerPermission: "payment.batch.review",
},
});
expect(createNotificationsWithRecordsMock).toHaveBeenCalledWith(
expect.any(Object),
expect.objectContaining({
recipientEmployeeIds: [MAKER_ID],
type: "payment_batch.execution_requested",
targetType: "payment_batch",
targetId: BATCH_ID,
}),
);
expect(flushNotificationDispatchTasksMock).toHaveBeenCalledWith(
expect.objectContaining({
tasks: [expect.objectContaining({
type: "payment_batch.execution_requested",
targetPath: `/payment-batches?id=${BATCH_ID}`,
})],
}),
);
await app.close();
});
it("falls back to another active finance payment manager after review when the maker is unavailable", async () => {
const fallbackFinanceId = "dddddddd-dddd-4ddd-8ddd-dddddddddddd";
createNotificationsWithRecordsMock.mockResolvedValueOnce([
{ id: "notif-execute-fallback", recipient_employee_id: fallbackFinanceId },
]);
const { app } = await buildApp({
actor: {
id: REVIEWER_ID,
department_id: "dept-1",
permissionCodes: ["payment.batch.review"],
roleCodes: ["manager"],
},
batch: {
status: "draft",
reviewed_at: null,
reviewed_by: null,
},
employees: [
{ id: fallbackFinanceId, employee_no: "FIN002", status: "active", roles: [{ role_code: "finance" }] },
{ id: REVIEWER_ID, employee_no: "MGR001", status: "active", roles: [{ role_code: "manager" }] },
],
});
const response = await app.inject({
method: "POST",
url: `/api/payment-batches/${BATCH_ID}/review`,
headers: { authorization: "Bearer test" },
payload: {},
});
expect(response.statusCode, response.body).toBe(200);
expect(createNotificationsWithRecordsMock).toHaveBeenCalledWith(
expect.any(Object),
expect.objectContaining({
recipientEmployeeIds: [fallbackFinanceId],
type: "payment_batch.execution_requested",
}),
);
await app.close();
});
@@ -898,6 +994,98 @@ describe("payment batch reimbursement routes", () => {
await app.close();
});
it("notifies active non-maker payment reviewers after creating a reimbursement batch", async () => {
createNotificationsWithRecordsMock.mockResolvedValueOnce([
{ id: "notif-review-1", recipient_employee_id: REVIEWER_ID },
]);
const { app, tx } = await buildApp();
const response = await app.inject({
method: "POST",
url: "/api/payment-batches",
headers: { authorization: "Bearer test" },
payload: {
entityType: "reimbursement",
name: "本周付款",
entityIds: [REIMBURSEMENT_ID],
},
});
expect(response.statusCode).toBe(201);
expect(createNotificationsWithRecordsMock).toHaveBeenCalledWith(
tx,
expect.objectContaining({
recipientEmployeeIds: [REVIEWER_ID],
type: "payment_batch.review_requested",
targetType: "payment_batch",
targetId: BATCH_ID,
}),
);
expect(flushNotificationDispatchTasksMock).toHaveBeenCalledWith(
expect.objectContaining({
tasks: [expect.objectContaining({
type: "payment_batch.review_requested",
targetPath: `/payment-batches?id=${BATCH_ID}`,
})],
}),
);
await app.close();
});
it("creates no payment review notification when no eligible non-maker reviewer exists", async () => {
const { app } = await buildApp({
employees: [
{ id: ACTOR_ID, employee_no: "FIN001", status: "active", roles: [{ role_code: "finance" }] },
],
});
const response = await app.inject({
method: "POST",
url: "/api/payment-batches",
headers: { authorization: "Bearer test" },
payload: {
entityType: "reimbursement",
name: "无人复核批次",
entityIds: [REIMBURSEMENT_ID],
},
});
expect(response.statusCode).toBe(201);
expect(createNotificationsWithRecordsMock).toHaveBeenCalledWith(
expect.any(Object),
expect.objectContaining({ recipientEmployeeIds: [] }),
);
expect(flushNotificationDispatchTasksMock).not.toHaveBeenCalled();
await app.close();
});
it("keeps a created batch when payment review notification delivery fails", async () => {
createNotificationsWithRecordsMock.mockResolvedValueOnce([
{ id: "notif-review-failed", recipient_employee_id: REVIEWER_ID },
]);
flushNotificationDispatchTasksMock.mockRejectedValueOnce(new Error("synthetic dispatch failure"));
const { app, state } = await buildApp();
const response = await app.inject({
method: "POST",
url: "/api/payment-batches",
headers: { authorization: "Bearer test" },
payload: {
entityType: "reimbursement",
name: "投递失败不回滚",
entityIds: [REIMBURSEMENT_ID],
},
});
expect(response.statusCode).toBe(201);
expect(state.batch.status).toBe("draft");
expect(state.batch.items).toHaveLength(1);
await app.close();
});
it("adds a non-identifying random suffix to concurrent-style batch numbers", async () => {
const { app, tx } = await buildApp();
const payload = {
@@ -322,7 +322,7 @@ describe("GET /api/reimbursements/:id detail enhancements", () => {
expect.objectContaining({ key: "submitted", state: "completed", actorName: "李四", result: "已提交" }),
expect.objectContaining({ key: "approval_manager-task", label: "主管审批", state: "completed", actorName: "王经理", result: "通过" }),
expect.objectContaining({ key: "approval_finance-task", label: "财务审批", state: "current", actorName: "财务专员", result: "处理中" }),
expect.objectContaining({ key: "payment_batch_review", state: "pending", actorName: null, detail: "待财务创建付款批次" }),
expect.objectContaining({ key: "payment_batch_review", state: "pending", actorName: null, detail: "待财务安排付款" }),
expect.objectContaining({ key: "payment_and_receipt", state: "pending", actorName: null }),
]);
@@ -598,11 +598,11 @@ describe("GET /api/reimbursements/:id detail enhancements", () => {
});
it.each([
["draft", "current", "pending", "待所在付款批次复核通过"],
["reviewed", "completed", "current", "所在付款批次已复核,待执行付款"],
["executed", "completed", "completed", "付款与回单已留存"],
["failed", "completed", "exception", "所在付款批次执行失败,待财务重新处理"],
["cancelled", "exception", "pending", "待财务重新创建付款批次"],
["draft", "current", "pending", "待付款复核通过后由财务登记,非审批环节"],
["reviewed", "completed", "current", "待财务完成付款并登记回单,非审批环节"],
["executed", "completed", "completed", "付款和回单已留存"],
["failed", "completed", "exception", "付款失败,待财务重新处理,非审批环节"],
["cancelled", "exception", "pending", "待财务重新安排付款,非审批环节"],
])("maps %s payment batch without exposing a batch link to ordinary applicants", async (status, reviewState, paymentState, detail) => {
const paymentBatchItem = {
id: "batch-item-1",
@@ -670,7 +670,7 @@ describe("GET /api/reimbursements/:id detail enhancements", () => {
});
expect(response.statusCode).toBe(200);
expect(response.json().data.processingProgress.stages[3]).toMatchObject({
detail: "所在付款批次待非制单人复核",
detail: "待非制单人复核付款",
actorName: null,
targetHref: "/payment-batches?id=batch-1",
});
@@ -691,8 +691,8 @@ describe("GET /api/reimbursements/:id detail enhancements", () => {
expect(response.json().data.processingProgress.stages[3]).toMatchObject({
state: "current",
actorName: null,
result: "待建批次",
detail: "待财务创建付款批次",
result: "待安排",
detail: "待财务安排付款",
});
await app.close();