Files
tilbudgivern/archive/test-files/test-analytics-api.js
alexpolo1 4a372d2e28 clean up
2025-10-30 18:28:58 +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);