完善报销通知与付款进度(08-01-reimbursement-notification-progress-clarity)
这个提交包含在:
@@ -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 = {
|
||||
|
||||
在新工单中引用
屏蔽一个用户