diff --git a/src/cli/program/message/register.discord-admin.test.ts b/src/cli/program/message/register.discord-admin.test.ts new file mode 100644 index 00000000000..4432510ede5 --- /dev/null +++ b/src/cli/program/message/register.discord-admin.test.ts @@ -0,0 +1,70 @@ +import { Command } from "commander"; +import { describe, expect, it, vi } from "vitest"; +import type { MessageCliHelpers } from "./helpers.js"; +import { registerMessageDiscordAdminCommands } from "./register.discord-admin.js"; + +function createStubHelpers(): MessageCliHelpers { + const identity = (cmd: Command) => cmd; + const runMessageAction = vi.fn(); + return { + withMessageBase: identity, + withMessageTarget: identity, + withRequiredMessageTarget: identity, + runMessageAction, + } as MessageCliHelpers; +} + +function getSubcommandNames(parent: Command): string[] { + return parent.commands.map((c) => c.name()); +} + +describe("registerMessageDiscordAdminCommands", () => { + it("registers channel create/edit/delete/move subcommands", () => { + const message = new Command("message"); + const helpers = createStubHelpers(); + registerMessageDiscordAdminCommands(message, helpers); + + const channel = message.commands.find((c) => c.name() === "channel"); + expect(channel).toBeDefined(); + + const channelSubs = getSubcommandNames(channel!); + expect(channelSubs).toContain("info"); + expect(channelSubs).toContain("list"); + expect(channelSubs).toContain("create"); + expect(channelSubs).toContain("edit"); + expect(channelSubs).toContain("delete"); + expect(channelSubs).toContain("move"); + }); + + it("channel create requires --guild-id and --name", () => { + const message = new Command("message"); + registerMessageDiscordAdminCommands(message, createStubHelpers()); + + const channel = message.commands.find((c) => c.name() === "channel")!; + const create = channel.commands.find((c) => c.name() === "create")!; + const help = create.helpInformation(); + expect(help).toContain("--guild-id"); + expect(help).toContain("--name"); + }); + + it("channel delete requires --channel-id", () => { + const message = new Command("message"); + registerMessageDiscordAdminCommands(message, createStubHelpers()); + + const channel = message.commands.find((c) => c.name() === "channel")!; + const del = channel.commands.find((c) => c.name() === "delete")!; + const help = del.helpInformation(); + expect(help).toContain("--channel-id"); + }); + + it("channel move requires --guild-id and --channel-id", () => { + const message = new Command("message"); + registerMessageDiscordAdminCommands(message, createStubHelpers()); + + const channel = message.commands.find((c) => c.name() === "channel")!; + const move = channel.commands.find((c) => c.name() === "move")!; + const help = move.helpInformation(); + expect(help).toContain("--guild-id"); + expect(help).toContain("--channel-id"); + }); +}); diff --git a/src/cli/program/message/register.discord-admin.ts b/src/cli/program/message/register.discord-admin.ts index de806dfede9..71907c3d743 100644 --- a/src/cli/program/message/register.discord-admin.ts +++ b/src/cli/program/message/register.discord-admin.ts @@ -57,6 +57,64 @@ export function registerMessageDiscordAdminCommands(message: Command, helpers: M await helpers.runMessageAction("channel-list", opts); }); + helpers + .withMessageBase( + channel + .command("create") + .description("Create a channel") + .requiredOption("--guild-id ", "Guild id") + .requiredOption("--name ", "Channel name"), + ) + .option("--type ", "Channel type (0=text, 2=voice, 4=category, 15=forum)") + .option("--parent-id ", "Parent category id") + .option("--topic ", "Channel topic") + .option("--position ", "Sort position") + .option("--nsfw", "Mark as NSFW") + .action(async (opts) => { + await helpers.runMessageAction("channel-create", opts); + }); + + helpers + .withMessageBase( + channel + .command("edit") + .description("Edit a channel") + .requiredOption("--channel-id ", "Channel id"), + ) + .option("--name ", "New channel name") + .option("--topic ", "New channel topic") + .option("--position ", "Sort position") + .option("--parent-id ", "Parent category id") + .option("--nsfw", "Mark as NSFW") + .action(async (opts) => { + await helpers.runMessageAction("channel-edit", opts); + }); + + helpers + .withMessageBase( + channel + .command("delete") + .description("Delete a channel") + .requiredOption("--channel-id ", "Channel id"), + ) + .action(async (opts) => { + await helpers.runMessageAction("channel-delete", opts); + }); + + helpers + .withMessageBase( + channel + .command("move") + .description("Move a channel") + .requiredOption("--guild-id ", "Guild id") + .requiredOption("--channel-id ", "Channel id"), + ) + .option("--parent-id ", "Target parent category id") + .option("--position ", "Sort position") + .action(async (opts) => { + await helpers.runMessageAction("channel-move", opts); + }); + const member = message.command("member").description("Member actions"); helpers .withMessageBase(