feat(bill,flow): add unified bill trace and flow get diagnostic engine (Phase 2)
This commit is contained in:
1 parent
7891959853
commit
ffec604ed9
10 files changed
+970
-32
No files matched your search
@@ -0,0 +1,248 @@
|
||||
import { describe, expect, it, spyOn, afterEach } from "bun:test";
|
||||
import { handleFlowCommand } from "./flow.js";
|
||||
import { handleBillCommand } from "./bill/index.js";
|
||||
import { findCommandByArea } from "../registry.js";
|
||||
import * as sessionModule from "../../core/http/session-client.js";
|
||||
import type { CliRuntime } from "../types.js";
|
||||
import type { CorpConfig } from "../../core/config/types.js";
|
||||
|
||||
const mockCorp: CorpConfig = {
|
||||
id: "corp-test-1",
|
||||
name: "测试企业",
|
||||
baseUrl: "https://app.ekuaibao.com",
|
||||
source: "openapi",
|
||||
credentials: {
|
||||
accessToken: "mock-token",
|
||||
corpId: "corp-test-1",
|
||||
staffId: "corp-test-1:STAFF_TEST",
|
||||
},
|
||||
};
|
||||
|
||||
const mockRuntime: CliRuntime = {
|
||||
corpContext: {
|
||||
listCorps: () => [mockCorp],
|
||||
getCurrent: () => mockCorp,
|
||||
switchCorp: () => true,
|
||||
resolve: () => mockCorp,
|
||||
} as any,
|
||||
selectedCorp: mockCorp,
|
||||
jsonMode: false,
|
||||
outputOptions: {},
|
||||
};
|
||||
|
||||
describe("CLI - flow & trace 全域透视与穿透诊断命令族", () => {
|
||||
let spies: ReturnType<typeof spyOn>[] = [];
|
||||
|
||||
afterEach(() => {
|
||||
for (const spy of spies) {
|
||||
spy.mockRestore();
|
||||
}
|
||||
spies = [];
|
||||
});
|
||||
|
||||
it("registry 正确注册 flow 命令与 trace 别名", () => {
|
||||
const flowDef = findCommandByArea("flow");
|
||||
expect(flowDef).toBeDefined();
|
||||
expect(flowDef?.area).toBe("flow");
|
||||
expect(flowDef?.aliases).toContain("trace");
|
||||
|
||||
const traceDef = findCommandByArea("trace");
|
||||
expect(traceDef).toBeDefined();
|
||||
expect(traceDef?.area).toBe("flow");
|
||||
});
|
||||
|
||||
it("未选中企业时返回错误并提示切换企业", async () => {
|
||||
const res = await handleFlowCommand(
|
||||
{
|
||||
area: "flow",
|
||||
action: "get",
|
||||
args: ["ZJ-001"],
|
||||
options: {},
|
||||
raw: ["flow", "get", "ZJ-001"],
|
||||
},
|
||||
{ ...mockRuntime, selectedCorp: null }
|
||||
);
|
||||
expect(res.exitCode).toBe(1);
|
||||
expect(res.stderr).toContain("未选中企业");
|
||||
});
|
||||
|
||||
it("hose-use flow --help 输出帮助信息", async () => {
|
||||
const res = await handleFlowCommand(
|
||||
{
|
||||
area: "flow",
|
||||
action: undefined,
|
||||
args: [],
|
||||
options: { help: true },
|
||||
raw: ["flow", "--help"],
|
||||
},
|
||||
mockRuntime
|
||||
);
|
||||
expect(res.exitCode).toBe(0);
|
||||
expect(res.stdout).toContain("hose-use flow - 审批流全域透视与穿透诊断命令族");
|
||||
expect(res.stdout).toContain("hose-use flow get <单号|ID>");
|
||||
});
|
||||
|
||||
it("hose-use flow <单号> (位置参数) 自动识别并穿透诊断", async () => {
|
||||
const mockRawFlow = {
|
||||
id: "backlog-1",
|
||||
state: "APPROVING",
|
||||
flowId: {
|
||||
id: "flow-1",
|
||||
state: "APPROVING",
|
||||
form: {
|
||||
code: "ZJ-20261014-001",
|
||||
title: "转转合同付款",
|
||||
payMoney: "12500.00",
|
||||
submitterId: { id: "u1", name: "张敏" },
|
||||
expenseDepartment: { name: "财务部" },
|
||||
},
|
||||
plan: {
|
||||
nodes: [
|
||||
{ id: "n1", name: "出纳打款", state: "APPROVING", approverId: { id: "u2", name: "李出纳" } },
|
||||
],
|
||||
},
|
||||
logs: [],
|
||||
},
|
||||
};
|
||||
|
||||
const mockClient = {
|
||||
post: async () => new Response(JSON.stringify({ value: mockRawFlow })),
|
||||
} as any;
|
||||
|
||||
spies.push(spyOn(sessionModule, "createSessionClient").mockResolvedValue(mockClient));
|
||||
|
||||
const res = await handleFlowCommand(
|
||||
{
|
||||
area: "flow",
|
||||
action: "zj-20261014-001",
|
||||
args: [],
|
||||
positional: ["flow", "ZJ-20261014-001"],
|
||||
options: {},
|
||||
raw: ["flow", "ZJ-20261014-001"],
|
||||
},
|
||||
mockRuntime
|
||||
);
|
||||
|
||||
expect(res.exitCode).toBe(0);
|
||||
expect(res.stdout).toContain("单据全域穿透诊断 [ZJ-20261014-001]");
|
||||
expect(res.stdout).toContain("提报人员");
|
||||
expect(res.stdout).toContain("张敏");
|
||||
expect(res.stdout).toContain("待办处理人: 李出纳");
|
||||
expect(res.stdout).toContain("出纳打款");
|
||||
});
|
||||
|
||||
it("hose-use flow get <单号> --json 结构化输出", async () => {
|
||||
const mockRawFlow = {
|
||||
id: "backlog-2",
|
||||
state: "PAYING",
|
||||
flowId: {
|
||||
id: "flow-2",
|
||||
state: "PAYING",
|
||||
form: {
|
||||
code: "ZJ-20261014-002",
|
||||
title: "资金调拨",
|
||||
},
|
||||
plan: {
|
||||
nodes: [
|
||||
{ id: "n1", name: "出纳打款", state: "APPROVING" },
|
||||
],
|
||||
},
|
||||
logs: [],
|
||||
},
|
||||
};
|
||||
|
||||
const mockClient = {
|
||||
post: async () => new Response(JSON.stringify({ value: mockRawFlow })),
|
||||
} as any;
|
||||
|
||||
spies.push(spyOn(sessionModule, "createSessionClient").mockResolvedValue(mockClient));
|
||||
|
||||
const res = await handleFlowCommand(
|
||||
{
|
||||
area: "flow",
|
||||
action: "get",
|
||||
args: ["ZJ-20261014-002"],
|
||||
positional: ["flow", "get", "ZJ-20261014-002"],
|
||||
options: { json: true },
|
||||
raw: ["flow", "get", "ZJ-20261014-002", "--json"],
|
||||
},
|
||||
{ ...mockRuntime, jsonMode: true }
|
||||
);
|
||||
|
||||
expect(res.exitCode).toBe(0);
|
||||
const parsed = JSON.parse(res.stdout);
|
||||
expect(parsed.found).toBe(true);
|
||||
expect(parsed.billCode).toBe("ZJ-20261014-002");
|
||||
expect(parsed.diagnostic.stage).toBe("PAYING");
|
||||
expect(parsed.diagnostic.canApprove).toBe(false);
|
||||
expect(parsed.diagnostic.advice).toContain("400");
|
||||
});
|
||||
|
||||
it("hose-use bill trace <单号> 平滑集成并完成诊断", async () => {
|
||||
const mockRawFlow = {
|
||||
id: "backlog-3",
|
||||
state: "APPROVING",
|
||||
flowId: {
|
||||
id: "flow-3",
|
||||
state: "APPROVING",
|
||||
form: {
|
||||
code: "BX-999",
|
||||
title: "日常差旅报销",
|
||||
},
|
||||
plan: {
|
||||
nodes: [
|
||||
{ id: "n1", name: "总监审批", state: "APPROVING" },
|
||||
],
|
||||
},
|
||||
logs: [],
|
||||
},
|
||||
};
|
||||
|
||||
const mockClient = {
|
||||
post: async () => new Response(JSON.stringify({ value: mockRawFlow })),
|
||||
} as any;
|
||||
|
||||
spies.push(spyOn(sessionModule, "createSessionClient").mockResolvedValue(mockClient));
|
||||
|
||||
const res = await handleBillCommand(
|
||||
{
|
||||
area: "bill",
|
||||
action: "trace",
|
||||
args: ["BX-999"],
|
||||
positional: ["bill", "trace", "BX-999"],
|
||||
options: {},
|
||||
raw: ["bill", "trace", "BX-999"],
|
||||
},
|
||||
mockRuntime
|
||||
);
|
||||
|
||||
expect(res.exitCode).toBe(0);
|
||||
expect(res.stdout).toContain("单据全域穿透诊断 [BX-999]");
|
||||
expect(res.stdout).toContain("总监审批");
|
||||
expect(res.stdout).toContain("是否可审批: ✅ 是");
|
||||
});
|
||||
|
||||
it("未找到单据时返回 exitCode 1 与排障建议", async () => {
|
||||
const mockClient = {
|
||||
post: async () => new Response(JSON.stringify({ items: [] })),
|
||||
} as any;
|
||||
|
||||
spies.push(spyOn(sessionModule, "createSessionClient").mockResolvedValue(mockClient));
|
||||
|
||||
const res = await handleFlowCommand(
|
||||
{
|
||||
area: "flow",
|
||||
action: "get",
|
||||
args: ["UNKNOWN-BILL"],
|
||||
positional: ["flow", "get", "UNKNOWN-BILL"],
|
||||
options: {},
|
||||
raw: ["flow", "get", "UNKNOWN-BILL"],
|
||||
},
|
||||
mockRuntime
|
||||
);
|
||||
|
||||
expect(res.exitCode).toBe(1);
|
||||
expect(res.stderr).toContain("[NOT FOUND]");
|
||||
expect(res.stderr).toContain("诊断提示");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user