/** * `@ar-agents/whatsapp/testing` — fixtures + mock client for tests. * * What you get: * * - **Factories**: `mockIncomingTextEnvelope`, `mockIncomingButtonReply`, * `mockIncomingListReply`, `mockMessageStatusEnvelope`. They produce the * raw Meta-shaped JSON envelope (the body Meta posts to your webhook), * ready to feed into `parseWebhookEvents`. * * - **`mockSendTextResult`** / **`mockTemplateResult`** — the response * shape Meta returns from `POST /messages`. * * - **`mockSignedWebhook`** — produces a `{ rawBody, headers }` pair whose * `x-hub-signature-256` header passes `verifyWebhookSignature` against * the same `appSecret`. Drops directly into your webhook-handler test. * * - **`MockWhatsAppClient`** — stand-in for `WhatsAppClient`. Records * every method call so tests assert on what was sent without hitting * the live Meta Graph. */ type RawWebhookEnvelope = { object: "whatsapp_business_account"; entry: Array<{ id: string; changes: Array<{ field: "messages"; value: Record; }>; }>; }; declare function mockIncomingTextEnvelope(overrides?: { from?: string; body?: string; messageId?: string; ts?: number; }): RawWebhookEnvelope; declare function mockIncomingButtonReply(overrides?: { from?: string; buttonId?: string; buttonTitle?: string; }): RawWebhookEnvelope; declare function mockIncomingListReply(overrides?: { from?: string; rowId?: string; rowTitle?: string; }): RawWebhookEnvelope; declare function mockMessageStatusEnvelope(args?: { messageId?: string; status?: "sent" | "delivered" | "read" | "failed"; to?: string; }): RawWebhookEnvelope; declare function mockSendTextResult(overrides?: { wamid?: string; to?: string; }): { messaging_product: "whatsapp"; contacts: { wa_id: string; input: string; }[]; messages: { id: string; message_status: "accepted"; }[]; }; declare function mockTemplateResult(overrides?: { wamid?: string; to?: string; }): { messaging_product: "whatsapp"; contacts: { wa_id: string; input: string; }[]; messages: { id: string; message_status: "accepted"; }[]; }; /** * Produce a `{ rawBody, headers }` pair whose `x-hub-signature-256` is a * real HMAC-SHA256 against `appSecret`. Pass to `verifyWebhookSignature` * (from `@ar-agents/whatsapp`) and it'll accept it. */ declare function mockSignedWebhook(args: { appSecret: string; envelope?: RawWebhookEnvelope; }): Promise<{ rawBody: string; headers: Headers; envelope: RawWebhookEnvelope; }>; type Recorded = { method: "sendText"; args: { to: string; body: string; }; } | { method: "sendTemplate"; args: { to: string; templateName: string; languageCode: string; }; } | { method: "sendMedia"; args: { to: string; mediaType: string; url: string; }; } | { method: "sendButtons"; args: { to: string; body: string; buttons: unknown; }; } | { method: "sendList"; args: { to: string; body: string; sections: unknown; }; } | { method: "markRead"; args: { messageId: string; }; }; declare class MockWhatsAppClient { /** Append-only log of every method call. Inspect in your test assertions. */ readonly calls: Recorded[]; sendText(to: string, body: string): Promise<{ messaging_product: "whatsapp"; contacts: { wa_id: string; input: string; }[]; messages: { id: string; message_status: "accepted"; }[]; }>; sendTemplate(to: string, templateName: string, languageCode?: string): Promise<{ messaging_product: "whatsapp"; contacts: { wa_id: string; input: string; }[]; messages: { id: string; message_status: "accepted"; }[]; }>; sendMedia(to: string, mediaType: string, url: string): Promise<{ messaging_product: "whatsapp"; contacts: { wa_id: string; input: string; }[]; messages: { id: string; message_status: "accepted"; }[]; }>; sendButtons(to: string, body: string, buttons: unknown): Promise<{ messaging_product: "whatsapp"; contacts: { wa_id: string; input: string; }[]; messages: { id: string; message_status: "accepted"; }[]; }>; sendList(to: string, body: string, sections: unknown): Promise<{ messaging_product: "whatsapp"; contacts: { wa_id: string; input: string; }[]; messages: { id: string; message_status: "accepted"; }[]; }>; markRead(messageId: string): Promise<{ success: boolean; }>; /** Reset the recorded calls between tests. */ reset(): void; } export { MockWhatsAppClient, type RawWebhookEnvelope, mockIncomingButtonReply, mockIncomingListReply, mockIncomingTextEnvelope, mockMessageStatusEnvelope, mockSendTextResult, mockSignedWebhook, mockTemplateResult };