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:
@@ -7,9 +7,9 @@ import type { ExportFormat } from '../ts/interfaces/common.js';
|
||||
tap.test('EInvoice should have the correct default properties', async () => {
|
||||
const einvoice = new EInvoice();
|
||||
|
||||
expect(einvoice.type).toEqual('invoice');
|
||||
expect(einvoice.invoiceType).toEqual('debitnote');
|
||||
expect(einvoice.status).toEqual('invoice');
|
||||
expect(einvoice.type).toEqual('accounting-doc');
|
||||
expect(einvoice.accountingDocType).toEqual('invoice');
|
||||
expect(einvoice.status).toEqual('issued');
|
||||
expect(einvoice.from).toBeTruthy();
|
||||
expect(einvoice.to).toBeTruthy();
|
||||
expect(einvoice.items).toBeArray();
|
||||
@@ -20,9 +20,23 @@ tap.test('EInvoice should have the correct default properties', async () => {
|
||||
tap.test('EInvoice should export XML in the correct format', async () => {
|
||||
const einvoice = new EInvoice();
|
||||
einvoice.id = 'TEST-XML-EXPORT';
|
||||
einvoice.invoiceId = 'TEST-XML-EXPORT';
|
||||
einvoice.accountingDocId = 'TEST-XML-EXPORT';
|
||||
einvoice.from.name = 'Test Seller';
|
||||
einvoice.from.address = {
|
||||
streetName: 'Seller Street',
|
||||
houseNumber: '1',
|
||||
city: 'Berlin',
|
||||
postalCode: '10115',
|
||||
country: 'Germany'
|
||||
};
|
||||
einvoice.to.name = 'Test Buyer';
|
||||
einvoice.to.address = {
|
||||
streetName: 'Buyer Street',
|
||||
houseNumber: '2',
|
||||
city: 'Munich',
|
||||
postalCode: '80331',
|
||||
country: 'Germany'
|
||||
};
|
||||
|
||||
// Add an item
|
||||
einvoice.items.push({
|
||||
@@ -98,7 +112,7 @@ tap.test('EInvoice should load XML correctly', async () => {
|
||||
const einvoice = await EInvoice.fromXml(sampleXml);
|
||||
|
||||
// Check that the EInvoice instance has the expected properties
|
||||
expect(einvoice.id).toEqual('TEST-XML-LOAD');
|
||||
expect(einvoice.accountingDocId).toEqual('TEST-XML-LOAD');
|
||||
expect(einvoice.from.name).toEqual('XML Seller');
|
||||
expect(einvoice.to.name).toEqual('XML Buyer');
|
||||
expect(einvoice.currency).toEqual('EUR');
|
||||
@@ -109,9 +123,23 @@ tap.test('EInvoice should maintain data integrity through export/import cycle',
|
||||
// Create a sample invoice
|
||||
const originalInvoice = new EInvoice();
|
||||
originalInvoice.id = 'TEST-CIRCULAR';
|
||||
originalInvoice.invoiceId = 'TEST-CIRCULAR';
|
||||
originalInvoice.accountingDocId = 'TEST-CIRCULAR';
|
||||
originalInvoice.from.name = 'Circular Seller';
|
||||
originalInvoice.from.address = {
|
||||
streetName: 'Circular Street',
|
||||
houseNumber: '10',
|
||||
city: 'Hamburg',
|
||||
postalCode: '20095',
|
||||
country: 'Germany'
|
||||
};
|
||||
originalInvoice.to.name = 'Circular Buyer';
|
||||
originalInvoice.to.address = {
|
||||
streetName: 'Buyer Avenue',
|
||||
houseNumber: '20',
|
||||
city: 'Frankfurt',
|
||||
postalCode: '60311',
|
||||
country: 'Germany'
|
||||
};
|
||||
|
||||
// Add an item
|
||||
originalInvoice.items.push({
|
||||
@@ -131,7 +159,7 @@ tap.test('EInvoice should maintain data integrity through export/import cycle',
|
||||
const importedInvoice = await EInvoice.fromXml(xml);
|
||||
|
||||
// Check that key properties match
|
||||
expect(importedInvoice.id).toEqual(originalInvoice.id);
|
||||
expect(importedInvoice.accountingDocId).toEqual(originalInvoice.accountingDocId);
|
||||
expect(importedInvoice.from.name).toEqual(originalInvoice.from.name);
|
||||
expect(importedInvoice.to.name).toEqual(originalInvoice.to.name);
|
||||
|
||||
@@ -146,18 +174,43 @@ tap.test('EInvoice should maintain data integrity through export/import cycle',
|
||||
tap.test('EInvoice should validate XML correctly', async () => {
|
||||
const einvoice = new EInvoice();
|
||||
einvoice.id = 'TEST-VALIDATION';
|
||||
einvoice.invoiceId = 'TEST-VALIDATION';
|
||||
einvoice.accountingDocId = 'TEST-VALIDATION';
|
||||
einvoice.from.name = 'Validation Seller';
|
||||
einvoice.from.address = {
|
||||
streetName: 'Validation Street',
|
||||
houseNumber: '5',
|
||||
city: 'Stuttgart',
|
||||
postalCode: '70173',
|
||||
country: 'Germany'
|
||||
};
|
||||
einvoice.to.name = 'Validation Buyer';
|
||||
einvoice.to.address = {
|
||||
streetName: 'Test Road',
|
||||
houseNumber: '15',
|
||||
city: 'Cologne',
|
||||
postalCode: '50667',
|
||||
country: 'Germany'
|
||||
};
|
||||
|
||||
// Add an item to pass BR-16 validation
|
||||
einvoice.items.push({
|
||||
position: 1,
|
||||
name: 'Validation Product',
|
||||
articleNumber: 'VP-001',
|
||||
unitType: 'EA',
|
||||
unitQuantity: 1,
|
||||
unitNetPrice: 50,
|
||||
vatPercentage: 19
|
||||
});
|
||||
|
||||
// Export as Factur-X
|
||||
const xml = await einvoice.exportXml('facturx');
|
||||
|
||||
// Set the XML string for validation
|
||||
einvoice['xmlString'] = xml;
|
||||
// Create a new invoice from the XML to properly set format
|
||||
const einvoiceForValidation = await EInvoice.fromXml(xml);
|
||||
|
||||
// Validate the XML
|
||||
const result = await einvoice.validate(ValidationLevel.SYNTAX);
|
||||
const result = await einvoiceForValidation.validate(ValidationLevel.SYNTAX);
|
||||
|
||||
// Check that validation passed
|
||||
expect(result.valid).toBeTrue();
|
||||
|
Reference in New Issue
Block a user