BREAKING CHANGE(XInvoice): Refactor XInvoice API for XML handling and PDF export by replacing deprecated methods (addXmlString and getParsedXmlData) with fromXml and loadXml, and by introducing a new ExportFormat type for type-safe export. Update tests accordingly.

This commit is contained in:
2025-03-20 14:39:32 +00:00
parent d954fb4768
commit 9510d851af
10 changed files with 174 additions and 72 deletions

View File

@ -113,31 +113,28 @@ tap.test('Circular encode/decode with different invoice types', async () => {
// Test with full XInvoice class for complete cycle
tap.test('Full XInvoice circular processing test', async () => {
// Create an XInvoice instance
const xInvoice = new XInvoice();
// First, generate XML from our letter data
const encoder = new FacturXEncoder();
const xml = encoder.createFacturXXml(testLetterData);
// Add XML to XInvoice
await xInvoice.addXmlString(xml);
// Create XInvoice from XML
const xInvoice = await XInvoice.fromXml(xml);
// Now extract data back
const parsedData = await xInvoice.getParsedXmlData();
// Extract structured data from the loaded invoice
const content = xInvoice.content;
// Verify we got invoice data back
expect(parsedData).toBeTypeOf('object');
expect(parsedData.InvoiceNumber).toBeDefined();
expect(parsedData.Seller).toBeDefined();
expect(parsedData.Buyer).toBeDefined();
expect(content).toBeDefined();
expect(content.invoiceData).toBeDefined();
expect(content.invoiceData.id).toBeDefined();
expect(content.invoiceData.billedBy).toBeDefined();
expect(content.invoiceData.billedTo).toBeDefined();
// Since the decoder doesn't fully extract the exact ID string yet, we need to be lenient
// with our expectations, so we just check that we have valid data populated
expect(parsedData.InvoiceNumber).toBeDefined();
expect(parsedData.InvoiceNumber.length).toBeGreaterThan(0);
expect(parsedData.Seller.Name).toBeDefined();
expect(parsedData.Buyer.Name).toBeDefined();
// Verify that the data matches our input
expect(content.invoiceData.id).toBeDefined();
expect(content.invoiceData.id.length).toBeGreaterThan(0);
expect(content.invoiceData.billedBy.name).toBeDefined();
expect(content.invoiceData.billedTo.name).toBeDefined();
});
// Test with different invoice contents