- bill list --state=draft/草稿 改走 flows/my 草稿列表,修复草稿不在 invoice/search 台账索引中导致 --state=draft 返回空的问题 - 新增 --template/--title/--staff/--page 过滤与分页;服务端 RQL 结合 客户端兜底匹配,模板版本化 ID 自动剥离哈希 - bill get 新增 flowId 直读通道,工作流/他人创建的草稿无需 flows/my 可见 - 补充域层与 CLI 单测、bill 文档、Skill 与 OpenAPI 参数说明 Fixes #153 Co-Authored-By: Claude <noreply@anthropic.com>
107 lines
4.0 KiB
TypeScript
107 lines
4.0 KiB
TypeScript
import { afterEach, describe, expect, it, spyOn } from "bun:test";
|
|
import * as session from "../../../core/http/hose-web-session-client.js";
|
|
import { parseArgs } from "../../parser.js";
|
|
import { createBillActionContext } from "./context.js";
|
|
import { handleList } from "./search.js";
|
|
|
|
const spies: Array<{ mockRestore(): void }> = [];
|
|
afterEach(() => {
|
|
for (const spy of spies.splice(0).reverse()) spy.mockRestore();
|
|
});
|
|
|
|
function json(value: unknown): Response {
|
|
return new Response(JSON.stringify(value));
|
|
}
|
|
|
|
function draftClient(corpId: string) {
|
|
const flowsPosts: any[] = [];
|
|
const client = {
|
|
get: async (url: string) => {
|
|
if (url.includes("staffs/actives")) {
|
|
return json({ items: [{ id: "staff-1", name: "张三", code: "1001" }] });
|
|
}
|
|
return json({});
|
|
},
|
|
post: async (url: string, payload: any) => {
|
|
if (url.includes("datalink/entity/search")) return json({ items: [] });
|
|
if (url.endsWith("/flows/my")) {
|
|
flowsPosts.push({ url, payload, corpId });
|
|
return json({
|
|
count: 1,
|
|
items: [{
|
|
flow: {
|
|
id: "flow-cli-draft",
|
|
state: "draft",
|
|
formType: "payment",
|
|
createTime: 1781682826000,
|
|
updateTime: 1781682870000,
|
|
},
|
|
form: {
|
|
code: "FK26000009",
|
|
title: "付款草稿CLI",
|
|
specificationId: { id: "spec-pay", name: "对公付款单" },
|
|
submitterId: { id: "staff-1", name: "张三", code: "1001" },
|
|
payMoney: { standard: "10.00", standardSymbol: "¥", standardStrCode: "CNY" },
|
|
},
|
|
}],
|
|
});
|
|
}
|
|
return json({});
|
|
},
|
|
};
|
|
return { client, flowsPosts };
|
|
}
|
|
|
|
function context(args: string[], corpId: string, jsonMode: boolean) {
|
|
const corp = { id: corpId, name: "测试企业", credentials: { corpId } };
|
|
return createBillActionContext(parseArgs(args), { jsonMode, selectedCorp: corp } as any);
|
|
}
|
|
|
|
describe("bill list draft mode", () => {
|
|
it("routes --state=draft to flows/my with template, title, submitter and page filters", async () => {
|
|
const { client, flowsPosts } = draftClient("cli-draft-corp-json");
|
|
spies.push(spyOn(session, "createSessionClient").mockResolvedValue(client as any));
|
|
|
|
const args = [
|
|
"bill", "list", "--state=draft", "--mine",
|
|
`--template=spec-pay:${"a".repeat(32)}`,
|
|
"--title=付款", "--staff=张三",
|
|
"--page=2", "--count=10", "--json",
|
|
];
|
|
const result = await handleList(context(args, "cli-draft-corp-json", true));
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
const output = JSON.parse(result.stdout);
|
|
expect(output.total).toBe(1);
|
|
expect(output.items[0]).toMatchObject({
|
|
billId: "flow-cli-draft",
|
|
billCode: "FK26000009",
|
|
billName: "付款草稿CLI",
|
|
state: "draft",
|
|
});
|
|
expect(output.items[0].amount).toContain("10.00");
|
|
|
|
expect(flowsPosts).toHaveLength(1);
|
|
const filterBy = flowsPosts[0].payload.json.filterBy as string;
|
|
expect(filterBy).toContain('(state.in("draft"))');
|
|
expect(filterBy).toContain('INSTR(form.title, "付款")');
|
|
expect(filterBy).toContain('INSTR(form.specificationId, "spec-pay")');
|
|
expect(filterBy).not.toContain("a".repeat(32));
|
|
expect(filterBy).toContain('INSTR(form.submitterId, "staff-1")');
|
|
expect(flowsPosts[0].payload.json.limit).toEqual({ start: 10, count: 10 });
|
|
expect(flowsPosts[0].payload.json.orderBy).toEqual([{ value: "createTime", order: "DESC" }]);
|
|
});
|
|
|
|
it("renders a draft-specific text header for --state=草稿", async () => {
|
|
const { client } = draftClient("cli-draft-corp-text");
|
|
spies.push(spyOn(session, "createSessionClient").mockResolvedValue(client as any));
|
|
|
|
const result = await handleList(context(["bill", "list", "--state=草稿"], "cli-draft-corp-text", false));
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.stdout).toContain("单据草稿列表");
|
|
expect(result.stdout).toContain("FK26000009");
|
|
expect(result.stdout).toContain("bill submit");
|
|
});
|
|
});
|