Merge 4178d65a09597b0ab4e885ff5e71b502274ce18b into 5e417b44e1540f528d2ae63e3e20229a902d1db2
This commit is contained in:
commit
36c446445f
70
src/cli/program/message/register.discord-admin.test.ts
Normal file
70
src/cli/program/message/register.discord-admin.test.ts
Normal file
@ -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");
|
||||
});
|
||||
});
|
||||
@ -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 <id>", "Guild id")
|
||||
.requiredOption("--name <name>", "Channel name"),
|
||||
)
|
||||
.option("--type <n>", "Channel type (0=text, 2=voice, 4=category, 15=forum)")
|
||||
.option("--parent-id <id>", "Parent category id")
|
||||
.option("--topic <text>", "Channel topic")
|
||||
.option("--position <n>", "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 <id>", "Channel id"),
|
||||
)
|
||||
.option("--name <name>", "New channel name")
|
||||
.option("--topic <text>", "New channel topic")
|
||||
.option("--position <n>", "Sort position")
|
||||
.option("--parent-id <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 <id>", "Channel id"),
|
||||
)
|
||||
.action(async (opts) => {
|
||||
await helpers.runMessageAction("channel-delete", opts);
|
||||
});
|
||||
|
||||
helpers
|
||||
.withMessageBase(
|
||||
channel
|
||||
.command("move")
|
||||
.description("Move a channel")
|
||||
.requiredOption("--guild-id <id>", "Guild id")
|
||||
.requiredOption("--channel-id <id>", "Channel id"),
|
||||
)
|
||||
.option("--parent-id <id>", "Target parent category id")
|
||||
.option("--position <n>", "Sort position")
|
||||
.action(async (opts) => {
|
||||
await helpers.runMessageAction("channel-move", opts);
|
||||
});
|
||||
|
||||
const member = message.command("member").description("Member actions");
|
||||
helpers
|
||||
.withMessageBase(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user