const axios = require('axios'); async function testTenantStats() { try { console.log('šŸ” Testing tenant statistics endpoint...'); // First login to get authentication token console.log('šŸ” Logging in as superadmin...'); const loginResponse = await axios.post('http://localhost:4040/api/auth/login', { email: 'superadmin@gmail.com', password: 'SuperAdmin3465#' }); if (loginResponse.status !== 200) { throw new Error(`Login failed with status: ${loginResponse.status}`); } const token = loginResponse.data.token; console.log('āœ… Login successful'); const response = await axios.get('http://localhost:4040/api/tenant/statistics', { headers: { 'Authorization': `Bearer ${token}` } }); if (response.status === 200) { console.log('āœ… Tenant statistics endpoint working'); console.log('\nšŸ“Š Tenant Statistics Response:'); console.log(JSON.stringify(response.data, null, 2)); // Check if response has topTenants array const tenants = response.data.topTenants || []; if (tenants.length > 0) { console.log('\nšŸ“‹ Top Tenants:'); tenants.forEach((tenant, index) => { console.log(`\n${index + 1}. ${tenant.tenantName} (ID: ${tenant.tenantId})`); console.log(` šŸ“ˆ Evaluations Used (from results): ${tenant.evaluationsUsed}`); console.log(` šŸ’³ Credit Operations Used: ${tenant.creditOperationsUsed}`); console.log(` šŸ“‹ Total Evaluations from Jobs: ${tenant.totalEvaluationsFromJobs}`); console.log(` āœ… Completed Evaluations: ${tenant.completedEvaluations}`); console.log(` āŒ Failed Evaluations: ${tenant.failedEvaluations}`); console.log(` šŸ’° Evaluations Remaining: ${tenant.evaluationsRemaining}`); console.log(` šŸ“… Last Evaluation: ${tenant.lastEvaluationDate || 'N/A'}`); console.log(` šŸ’³ Last Credit Operation: ${tenant.lastCreditOperation || 'N/A'}`); // Highlight discrepancies if (tenant.evaluationsUsed !== tenant.creditOperationsUsed) { console.log(` āš ļø DISCREPANCY: ${tenant.evaluationsUsed} results vs ${tenant.creditOperationsUsed} credit operations`); } }); // Find Emilio's Organization specifically const emilioTenant = tenants.find(t => t.name && t.name.includes('Emilio')); if (emilioTenant) { console.log('\nšŸŽÆ Emilio\'s Organization Details:'); console.log(` Evaluation Results: ${emilioTenant.evaluationsUsed}`); console.log(` Credit Operations: ${emilioTenant.creditOperationsUsed || 'N/A'}`); console.log(` Discrepancy: ${emilioTenant.evaluationsUsed - (emilioTenant.creditOperationsUsed || 0)}`); } } else { console.log('\nāš ļø No tenant data found in topTenants'); } } else { console.log(`āŒ Request failed with status: ${response.status}`); } } catch (error) { console.error('āŒ Error testing tenant statistics:', error.message); if (error.response) { console.error('Response status:', error.response.status); console.error('Response data:', error.response.data); } } } testTenantStats();