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:
41
test/test.ts
41
test/test.ts
@ -12,12 +12,22 @@ import { FacturXDecoder } from '../ts/formats/facturx.decoder.js';
|
||||
tap.test('XInvoice should initialize correctly', async () => {
|
||||
const xInvoice = new xinvoice.XInvoice();
|
||||
expect(xInvoice).toBeTypeOf('object');
|
||||
expect(xInvoice.addPdfBuffer).toBeTypeOf('function');
|
||||
expect(xInvoice.addXmlString).toBeTypeOf('function');
|
||||
expect(xInvoice.addLetterData).toBeTypeOf('function');
|
||||
expect(xInvoice.getXInvoice).toBeTypeOf('function');
|
||||
expect(xInvoice.getXmlData).toBeTypeOf('function');
|
||||
expect(xInvoice.getParsedXmlData).toBeTypeOf('function');
|
||||
|
||||
// Check if essential methods exist
|
||||
expect(xInvoice.loadPdf).toBeTypeOf('function');
|
||||
expect(xInvoice.loadXml).toBeTypeOf('function');
|
||||
expect(xInvoice.validate).toBeTypeOf('function');
|
||||
expect(xInvoice.isValid).toBeTypeOf('function');
|
||||
expect(xInvoice.getValidationErrors).toBeTypeOf('function');
|
||||
expect(xInvoice.exportXml).toBeTypeOf('function');
|
||||
expect(xInvoice.exportPdf).toBeTypeOf('function');
|
||||
|
||||
// Check if the properties exist
|
||||
expect(xInvoice.type).toBeDefined();
|
||||
expect(xInvoice.from).toBeDefined();
|
||||
expect(xInvoice.to).toBeDefined();
|
||||
expect(xInvoice.content).toBeDefined();
|
||||
|
||||
return true; // Explicitly return true
|
||||
});
|
||||
|
||||
@ -67,29 +77,28 @@ tap.test('FacturXDecoder should be created correctly', async () => {
|
||||
tap.test('XInvoice should throw errors for missing data', async () => {
|
||||
const xInvoice = new xinvoice.XInvoice();
|
||||
|
||||
// Test missing PDF buffer
|
||||
// Test validation without any data
|
||||
try {
|
||||
await xInvoice.getXmlData();
|
||||
tap.fail('Should have thrown an error for missing PDF buffer');
|
||||
await xInvoice.validate();
|
||||
tap.fail('Should have thrown an error for missing XML data');
|
||||
} catch (error) {
|
||||
expect(error).toBeTypeOf('object');
|
||||
expect(error instanceof Error).toEqual(true);
|
||||
}
|
||||
|
||||
// Test missing XML string and letter data for embedding
|
||||
// Test exporting PDF without PDF data
|
||||
try {
|
||||
await xInvoice.addPdfBuffer(new Uint8Array(10));
|
||||
await xInvoice.getXInvoice();
|
||||
tap.fail('Should have thrown an error for missing XML string or letter data');
|
||||
await xInvoice.exportPdf();
|
||||
tap.fail('Should have thrown an error for missing PDF data');
|
||||
} catch (error) {
|
||||
expect(error).toBeTypeOf('object');
|
||||
expect(error instanceof Error).toEqual(true);
|
||||
}
|
||||
|
||||
// Test missing XML string for parsing
|
||||
// Test loading invalid XML
|
||||
try {
|
||||
await xInvoice.getParsedXmlData();
|
||||
tap.fail('Should have thrown an error for missing XML string');
|
||||
await xInvoice.loadXml("This is not XML");
|
||||
tap.fail('Should have thrown an error for invalid XML');
|
||||
} catch (error) {
|
||||
expect(error).toBeTypeOf('object');
|
||||
expect(error instanceof Error).toEqual(true);
|
||||
|
Reference in New Issue
Block a user