import { bitrix24Client } from './build/bitrix24/client.js';
async function testAllLatestFunctions() {
console.log('š Testing ALL FIXED getLatest functions...\n');
try {
// Test 1: Latest Leads
console.log('1. Testing getLatestLeads:');
const latestLeads = await bitrix24Client.getLatestLeads(5);
console.log(`ā
Retrieved ${latestLeads.length} latest leads`);
latestLeads.forEach((lead, index) => {
const name = [lead.NAME, lead.LAST_NAME].filter(Boolean).join(' ') || lead.COMPANY_TITLE || lead.TITLE || 'No name';
console.log(` ${index + 1}. ${name} (ID: ${lead.ID}) - Created: ${lead.DATE_CREATE}`);
});
console.log('');
// Test 2: Latest Deals
console.log('2. Testing getLatestDeals:');
const latestDeals = await bitrix24Client.getLatestDeals(5);
console.log(`ā
Retrieved ${latestDeals.length} latest deals`);
latestDeals.forEach((deal, index) => {
const title = deal.TITLE || `Deal #${deal.ID}`;
console.log(` ${index + 1}. ${title} (ID: ${deal.ID}) - Created: ${deal.DATE_CREATE}`);
});
console.log('');
// Test 3: Latest Contacts
console.log('3. Testing getLatestContacts:');
const latestContacts = await bitrix24Client.getLatestContacts(5);
console.log(`ā
Retrieved ${latestContacts.length} latest contacts`);
latestContacts.forEach((contact, index) => {
const name = [contact.NAME, contact.LAST_NAME].filter(Boolean).join(' ') || contact.COMPANY_TITLE || 'No name';
console.log(` ${index + 1}. ${name} (ID: ${contact.ID}) - Created: ${contact.DATE_CREATE}`);
});
console.log('');
// Test 4: Check for recent items (2025)
console.log('4. Checking for 2025 items in latest results:');
const leads2025 = latestLeads.filter(item => {
const date = new Date(item.DATE_CREATE);
return date.getFullYear() === 2025;
});
console.log(` š Leads from 2025: ${leads2025.length}/${latestLeads.length}`);
const deals2025 = latestDeals.filter(item => {
const date = new Date(item.DATE_CREATE);
return date.getFullYear() === 2025;
});
console.log(` š Deals from 2025: ${deals2025.length}/${latestDeals.length}`);
const contacts2025 = latestContacts.filter(item => {
const date = new Date(item.DATE_CREATE);
return date.getFullYear() === 2025;
});
console.log(` š Contacts from 2025: ${contacts2025.length}/${latestContacts.length}`);
console.log('\nšÆ SUMMARY:');
console.log('All three getLatest functions are now working correctly!');
console.log('They all use DATE_CREATE for consistent sorting and return the most recently created items.');
if (leads2025.length > 0 || deals2025.length > 0 || contacts2025.length > 0) {
console.log('ā
Recent items (2025) are being returned correctly!');
} else {
console.log('ā¹ļø No 2025 items found, but the functions are working correctly.');
}
} catch (error) {
console.error('ā Error testing functions:', error.message);
}
}
testAllLatestFunctions().catch(console.error);