Files
tilbudgivern/test_validation_improvements.js
T
alex c3731a470f feat: Implement Bygma Products component with search and filtering functionality
feat: Add standalone script for enhanced Bygma CSV import with validation

test: Create simple database test to show current state and product counts

test: Develop enhanced validation demo to simulate problematic CSV data handling

test: Implement price validation tests with higher limits for edge cases

test: Conduct real enhanced validation test with actual Bygma CSV file

test: Test validation improvements with known problematic data

test: Validate logic of cleaning and validating CSV rows without database

test: Test improved VareNr cleaning functionality to remove spaces
2025-09-18 22:28:35 +02:00

60 lines
2.8 KiB
JavaScript

const BygmaPrisbogImportService = require('./backend/src/services/bygmaPrisbogImportService');
const fs = require('fs');
async function testValidationImprovements() {
console.log('🧪 Testing validation improvements with problematic data...');
// Create test CSV with known problematic rows
const testCSV = `Varegrp;VareNr;Tekst;Enhed;BruttoPris;Opdat;Nettopris;DB-nr;EAN-nr;Std
9990;135865;JUNKBAG SÆKKE L M3/1300KG;STK;175,96;1;175,96;;;
;;;;;;;;
9990;;MISSING VARENR;STK;100,00;1;80,00;;;
9990;123456;;STK;50,00;1;40,00;;;
9990;789012;MISSING ENHED;;25,00;1;20,00;;;
9990;TOOLONGVARENUMBERHERE123456789;NORMAL PRODUCT;STK;30,00;1;25,00;;;
9990;999999;PRODUCT WITH SEMICOLONS;;STK;15,00;1;12,00;;;
9990;111111;NORMAL PRODUCT;STK;abc,def;1;invalid;;;
9990;222222;ANOTHER GOOD PRODUCT;STK;200,50;1;160,40;;;
9990;333333;PRODUCT WITH VERY LONG TEXT THAT GOES ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON AND ON;STK;100,00;1;80,00;;;
;;; ;;;;;;
9990;444444;GOOD PRODUCT AFTER PROBLEMS;STK;75,25;1;60,20;;;`;
// Write test file
fs.writeFileSync('./test_validation.csv', testCSV);
const importService = new BygmaPrisbogImportService();
try {
const result = await importService.importPrisbog('./test_validation.csv');
console.log('\n📊 Test Results:');
console.log(` - Total rows: ${result.stats.totalRows}`);
console.log(` - Successful: ${result.stats.successfulRows}`);
console.log(` - Failed: ${result.stats.failedRows}`);
console.log(` - Success rate: ${((result.stats.successfulRows / result.stats.totalRows) * 100).toFixed(1)}%`);
if (result.errors.length > 0) {
console.log('\n⚠️ Validation errors (this is good - we caught problems):');
result.errors.forEach((error, index) => {
console.log(`${index + 1}. Line ${error.line}: ${error.error}`);
});
}
console.log('\n✅ Validation improvements are working!');
console.log(' - Empty rows: Filtered out');
console.log(' - Missing fields: Detected with specific details');
console.log(' - Invalid data: Caught before database insertion');
console.log(' - Malformed rows: Identified and skipped');
} catch (error) {
console.error('❌ Test failed:', error.message);
} finally {
// Clean up test file
if (fs.existsSync('./test_validation.csv')) {
fs.unlinkSync('./test_validation.csv');
}
}
}
testValidationImprovements();