Skip to content

Commit

Permalink
chore: add test for whats app provider
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniodinovi committed Oct 4, 2023
1 parent c3132a9 commit 85c348b
Showing 1 changed file with 79 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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);


});

0 comments on commit 85c348b

Please sign in to comment.