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"); }); });