Add leads handlers, WhatsApp integration, and test files
This commit is contained in:
50
apps/whatsapp-sync/tests/whatsapp-leads.test.js
Normal file
50
apps/whatsapp-sync/tests/whatsapp-leads.test.js
Normal file
@@ -0,0 +1,50 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
describe('whatsapp-leads.js module', () => {
|
||||
const scriptPath = path.join(__dirname, '../src/whatsapp-leads.js');
|
||||
|
||||
test('script file exists', () => {
|
||||
expect(fs.existsSync(scriptPath)).toBe(true);
|
||||
});
|
||||
|
||||
test('exports normalizePhone function', () => {
|
||||
const script = require(scriptPath);
|
||||
expect(typeof script.normalizePhone).toBe('function');
|
||||
});
|
||||
|
||||
test('exports isGroupChat function', () => {
|
||||
const script = require(scriptPath);
|
||||
expect(typeof script.isGroupChat).toBe('function');
|
||||
});
|
||||
});
|
||||
|
||||
describe('WhatsApp message filtering', () => {
|
||||
const scriptPath = path.join(__dirname, '../src/whatsapp-leads.js');
|
||||
|
||||
test('filters out group messages (only 1:1 chats)', () => {
|
||||
const groupMessage = {
|
||||
key: { remoteJid: '1234567890@g group' },
|
||||
message: { conversation: 'Group message' },
|
||||
};
|
||||
|
||||
const personalMessage = {
|
||||
key: { remoteJid: '1234567890@c.us' },
|
||||
message: { conversation: 'Personal message' },
|
||||
};
|
||||
|
||||
expect(isGroupChat(groupMessage)).toBe(true);
|
||||
expect(isGroupChat(personalMessage)).toBe(false);
|
||||
});
|
||||
|
||||
test('normalizes phone numbers', () => {
|
||||
const script = require(scriptPath);
|
||||
expect(script.normalizePhone('+5521987654321')).toBe('+5521987654321');
|
||||
expect(script.normalizePhone('21987654321')).toBe('+21987654321');
|
||||
expect(script.normalizePhone('')).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
function isGroupChat(message) {
|
||||
return message.key.remoteJid?.includes('@g');
|
||||
}
|
||||
Reference in New Issue
Block a user