feat(G2-1,G2-2,G2-3): 扩展预算编号与工作流跨域桥接

这个提交包含在:
2026-03-07 18:59:44 +08:00
父节点 09b6f4fbb0
当前提交 52558f22c3
共修改 12 个文件,包含 1211 行新增和 175 行删除
@@ -0,0 +1,77 @@
const {
resolveBudgetScope,
resolveBudgetScopeType,
selectBudgetPoolCandidate,
} = require("../../src/services/budgetPool");
describe("budgetPool service", () => {
it("resolves cost center scope with legal entity", () => {
expect(
resolveBudgetScope({
legalEntityId: "le-1",
costCenterId: "cc-1",
}),
).toEqual({
scopeType: "cost_center_scoped",
departmentId: null,
legalEntityId: "le-1",
costCenterId: "cc-1",
});
});
it("rejects mixed department and master-data dimensions", () => {
expect(() =>
resolveBudgetScope({
departmentId: "dept-1",
legalEntityId: "le-1",
}),
).toThrow(/参数校验失败/);
});
it("prefers cost center budget over department and global budgets", () => {
const selected = selectBudgetPoolCandidate(
[
{ id: "global-1", department_id: null, legal_entity_id: null, cost_center_id: null },
{ id: "dept-1", department_id: "dept-a", legal_entity_id: null, cost_center_id: null },
{ id: "scope-1", department_id: null, legal_entity_id: "le-1", cost_center_id: "cc-1" },
],
{
departmentId: "dept-a",
legalEntityId: "le-1",
costCenterId: "cc-1",
},
);
expect(selected?.id).toBe("scope-1");
expect(resolveBudgetScopeType(selected)).toBe("cost_center_scoped");
});
it("falls back to legacy department budget when no scoped budget exists", () => {
const selected = selectBudgetPoolCandidate(
[
{ id: "global-1", department_id: null, legal_entity_id: null, cost_center_id: null },
{ id: "dept-1", department_id: "dept-a", legal_entity_id: null, cost_center_id: null },
],
{
departmentId: "dept-a",
},
);
expect(selected?.id).toBe("dept-1");
});
it("throws when same-priority pools are ambiguous", () => {
expect(() =>
selectBudgetPoolCandidate(
[
{ id: "scope-1", department_id: null, legal_entity_id: "le-1", cost_center_id: "cc-1" },
{ id: "scope-2", department_id: null, legal_entity_id: "le-1", cost_center_id: "cc-1" },
],
{
legalEntityId: "le-1",
costCenterId: "cc-1",
},
),
).toThrow(/参数校验失败/);
});
});