R56 A1-A6:费用标准管控
这个提交包含在:
@@ -0,0 +1,134 @@
|
||||
const Fastify = require("fastify");
|
||||
|
||||
const workflowRoutes = require("../../../src/routes/workflow");
|
||||
|
||||
const TASK_ID = "11111111-1111-4111-8111-111111111111";
|
||||
const EMPLOYEE_ID = "22222222-2222-4222-8222-222222222222";
|
||||
|
||||
async function buildApp(options = {}) {
|
||||
const app = Fastify();
|
||||
const actor = options.actor ?? {
|
||||
id: EMPLOYEE_ID,
|
||||
roleCodes: [],
|
||||
permissionCodes: [],
|
||||
};
|
||||
|
||||
const prisma = {
|
||||
delegationGrant: {
|
||||
findMany: vi.fn(async () => []),
|
||||
},
|
||||
workflowTask: {
|
||||
findFirst: vi.fn(async () => ({
|
||||
id: TASK_ID,
|
||||
instance_id: "33333333-3333-4333-8333-333333333333",
|
||||
step_id: "approval_1_finance",
|
||||
step_name: "财务审批",
|
||||
assignee_id: EMPLOYEE_ID,
|
||||
assignee_role: null,
|
||||
status: "completed",
|
||||
outcome: "approved",
|
||||
comment: "已核验",
|
||||
created_at: new Date("2026-04-08T08:00:00.000Z"),
|
||||
completed_at: new Date("2026-04-08T09:00:00.000Z"),
|
||||
workflow_instance: {
|
||||
id: "33333333-3333-4333-8333-333333333333",
|
||||
entity_type: "reimbursement",
|
||||
entity_id: "44444444-4444-4444-8444-444444444444",
|
||||
current_status: "pending",
|
||||
current_step_id: "approval_1_finance",
|
||||
context_data: {
|
||||
standardViolations: [
|
||||
{
|
||||
itemId: "item-1",
|
||||
expenseTypeName: "交通费",
|
||||
amount: "180.00",
|
||||
standardName: "交通费上限",
|
||||
maxAmount: "120.00",
|
||||
exceededAmount: "60.00",
|
||||
controlMode: "warn",
|
||||
},
|
||||
],
|
||||
},
|
||||
started_at: new Date("2026-04-08T08:00:00.000Z"),
|
||||
completed_at: null,
|
||||
reimbursement_form: {
|
||||
id: "44444444-4444-4444-8444-444444444444",
|
||||
form_number: "BX-20260408-001",
|
||||
status: "reviewing",
|
||||
total_amount: "180.00",
|
||||
reimbursement_date: new Date("2026-04-08T00:00:00.000Z"),
|
||||
description: "测试报销",
|
||||
owner: {
|
||||
id: EMPLOYEE_ID,
|
||||
employee_no: "E001",
|
||||
name: "申请人",
|
||||
},
|
||||
submitter: {
|
||||
id: EMPLOYEE_ID,
|
||||
employee_no: "E001",
|
||||
name: "申请人",
|
||||
},
|
||||
items: [],
|
||||
},
|
||||
leave_request: null,
|
||||
purchase_request: null,
|
||||
travel_request: null,
|
||||
},
|
||||
})),
|
||||
findUnique: vi.fn(async () => ({
|
||||
id: TASK_ID,
|
||||
})),
|
||||
},
|
||||
workflowHistory: {
|
||||
findMany: vi.fn(async () => []),
|
||||
},
|
||||
};
|
||||
|
||||
app.decorate("prisma", prisma);
|
||||
app.decorate("config", {
|
||||
imNotifierEnabled: false,
|
||||
emailEnabled: false,
|
||||
});
|
||||
app.decorate("authenticate", async (request) => {
|
||||
request.employee = actor;
|
||||
});
|
||||
app.decorate("requirePermission", () => async (request) => {
|
||||
request.employee = actor;
|
||||
});
|
||||
app.decorate("assertEntityPermission", () => {});
|
||||
app.setErrorHandler((error, request, reply) => {
|
||||
reply.status(error.statusCode || 500).send({
|
||||
requestId: request.id,
|
||||
error: {
|
||||
code: error.code || "SYS_001",
|
||||
message: error.message,
|
||||
details: error.details ?? null,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
await app.register(workflowRoutes, { prefix: "/api" });
|
||||
return { app, prisma };
|
||||
}
|
||||
|
||||
describe("workflow task detail route", () => {
|
||||
it("returns reimbursement workflow contextData.standardViolations", async () => {
|
||||
const { app } = await buildApp();
|
||||
|
||||
const response = await app.inject({
|
||||
method: "GET",
|
||||
url: `/api/workflow/tasks/${TASK_ID}`,
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.json().data.workflowInstance.contextData.standardViolations).toEqual([
|
||||
expect.objectContaining({
|
||||
itemId: "item-1",
|
||||
controlMode: "warn",
|
||||
exceededAmount: "60.00",
|
||||
}),
|
||||
]);
|
||||
|
||||
await app.close();
|
||||
});
|
||||
});
|
||||
在新工单中引用
屏蔽一个用户