R5-M1-M5 收口正式审批规则与移动反馈
这个提交包含在:
@@ -3,6 +3,8 @@ const Fastify = require("fastify");
|
||||
const { AppError } = require("../../../src/utils/AppError");
|
||||
const workflowRoutes = require("../../../src/routes/workflow");
|
||||
|
||||
const APPLICANT_ID = "55555555-5555-4555-8555-555555555555";
|
||||
|
||||
function buildTaskRow() {
|
||||
return {
|
||||
id: "11111111-1111-4111-8111-111111111111",
|
||||
@@ -51,6 +53,39 @@ function buildTx({ entityType, targetRoleCode = "manager", transferCount = 0 })
|
||||
employee: {
|
||||
findUnique: vi.fn().mockResolvedValue(buildTarget(targetRoleCode)),
|
||||
},
|
||||
reimbursementForm: {
|
||||
findUnique: vi.fn().mockResolvedValue({
|
||||
id: "33333333-3333-4333-8333-333333333333",
|
||||
owner_id: APPLICANT_ID,
|
||||
submitter_id: APPLICANT_ID,
|
||||
owner: { id: APPLICANT_ID, name: "申请人" },
|
||||
}),
|
||||
},
|
||||
leaveRequest: {
|
||||
findUnique: vi.fn().mockResolvedValue({
|
||||
id: "33333333-3333-4333-8333-333333333333",
|
||||
owner_id: APPLICANT_ID,
|
||||
owner: { id: APPLICANT_ID, name: "申请人" },
|
||||
}),
|
||||
},
|
||||
purchaseRequest: {
|
||||
findUnique: vi.fn().mockResolvedValue({
|
||||
id: "33333333-3333-4333-8333-333333333333",
|
||||
request_no: "CG-TEST",
|
||||
applicant_id: APPLICANT_ID,
|
||||
submitter_id: APPLICANT_ID,
|
||||
applicant: { id: APPLICANT_ID, name: "申请人" },
|
||||
}),
|
||||
},
|
||||
travelRequest: {
|
||||
findUnique: vi.fn().mockResolvedValue({
|
||||
id: "33333333-3333-4333-8333-333333333333",
|
||||
request_no: "CL-TEST",
|
||||
applicant_employee_id: APPLICANT_ID,
|
||||
submitter_id: APPLICANT_ID,
|
||||
applicant: { id: APPLICANT_ID, name: "申请人" },
|
||||
}),
|
||||
},
|
||||
workflowTask: {
|
||||
update: vi.fn().mockResolvedValue({ id: "11111111-1111-4111-8111-111111111111" }),
|
||||
},
|
||||
@@ -132,7 +167,7 @@ describe("workflow transfer route", () => {
|
||||
prisma: buildPrisma(tx),
|
||||
employee: {
|
||||
id: "actor-1",
|
||||
roleCodes: [],
|
||||
roleCodes: ["manager"],
|
||||
permissionCodes: ["expense.transfer"],
|
||||
},
|
||||
});
|
||||
@@ -188,7 +223,7 @@ describe("workflow transfer route", () => {
|
||||
prisma: buildPrisma(tx),
|
||||
employee: {
|
||||
id: "actor-1",
|
||||
roleCodes: [],
|
||||
roleCodes: ["manager"],
|
||||
permissionCodes: ["expense.transfer"],
|
||||
},
|
||||
});
|
||||
@@ -217,13 +252,80 @@ describe("workflow transfer route", () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
it("does not treat admin-only target as a business approver", async () => {
|
||||
const tx = buildTx({ entityType: "reimbursement", targetRoleCode: "admin" });
|
||||
const app = await buildApp({
|
||||
prisma: buildPrisma(tx),
|
||||
employee: {
|
||||
id: "actor-1",
|
||||
roleCodes: ["manager"],
|
||||
permissionCodes: ["expense.transfer"],
|
||||
},
|
||||
});
|
||||
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: `/api/workflow/tasks/${buildTaskRow().id}/transfer`,
|
||||
headers: { authorization: "Bearer test" },
|
||||
payload: {
|
||||
toApproverId: "44444444-4444-4444-8444-444444444444",
|
||||
reason: "当前事项需转交对应审批人继续处理,请及时跟进。",
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(409);
|
||||
expect(response.json().error.details).toEqual(
|
||||
expect.objectContaining({
|
||||
toApproverId: "target_not_approver",
|
||||
}),
|
||||
);
|
||||
expect(tx.workflowTask.update).not.toHaveBeenCalled();
|
||||
|
||||
await app.close();
|
||||
});
|
||||
|
||||
it("rejects transfer to the applicant", async () => {
|
||||
const tx = buildTx({ entityType: "leave", targetRoleCode: "manager" });
|
||||
const app = await buildApp({
|
||||
prisma: buildPrisma(tx),
|
||||
employee: {
|
||||
id: "actor-1",
|
||||
roleCodes: ["manager"],
|
||||
permissionCodes: ["expense.transfer"],
|
||||
},
|
||||
});
|
||||
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: `/api/workflow/tasks/${buildTaskRow().id}/transfer`,
|
||||
headers: { authorization: "Bearer test" },
|
||||
payload: {
|
||||
toApproverId: APPLICANT_ID,
|
||||
reason: "当前事项需转交对应审批人继续处理,请及时跟进。",
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(409);
|
||||
expect(response.json().error).toEqual(
|
||||
expect.objectContaining({
|
||||
code: "VALID_001",
|
||||
details: expect.objectContaining({
|
||||
workflow: "self_approval_not_allowed",
|
||||
}),
|
||||
}),
|
||||
);
|
||||
expect(tx.workflowTask.update).not.toHaveBeenCalled();
|
||||
|
||||
await app.close();
|
||||
});
|
||||
|
||||
it("returns WORKFLOW_003 when transfer chain exceeds limit", async () => {
|
||||
const tx = buildTx({ entityType: "leave", transferCount: 3 });
|
||||
const app = await buildApp({
|
||||
prisma: buildPrisma(tx),
|
||||
employee: {
|
||||
id: "actor-1",
|
||||
roleCodes: [],
|
||||
roleCodes: ["manager"],
|
||||
permissionCodes: ["expense.transfer"],
|
||||
},
|
||||
});
|
||||
|
||||
在新工单中引用
屏蔽一个用户