import { ChannelType } from "discord.js"; import { TourScheduleEngine } from "../../src/tour-schedule"; describe("TourScheduleEngine flow", () => { it("handles FIFO next flow and announcement dispatch", async () => { const send = jest.fn().mockResolvedValue(undefined); const guild = { id: "guild-1", members: { fetch: jest.fn().mockResolvedValue({ voice: { channelId: "stage-1", setSuppressed: jest.fn().mockResolvedValue(undefined), }, }), }, channels: { fetch: jest .fn() .mockImplementation(async (channelId: string) => { if (channelId === "stage-1") { return { type: ChannelType.GuildStageVoice, }; } if (channelId === "announce-1") { return { isSendable: () => true, send, }; } return null; }), }, } as any; const engine = new TourScheduleEngine({ stageChannelId: "stage-1", announceChannelId: "announce-1", }); engine.join("guild-1", "user-a"); engine.join("guild-1", "user-b"); const first = await engine.next(guild); const second = await engine.next(guild); expect(first).toEqual({ nextUserId: "user-a", remaining: 1, stageResult: "promoted", }); expect(second).toEqual({ nextUserId: "user-b", remaining: 0, stageResult: "promoted", }); expect(send).toHaveBeenNthCalledWith( 1, "Next up: <@user-a>. Queue remaining: 1.", ); expect(send).toHaveBeenNthCalledWith( 2, "Next up: <@user-b>. Queue remaining: 0.", ); }); });