Files
tilbudgivern/test-analytics-api.js
alexpolo1 1d79f4710d feat: Implement comprehensive analytics population and data synchronization
- Added SimpleAnalyticsPopulator class for populating project, employee, customer analytics, and daily metrics.
- Integrated MySQL database connections for tilbudgivern and ordrestyring_local databases.
- Developed sync_ordrestyring_data_old.sh script for comprehensive data synchronization from Ordrestyring API.
- Created test scripts for analytics API and services to validate functionality and data integrity.
- Introduced FixedHistoricalQuoteCalculator and HistoricalQuoteCalculator for generating quotes based on historical data.
- Implemented vary-profit-margins.js to introduce variability in profit margins based on project size and customer type.
2025-10-14 13:06:02 +00:00

55 lines
2.2 KiB
JavaScript

const axios = require('axios');
async function testAnalyticsAPI() {
console.log('🧪 Testing Analytics API with Real Data...\n');
const baseURL = 'http://localhost:3001/api/analytics';
const tests = [
{ name: 'Overall KPIs', endpoint: '/kpis' },
{ name: 'Executive Summary', endpoint: '/executive-summary' },
{ name: 'Employee Performance', endpoint: '/employees' },
{ name: 'Customer Analytics', endpoint: '/customers' },
{ name: 'Benchmarks', endpoint: '/benchmarks' }
];
for (const test of tests) {
try {
console.log(`📊 Testing ${test.name}...`);
const response = await axios.get(`${baseURL}${test.endpoint}`);
if (response.data) {
console.log(`${test.name} - SUCCESS`);
// Show key metrics from response
if (test.endpoint === '/kpis' && response.data.success) {
const kpis = response.data.data;
console.log(` - Total Projects: ${kpis.totalProjects}`);
console.log(` - Total Revenue: ${(kpis.totalRevenue / 1000000).toFixed(1)}M DKK`);
console.log(` - Active Customers: ${kpis.activeCustomers}`);
console.log(` - Avg Profit Margin: ${kpis.avgProfitMargin?.toFixed(1)}%`);
}
if (test.endpoint === '/executive-summary' && response.data.success) {
const summary = response.data.data;
console.log(` - Business Health: ${summary.businessHealth}`);
console.log(` - Top Performers: ${summary.topPerformers?.length || 0} employees`);
console.log(` - Key Insights: ${summary.keyInsights?.length || 0} insights`);
}
} else {
console.log(`⚠️ ${test.name} - Empty response`);
}
} catch (error) {
console.log(`${test.name} - ERROR: ${error.message}`);
}
console.log(''); // Space between tests
}
console.log('🎯 Analytics API Test Complete!');
}
// Run test
testAnalyticsAPI().catch(console.error);