import { tap, expect } from '@push.rocks/tapbundle'; import * as getInvoices from './assets/getasset.js'; import { FacturXEncoder } from '../ts/formats/facturx.encoder.js'; import { FacturXDecoder } from '../ts/formats/facturx.decoder.js'; import { XInvoice } from '../ts/classes.xinvoice.js'; // Sample test letter data const testLetterData = getInvoices.letterObjects.letter1.demoLetter; // Test encoder/decoder at a basic level tap.test('Basic encoder/decoder test', async () => { // Create a simple encoder const encoder = new FacturXEncoder(); // Verify it has the correct methods expect(encoder).toBeTypeOf('object'); expect(encoder.createFacturXXml).toBeTypeOf('function'); expect(encoder.createZugferdXml).toBeTypeOf('function'); // For backward compatibility // Create a simple decoder const decoder = new FacturXDecoder('Test'); // Verify it has the correct method expect(decoder).toBeTypeOf('object'); expect(decoder.getLetterData).toBeTypeOf('function'); // Create a simple XInvoice instance const xInvoice = new XInvoice(); // Verify it has the correct methods expect(xInvoice).toBeTypeOf('object'); expect(xInvoice.addXmlString).toBeTypeOf('function'); expect(xInvoice.getParsedXmlData).toBeTypeOf('function'); }); // Test ZUGFeRD XML format validation tap.test('ZUGFeRD XML format validation', async () => { // Create a sample XML string directly const sampleXml = ` LL-INV-48765 `; // Create an XInvoice instance const xInvoice = new XInvoice(); // Detect the format const format = xInvoice['identifyXmlFormat'](sampleXml); // Check that the format is correctly identified as ZUGFeRD/CII expect(format).toEqual('ZUGFeRD/CII'); }); // Test invoice data extraction tap.test('Invoice data extraction from ZUGFeRD XML', async () => { // Create a sample XML string directly const sampleXml = ` ${testLetterData.content.invoiceData.id} ${testLetterData.content.invoiceData.billedBy.name} ${testLetterData.content.invoiceData.billedTo.name} `; // Create an XInvoice instance and parse the XML const xInvoice = new XInvoice(); await xInvoice.addXmlString(sampleXml); // Parse the XML to an invoice object const parsedInvoice = await xInvoice.getParsedXmlData(); // Check that core information was extracted correctly expect(parsedInvoice.InvoiceNumber).not.toEqual(''); expect(parsedInvoice.Seller.Name).not.toEqual(''); }); // Start the test suite tap.start();