#!/usr/bin/env node /** * Microservices Architecture Test Script * Tests: Frontend (3001) → API Gateway (8000) → Git Integration (8012) */ const axios = require('axios'); const SERVICES = { FRONTEND: 'http://localhost:3001', API_GATEWAY: 'http://localhost:8000', GIT_INTEGRATION: 'http://localhost:8012' }; const TEST_ENDPOINTS = [ // GitHub Integration Endpoints { path: '/api/github/health', method: 'GET', service: 'git-integration' }, { path: '/api/github/auth/github/status', method: 'GET', service: 'git-integration' }, // Diff Viewer Endpoints { path: '/api/diffs/repositories', method: 'GET', service: 'git-integration' }, // AI Streaming Endpoints { path: '/api/ai/streaming-sessions', method: 'GET', service: 'git-integration' }, // VCS Endpoints { path: '/api/vcs/github/auth/start', method: 'GET', service: 'git-integration' } ]; async function testServiceHealth(serviceName, baseUrl) { console.log(`\nšŸ” Testing ${serviceName} health...`); try { const response = await axios.get(`${baseUrl}/health`, { timeout: 5000 }); console.log(`āœ… ${serviceName} is healthy: ${response.status}`); return true; } catch (error) { console.log(`āŒ ${serviceName} is unhealthy: ${error.message}`); return false; } } async function testEndpoint(endpoint) { console.log(`\nšŸ” Testing ${endpoint.method} ${endpoint.path}...`); // Test direct service call try { const directUrl = `${SERVICES.GIT_INTEGRATION}${endpoint.path}`; const directResponse = await axios({ method: endpoint.method, url: directUrl, timeout: 10000, validateStatus: () => true }); console.log(`āœ… Direct service call: ${directResponse.status}`); } catch (error) { console.log(`āŒ Direct service call failed: ${error.message}`); } // Test through API Gateway try { const gatewayUrl = `${SERVICES.API_GATEWAY}${endpoint.path}`; const gatewayResponse = await axios({ method: endpoint.method, url: gatewayUrl, timeout: 10000, validateStatus: () => true }); console.log(`āœ… Gateway call: ${gatewayResponse.status}`); } catch (error) { console.log(`āŒ Gateway call failed: ${error.message}`); } } async function testFrontendIntegration() { console.log(`\nšŸ” Testing Frontend Integration...`); // Test if frontend is running try { const response = await axios.get(SERVICES.FRONTEND, { timeout: 5000 }); console.log(`āœ… Frontend is accessible: ${response.status}`); } catch (error) { console.log(`āŒ Frontend is not accessible: ${error.message}`); return false; } return true; } async function runArchitectureTest() { console.log('šŸš€ Starting Microservices Architecture Test'); console.log('='.repeat(60)); // Test service health const gitIntegrationHealthy = await testServiceHealth('Git Integration Service', SERVICES.GIT_INTEGRATION); const apiGatewayHealthy = await testServiceHealth('API Gateway', SERVICES.API_GATEWAY); const frontendHealthy = await testFrontendIntegration(); console.log('\nšŸ“Š Service Health Summary:'); console.log(`Git Integration (8012): ${gitIntegrationHealthy ? 'āœ…' : 'āŒ'}`); console.log(`API Gateway (8000): ${apiGatewayHealthy ? 'āœ…' : 'āŒ'}`); console.log(`Frontend (3001): ${frontendHealthy ? 'āœ…' : 'āŒ'}`); if (!gitIntegrationHealthy || !apiGatewayHealthy) { console.log('\nāŒ Critical services are down. Please start the services first.'); console.log('Run: docker-compose up -d'); return; } // Test endpoints console.log('\nšŸ” Testing Endpoints...'); for (const endpoint of TEST_ENDPOINTS) { await testEndpoint(endpoint); } // Test routing flow console.log('\nšŸ” Testing Routing Flow...'); console.log('Frontend (3001) → API Gateway (8000) → Git Integration (8012)'); // Test a simple endpoint through the complete flow try { const testUrl = `${SERVICES.API_GATEWAY}/api/github/health`; const response = await axios.get(testUrl, { timeout: 10000 }); console.log(`āœ… Complete flow test: ${response.status}`); console.log(`Response: ${JSON.stringify(response.data, null, 2)}`); } catch (error) { console.log(`āŒ Complete flow test failed: ${error.message}`); } console.log('\nšŸŽÆ Architecture Test Complete'); console.log('='.repeat(60)); if (gitIntegrationHealthy && apiGatewayHealthy && frontendHealthy) { console.log('āœ… All services are healthy and properly configured!'); console.log('\nšŸ“‹ Next Steps:'); console.log('1. Start all services: docker-compose up -d'); console.log('2. Test frontend at: http://localhost:3001'); console.log('3. Test API Gateway at: http://localhost:8000'); console.log('4. Test Git Integration at: http://localhost:8012'); } else { console.log('āŒ Some services need attention. Check the logs above.'); } } // Run the test if (require.main === module) { runArchitectureTest().catch(console.error); } module.exports = { runArchitectureTest, testServiceHealth, testEndpoint };