Add leads handlers, WhatsApp integration, and test files

This commit is contained in:
2026-05-02 17:40:38 +00:00
parent 8833e38b80
commit 57e6e5a6fd
24 changed files with 2305 additions and 115 deletions

View 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');
}