test: cover explicit mention gating across channels
This commit is contained in:
55
src/web/auto-reply/mentions.test.ts
Normal file
55
src/web/auto-reply/mentions.test.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { WebInboundMsg } from "./types.js";
|
||||
import { isBotMentionedFromTargets, resolveMentionTargets } from "./mentions.js";
|
||||
|
||||
const makeMsg = (overrides: Partial<WebInboundMsg>): WebInboundMsg =>
|
||||
({
|
||||
id: "m1",
|
||||
from: "120363401234567890@g.us",
|
||||
conversationId: "120363401234567890@g.us",
|
||||
to: "15551234567@s.whatsapp.net",
|
||||
accountId: "default",
|
||||
body: "",
|
||||
chatType: "group",
|
||||
chatId: "120363401234567890@g.us",
|
||||
sendComposing: async () => {},
|
||||
reply: async () => {},
|
||||
sendMedia: async () => {},
|
||||
...overrides,
|
||||
}) as WebInboundMsg;
|
||||
|
||||
describe("isBotMentionedFromTargets", () => {
|
||||
const mentionCfg = { mentionRegexes: [/\bclawd\b/i] };
|
||||
|
||||
it("ignores regex matches when other mentions are present", () => {
|
||||
const msg = makeMsg({
|
||||
body: "@Clawd please help",
|
||||
mentionedJids: ["19998887777@s.whatsapp.net"],
|
||||
selfE164: "+15551234567",
|
||||
selfJid: "15551234567@s.whatsapp.net",
|
||||
});
|
||||
const targets = resolveMentionTargets(msg);
|
||||
expect(isBotMentionedFromTargets(msg, mentionCfg, targets)).toBe(false);
|
||||
});
|
||||
|
||||
it("matches explicit self mentions", () => {
|
||||
const msg = makeMsg({
|
||||
body: "hey",
|
||||
mentionedJids: ["15551234567@s.whatsapp.net"],
|
||||
selfE164: "+15551234567",
|
||||
selfJid: "15551234567@s.whatsapp.net",
|
||||
});
|
||||
const targets = resolveMentionTargets(msg);
|
||||
expect(isBotMentionedFromTargets(msg, mentionCfg, targets)).toBe(true);
|
||||
});
|
||||
|
||||
it("falls back to regex when no mentions are present", () => {
|
||||
const msg = makeMsg({
|
||||
body: "clawd can you help?",
|
||||
selfE164: "+15551234567",
|
||||
selfJid: "15551234567@s.whatsapp.net",
|
||||
});
|
||||
const targets = resolveMentionTargets(msg);
|
||||
expect(isBotMentionedFromTargets(msg, mentionCfg, targets)).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user