feat(core): improve in-memory validation, FatturaPA detection coverage, and published type compatibility
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
import { EInvoice } from '../ts/einvoice.js';
|
||||
import { EInvoiceFormatError } from '../ts/errors.js';
|
||||
import { ValidationLevel } from '../ts/interfaces/common.js';
|
||||
import type { ExportFormat } from '../ts/interfaces/common.js';
|
||||
|
||||
@@ -217,5 +218,57 @@ tap.test('EInvoice should validate XML correctly', async () => {
|
||||
expect(result.errors).toHaveLength(0);
|
||||
});
|
||||
|
||||
tap.test('EInvoice should validate programmatic invoices without loaded XML', async () => {
|
||||
const emptyInvoice = new EInvoice();
|
||||
const emptyValidation = await emptyInvoice.validate();
|
||||
|
||||
expect(emptyValidation.valid).toBeFalse();
|
||||
expect(emptyValidation.errors.some(error => error.code === 'BR-01')).toBeTrue();
|
||||
expect(emptyValidation.errors.some(error => error.code === 'BR-16')).toBeTrue();
|
||||
|
||||
const validInvoice = new EInvoice();
|
||||
validInvoice.accountingDocId = 'TEST-IN-MEMORY';
|
||||
validInvoice.from.name = 'Programmatic Seller';
|
||||
validInvoice.from.address = {
|
||||
streetName: 'Seller Street',
|
||||
houseNumber: '1',
|
||||
city: 'Berlin',
|
||||
postalCode: '10115',
|
||||
country: 'DE'
|
||||
};
|
||||
validInvoice.to.name = 'Programmatic Buyer';
|
||||
validInvoice.to.address = {
|
||||
streetName: 'Buyer Street',
|
||||
houseNumber: '2',
|
||||
city: 'Hamburg',
|
||||
postalCode: '20095',
|
||||
country: 'DE'
|
||||
};
|
||||
validInvoice.items.push({
|
||||
position: 1,
|
||||
name: 'Programmatic Product',
|
||||
articleNumber: 'PP-001',
|
||||
unitType: 'EA',
|
||||
unitQuantity: 1,
|
||||
unitNetPrice: 100,
|
||||
vatPercentage: 19
|
||||
});
|
||||
|
||||
const validResult = await validInvoice.validate(ValidationLevel.BUSINESS);
|
||||
expect(validResult.valid).toBeTrue();
|
||||
expect(validResult.errors).toHaveLength(0);
|
||||
});
|
||||
|
||||
tap.test('EInvoice should reject unsupported invoice types explicitly', async () => {
|
||||
const einvoice = new EInvoice();
|
||||
|
||||
try {
|
||||
einvoice.invoiceType = 'creditnote';
|
||||
expect(true).toBeFalse();
|
||||
} catch (error) {
|
||||
expect(error).toBeInstanceOf(EInvoiceFormatError);
|
||||
}
|
||||
});
|
||||
|
||||
// Run the tests
|
||||
tap.start();
|
||||
|
||||
Reference in New Issue
Block a user