File size: 1,641 Bytes
fc93158 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | import { Command } from "commander";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
const configureCommandFromSectionsArgMock = vi.fn();
const runtime = {
log: vi.fn(),
error: vi.fn(),
exit: vi.fn(),
};
vi.mock("../../commands/configure.js", () => ({
CONFIGURE_WIZARD_SECTIONS: ["auth", "channels", "gateway", "agent"],
configureCommandFromSectionsArg: configureCommandFromSectionsArgMock,
}));
vi.mock("../../runtime.js", () => ({
defaultRuntime: runtime,
}));
let registerConfigureCommand: typeof import("./register.configure.js").registerConfigureCommand;
beforeAll(async () => {
({ registerConfigureCommand } = await import("./register.configure.js"));
});
describe("registerConfigureCommand", () => {
async function runCli(args: string[]) {
const program = new Command();
registerConfigureCommand(program);
await program.parseAsync(args, { from: "user" });
}
beforeEach(() => {
vi.clearAllMocks();
configureCommandFromSectionsArgMock.mockResolvedValue(undefined);
});
it("forwards repeated --section values", async () => {
await runCli(["configure", "--section", "auth", "--section", "channels"]);
expect(configureCommandFromSectionsArgMock).toHaveBeenCalledWith(["auth", "channels"], runtime);
});
it("reports errors through runtime when configure command fails", async () => {
configureCommandFromSectionsArgMock.mockRejectedValueOnce(new Error("configure failed"));
await runCli(["configure"]);
expect(runtime.error).toHaveBeenCalledWith("Error: configure failed");
expect(runtime.exit).toHaveBeenCalledWith(1);
});
});
|