fix: 统一单据写前校验与传输结果契约

将模板、当前员工、草稿创建/删除、审批计划和送审共七处 HTTP 调用收口到 bill/api.ts,业务层函数签名保持兼容。创建与预演复用实际规格校验,缺失明细规格、必填字段或超长文本均先于写入拒绝。
统一检查已知业务错误及有效流程 ID,保留 flow/value/裸对象成功包装与已有单号字段;补充业务拒绝、HTTP 失败、无效 ID、计划失败不送审及 CLI 非零退出回归,同步域文档。

验证:bun test 911 通过、0 失败;bun run check、git diff --check 通过。未调用真实企业接口。
This commit is contained in:
gitea committed 2026-10-29 18:14:52 +08:00
1 parent 9916936eae
commit 51fb54dfe8
11 files changed
+222 -101

No files matched your search

+15
View File
@@ -1,6 +1,7 @@
import { expect, test } from "bun:test";
import { handleCreate } from "./create.js";
import { parseArgs } from "../../parser.js";
import { cliErrorResult } from "../../runner.js";
test("create dry-run resolves the same available fee as execution and never posts", async () => {
const writes: any[] = [];
@@ -21,3 +22,17 @@ test("create dry-run resolves the same available fee as execution and never post
await expect(handleCreate(context([...base, "--fee-type", "不存在", "--dry-run"]))).rejects.toThrow("费用类型");
expect(writes).toHaveLength(1);
});
test("创建收到业务错误时由 CLI 错误边界返回非零,不输出创建成功", async () => {
const client = {
get: (url: string) => ({ json: async () => url.includes("specifications/")
? { items: [{ id: "spec", name: "模板", components: [{ field: "title" }] }] }
: url.includes("staffs/me") ? { value: { staff: { id: "staff", defaultDepartment: "dept" } } }
: { items: [{ id: "fee", name: "费用", expenseSpecificationId: "detail" }] } }),
post: () => ({ json: async () => ({ errorCode: "REJECTED", errorMessage: "服务端拒绝创建" }) }),
};
const context = { parsed: parseArgs(["bill", "create", "--template", `spec:${"a".repeat(32)}`, "--yes", "--json"]), runtime: { jsonMode: true }, corpId: "corp", getClient: async () => client, requireWriteConfirmation: async () => {} } as any;
const result = await handleCreate(context).catch(error => cliErrorResult(error, true));
expect(result.exitCode).not.toBe(0);
expect(JSON.parse(result.stdout)).toMatchObject({ error: true, message: "服务端拒绝创建" });
});