From 85c348bc73374696f262f28c5ef67625ec54d1f3 Mon Sep 17 00:00:00 2001 From: Antonio Di Novi Date: Wed, 4 Oct 2023 11:14:31 +0200 Subject: [PATCH] chore: add test for whats app provider --- .../lib/whatsapp-business.provider.spec.ts | 80 ++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/providers/whatsapp-business/src/lib/whatsapp-business.provider.spec.ts b/providers/whatsapp-business/src/lib/whatsapp-business.provider.spec.ts index b31d15faa8bf..6ac07c62fe91 100644 --- a/providers/whatsapp-business/src/lib/whatsapp-business.provider.spec.ts +++ b/providers/whatsapp-business/src/lib/whatsapp-business.provider.spec.ts @@ -1,3 +1,81 @@ import { WhatsappBusinessChatProvider } from './whatsapp-business.provider'; -test('should trigger whatsapp-business library correctly', async () => {}); +const mockConfig = { + apiKey: "TEST_API_KEY", + apiVersion: "TEST_API_VERSION", + applicationId: "TEST_APPLICATION_ID" +}; + +const mockMessage = { + channel: "phone_number", + content: JSON.stringify({ + "name": "template_request", + "language": { + "code": "it" + }, + "components": [ + { + "type": "header", + "parameters": [ + { + "type": "text", + "text": "135345345" + } + ] + }, + { + "type": "body", + "parameters": [ + { + "type": "text", + "text": "135345345" + }, + { + "type": "text", + "text": "135345345" + }, + { + "type": "text", + "text": "135345345" + } + ] + }, + { + "type": "button", + "sub_type": "quick_reply", + "index": "0", + "parameters": [ + { + "type": "payload", + "payload": "test" + } + ] + } + ] + }) +} + +test('should trigger whatsapp-business library correctly', async () => { + + const provider = new WhatsappBusinessChatProvider(mockConfig) + + await provider.sendMessage(mockMessage); + + const spy = jest + .spyOn(provider, 'sendMessage') + .mockImplementation(async () => { + return { + id: '67890-test', + date: new Date().toISOString(), + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } as any; + }); + + await provider.sendMessage(mockMessage); + + expect(spy).toHaveBeenCalled(); + + expect(spy).toHaveBeenCalledWith(mockMessage); + + +});