BREAKING CHANGE(core): Rebrand XInvoice to EInvoice: update package name, class names, imports, and documentation
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
import { tap, expect } from '@push.rocks/tapbundle';
|
||||
import { XInvoice } from '../ts/classes.xinvoice.js';
|
||||
import { EInvoice } from '../ts/einvoice.js';
|
||||
import { InvoiceFormat } from '../ts/interfaces/common.js';
|
||||
import * as fs from 'fs/promises';
|
||||
import * as path from 'path';
|
||||
|
||||
// Test a focused subset of corpus files
|
||||
tap.test('XInvoice should handle a focused subset of corpus files', async () => {
|
||||
tap.test('EInvoice should handle a focused subset of corpus files', async () => {
|
||||
// Get a small subset of files for focused testing
|
||||
const ciiFiles = await findFiles(path.join(process.cwd(), 'test/assets/corpus/XML-Rechnung/CII'), '.xml', 5);
|
||||
const ublFiles = await findFiles(path.join(process.cwd(), 'test/assets/corpus/XML-Rechnung/UBL'), '.xml', 5);
|
||||
@ -55,13 +55,13 @@ async function testXmlFile(file: string, expectedFormat: InvoiceFormat): Promise
|
||||
// Read the file
|
||||
const xmlContent = await fs.readFile(file, 'utf8');
|
||||
|
||||
// Create XInvoice from XML
|
||||
const xinvoice = await XInvoice.fromXml(xmlContent);
|
||||
// Create EInvoice from XML
|
||||
const einvoice = await EInvoice.fromXml(xmlContent);
|
||||
|
||||
// Check that the XInvoice instance has the expected properties
|
||||
if (xinvoice && xinvoice.from && xinvoice.to && xinvoice.items) {
|
||||
// Check that the EInvoice instance has the expected properties
|
||||
if (einvoice && einvoice.from && einvoice.to && einvoice.items) {
|
||||
// Check that the format is detected correctly
|
||||
const format = xinvoice.getFormat();
|
||||
const format = einvoice.getFormat();
|
||||
const isCorrectFormat = format === expectedFormat ||
|
||||
(expectedFormat === InvoiceFormat.CII && format === InvoiceFormat.FACTURX) ||
|
||||
(expectedFormat === InvoiceFormat.FACTURX && format === InvoiceFormat.CII) ||
|
||||
@ -76,14 +76,14 @@ async function testXmlFile(file: string, expectedFormat: InvoiceFormat): Promise
|
||||
exportFormat = 'xrechnung';
|
||||
}
|
||||
|
||||
const exportedXml = await xinvoice.exportXml(exportFormat as any);
|
||||
const exportedXml = await einvoice.exportXml(exportFormat as any);
|
||||
|
||||
if (exportedXml) {
|
||||
console.log('✅ Success: File loaded, format detected correctly, and exported successfully');
|
||||
console.log(`Format: ${format}`);
|
||||
console.log(`From: ${xinvoice.from.name}`);
|
||||
console.log(`To: ${xinvoice.to.name}`);
|
||||
console.log(`Items: ${xinvoice.items.length}`);
|
||||
console.log(`From: ${einvoice.from.name}`);
|
||||
console.log(`To: ${einvoice.to.name}`);
|
||||
console.log(`Items: ${einvoice.items.length}`);
|
||||
|
||||
// Save the exported XML for inspection
|
||||
const testDir = path.join(process.cwd(), 'test', 'output', 'focused');
|
||||
@ -176,23 +176,23 @@ async function testPdfFile(file: string): Promise<void> {
|
||||
// Save the extracted XML for inspection
|
||||
await fs.writeFile(path.join(testDir, `${path.basename(file)}-extracted.xml`), xmlContent);
|
||||
|
||||
// Try to create XInvoice from the extracted XML
|
||||
// Try to create EInvoice from the extracted XML
|
||||
try {
|
||||
const xinvoice = await XInvoice.fromXml(xmlContent);
|
||||
const einvoice = await EInvoice.fromXml(xmlContent);
|
||||
|
||||
if (xinvoice && xinvoice.from && xinvoice.to && xinvoice.items) {
|
||||
console.log('✅ Successfully created XInvoice from extracted XML');
|
||||
console.log(`Format: ${xinvoice.getFormat()}`);
|
||||
console.log(`From: ${xinvoice.from.name}`);
|
||||
console.log(`To: ${xinvoice.to.name}`);
|
||||
console.log(`Items: ${xinvoice.items.length}`);
|
||||
if (einvoice && einvoice.from && einvoice.to && einvoice.items) {
|
||||
console.log('✅ Successfully created EInvoice from extracted XML');
|
||||
console.log(`Format: ${einvoice.getFormat()}`);
|
||||
console.log(`From: ${einvoice.from.name}`);
|
||||
console.log(`To: ${einvoice.to.name}`);
|
||||
console.log(`Items: ${einvoice.items.length}`);
|
||||
|
||||
// Try to export the invoice back to XML
|
||||
try {
|
||||
const exportedXml = await xinvoice.exportXml('facturx');
|
||||
const exportedXml = await einvoice.exportXml('facturx');
|
||||
|
||||
if (exportedXml) {
|
||||
console.log('✅ Successfully exported XInvoice back to XML');
|
||||
console.log('✅ Successfully exported EInvoice back to XML');
|
||||
|
||||
// Save the exported XML for inspection
|
||||
await fs.writeFile(path.join(testDir, `${path.basename(file)}-reexported.xml`), exportedXml);
|
||||
@ -203,30 +203,30 @@ async function testPdfFile(file: string): Promise<void> {
|
||||
console.log(`❌ Export error: ${exportError.message}`);
|
||||
}
|
||||
} else {
|
||||
console.log('❌ Missing required properties in created XInvoice');
|
||||
console.log('❌ Missing required properties in created EInvoice');
|
||||
}
|
||||
} catch (xmlError) {
|
||||
console.log(`❌ Error creating XInvoice from extracted XML: ${xmlError.message}`);
|
||||
console.log(`❌ Error creating EInvoice from extracted XML: ${xmlError.message}`);
|
||||
}
|
||||
} else {
|
||||
console.log('❌ No XML found in PDF');
|
||||
}
|
||||
|
||||
// Try to create XInvoice directly from PDF
|
||||
// Try to create EInvoice directly from PDF
|
||||
try {
|
||||
const xinvoice = await XInvoice.fromPdf(pdfBuffer);
|
||||
const einvoice = await EInvoice.fromPdf(pdfBuffer);
|
||||
|
||||
if (xinvoice && xinvoice.from && xinvoice.to && xinvoice.items) {
|
||||
console.log('✅ Successfully created XInvoice directly from PDF');
|
||||
console.log(`Format: ${xinvoice.getFormat()}`);
|
||||
console.log(`From: ${xinvoice.from.name}`);
|
||||
console.log(`To: ${xinvoice.to.name}`);
|
||||
console.log(`Items: ${xinvoice.items.length}`);
|
||||
if (einvoice && einvoice.from && einvoice.to && einvoice.items) {
|
||||
console.log('✅ Successfully created EInvoice directly from PDF');
|
||||
console.log(`Format: ${einvoice.getFormat()}`);
|
||||
console.log(`From: ${einvoice.from.name}`);
|
||||
console.log(`To: ${einvoice.to.name}`);
|
||||
console.log(`Items: ${einvoice.items.length}`);
|
||||
} else {
|
||||
console.log('❌ Missing required properties in created XInvoice');
|
||||
console.log('❌ Missing required properties in created EInvoice');
|
||||
}
|
||||
} catch (pdfError) {
|
||||
console.log(`❌ Error creating XInvoice directly from PDF: ${pdfError.message}`);
|
||||
console.log(`❌ Error creating EInvoice directly from PDF: ${pdfError.message}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`❌ Error processing the file: ${error.message}`);
|
||||
|
Reference in New Issue
Block a user