Files
roa2web-service-auto/reports-app/frontend/tests/integration/global-setup.js
Marius Mutu 12ac2b671e feat: Frontend CSS refactoring and test improvements
Frontend:
- Refactored CSS architecture with new utility classes
- Updated dashboard components styling
- Improved responsive grid system
- Enhanced typography and variables
- Updated E2E and integration tests

Added:
- Claude Code slash commands for validation
- SSH tunnel and start test scripts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 21:08:47 +02:00

138 lines
4.8 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Global setup for real API integration tests
* Ensures SSH tunnel and backend services are running
*/
// import path from 'path';
// import { fileURLToPath } from 'url';
// const __filename = fileURLToPath(import.meta.url);
// const __dirname = path.dirname(__filename);
export default async function globalSetup() {
console.log('🔧 Setting up real API integration test environment...');
// Root directory for reference if needed later
// const rootDir = path.resolve(__dirname, '../../../../../..');
try {
// Check if SSH tunnel is running by testing Oracle port
console.log('📡 Checking SSH tunnel status...');
try {
const response = await fetch('http://localhost:8000/health', { timeout: 5000 });
const health = await response.json();
if (health.database === 'connected') {
console.log('✅ SSH tunnel appears to be working (database connected)');
} else {
console.log('⚠️ Database not connected - SSH tunnel may need to be started manually');
}
} catch (error) {
console.log('⚠️ Could not check tunnel status - continuing anyway');
}
// Check backend health
console.log('🏥 Checking backend health...');
try {
const healthResponse = await fetch('http://localhost:8000/health', {
timeout: 10000
});
if (!healthResponse.ok) {
throw new Error(`Backend health check failed: ${healthResponse.status}`);
}
const healthData = await healthResponse.json();
console.log('✅ Backend health check passed:', healthData);
} catch (error) {
console.error('❌ Backend health check failed:', error.message);
throw new Error('Backend is not available for integration tests');
}
// Check frontend availability
console.log('🌐 Checking frontend availability...');
try {
const frontendResponse = await fetch('http://localhost:3001', {
timeout: 10000
});
if (!frontendResponse.ok) {
throw new Error(`Frontend not available: ${frontendResponse.status}`);
}
console.log('✅ Frontend is available');
} catch (error) {
console.error('❌ Frontend availability check failed:', error.message);
throw new Error('Frontend is not available for integration tests');
}
// Validate environment variables
console.log('🔐 Validating environment configuration...');
const requiredEnvVars = [
'ORACLE_USER',
'ORACLE_PASSWORD',
'ORACLE_HOST',
'ORACLE_PORT',
'ORACLE_SID'
];
const missingVars = requiredEnvVars.filter(varName => !process.env[varName]);
if (missingVars.length > 0) {
console.warn('⚠️ Missing environment variables:', missingVars.join(', '));
console.log(' Some tests may use default values');
} else {
console.log('✅ All required environment variables are set');
}
// Test database connectivity through backend
console.log('🗄️ Testing database connectivity...');
try {
const dbTestResponse = await fetch('http://localhost:8000/api/companies', {
timeout: 15000
});
if (dbTestResponse.ok) {
const companies = await dbTestResponse.json();
console.log(`✅ Database connectivity verified (${companies.length} companies found)`);
// Check if ROMFAST is available
const romfast = companies.find(c => c.id_firma === 'ROMFAST');
if (romfast) {
console.log('✅ ROMFAST company data available for testing');
} else {
console.warn('⚠️ ROMFAST company not found in test data');
}
} else {
console.warn('⚠️ Database connectivity test returned:', dbTestResponse.status);
}
} catch (error) {
console.warn('⚠️ Database connectivity test failed:', error.message);
console.log(' Tests will proceed but may fail if database is not accessible');
}
console.log('🎯 Global setup completed successfully');
// Store setup metadata for tests
global.__INTEGRATION_SETUP__ = {
timestamp: new Date().toISOString(),
backend: 'http://localhost:8000',
frontend: 'http://localhost:3001',
sshTunnelActive: true,
environmentValidated: true
};
} catch (error) {
console.error('❌ Global setup encountered error:', error.message);
console.log(' Continuing with tests - they may fail if services are not available');
// Don't fail setup - let individual tests handle service unavailability
global.__INTEGRATION_SETUP__ = {
timestamp: new Date().toISOString(),
backend: 'http://localhost:8000',
frontend: 'http://localhost:3001',
sshTunnelActive: false,
environmentValidated: false,
setupError: error.message
};
}
}