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
79 lines
1.9 KiB
JavaScript
79 lines
1.9 KiB
JavaScript
/**
|
|
* Test the updated price validation with higher limits
|
|
*/
|
|
|
|
const BygmaPrisbogImportService = require('./backend/src/services/bygmaPrisbogImportService');
|
|
|
|
function testPriceValidation() {
|
|
const importService = new BygmaPrisbogImportService();
|
|
|
|
console.log('🧪 Testing updated price validation...\n');
|
|
|
|
// Test data with high but realistic prices
|
|
const testRows = [
|
|
{
|
|
Varegrp: '5550',
|
|
VareNr: '325490',
|
|
Tekst: 'JUMBO STILLADSTRAILER 1400KG RULLESTILLADS 8M',
|
|
Enhed: 'STK',
|
|
BruttoPris: '117995,00',
|
|
Opdat: '1',
|
|
Nettopris: '82596,50',
|
|
'DB-nr': '',
|
|
'EAN-nr': '',
|
|
Std: ''
|
|
},
|
|
{
|
|
Varegrp: '5550',
|
|
VareNr: '325491',
|
|
Tekst: 'MEGA KRAN UDSTYR 200KG KAPACITET',
|
|
Enhed: 'STK',
|
|
BruttoPris: '250000,00',
|
|
Opdat: '1',
|
|
Nettopris: '187500,00',
|
|
'DB-nr': '',
|
|
'EAN-nr': '',
|
|
Std: ''
|
|
},
|
|
{
|
|
Varegrp: '5550',
|
|
VareNr: '325492',
|
|
Tekst: 'INVALID PRICE - SHOULD FAIL',
|
|
Enhed: 'STK',
|
|
BruttoPris: '1000000,00',
|
|
Opdat: '1',
|
|
Nettopris: '750000,00',
|
|
'DB-nr': '',
|
|
'EAN-nr': '',
|
|
Std: ''
|
|
}
|
|
];
|
|
|
|
for (let i = 0; i < testRows.length; i++) {
|
|
const row = testRows[i];
|
|
const lineNumber = i + 1;
|
|
|
|
try {
|
|
console.log(`Test ${lineNumber}: ${row.Tekst}`);
|
|
console.log(` Prices: Brutto=${row.BruttoPris}, Netto=${row.Nettopris}`);
|
|
|
|
// Process the row (this will validate prices)
|
|
const result = importService.processRow(row, lineNumber);
|
|
|
|
console.log(`✅ Success! Price validation passed`);
|
|
console.log('');
|
|
|
|
} catch (error) {
|
|
if (error.message.includes('Prices too high')) {
|
|
console.log(`❌ Price too high (expected): ${error.message}`);
|
|
} else {
|
|
console.log(`❌ Other error: ${error.message}`);
|
|
}
|
|
console.log('');
|
|
}
|
|
}
|
|
}
|
|
|
|
// Run the test
|
|
testPriceValidation();
|