52 lines
2.2 KiB
TypeScript
52 lines
2.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { addCommand, auditCommand, backupCommand, createCommand, mainCommand, opsCommand } from "./index.js";
|
|
|
|
async function resolveValue<T>(value: T | (() => T) | (() => Promise<T>)): Promise<T> {
|
|
if (typeof value === "function") {
|
|
return await (value as () => T | Promise<T>)();
|
|
}
|
|
return value;
|
|
}
|
|
|
|
describe("cli main command", () => {
|
|
it("exposes the backup subcommand tree", async () => {
|
|
const mainMeta = await resolveValue(mainCommand.meta);
|
|
expect(mainMeta).toMatchObject({ name: "hivegrid-cli" });
|
|
|
|
const backupMeta = await resolveValue(backupCommand.meta);
|
|
expect(backupMeta).toMatchObject({ name: "backup" });
|
|
|
|
const backupSubCommands = await resolveValue(backupCommand.subCommands);
|
|
expect(Object.keys(backupSubCommands ?? {}).sort()).toEqual(["create", "list", "restore", "rotate", "verify"]);
|
|
});
|
|
|
|
it("registers the create + add scaffolding groups", async () => {
|
|
const subs = await resolveValue(mainCommand.subCommands);
|
|
const keys = Object.keys(subs ?? {});
|
|
expect(keys).toContain("create");
|
|
expect(keys).toContain("add");
|
|
|
|
const createSubs = await resolveValue(createCommand.subCommands);
|
|
expect(Object.keys(createSubs ?? {}).sort()).toEqual(["entity", "module", "route"]);
|
|
|
|
const addSubs = await resolveValue(addCommand.subCommands);
|
|
expect(Object.keys(addSubs ?? {}).sort()).toEqual(["event-type", "hook", "permission"]);
|
|
});
|
|
|
|
it("registers the ops command group with doctor / migrate-tenant / impersonate", async () => {
|
|
const subs = await resolveValue(mainCommand.subCommands);
|
|
expect(Object.keys(subs ?? {})).toContain("ops");
|
|
|
|
const opsSubs = await resolveValue(opsCommand.subCommands);
|
|
expect(Object.keys(opsSubs ?? {}).sort()).toEqual(["doctor", "impersonate", "migrate-tenant"]);
|
|
});
|
|
|
|
it("registers the audit command group with verify-chain / export-pdf", async () => {
|
|
const subs = await resolveValue(mainCommand.subCommands);
|
|
expect(Object.keys(subs ?? {})).toContain("audit");
|
|
|
|
const auditSubs = await resolveValue(auditCommand.subCommands);
|
|
expect(Object.keys(auditSubs ?? {}).sort()).toEqual(["export-pdf", "verify-chain"]);
|
|
});
|
|
});
|