Files
hose-use/src/cli/mutation.test.ts
T
gitea 8c6ee6ca89 refactor(cli): split commands/bill.ts into bill/{context,approve,search,flow,related,meta,index}.ts
The five closures that captured corp/client/confirmation state move
into a per-invocation createBillActionContext factory; case bodies
become ctx-taking handlers grouped by concern (approval write actions,
list/get, flow/risk/budget, refs/relations/attachments/download,
schema/link/spec). index.ts keeps the original switch semantics.
No behavior change: tsc clean, 316 tests pass.
2026-10-04 14:18:29 +08:00

58 lines
1.6 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import { handleBillCommand } from "./commands/bill/index.js";
import type { CliRuntime } from "./types.js";
const runtime: CliRuntime = {
corpContext: {} as any,
selectedCorp: {
id: "corp-test",
name: "测试企业",
source: "account",
baseUrl: "https://app.ekuaibao.com",
credentials: {
corpId: "corp-test",
staffId: "staff-test",
accessToken: "token-test",
},
},
jsonMode: true,
};
describe("CLI mutation protocol", () => {
test("bill --dry-run returns a preview without creating an API client", async () => {
const result = await handleBillCommand(
{
area: "bill",
action: "approve",
args: ["S26000001"],
options: { "dry-run": true },
raw: ["bill", "approve", "S26000001", "--dry-run"],
},
runtime
);
expect(result.exitCode).toBe(0);
const preview = JSON.parse(result.stdout);
expect(preview.dryRun).toBe(true);
expect(preview.operation).toBe("同意单据审批");
expect(preview.target).toBe("S26000001");
expect(preview.nextAction).not.toContain("--dry-run");
expect(preview.nextAction).toContain("--yes");
});
test("bill write without confirmation is rejected before the API call", async () => {
await expect(
handleBillCommand(
{
area: "bill",
action: "approve",
args: ["S26000001"],
options: {},
raw: ["bill", "approve", "S26000001"],
},
runtime
)
).rejects.toThrow("--yes");
});
});