208 lines
6.3 KiB
TypeScript
208 lines
6.3 KiB
TypeScript
#!/usr/bin/env ts-node
|
||
/**
|
||
* Verification script for Excel integration
|
||
* Tests that Excel data is correctly parsed and integrated into products
|
||
*/
|
||
|
||
// Import from the compiled lib directory
|
||
import { getExcelTechnicalDataForProduct, getExcelRowsForProduct } from '../lib/excel-products';
|
||
import { getAllProducts, enrichProductWithExcelData } from '../lib/data';
|
||
|
||
interface TestResult {
|
||
name: string;
|
||
passed: boolean;
|
||
message: string;
|
||
details?: any;
|
||
}
|
||
|
||
const results: TestResult[] = [];
|
||
|
||
function addResult(name: string, passed: boolean, message: string, details?: any): void {
|
||
results.push({ name, passed, message, details });
|
||
console.log(`${passed ? '✓' : '✗'} ${name}: ${message}`);
|
||
}
|
||
|
||
async function runTests(): Promise<void> {
|
||
console.log('🔍 Starting Excel Integration Verification...\n');
|
||
|
||
// Test 1: Check if Excel files exist and can be parsed
|
||
console.log('Test 1: Excel File Parsing');
|
||
try {
|
||
const testProduct = {
|
||
name: 'NA2XS(FL)2Y',
|
||
slug: 'na2xsfl2y-3',
|
||
sku: 'NA2XS(FL)2Y-high-voltage-cables',
|
||
translationKey: 'na2xsfl2y-3'
|
||
};
|
||
|
||
const excelData = getExcelTechnicalDataForProduct(testProduct);
|
||
|
||
if (excelData && excelData.configurations.length > 0) {
|
||
addResult(
|
||
'Excel File Parsing',
|
||
true,
|
||
`Successfully parsed Excel data with ${excelData.configurations.length} configurations`,
|
||
{ configurations: excelData.configurations.slice(0, 3) }
|
||
);
|
||
} else {
|
||
addResult(
|
||
'Excel File Parsing',
|
||
false,
|
||
'No Excel data found for test product',
|
||
{ product: testProduct }
|
||
);
|
||
}
|
||
} catch (error) {
|
||
addResult('Excel File Parsing', false, `Error: ${error}`);
|
||
}
|
||
|
||
// Test 2: Check Excel data structure
|
||
console.log('\nTest 2: Excel Data Structure');
|
||
try {
|
||
const testProduct = {
|
||
name: 'NA2XS(FL)2Y',
|
||
slug: 'na2xsfl2y-3',
|
||
sku: 'NA2XS(FL)2Y-high-voltage-cables',
|
||
translationKey: 'na2xsfl2y-3'
|
||
};
|
||
|
||
const excelData = getExcelTechnicalDataForProduct(testProduct);
|
||
|
||
if (excelData) {
|
||
const hasConfigurations = Array.isArray(excelData.configurations) && excelData.configurations.length > 0;
|
||
const hasAttributes = Array.isArray(excelData.attributes);
|
||
|
||
addResult(
|
||
'Excel Data Structure',
|
||
hasConfigurations && hasAttributes,
|
||
`Configurations: ${hasConfigurations ? '✓' : '✗'}, Attributes: ${hasAttributes ? '✓' : '✗'}`,
|
||
{
|
||
configCount: excelData.configurations.length,
|
||
attrCount: excelData.attributes.length,
|
||
sampleAttributes: excelData.attributes.slice(0, 2)
|
||
}
|
||
);
|
||
} else {
|
||
addResult('Excel Data Structure', false, 'No Excel data returned');
|
||
}
|
||
} catch (error) {
|
||
addResult('Excel Data Structure', false, `Error: ${error}`);
|
||
}
|
||
|
||
// Test 3: Check product enrichment
|
||
console.log('\nTest 3: Product Enrichment');
|
||
try {
|
||
const products = getAllProducts();
|
||
const testProduct = products.find(p => p.slug === 'na2xsfl2y-3');
|
||
|
||
if (!testProduct) {
|
||
addResult('Product Enrichment', false, 'Test product not found in data');
|
||
} else {
|
||
const enriched = enrichProductWithExcelData(testProduct);
|
||
|
||
const hasExcelConfig = enriched.excelConfigurations && enriched.excelConfigurations.length > 0;
|
||
const hasExcelAttrs = enriched.excelAttributes && enriched.excelAttributes.length > 0;
|
||
|
||
addResult(
|
||
'Product Enrichment',
|
||
hasExcelConfig && hasExcelAttrs,
|
||
`Enrichment successful: ${hasExcelConfig && hasExcelAttrs ? '✓' : '✗'}`,
|
||
{
|
||
originalAttributes: testProduct.attributes.length,
|
||
excelConfigurations: enriched.excelConfigurations?.length || 0,
|
||
excelAttributes: enriched.excelAttributes?.length || 0
|
||
}
|
||
);
|
||
}
|
||
} catch (error) {
|
||
addResult('Product Enrichment', false, `Error: ${error}`);
|
||
}
|
||
|
||
// Test 4: Check multiple products
|
||
console.log('\nTest 4: Multiple Product Support');
|
||
try {
|
||
const products = getAllProducts();
|
||
const sampleProducts = products.slice(0, 3);
|
||
|
||
let successCount = 0;
|
||
const details: any[] = [];
|
||
|
||
for (const product of sampleProducts) {
|
||
const enriched = enrichProductWithExcelData(product);
|
||
const hasExcelData = enriched.excelConfigurations || enriched.excelAttributes;
|
||
|
||
if (hasExcelData) {
|
||
successCount++;
|
||
details.push({
|
||
name: product.name,
|
||
slug: product.slug,
|
||
configs: enriched.excelConfigurations?.length || 0,
|
||
attrs: enriched.excelAttributes?.length || 0
|
||
});
|
||
}
|
||
}
|
||
|
||
addResult(
|
||
'Multiple Product Support',
|
||
successCount > 0,
|
||
`Enriched ${successCount} out of ${sampleProducts.length} products`,
|
||
{ details }
|
||
);
|
||
} catch (error) {
|
||
addResult('Multiple Product Support', false, `Error: ${error}`);
|
||
}
|
||
|
||
// Test 5: Check raw Excel rows
|
||
console.log('\nTest 5: Raw Excel Data Access');
|
||
try {
|
||
const testProduct = {
|
||
name: 'NA2XS(FL)2Y',
|
||
slug: 'na2xsfl2y-3',
|
||
sku: 'NA2XS(FL)2Y-high-voltage-cables',
|
||
translationKey: 'na2xsfl2y-3'
|
||
};
|
||
|
||
const rows = getExcelRowsForProduct(testProduct);
|
||
|
||
addResult(
|
||
'Raw Excel Data Access',
|
||
rows.length > 0,
|
||
`Found ${rows.length} raw rows for test product`,
|
||
{
|
||
sampleRow: rows[0] ? Object.keys(rows[0]).slice(0, 5) : 'No rows'
|
||
}
|
||
);
|
||
} catch (error) {
|
||
addResult('Raw Excel Data Access', false, `Error: ${error}`);
|
||
}
|
||
|
||
// Summary
|
||
console.log('\n📊 Test Summary:');
|
||
console.log('='.repeat(50));
|
||
|
||
const passed = results.filter(r => r.passed).length;
|
||
const total = results.length;
|
||
|
||
console.log(`Passed: ${passed}/${total}`);
|
||
console.log(`Failed: ${total - passed}/${total}`);
|
||
|
||
if (passed === total) {
|
||
console.log('\n🎉 All tests passed! Excel integration is working correctly.');
|
||
} else {
|
||
console.log('\n⚠️ Some tests failed. Please review the details above.');
|
||
console.log('\nFailed tests:');
|
||
results.filter(r => !r.passed).forEach(r => {
|
||
console.log(` - ${r.name}: ${r.message}`);
|
||
if (r.details) console.log(` Details:`, r.details);
|
||
});
|
||
}
|
||
|
||
// Exit with appropriate code
|
||
process.exit(passed === total ? 0 : 1);
|
||
}
|
||
|
||
// Run tests
|
||
runTests().catch(error => {
|
||
console.error('Fatal error:', error);
|
||
process.exit(1);
|
||
}); |