Support paid flow states, freeflow pay actions, and clean pending nodes

This commit is contained in:
gitea committed 2026-09-14 17:34:35 +08:00
1 parent d5f68ea2f3
commit 6c6b3034a0
3 files changed
+239 -81

No files matched your search

+91 -2
View File
@@ -18,7 +18,9 @@ import {
getHoseFlow,
getHoseOpenFlow,
getHoseCloseFlow,
alignApprovalRunsWithHoseFlow
alignApprovalRunsWithHoseFlow,
formatAiDecision,
formatHumanOpinionLines
} from "./flow.js";
import {
searchCloseBacklogs,
@@ -910,6 +912,93 @@ describe("Hose Flow Domain", () => {
expect(r2.eHumanComment).toBe("上级主管(张舒):当前审核节点");
expect(r2.auditDrift).toBe(false);
});
test("handles completed paid flow: resolves through, deduplicates opinions, omits cc, and clears pending", () => {
const runs = [
{
id: "run-paid",
sourceDocumentSN: "B26002324",
taskMode: "assisted",
createdAt: 10000,
status: "completed",
manualApprovalStatus: "APPROVED",
result: { decision: "EXEMPT_APPROVE" }
}
] as any[];
const flow = {
state: "已支付",
rawState: "paid",
history: [
{ time: 8000, action: "提交送审", rawAction: "freeflow.submit", operator: { name: "高思琦" } },
{ time: 11000, action: "审批同意", rawAction: "freeflow.agree", nodeName: "上级主管", operator: { name: "张舒" } },
{ time: 12000, action: "审批同意", rawAction: "freeflow.agree", nodeName: "财务助理", operator: { name: "熊雪倩" } },
{ time: 13000, action: "自动同意", rawAction: "freeflow.autoAgree", nodeName: "部门主管", operator: { name: "张舒" } },
{ time: 14000, action: "发表评论", rawAction: "freeflow.comment", comment: "ETA2026年家庭日费用报销", operator: { name: "高思琦" } },
{ time: 14500, action: "发表评论", rawAction: "freeflow.comment", comment: "ETA2026年家庭日费用报销", operator: { name: "高思琦" } },
{ time: 15000, action: "支付完成", rawAction: "freeflow.pay", operator: { name: "高思琦" } },
{ time: 16000, action: "抄送通知", rawAction: "freeflow.carbonCopy", operator: { name: "高思琦" } }
],
pending: []
} as any;
const aligned = alignApprovalRunsWithHoseFlow(runs, flow);
const r = aligned.get("run-paid")!;
expect(r.aiDecision).toBe("备注通过");
expect(r.eHumanAction).toBe("通过");
expect(r.auditDrift).toBe(false);
// Verify opinions:
// 1. Agree nodes present
expect(r.eHumanComment).toContain("上级主管(张舒): 同意");
expect(r.eHumanComment).toContain("财务助理(熊雪倩): 同意");
expect(r.eHumanComment).toContain("部门主管(张舒): 自动同意");
// 2. Duplicate comment deduplicated (appears only once)
const matches = r.eHumanComment.match(/高思琦: ETA2026年家庭日费用报销/g);
expect(matches?.length).toBe(1);
// 3. freeflow.pay mapped to 支付完成
expect(r.eHumanComment).toContain("高思琦: 支付完成");
// 4. freeflow.carbonCopy omitted
expect(r.eHumanComment).not.toContain("freeflow.carbonCopy");
expect(r.eHumanComment).not.toContain("抄送通知");
// 5. No pending node appended
expect(r.eHumanComment).not.toContain("当前审核节点");
});
});
describe("Pending and end-state handling", () => {
test("parseHoseOpenPending filters out CANCELED / PROCESSED nodes even with logId -1", () => {
const allLogs = [
{ id: "1", logId: -1, state: "CANCELED", nodeName: "已取消节点", ownerId: "user-1" },
{ id: "2", logId: -1, state: "APPROVING", nodeName: "当前待审节点", ownerId: "user-2" }
] as any[];
const pending = parseHoseOpenPending(allLogs);
expect(pending.length).toBe(1);
expect(pending[0]?.name).toBe("当前待审节点");
});
test("parseHoseOpenComposite clears pending nodes when flow is paid or completed", () => {
const composite = {
flowDetails: {
id: "flow-1",
state: "paid",
logs: []
},
allLogs: [
{ id: "1", logId: -1, state: "APPROVING", nodeName: "残留待审节点", ownerId: "user-1" }
]
} as any;
const detail = parseHoseOpenComposite(composite);
expect(detail?.state).toBe("已支付");
expect(detail?.pending).toEqual([]);
});
test("formatAiDecision maps codes to Chinese labels", () => {
expect(formatAiDecision("EXEMPT_APPROVE")).toBe("备注通过");
expect(formatAiDecision("ERROR")).toBe("错误");
expect(formatAiDecision("APPROVE")).toBe("通过");
expect(formatAiDecision("REJECT")).toBe("驳回");
expect(formatAiDecision("REVIEW")).toBe("转交复核");
});
});
});