Files
hose-use/src/cli/commands/auth.test.ts
T

84 lines
2.1 KiB
TypeScript

import { describe, it, expect } from "bun:test";
import { handleAuthCommand } from "./auth.js";
import type { CliRuntime } from "../types.js";
describe("cli/commands/auth > aliases and subcommands", () => {
const dummyRuntime: CliRuntime = {
corpContext: {
listCorps: () => [],
getCurrent: () => null,
switchCorp: () => false,
resolve: () => null,
} as any,
selectedCorp: null,
jsonMode: false,
};
it("maps auth list to handleAccounts smoothly", async () => {
const res = await handleAuthCommand(
{
area: "auth",
action: "list",
args: [],
options: {},
raw: ["auth", "list"],
},
dummyRuntime
);
expect(res.exitCode).toBe(0);
// 应该输出已保存账号表格或无账号提示
expect(res.stdout).toMatch(/(已保存账号列表|暂无保存的账号)/);
});
it("supports auth accounts with --json mode", async () => {
const jsonRuntime = { ...dummyRuntime, jsonMode: true };
const res = await handleAuthCommand(
{
area: "auth",
action: "list",
args: [],
options: { json: true },
raw: ["auth", "list", "--json"],
},
jsonRuntime
);
expect(res.exitCode).toBe(0);
const data = JSON.parse(res.stdout);
expect(data).toHaveProperty("accounts");
});
it("handles auth status / current aliases without crash", async () => {
const res = await handleAuthCommand(
{
area: "auth",
action: "current",
args: [],
options: {},
raw: ["auth", "current"],
},
dummyRuntime
);
expect(res.exitCode).toBe(0);
expect(res.stdout).toContain("当前登录与企业状态");
});
it("supports auth sync-seal --dry-run", async () => {
const res = await handleAuthCommand(
{
area: "auth",
action: "sync-seal",
args: [],
options: { "dry-run": true },
raw: ["auth", "sync-seal", "--dry-run"],
},
dummyRuntime
);
expect(res.exitCode).toBe(0);
expect(res.stdout).toContain("从 seal-use 同步企业 OpenAPI 持久化密钥");
});
});