feat(datalink,platform): add ledger math audit, continuity check, and in-line declarative batch update

This commit is contained in:
gitea committed 2026-10-14 22:25:48 +08:00
1 parent d3f7d3efbc
commit cd0aa2bf41
8 files changed
+984 -26

No files matched your search

+150
View File
@@ -255,4 +255,154 @@ describe("CLI - platform 命令与 record 动作", () => {
expect(res.stdout).toContain("Dry-Run 预览");
expect(editSpy).not.toHaveBeenCalled();
});
it("platform records 支持 --sum 数学核算与 --group-by 分组统计", async () => {
spies.push(spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any));
spies.push(spyOn(services, "resolvePlatform").mockResolvedValue(mockPlatform as any));
spies.push(spyOn(services, "resolveEntity").mockResolvedValue({
...mockEntity,
fields: [
{ name: "fee", label: "租赁费用", type: "money" },
{ name: "status", label: "状态", type: "text" },
],
} as any));
spies.push(
spyOn(services, "fetchAllEntityRecords").mockResolvedValue({
data: [
{ id: "1", fee: 1000, status: "A" },
{ id: "2", fee: 2000, status: "A" },
{ id: "3", fee: 3000, status: "B" },
],
total: 3,
actions: [],
components: [],
path: null,
template: null,
})
);
const res = await handlePlatformCommand(
{
area: "platform",
action: "records",
args: ["platform-1", "entity-1"],
options: { sum: "租赁费用", "group-by": "状态" },
raw: ["platform", "records", "platform-1", "entity-1", "--sum=租赁费用", "--group-by=状态"],
},
dummyRuntime
);
expect(res.exitCode).toBe(0);
expect(res.stdout).toContain("台账数学聚合核算");
expect(res.stdout).toContain("总合计 (SUM)");
expect(res.stdout).toContain("6000");
expect(res.stdout).toContain("按 [状态] 分组统计");
});
it("platform audit 支持 --check-continuous 与 --expect 基线离群诊断", async () => {
spies.push(spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any));
spies.push(spyOn(services, "resolvePlatform").mockResolvedValue(mockPlatform as any));
spies.push(spyOn(services, "resolveEntity").mockResolvedValue({
...mockEntity,
fields: [
{ name: "seq", label: "摊销序号", type: "number" },
{ name: "fee", label: "租赁费用", type: "money" },
],
} as any));
spies.push(
spyOn(services, "fetchAllEntityRecords").mockResolvedValue({
data: [
{ id: "1", seq: 1, fee: 78787.55 },
{ id: "2", seq: 3, fee: 0 },
],
total: 2,
actions: [],
components: [],
path: null,
template: null,
})
);
const res = await handlePlatformCommand(
{
area: "platform",
action: "audit",
args: ["platform-1", "entity-1"],
options: { "check-continuous": "摊销序号", expect: "租赁费用 ~= 78787.55" },
raw: ["platform", "audit", "platform-1", "entity-1", "--check-continuous=摊销序号", "--expect=租赁费用 ~= 78787.55"],
},
dummyRuntime
);
expect(res.exitCode).toBe(0);
expect(res.stdout).toContain("台账序号连续性体检");
expect(res.stdout).toContain("断层缺失期数 (MISSING)");
expect(res.stdout).toContain("缺少 [2]");
expect(res.stdout).toContain("基线离群异常核对");
expect(res.stdout).toContain("偏离差额");
});
it("platform update 支持 --where 声明式筛选与 --set 原地修改(含 --dry-run 与 --yes)", async () => {
spies.push(spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any));
spies.push(spyOn(services, "resolvePlatform").mockResolvedValue(mockPlatform as any));
spies.push(spyOn(services, "resolveEntity").mockResolvedValue({
...mockEntity,
fields: [
{ name: "fee", label: "租赁费用", type: "money" },
{ name: "status", label: "状态", type: "text" },
],
} as any));
spies.push(
spyOn(services, "fetchAllEntityRecords").mockResolvedValue({
data: [
{ id: "r-1", fee: 0, status: "PENDING" },
{ id: "r-2", fee: 78787.55, status: "DONE" },
],
total: 2,
actions: [],
components: [],
path: null,
template: null,
})
);
spies.push(
spyOn(api, "getRecordDetail").mockResolvedValue({
dataLink: { id: "r-1", active: true, fee: 0, status: "PENDING" },
})
);
const editSpy = spyOn(api, "editRecord").mockResolvedValue({ id: "r-1" } as any);
spies.push(editSpy);
// 1. Dry-run 模式测试
const dryRes = await handlePlatformCommand(
{
area: "platform",
action: "update",
args: ["platform-1", "entity-1"],
options: { where: "租赁费用 == 0", set: "租赁费用 = 78787.55", "dry-run": true },
raw: ["platform", "update", "platform-1", "entity-1", "--where=租赁费用 == 0", "--set=租赁费用 = 78787.55", "--dry-run"],
},
dummyRuntime
);
expect(dryRes.exitCode).toBe(0);
expect(dryRes.stdout).toContain("Dry-Run 预览");
expect(dryRes.stdout).toContain("r-1");
expect(editSpy).not.toHaveBeenCalled();
// 2. 真实确认执行测试 (--yes)
const execRes = await handlePlatformCommand(
{
area: "platform",
action: "update",
args: ["platform-1", "entity-1"],
options: { where: "租赁费用 == 0", set: "租赁费用 = 78787.55", yes: true },
raw: ["platform", "update", "platform-1", "entity-1", "--where=租赁费用 == 0", "--set=租赁费用 = 78787.55", "--yes"],
},
dummyRuntime
);
expect(execRes.exitCode).toBe(0);
expect(execRes.stdout).toContain("已执行");
expect(editSpy).toHaveBeenCalled();
});
});