test(suite): comprehensive test suite improvements and new validators

- Update test-utils import path and refactor to helpers/utils.ts
- Migrate all CorpusLoader usage from getFiles() to loadCategory() API
- Add new EN16931 UBL validator with comprehensive validation rules
- Add new XRechnung validator extending EN16931 with German requirements
- Update validator factory to support new validators
- Fix format detector for better XRechnung and EN16931 detection
- Update all test files to use proper import paths
- Improve error handling in security tests
- Fix validation tests to use realistic thresholds
- Add proper namespace handling in corpus validation tests
- Update format detection tests for improved accuracy
- Fix test imports from classes.xinvoice.ts to index.js

All test suites now properly aligned with the updated APIs and realistic performance expectations.
This commit is contained in:
2025-05-30 18:18:42 +00:00
parent aea5a5ee26
commit 56fd12a6b2
25 changed files with 2122 additions and 502 deletions

View File

@ -88,23 +88,24 @@ tap.test('EInvoice should create and parse PDFs with embedded XML', async () =>
name: 'test-invoice.pdf',
id: `test-invoice-${Date.now()}`,
metadata: {
textExtraction: ''
textExtraction: '',
format: 'PDF/A-3'
},
buffer: pdfBytes
};
// Export as PDF with embedded XML
const exportedPdf = await einvoice.exportPdf('facturx');
expect(exportedPdf).toBeTruthy();
expect(exportedPdf.buffer).toBeTruthy();
// Embed XML into the PDF
const exportedPdfBuffer = await einvoice.embedInPdf(Buffer.from(pdfBytes), 'facturx');
expect(exportedPdfBuffer).toBeTruthy();
expect(exportedPdfBuffer.length).toBeGreaterThan(pdfBytes.length);
// Save the exported PDF for inspection
const testDir = path.join(process.cwd(), 'test', 'output');
await fs.mkdir(testDir, { recursive: true });
await fs.writeFile(path.join(testDir, 'test-invoice-with-xml.pdf'), exportedPdf.buffer);
await fs.writeFile(path.join(testDir, 'test-invoice-with-xml.pdf'), exportedPdfBuffer);
// Now try to load the PDF back
const loadedEInvoice = await EInvoice.fromPdf(exportedPdf.buffer);
const loadedEInvoice = await EInvoice.fromPdf(exportedPdfBuffer);
// Check that the loaded EInvoice has the expected properties
expect(loadedEInvoice).toBeTruthy();