-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add test for whats app provider
- Loading branch information
1 parent
487e668
commit cad2300
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
providers/whatsapp-business/src/lib/whatsapp-business.provider.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { WhatsappBusinessChatProvider } from './whatsapp-business.provider'; | ||
|
||
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); | ||
|
||
|
||
}); |