#!/usr/bin/env node 'use strict'; const path = require('path'); require('dotenv').config({ path: './environment.env' }); const axios = require('axios'); const https = require('https'); const BASE_URL = 'https://localhost:4100'; const TOKEN = process.env.DASHBOARD_TEST_TOKEN || process.env.AUTH_TOKEN || process.env.TEST_AUTH_TOKEN || ''; const httpsAgent = new https.Agent({ rejectUnauthorized: false }); const client = axios.create({ baseURL: BASE_URL, validateStatus: () => true, httpsAgent, headers: TOKEN ? { Authorization: `Bearer ${TOKEN}` } : {} }); async function test() { console.log('Testing GET /api/dashboard/pilot/snapshot'); console.log(`Base URL: ${BASE_URL}`); console.log(`Auth Token: ${TOKEN ? 'Present' : 'MISSING'}\n`); try { // First test an existing endpoint to verify connection console.log('1. Testing existing endpoint (GET /api/dashboard/pilot/kpi)...'); const kpiRes = await client.get('/api/dashboard/pilot/kpi?tz=UTC'); console.log(` Status: ${kpiRes.status}`); console.log(` Data keys: ${Object.keys(kpiRes.data).join(', ')}\n`); // Now test the snapshot endpoint console.log('2. Testing snapshot endpoint (GET /api/dashboard/pilot/snapshot)...'); const snapshotRes = await client.get('/api/dashboard/pilot/snapshot?tz=UTC'); console.log(` Status: ${snapshotRes.status}`); console.log(` Data: ${JSON.stringify(snapshotRes.data, null, 2)}\n`); if (snapshotRes.status === 404) { console.log('❌ Snapshot endpoint is returning 404 (Not Found)'); console.log(' This means the route is not being matched.'); } else if (snapshotRes.status === 200) { console.log('✅ Snapshot endpoint is working!'); console.log(` Returned modules: ${Object.keys(snapshotRes.data).join(', ')}`); } else { console.log(`⚠️ Unexpected status: ${snapshotRes.status}`); } } catch (err) { console.error('Error:', err.message); if (err.code === 'ECONNREFUSED' || err.code === 'ECONNRESET') { console.error(`⚠️ Server not reachable at ${BASE_URL}`); } } } test();