feat(core): improve in-memory validation, FatturaPA detection coverage, and published type compatibility
This commit is contained in:
@@ -3,6 +3,7 @@ import { promises as fs } from 'fs';
|
||||
import * as path from 'path';
|
||||
import { CorpusLoader } from '../../helpers/corpus.loader.js';
|
||||
import { PerformanceTracker } from '../../helpers/performance.tracker.js';
|
||||
import { InvoiceFormat } from '../../../ts/interfaces/common.js';
|
||||
|
||||
tap.test('FD-09: FatturaPA Format Detection - should correctly identify Italian FatturaPA invoices', async () => {
|
||||
// Get FatturaPA test files from corpus
|
||||
@@ -18,8 +19,14 @@ tap.test('FD-09: FatturaPA Format Detection - should correctly identify Italian
|
||||
|
||||
// Import the format detector
|
||||
const { FormatDetector } = await import('../../../ts/formats/utils/format.detector.js');
|
||||
const sampledFiles = allFatturapaFiles.slice(0, 10);
|
||||
|
||||
for (const filePath of allFatturapaFiles.slice(0, 10)) { // Test first 10 for performance
|
||||
if (sampledFiles.length === 0) {
|
||||
console.log('No FatturaPA corpus files available for detection test');
|
||||
return;
|
||||
}
|
||||
|
||||
for (const filePath of sampledFiles) {
|
||||
const fileName = path.basename(filePath);
|
||||
|
||||
try {
|
||||
@@ -35,9 +42,7 @@ tap.test('FD-09: FatturaPA Format Detection - should correctly identify Italian
|
||||
{ file: fileName }
|
||||
);
|
||||
|
||||
// Verify it's detected as FatturaPA
|
||||
if (format.toString().toLowerCase().includes('fatturapa') ||
|
||||
format.toString().toLowerCase().includes('fattura')) {
|
||||
if (format === InvoiceFormat.FATTURAPA) {
|
||||
successCount++;
|
||||
console.log(`✓ ${fileName}: Correctly detected as FatturaPA`);
|
||||
} else {
|
||||
@@ -46,9 +51,9 @@ tap.test('FD-09: FatturaPA Format Detection - should correctly identify Italian
|
||||
file: fileName,
|
||||
error: `Detected as ${format} instead of FatturaPA`
|
||||
});
|
||||
console.log(`○ ${fileName}: Detected as ${format} (FatturaPA detection may need implementation)`);
|
||||
console.log(`✗ ${fileName}: Detected as ${format} instead of FatturaPA`);
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
failureCount++;
|
||||
failures.push({
|
||||
file: fileName,
|
||||
@@ -78,13 +83,8 @@ tap.test('FD-09: FatturaPA Format Detection - should correctly identify Italian
|
||||
console.log(` P95: ${perfSummary.p95.toFixed(2)}ms`);
|
||||
}
|
||||
|
||||
// Note: FatturaPA detection may not be fully implemented yet
|
||||
if (successCount === 0 && allFatturapaFiles.length > 0) {
|
||||
console.log('Note: FatturaPA format detection may need implementation');
|
||||
}
|
||||
|
||||
// Expect at least some files to be processed without error
|
||||
expect(successCount + failureCount).toBeGreaterThan(0);
|
||||
expect(successCount).toEqual(sampledFiles.length);
|
||||
expect(failureCount).toEqual(0);
|
||||
});
|
||||
|
||||
tap.test('FD-09: FatturaPA Structure Detection - should detect FatturaPA by root element', async () => {
|
||||
@@ -129,20 +129,8 @@ tap.test('FD-09: FatturaPA Structure Detection - should detect FatturaPA by root
|
||||
);
|
||||
|
||||
console.log(`${test.name}: Detected as ${format}`);
|
||||
|
||||
// Should detect as FatturaPA (if implemented) or at least not as other formats
|
||||
const formatStr = format.toString().toLowerCase();
|
||||
const isNotOtherFormats = !formatStr.includes('ubl') &&
|
||||
!formatStr.includes('cii') &&
|
||||
!formatStr.includes('zugferd');
|
||||
|
||||
if (formatStr.includes('fattura')) {
|
||||
console.log(` ✓ Correctly identified as FatturaPA`);
|
||||
} else if (isNotOtherFormats) {
|
||||
console.log(` ○ Not detected as other formats (FatturaPA detection may need implementation)`);
|
||||
} else {
|
||||
console.log(` ✗ Incorrectly detected as other format`);
|
||||
}
|
||||
expect(format).toEqual(InvoiceFormat.FATTURAPA);
|
||||
console.log(' ✓ Correctly identified as FatturaPA');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -181,14 +169,8 @@ tap.test('FD-09: FatturaPA Version Detection - should detect different FatturaPA
|
||||
);
|
||||
|
||||
console.log(`FatturaPA ${test.version}: Detected as ${format}`);
|
||||
|
||||
// Should detect as FatturaPA regardless of version
|
||||
const formatStr = format.toString().toLowerCase();
|
||||
if (formatStr.includes('fattura')) {
|
||||
console.log(` ✓ Version ${test.version} correctly detected`);
|
||||
} else {
|
||||
console.log(` ○ Version detection may need implementation`);
|
||||
}
|
||||
expect(format).toEqual(InvoiceFormat.FATTURAPA);
|
||||
console.log(` ✓ Version ${test.version} correctly detected`);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -229,16 +211,10 @@ tap.test('FD-09: FatturaPA vs Other Formats - should distinguish from other XML
|
||||
);
|
||||
|
||||
console.log(`${test.name}: Detected as ${format}`);
|
||||
|
||||
const formatStr = format.toString().toLowerCase();
|
||||
const hasExpectedFormat = formatStr.includes(test.expectedFormat);
|
||||
|
||||
if (hasExpectedFormat) {
|
||||
console.log(` ✓ Correctly distinguished ${test.name}`);
|
||||
} else {
|
||||
console.log(` ○ Format distinction may need refinement`);
|
||||
}
|
||||
|
||||
expect(format.toString().toLowerCase()).toContain(test.expectedFormat);
|
||||
console.log(` ✓ Correctly distinguished ${test.name}`);
|
||||
}
|
||||
});
|
||||
|
||||
tap.start();
|
||||
tap.start();
|
||||
|
||||
Reference in New Issue
Block a user