diff --git a/src/channels/plugins/actions/discord.test.ts b/src/channels/plugins/actions/discord.test.ts index d68aba74b..46d8cd177 100644 --- a/src/channels/plugins/actions/discord.test.ts +++ b/src/channels/plugins/actions/discord.test.ts @@ -1,11 +1,41 @@ import { describe, expect, it } from "vitest"; import type { ClawdbotConfig } from "../../../config/config.js"; -import { discordMessageActions } from "./discord.js"; +type SendMessageDiscord = typeof import("../../../discord/send.js").sendMessageDiscord; +type SendPollDiscord = typeof import("../../../discord/send.js").sendPollDiscord; + +const sendMessageDiscord = vi.fn, ReturnType>( + async () => ({ ok: true }) as Awaited>, +); +const sendPollDiscord = vi.fn, ReturnType>( + async () => ({ ok: true }) as Awaited>, +); + +vi.mock("../../../discord/send.js", async () => { + const actual = await vi.importActual( + "../../../discord/send.js", + ); + return { + ...actual, + sendMessageDiscord: (...args: Parameters) => sendMessageDiscord(...args), + sendPollDiscord: (...args: Parameters) => sendPollDiscord(...args), + }; +}); + +const loadHandleDiscordMessageAction = async () => { + const mod = await import("./discord/handle-action.js"); + return mod.handleDiscordMessageAction; +}; + +const loadDiscordMessageActions = async () => { + const mod = await import("./discord.js"); + return mod.discordMessageActions; +}; describe("discord message actions", () => { - it("lists channel and upload actions by default", () => { + it("lists channel and upload actions by default", async () => { const cfg = { channels: { discord: { token: "d0" } } } as ClawdbotConfig; + const discordMessageActions = await loadDiscordMessageActions(); const actions = discordMessageActions.listActions?.({ cfg }) ?? []; expect(actions).toContain("emoji-upload"); @@ -13,10 +43,11 @@ describe("discord message actions", () => { expect(actions).toContain("channel-create"); }); - it("respects disabled channel actions", () => { + it("respects disabled channel actions", async () => { const cfg = { channels: { discord: { token: "d0", actions: { channels: false } } }, } as ClawdbotConfig; + const discordMessageActions = await loadDiscordMessageActions(); const actions = discordMessageActions.listActions?.({ cfg }) ?? []; expect(actions).not.toContain("channel-create");