feat: initial setup with WhatsApp CRM apps and sync services
This commit is contained in:
147
apps/whatsapp-sync/tests/contact-management.test.js
Normal file
147
apps/whatsapp-sync/tests/contact-management.test.js
Normal file
@@ -0,0 +1,147 @@
|
||||
var MockDatabase = function() {
|
||||
this.contacts = [];
|
||||
this.messages = [];
|
||||
this.tasks = [];
|
||||
};
|
||||
|
||||
MockDatabase.prototype.exec = function(sql) {
|
||||
return [];
|
||||
};
|
||||
|
||||
MockDatabase.prototype.prepare = function(sql) {
|
||||
var self = this;
|
||||
|
||||
return {
|
||||
run: function() { return { lastInsertRowid: 1, changes: 1 }; },
|
||||
get: function() { return undefined; },
|
||||
all: function() { return []; },
|
||||
};
|
||||
};
|
||||
|
||||
MockDatabase.prototype.close = function() {};
|
||||
|
||||
jest.mock('better-sqlite3', function() {
|
||||
return function() {
|
||||
return new MockDatabase();
|
||||
};
|
||||
});
|
||||
|
||||
describe('5. Contact Management', function() {
|
||||
var db;
|
||||
var database;
|
||||
|
||||
beforeEach(function() {
|
||||
jest.clearAllMocks();
|
||||
database = require('../src/database');
|
||||
db = database.initialize(':memory:');
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
if (db && db.close) {
|
||||
db.close();
|
||||
}
|
||||
});
|
||||
|
||||
describe('5.1 Contact Creation', function() {
|
||||
test('test_create_contact_with_required_fields - name, phone required', function() {
|
||||
var contact = {
|
||||
phone: '5511999999999',
|
||||
name: 'John Doe',
|
||||
};
|
||||
|
||||
var result = database.insertContact(db, contact);
|
||||
|
||||
expect(result).toBeDefined();
|
||||
expect(result.phone).toBe('5511999999999');
|
||||
});
|
||||
|
||||
test('test_create_contact_with_optional_fields - notes, schedule_date optional', function() {
|
||||
var contact = {
|
||||
phone: '5511888888888',
|
||||
name: 'Jane Doe',
|
||||
notes: 'Interested in product A',
|
||||
scheduleDate: 1700000000,
|
||||
};
|
||||
|
||||
var result = database.insertContact(db, contact);
|
||||
|
||||
expect(result).toBeDefined();
|
||||
});
|
||||
|
||||
test('test_create_contact_missing_name - throws ValidationError', function() {
|
||||
var contact = {
|
||||
phone: '5511777777777',
|
||||
};
|
||||
|
||||
expect(function() {
|
||||
database.insertContact(db, contact);
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
test('test_create_contact_missing_phone - throws ValidationError', function() {
|
||||
var contact = {
|
||||
name: 'Test User',
|
||||
};
|
||||
|
||||
try {
|
||||
database.insertContact(db, contact);
|
||||
} catch (e) {
|
||||
expect(e).toBeDefined();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('5.2 Contact Updates', function() {
|
||||
test('test_update_contact_stage_to_decidindo - stage change works', function() {
|
||||
var contact = {
|
||||
phone: '5511999999999',
|
||||
name: 'John Doe',
|
||||
stage: 'LEADS DE ENTRADA',
|
||||
};
|
||||
|
||||
database.insertContact(db, contact);
|
||||
var result = database.updateContactStage(db, '5511999999999', 'DECIDINDO');
|
||||
|
||||
expect(result).toBeDefined();
|
||||
});
|
||||
|
||||
test('test_update_contact_payment_status_to_paid - payment status update', function() {
|
||||
var contact = {
|
||||
phone: '5511999999999',
|
||||
name: 'John Doe',
|
||||
};
|
||||
|
||||
database.insertContact(db, contact);
|
||||
var result = database.updateContactPaymentStatus(db, '5511999999999', 'paid');
|
||||
|
||||
expect(result).toBeDefined();
|
||||
});
|
||||
|
||||
test('test_update_schedule_date - schedule date update', function() {
|
||||
var contact = {
|
||||
phone: '5511999999999',
|
||||
name: 'John Doe',
|
||||
};
|
||||
|
||||
database.insertContact(db, contact);
|
||||
var newDate = 1800000000;
|
||||
var result = database.updateContactScheduleDate(db, '5511999999999', newDate);
|
||||
|
||||
expect(result).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('5.3 Contact Queries', function() {
|
||||
test('test_list_contacts_by_stage - filter by stage', function() {
|
||||
var contacts = database.listContactsByStage(db, 'LEADS DE ENTRADA');
|
||||
|
||||
expect(Array.isArray(contacts)).toBe(true);
|
||||
});
|
||||
|
||||
test('test_list_contacts_with_payment_pending - filter by payment status', function() {
|
||||
var contacts = database.listContactsByPaymentStatus(db, 'pending');
|
||||
|
||||
expect(Array.isArray(contacts)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user