test(whatsapp): add context isolation coverage

Includes outbound gating, threading fallback, and web auto-reply context assertions.
This commit is contained in:
Peter Steinberger
2026-01-14 23:23:28 +00:00
parent a70937c926
commit fd41000bc3
3 changed files with 97 additions and 0 deletions

View File

@@ -168,6 +168,48 @@ describe("web auto-reply", () => {
expect(payload.Body).toContain("@bot ping");
expect(payload.Body).toContain("[from: Bob (+222)]");
});
it("passes conversation id through as From for group replies", async () => {
const sendMedia = vi.fn();
const reply = vi.fn().mockResolvedValue(undefined);
const sendComposing = vi.fn();
const resolver = vi.fn().mockResolvedValue({ text: "ok" });
let capturedOnMessage:
| ((msg: import("./inbound.js").WebInboundMessage) => Promise<void>)
| undefined;
const listenerFactory = async (opts: {
onMessage: (msg: import("./inbound.js").WebInboundMessage) => Promise<void>;
}) => {
capturedOnMessage = opts.onMessage;
return { close: vi.fn() };
};
await monitorWebChannel(false, listenerFactory, false, resolver);
expect(capturedOnMessage).toBeDefined();
await capturedOnMessage?.({
body: "@bot ping",
from: "123@g.us",
conversationId: "123@g.us",
chatId: "123@g.us",
chatType: "group",
to: "+2",
id: "g1",
senderE164: "+222",
senderName: "Bob",
mentionedJids: ["999@s.whatsapp.net"],
selfE164: "+999",
selfJid: "999@s.whatsapp.net",
sendComposing,
reply,
sendMedia,
});
const payload = resolver.mock.calls[0]?.[0] as { From?: string; To?: string };
expect(payload.From).toBe("123@g.us");
expect(payload.To).toBe("+2");
});
it("detects LID mentions using authDir mapping", async () => {
const sendMedia = vi.fn();
const reply = vi.fn().mockResolvedValue(undefined);