Files
omo-bot/tests/commands/sign-up.test.ts
T
zwitschi f6efd96733
CI-CD / Bot Lint Test Build (push) Failing after 11s
CI-CD / Dashboard Lint Build (push) Successful in 14s
CI-CD / Deploy to Coolify (push) Has been skipped
feat: Add deployment guide and update README for Coolify setup; include dotenv for environment variable management
2026-05-17 17:31:25 +02:00

95 lines
2.6 KiB
TypeScript

import { PermissionFlagsBits } from "discord.js";
import { signUpCommand } from "../../src/commands/sign-up";
import { getTourSchedule } from "../../src/tour-schedule";
jest.mock("../../src/tour-schedule", () => ({
getTourSchedule: jest.fn(),
}));
describe("signUpCommand", () => {
const queue = {
join: jest.fn(),
leave: jest.fn(),
list: jest.fn(),
clear: jest.fn(),
next: jest.fn(),
};
beforeEach(() => {
jest.clearAllMocks();
(getTourSchedule as jest.Mock).mockReturnValue(queue);
});
function createInteraction(action: string) {
return {
inGuild: () => true,
guildId: "guild-1",
user: { id: "user-1" },
guild: { id: "guild-1" },
memberPermissions: {
has: jest.fn(
(permission: bigint) =>
permission === PermissionFlagsBits.ManageChannels,
),
},
options: {
getSubcommand: () => action,
},
reply: jest.fn().mockResolvedValue(undefined),
};
}
it("joins queue and replies with position", async () => {
queue.join.mockReturnValue({ joined: true, position: 2 });
const interaction = createInteraction("join");
await signUpCommand.execute(interaction);
expect(queue.join).toHaveBeenCalledWith("guild-1", "user-1");
expect(interaction.reply).toHaveBeenCalledWith({
content: "Added to queue at position 2.",
ephemeral: true,
});
});
it("lists queue in FIFO order", async () => {
queue.list.mockReturnValue(["user-1", "user-2"]);
const interaction = createInteraction("list");
await signUpCommand.execute(interaction);
expect(interaction.reply).toHaveBeenCalledWith({
content: "1. <@user-1>\n2. <@user-2>",
ephemeral: true,
});
});
it("blocks next action when missing Manage Channels", async () => {
const interaction = createInteraction("next");
interaction.memberPermissions.has = jest.fn().mockReturnValue(false);
await signUpCommand.execute(interaction);
expect(interaction.reply).toHaveBeenCalledWith({
content: "Need Manage Channels permission for this action.",
ephemeral: true,
});
});
it("advances queue and announces stage status", async () => {
queue.next.mockResolvedValue({
nextUserId: "user-7",
remaining: 3,
stageResult: "promoted",
});
const interaction = createInteraction("next");
await signUpCommand.execute(interaction);
expect(interaction.reply).toHaveBeenCalledWith({
content: "Now up: <@user-7>\nQueue remaining: 3\nStage speaker promoted.",
ephemeral: false,
});
});
});