agmission/Development/server/tests/test_parsing_logic.js

47 lines
2.0 KiB
JavaScript

const SatLocProcessor = require('./helpers/satloc_application_processor');
const path = require('path');
async function testParsingLogic() {
console.log('=== Testing Parsing Logic Without Database ===\n');
const processor = new SatLocProcessor();
const logFilePath = path.join(__dirname, 'test-logs', 'Liquid_IF2_G4.log');
// Track parsing calls
let parseCallCount = 0;
const originalParseSatLocLogFile = processor.parseSatLocLogFile;
processor.parseSatLocLogFile = function(...args) {
parseCallCount++;
console.log(`📝 Parse call #${parseCallCount}: parsing log file...`);
return originalParseSatLocLogFile.apply(this, args);
};
try {
console.log('🔍 Testing parseSatLocLogFile directly...');
const parseResult = await processor.parseSatLocLogFile(logFilePath, {});
console.log('\n📊 Parse Results:');
console.log(`- Success: ${parseResult.success}`);
console.log(`- Parse calls made: ${parseCallCount}`);
console.log(`- Application details: ${parseResult.applicationDetails?.length || 0}`);
console.log(`- UTM Zone: ${parseResult.utmZone}`);
console.log(`- File size: ${(parseResult.fileSize / 1024 / 1024).toFixed(2)} MB`);
// Test grouping logic
console.log('\n🔍 Testing grouping logic...');
const jobGroups = processor.groupApplicationDetailsByJob(parseResult.applicationDetails);
console.log(`- Job groups found: ${Object.keys(jobGroups).length}`);
for (const [jobId, details] of Object.entries(jobGroups)) {
console.log(` - Job "${jobId}": ${details.length} details`);
}
console.log('\n✅ SUCCESS: Parsing and grouping logic works correctly!');
console.log(`✅ OPTIMIZATION: Only ${parseCallCount} parse call made (no duplication)`);
} catch (error) {
console.error('❌ Test failed:', error.message);
console.log(`Parse calls made before error: ${parseCallCount}`);
}
}
testParsingLogic();