110 lines
2.8 KiB
TypeScript
110 lines
2.8 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import type { ClawdbotConfig } from "../../config/config.js";
|
|
import { handleWhatsAppAction } from "./whatsapp-actions.js";
|
|
|
|
const sendReactionWhatsApp = vi.fn(async () => undefined);
|
|
|
|
vi.mock("../../web/outbound.js", () => ({
|
|
sendReactionWhatsApp: (...args: unknown[]) => sendReactionWhatsApp(...args),
|
|
}));
|
|
|
|
const enabledConfig = {
|
|
channels: { whatsapp: { actions: { reactions: true } } },
|
|
} as ClawdbotConfig;
|
|
|
|
describe("handleWhatsAppAction", () => {
|
|
it("adds reactions", async () => {
|
|
await handleWhatsAppAction(
|
|
{
|
|
action: "react",
|
|
chatJid: "123@s.whatsapp.net",
|
|
messageId: "msg1",
|
|
emoji: "✅",
|
|
},
|
|
enabledConfig,
|
|
);
|
|
expect(sendReactionWhatsApp).toHaveBeenCalledWith("123@s.whatsapp.net", "msg1", "✅", {
|
|
verbose: false,
|
|
fromMe: undefined,
|
|
participant: undefined,
|
|
accountId: undefined,
|
|
});
|
|
});
|
|
|
|
it("removes reactions on empty emoji", async () => {
|
|
await handleWhatsAppAction(
|
|
{
|
|
action: "react",
|
|
chatJid: "123@s.whatsapp.net",
|
|
messageId: "msg1",
|
|
emoji: "",
|
|
},
|
|
enabledConfig,
|
|
);
|
|
expect(sendReactionWhatsApp).toHaveBeenCalledWith("123@s.whatsapp.net", "msg1", "", {
|
|
verbose: false,
|
|
fromMe: undefined,
|
|
participant: undefined,
|
|
accountId: undefined,
|
|
});
|
|
});
|
|
|
|
it("removes reactions when remove flag set", async () => {
|
|
await handleWhatsAppAction(
|
|
{
|
|
action: "react",
|
|
chatJid: "123@s.whatsapp.net",
|
|
messageId: "msg1",
|
|
emoji: "✅",
|
|
remove: true,
|
|
},
|
|
enabledConfig,
|
|
);
|
|
expect(sendReactionWhatsApp).toHaveBeenCalledWith("123@s.whatsapp.net", "msg1", "", {
|
|
verbose: false,
|
|
fromMe: undefined,
|
|
participant: undefined,
|
|
accountId: undefined,
|
|
});
|
|
});
|
|
|
|
it("passes account scope and sender flags", async () => {
|
|
await handleWhatsAppAction(
|
|
{
|
|
action: "react",
|
|
chatJid: "123@s.whatsapp.net",
|
|
messageId: "msg1",
|
|
emoji: "🎉",
|
|
accountId: "work",
|
|
fromMe: true,
|
|
participant: "999@s.whatsapp.net",
|
|
},
|
|
enabledConfig,
|
|
);
|
|
expect(sendReactionWhatsApp).toHaveBeenCalledWith("123@s.whatsapp.net", "msg1", "🎉", {
|
|
verbose: false,
|
|
fromMe: true,
|
|
participant: "999@s.whatsapp.net",
|
|
accountId: "work",
|
|
});
|
|
});
|
|
|
|
it("respects reaction gating", async () => {
|
|
const cfg = {
|
|
channels: { whatsapp: { actions: { reactions: false } } },
|
|
} as ClawdbotConfig;
|
|
await expect(
|
|
handleWhatsAppAction(
|
|
{
|
|
action: "react",
|
|
chatJid: "123@s.whatsapp.net",
|
|
messageId: "msg1",
|
|
emoji: "✅",
|
|
},
|
|
cfg,
|
|
),
|
|
).rejects.toThrow(/WhatsApp reactions are disabled/);
|
|
});
|
|
});
|