598 lines
27 KiB
TypeScript
598 lines
27 KiB
TypeScript
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
|
import * as plugins from '../../../ts/plugins.js';
|
|
import { EInvoice } from '../../../ts/index.js';
|
|
import { CorpusLoader } from '../../helpers/corpus.loader.js';
|
|
|
|
const testTimeout = 300000; // 5 minutes timeout for conversion processing
|
|
|
|
// CONV-03: ZUGFeRD to XRechnung Conversion
|
|
// Tests conversion from ZUGFeRD format to XRechnung (German CIUS of EN16931)
|
|
// including profile adaptation, compliance checking, and German-specific requirements
|
|
|
|
tap.test('CONV-03: ZUGFeRD to XRechnung Conversion - Basic Conversion', async (tools) => {
|
|
|
|
try {
|
|
// Create a sample ZUGFeRD invoice for conversion testing
|
|
const sampleZugferdXml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
<rsm:CrossIndustryInvoice xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100"
|
|
xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100"
|
|
xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100">
|
|
<rsm:ExchangedDocumentContext>
|
|
<ram:GuidelineSpecifiedDocumentContextParameter>
|
|
<ram:ID>urn:cen.eu:en16931:2017#compliant#urn:zugferd.de:2p1:comfort</ram:ID>
|
|
</ram:GuidelineSpecifiedDocumentContextParameter>
|
|
</rsm:ExchangedDocumentContext>
|
|
<rsm:ExchangedDocument>
|
|
<ram:ID>ZUGFERD-TO-XRECHNUNG-001</ram:ID>
|
|
<ram:TypeCode>380</ram:TypeCode>
|
|
<ram:IssueDateTime>
|
|
<udt:DateTimeString format="102">20240115</udt:DateTimeString>
|
|
</ram:IssueDateTime>
|
|
<ram:IncludedNote>
|
|
<ram:Content>ZUGFeRD to XRechnung conversion test</ram:Content>
|
|
</ram:IncludedNote>
|
|
</rsm:ExchangedDocument>
|
|
<rsm:SupplyChainTradeTransaction>
|
|
<ram:IncludedSupplyChainTradeLineItem>
|
|
<ram:AssociatedDocumentLineDocument>
|
|
<ram:LineID>1</ram:LineID>
|
|
</ram:AssociatedDocumentLineDocument>
|
|
<ram:SpecifiedTradeProduct>
|
|
<ram:Name>ZUGFeRD Test Product</ram:Name>
|
|
<ram:Description>Product for ZUGFeRD to XRechnung conversion</ram:Description>
|
|
</ram:SpecifiedTradeProduct>
|
|
<ram:SpecifiedLineTradeAgreement>
|
|
<ram:NetPriceProductTradePrice>
|
|
<ram:ChargeAmount>50.00</ram:ChargeAmount>
|
|
</ram:NetPriceProductTradePrice>
|
|
</ram:SpecifiedLineTradeAgreement>
|
|
<ram:SpecifiedLineTradeDelivery>
|
|
<ram:BilledQuantity unitCode="C62">2</ram:BilledQuantity>
|
|
</ram:SpecifiedLineTradeDelivery>
|
|
<ram:SpecifiedLineTradeSettlement>
|
|
<ram:ApplicableTradeTax>
|
|
<ram:TypeCode>VAT</ram:TypeCode>
|
|
<ram:RateApplicablePercent>19.00</ram:RateApplicablePercent>
|
|
</ram:ApplicableTradeTax>
|
|
<ram:SpecifiedLineTradeSettlementMonetarySummation>
|
|
<ram:LineTotalAmount>100.00</ram:LineTotalAmount>
|
|
</ram:SpecifiedLineTradeSettlementMonetarySummation>
|
|
</ram:SpecifiedLineTradeSettlement>
|
|
</ram:IncludedSupplyChainTradeLineItem>
|
|
<ram:ApplicableHeaderTradeAgreement>
|
|
<ram:BuyerReference>BUYER-REF-123</ram:BuyerReference>
|
|
<ram:SellerTradeParty>
|
|
<ram:Name>ZUGFeRD Test Supplier GmbH</ram:Name>
|
|
<ram:PostalTradeAddress>
|
|
<ram:PostcodeCode>10115</ram:PostcodeCode>
|
|
<ram:LineOne>Friedrichstraße 123</ram:LineOne>
|
|
<ram:CityName>Berlin</ram:CityName>
|
|
<ram:CountryID>DE</ram:CountryID>
|
|
</ram:PostalTradeAddress>
|
|
<ram:SpecifiedTaxRegistration>
|
|
<ram:ID schemeID="VA">DE123456789</ram:ID>
|
|
</ram:SpecifiedTaxRegistration>
|
|
</ram:SellerTradeParty>
|
|
<ram:BuyerTradeParty>
|
|
<ram:Name>XRechnung Test Customer GmbH</ram:Name>
|
|
<ram:PostalTradeAddress>
|
|
<ram:PostcodeCode>80331</ram:PostcodeCode>
|
|
<ram:LineOne>Marienplatz 1</ram:LineOne>
|
|
<ram:CityName>München</ram:CityName>
|
|
<ram:CountryID>DE</ram:CountryID>
|
|
</ram:PostalTradeAddress>
|
|
</ram:BuyerTradeParty>
|
|
</ram:ApplicableHeaderTradeAgreement>
|
|
<ram:ApplicableHeaderTradeDelivery>
|
|
<ram:ActualDeliverySupplyChainEvent>
|
|
<ram:OccurrenceDateTime>
|
|
<udt:DateTimeString format="102">20240115</udt:DateTimeString>
|
|
</ram:OccurrenceDateTime>
|
|
</ram:ActualDeliverySupplyChainEvent>
|
|
</ram:ApplicableHeaderTradeDelivery>
|
|
<ram:ApplicableHeaderTradeSettlement>
|
|
<ram:InvoiceCurrencyCode>EUR</ram:InvoiceCurrencyCode>
|
|
<ram:ApplicableTradeTax>
|
|
<ram:CalculatedAmount>19.00</ram:CalculatedAmount>
|
|
<ram:TypeCode>VAT</ram:TypeCode>
|
|
<ram:BasisAmount>100.00</ram:BasisAmount>
|
|
<ram:RateApplicablePercent>19.00</ram:RateApplicablePercent>
|
|
</ram:ApplicableTradeTax>
|
|
<ram:SpecifiedTradeSettlementHeaderMonetarySummation>
|
|
<ram:LineTotalAmount>100.00</ram:LineTotalAmount>
|
|
<ram:TaxBasisTotalAmount>100.00</ram:TaxBasisTotalAmount>
|
|
<ram:TaxTotalAmount currencyID="EUR">19.00</ram:TaxTotalAmount>
|
|
<ram:GrandTotalAmount>119.00</ram:GrandTotalAmount>
|
|
<ram:DuePayableAmount>119.00</ram:DuePayableAmount>
|
|
</ram:SpecifiedTradeSettlementHeaderMonetarySummation>
|
|
</ram:ApplicableHeaderTradeSettlement>
|
|
</rsm:SupplyChainTradeTransaction>
|
|
</rsm:CrossIndustryInvoice>`;
|
|
|
|
const invoice = new EInvoice();
|
|
const parseResult = await invoice.fromXmlString(sampleZugferdXml);
|
|
expect(parseResult).toBeTruthy();
|
|
|
|
// Test ZUGFeRD to XRechnung conversion
|
|
console.log('Testing ZUGFeRD to XRechnung conversion...');
|
|
|
|
try {
|
|
const convertedXml = await invoice.toXmlString('UBL');
|
|
|
|
if (convertedXml) {
|
|
console.log('✓ ZUGFeRD to XRechnung conversion completed');
|
|
|
|
// Verify the converted format
|
|
expect(convertedXml).toBeTruthy();
|
|
expect(convertedXml.length).toBeGreaterThan(100);
|
|
|
|
// Check for XRechnung format characteristics
|
|
const xrechnungChecks = {
|
|
hasXrechnungCustomization: convertedXml.includes('urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung') ||
|
|
convertedXml.includes('XRechnung') ||
|
|
convertedXml.includes('xrechnung'),
|
|
hasUblNamespace: convertedXml.includes('urn:oasis:names:specification:ubl:schema:xsd:Invoice-2'),
|
|
hasPeppolProfile: convertedXml.includes('urn:fdc:peppol.eu:2017:poacc:billing:01:1.0'),
|
|
hasOriginalId: convertedXml.includes('ZUGFERD-TO-XRECHNUNG-001'),
|
|
hasGermanVat: convertedXml.includes('DE123456789'),
|
|
hasEurocurrency: convertedXml.includes('EUR')
|
|
};
|
|
|
|
console.log('XRechnung Format Verification:');
|
|
console.log(` XRechnung Customization: ${xrechnungChecks.hasXrechnungCustomization}`);
|
|
console.log(` UBL Namespace: ${xrechnungChecks.hasUblNamespace}`);
|
|
console.log(` PEPPOL Profile: ${xrechnungChecks.hasPeppolProfile}`);
|
|
console.log(` Original ID preserved: ${xrechnungChecks.hasOriginalId}`);
|
|
console.log(` German VAT preserved: ${xrechnungChecks.hasGermanVat}`);
|
|
console.log(` Euro currency preserved: ${xrechnungChecks.hasEurourrency}`);
|
|
|
|
if (xrechnungChecks.hasUblNamespace || xrechnungChecks.hasXrechnungCustomization) {
|
|
console.log('✓ Valid XRechnung format structure detected');
|
|
} else {
|
|
console.log('⚠ XRechnung format structure not clearly detected');
|
|
}
|
|
|
|
// Validate the converted invoice by parsing it
|
|
try {
|
|
const convertedInvoice = new EInvoice();
|
|
await convertedInvoice.fromXmlString(convertedXml);
|
|
const validationResult = await convertedInvoice.validate();
|
|
if (validationResult.valid) {
|
|
console.log('✓ Converted XRechnung invoice passes validation');
|
|
} else {
|
|
console.log(`⚠ Converted XRechnung validation issues: ${validationResult.errors?.length || 0} errors`);
|
|
if (validationResult.errors && validationResult.errors.length > 0) {
|
|
console.log(` First error: ${validationResult.errors[0].message}`);
|
|
}
|
|
}
|
|
} catch (validationError) {
|
|
console.log(`⚠ Converted XRechnung validation failed: ${validationError.message}`);
|
|
}
|
|
|
|
} else {
|
|
console.log('⚠ ZUGFeRD to XRechnung conversion returned no result');
|
|
}
|
|
|
|
} catch (conversionError) {
|
|
console.log(`⚠ ZUGFeRD to XRechnung conversion failed: ${conversionError.message}`);
|
|
}
|
|
|
|
} catch (error) {
|
|
console.log(`Basic ZUGFeRD to XRechnung conversion test failed: ${error.message}`);
|
|
}
|
|
|
|
// Conversion test completed
|
|
});
|
|
|
|
tap.test('CONV-03: ZUGFeRD to XRechnung Conversion - Profile Adaptation', async (tools) => {
|
|
|
|
// Test conversion of different ZUGFeRD profiles to XRechnung
|
|
const profileTests = [
|
|
{
|
|
name: 'ZUGFeRD MINIMUM to XRechnung',
|
|
zugferdXml: `<?xml version="1.0" encoding="UTF-8"?>
|
|
<rsm:CrossIndustryInvoice xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100"
|
|
xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100"
|
|
xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100">
|
|
<rsm:ExchangedDocumentContext>
|
|
<ram:GuidelineSpecifiedDocumentContextParameter>
|
|
<ram:ID>urn:cen.eu:en16931:2017#compliant#urn:zugferd.de:2p1:minimum</ram:ID>
|
|
</ram:GuidelineSpecifiedDocumentContextParameter>
|
|
</rsm:ExchangedDocumentContext>
|
|
<rsm:ExchangedDocument>
|
|
<ram:ID>MIN-TO-XRECHNUNG-001</ram:ID>
|
|
<ram:TypeCode>380</ram:TypeCode>
|
|
<ram:IssueDateTime>
|
|
<udt:DateTimeString format="102">20240115</udt:DateTimeString>
|
|
</ram:IssueDateTime>
|
|
</rsm:ExchangedDocument>
|
|
<rsm:SupplyChainTradeTransaction>
|
|
<ram:ApplicableHeaderTradeSettlement>
|
|
<ram:InvoiceCurrencyCode>EUR</ram:InvoiceCurrencyCode>
|
|
<ram:SpecifiedTradeSettlementHeaderMonetarySummation>
|
|
<ram:DuePayableAmount>119.00</ram:DuePayableAmount>
|
|
</ram:SpecifiedTradeSettlementHeaderMonetarySummation>
|
|
</ram:ApplicableHeaderTradeSettlement>
|
|
</rsm:SupplyChainTradeTransaction>
|
|
</rsm:CrossIndustryInvoice>`
|
|
},
|
|
{
|
|
name: 'ZUGFeRD BASIC to XRechnung',
|
|
zugferdXml: `<?xml version="1.0" encoding="UTF-8"?>
|
|
<CrossIndustryInvoice xmlns="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100">
|
|
<ExchangedDocumentContext>
|
|
<GuidelineSpecifiedDocumentContextParameter>
|
|
<ID>urn:cen.eu:en16931:2017#compliant#urn:zugferd.de:2p1:basic</ID>
|
|
</GuidelineSpecifiedDocumentContextParameter>
|
|
</ExchangedDocumentContext>
|
|
<ExchangedDocument>
|
|
<ID>BASIC-TO-XRECHNUNG-001</ID>
|
|
<TypeCode>380</TypeCode>
|
|
<IssueDateTime>
|
|
<DateTimeString format="102">20240115</DateTimeString>
|
|
</IssueDateTime>
|
|
</ExchangedDocument>
|
|
<SupplyChainTradeTransaction>
|
|
<ApplicableHeaderTradeAgreement>
|
|
<SellerTradeParty>
|
|
<Name>BASIC Supplier GmbH</Name>
|
|
</SellerTradeParty>
|
|
<BuyerTradeParty>
|
|
<Name>BASIC Customer GmbH</Name>
|
|
</BuyerTradeParty>
|
|
</ApplicableHeaderTradeAgreement>
|
|
<ApplicableHeaderTradeSettlement>
|
|
<InvoiceCurrencyCode>EUR</InvoiceCurrencyCode>
|
|
<SpecifiedTradeSettlementHeaderMonetarySummation>
|
|
<TaxBasisTotalAmount>100.00</TaxBasisTotalAmount>
|
|
<TaxTotalAmount currencyID="EUR">19.00</TaxTotalAmount>
|
|
<GrandTotalAmount>119.00</GrandTotalAmount>
|
|
<DuePayableAmount>119.00</DuePayableAmount>
|
|
</SpecifiedTradeSettlementHeaderMonetarySummation>
|
|
</ApplicableHeaderTradeSettlement>
|
|
</SupplyChainTradeTransaction>
|
|
</CrossIndustryInvoice>`
|
|
},
|
|
{
|
|
name: 'ZUGFeRD COMFORT to XRechnung',
|
|
zugferdXml: `<?xml version="1.0" encoding="UTF-8"?>
|
|
<CrossIndustryInvoice xmlns="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100">
|
|
<ExchangedDocumentContext>
|
|
<GuidelineSpecifiedDocumentContextParameter>
|
|
<ID>urn:cen.eu:en16931:2017#compliant#urn:zugferd.de:2p1:comfort</ID>
|
|
</GuidelineSpecifiedDocumentContextParameter>
|
|
</ExchangedDocumentContext>
|
|
<ExchangedDocument>
|
|
<ID>COMFORT-TO-XRECHNUNG-001</ID>
|
|
<TypeCode>380</TypeCode>
|
|
<IssueDateTime>
|
|
<DateTimeString format="102">20240115</DateTimeString>
|
|
</IssueDateTime>
|
|
</ExchangedDocument>
|
|
<SupplyChainTradeTransaction>
|
|
<IncludedSupplyChainTradeLineItem>
|
|
<AssociatedDocumentLineDocument>
|
|
<LineID>1</LineID>
|
|
</AssociatedDocumentLineDocument>
|
|
<SpecifiedTradeProduct>
|
|
<Name>COMFORT Test Product</Name>
|
|
</SpecifiedTradeProduct>
|
|
<SpecifiedLineTradeSettlement>
|
|
<SpecifiedTradeSettlementLineMonetarySummation>
|
|
<LineTotalAmount>100.00</LineTotalAmount>
|
|
</SpecifiedTradeSettlementLineMonetarySummation>
|
|
</SpecifiedLineTradeSettlement>
|
|
</IncludedSupplyChainTradeLineItem>
|
|
<ApplicableHeaderTradeSettlement>
|
|
<InvoiceCurrencyCode>EUR</InvoiceCurrencyCode>
|
|
<SpecifiedTradeSettlementHeaderMonetarySummation>
|
|
<LineTotalAmount>100.00</LineTotalAmount>
|
|
<TaxBasisTotalAmount>100.00</TaxBasisTotalAmount>
|
|
<TaxTotalAmount currencyID="EUR">19.00</TaxTotalAmount>
|
|
<GrandTotalAmount>119.00</GrandTotalAmount>
|
|
<DuePayableAmount>119.00</DuePayableAmount>
|
|
</SpecifiedTradeSettlementHeaderMonetarySummation>
|
|
</ApplicableHeaderTradeSettlement>
|
|
</SupplyChainTradeTransaction>
|
|
</CrossIndustryInvoice>`
|
|
}
|
|
];
|
|
|
|
for (const profileTest of profileTests) {
|
|
console.log(`Testing ${profileTest.name}...`);
|
|
|
|
try {
|
|
const invoice = new EInvoice();
|
|
const parseResult = await invoice.fromXmlString(profileTest.zugferdXml);
|
|
|
|
if (parseResult) {
|
|
try {
|
|
const convertedXml = await invoice.toXmlString('UBL');
|
|
|
|
if (convertedXml) {
|
|
console.log(`✓ ${profileTest.name} conversion completed`);
|
|
|
|
// Check profile-specific adaptations
|
|
const profileAdaptations = {
|
|
hasXrechnungProfile: convertedXml.includes('xrechnung') ||
|
|
convertedXml.includes('XRechnung'),
|
|
retainsOriginalId: convertedXml.includes('TO-XRECHNUNG-001'),
|
|
hasRequiredStructure: convertedXml.includes('<Invoice') ||
|
|
convertedXml.includes('<CrossIndustryInvoice'),
|
|
hasGermanContext: convertedXml.includes('urn:xoev-de:kosit') ||
|
|
convertedXml.includes('xrechnung')
|
|
};
|
|
|
|
console.log(` Profile adaptation results:`);
|
|
console.log(` XRechnung profile: ${profileAdaptations.hasXrechnungProfile}`);
|
|
console.log(` Original ID retained: ${profileAdaptations.retainsOriginalId}`);
|
|
console.log(` Required structure: ${profileAdaptations.hasRequiredStructure}`);
|
|
console.log(` German context: ${profileAdaptations.hasGermanContext}`);
|
|
|
|
if (profileAdaptations.hasRequiredStructure && profileAdaptations.retainsOriginalId) {
|
|
console.log(` ✓ Successful profile adaptation`);
|
|
} else {
|
|
console.log(` ⚠ Profile adaptation issues detected`);
|
|
}
|
|
|
|
} else {
|
|
console.log(`⚠ ${profileTest.name} conversion returned no result`);
|
|
}
|
|
} catch (convError) {
|
|
console.log(`⚠ ${profileTest.name} conversion failed: ${convError.message}`);
|
|
}
|
|
} else {
|
|
console.log(`⚠ ${profileTest.name} ZUGFeRD parsing failed`);
|
|
}
|
|
|
|
} catch (error) {
|
|
console.log(`✗ ${profileTest.name} test failed: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
// Profile adaptation test completed
|
|
});
|
|
|
|
tap.test('CONV-03: ZUGFeRD to XRechnung Conversion - German Compliance', async (tools) => {
|
|
|
|
// Test German-specific compliance requirements for XRechnung
|
|
const germanComplianceXml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
<CrossIndustryInvoice xmlns="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100">
|
|
<ExchangedDocumentContext>
|
|
<GuidelineSpecifiedDocumentContextParameter>
|
|
<ID>urn:cen.eu:en16931:2017#compliant#urn:zugferd.de:2p1:comfort</ID>
|
|
</GuidelineSpecifiedDocumentContextParameter>
|
|
</ExchangedDocumentContext>
|
|
<ExchangedDocument>
|
|
<ID>DE-COMPLIANCE-001</ID>
|
|
<TypeCode>380</TypeCode>
|
|
<IssueDateTime>
|
|
<DateTimeString format="102">20240115</DateTimeString>
|
|
</IssueDateTime>
|
|
</ExchangedDocument>
|
|
<SupplyChainTradeTransaction>
|
|
<ApplicableHeaderTradeAgreement>
|
|
<BuyerReference>BUYER-REF-12345</BuyerReference>
|
|
<SellerTradeParty>
|
|
<Name>Deutsche Lieferant GmbH</Name>
|
|
<PostalTradeAddress>
|
|
<PostcodeCode>10115</PostcodeCode>
|
|
<LineOne>Unter den Linden 1</LineOne>
|
|
<CityName>Berlin</CityName>
|
|
<CountryID>DE</CountryID>
|
|
</PostalTradeAddress>
|
|
<SpecifiedTaxRegistration>
|
|
<ID schemeID="VA">DE987654321</ID>
|
|
</SpecifiedTaxRegistration>
|
|
</SellerTradeParty>
|
|
<BuyerTradeParty>
|
|
<Name>Deutscher Kunde GmbH</Name>
|
|
<PostalTradeAddress>
|
|
<PostcodeCode>80331</PostcodeCode>
|
|
<LineOne>Maximilianstraße 1</LineOne>
|
|
<CityName>München</CityName>
|
|
<CountryID>DE</CountryID>
|
|
</PostalTradeAddress>
|
|
</BuyerTradeParty>
|
|
</ApplicableHeaderTradeAgreement>
|
|
<ApplicableHeaderTradeSettlement>
|
|
<PaymentReference>PAYMENT-REF-67890</PaymentReference>
|
|
<InvoiceCurrencyCode>EUR</InvoiceCurrencyCode>
|
|
<ApplicableTradeTax>
|
|
<CalculatedAmount>19.00</CalculatedAmount>
|
|
<TypeCode>VAT</TypeCode>
|
|
<BasisAmount>100.00</BasisAmount>
|
|
<RateApplicablePercent>19.00</RateApplicablePercent>
|
|
<CategoryCode>S</CategoryCode>
|
|
</ApplicableTradeTax>
|
|
<SpecifiedTradePaymentTerms>
|
|
<Description>Zahlbar innerhalb 30 Tagen ohne Abzug</Description>
|
|
<DueDateDateTime>
|
|
<DateTimeString format="102">20240214</DateTimeString>
|
|
</DueDateDateTime>
|
|
</SpecifiedTradePaymentTerms>
|
|
<SpecifiedTradeSettlementHeaderMonetarySummation>
|
|
<LineTotalAmount>100.00</LineTotalAmount>
|
|
<TaxBasisTotalAmount>100.00</TaxBasisTotalAmount>
|
|
<TaxTotalAmount currencyID="EUR">19.00</TaxTotalAmount>
|
|
<GrandTotalAmount>119.00</GrandTotalAmount>
|
|
<DuePayableAmount>119.00</DuePayableAmount>
|
|
</SpecifiedTradeSettlementHeaderMonetarySummation>
|
|
</ApplicableHeaderTradeSettlement>
|
|
</SupplyChainTradeTransaction>
|
|
</CrossIndustryInvoice>`;
|
|
|
|
try {
|
|
const invoice = new EInvoice();
|
|
const parseResult = await invoice.fromXmlString(germanComplianceXml);
|
|
|
|
if (parseResult) {
|
|
console.log('Testing German compliance requirements during conversion...');
|
|
|
|
try {
|
|
const convertedXml = await invoice.toXmlString('UBL');
|
|
|
|
if (convertedXml) {
|
|
|
|
// Check German-specific compliance requirements
|
|
const germanComplianceChecks = {
|
|
hasBuyerReference: convertedXml.includes('BUYER-REF-12345'),
|
|
hasPaymentReference: convertedXml.includes('PAYMENT-REF-67890'),
|
|
hasGermanVatNumber: convertedXml.includes('DE987654321'),
|
|
hasGermanAddresses: convertedXml.includes('Berlin') && convertedXml.includes('München'),
|
|
hasGermanPostCodes: convertedXml.includes('10115') && convertedXml.includes('80331'),
|
|
hasEuroCurrency: convertedXml.includes('EUR'),
|
|
hasStandardVatRate: convertedXml.includes('19.00'),
|
|
hasPaymentTerms: convertedXml.includes('30 Tagen') || convertedXml.includes('payment')
|
|
};
|
|
|
|
console.log('German Compliance Verification:');
|
|
console.log(` Buyer reference preserved: ${germanComplianceChecks.hasBuyerReference}`);
|
|
console.log(` Payment reference preserved: ${germanComplianceChecks.hasPaymentReference}`);
|
|
console.log(` German VAT number preserved: ${germanComplianceChecks.hasGermanVatNumber}`);
|
|
console.log(` German addresses preserved: ${germanComplianceChecks.hasGermanAddresses}`);
|
|
console.log(` German postal codes preserved: ${germanComplianceChecks.hasGermanPostCodes}`);
|
|
console.log(` Euro currency preserved: ${germanComplianceChecks.hasEuroCurrency}`);
|
|
console.log(` Standard VAT rate preserved: ${germanComplianceChecks.hasStandardVatRate}`);
|
|
console.log(` Payment terms preserved: ${germanComplianceChecks.hasPaymentTerms}`);
|
|
|
|
const complianceScore = Object.values(germanComplianceChecks).filter(Boolean).length;
|
|
const totalChecks = Object.values(germanComplianceChecks).length;
|
|
const compliancePercentage = (complianceScore / totalChecks) * 100;
|
|
|
|
console.log(`German compliance score: ${complianceScore}/${totalChecks} (${compliancePercentage.toFixed(1)}%)`);
|
|
|
|
if (compliancePercentage >= 80) {
|
|
console.log('✓ Good German compliance maintained');
|
|
} else {
|
|
console.log('⚠ German compliance issues detected');
|
|
}
|
|
|
|
} else {
|
|
console.log('⚠ German compliance conversion returned no result');
|
|
}
|
|
} catch (convError) {
|
|
console.log(`⚠ German compliance conversion failed: ${convError.message}`);
|
|
}
|
|
} else {
|
|
console.log('⚠ German compliance test - ZUGFeRD parsing failed');
|
|
}
|
|
|
|
} catch (error) {
|
|
console.log(`German compliance test failed: ${error.message}`);
|
|
}
|
|
|
|
// German compliance test completed
|
|
});
|
|
|
|
tap.test('CONV-03: ZUGFeRD to XRechnung Conversion - Corpus Testing', { timeout: testTimeout }, async (tools) => {
|
|
|
|
let processedFiles = 0;
|
|
let successfulConversions = 0;
|
|
let conversionErrors = 0;
|
|
let totalConversionTime = 0;
|
|
|
|
try {
|
|
const zugferdFiles = await CorpusLoader.getFiles('ZUGFERD_V2');
|
|
console.log(`Testing ZUGFeRD to XRechnung conversion with ${zugferdFiles.length} ZUGFeRD files`);
|
|
|
|
if (zugferdFiles.length === 0) {
|
|
console.log('⚠ No ZUGFeRD files found in corpus for conversion testing');
|
|
return;
|
|
}
|
|
|
|
// Process a subset of files for performance
|
|
const filesToProcess = zugferdFiles.slice(0, Math.min(6, zugferdFiles.length));
|
|
|
|
for (const filePath of filesToProcess) {
|
|
const fileName = plugins.path.basename(filePath);
|
|
const fileConversionStart = Date.now();
|
|
|
|
try {
|
|
processedFiles++;
|
|
|
|
const invoice = new EInvoice();
|
|
const parseResult = await invoice.fromFile(filePath);
|
|
|
|
if (parseResult) {
|
|
// Attempt conversion to XRechnung
|
|
try {
|
|
const convertedXml = await invoice.toXmlString('UBL');
|
|
|
|
const fileConversionTime = Date.now() - fileConversionStart;
|
|
totalConversionTime += fileConversionTime;
|
|
|
|
if (convertedXml) {
|
|
successfulConversions++;
|
|
|
|
console.log(`✓ ${fileName}: Converted to XRechnung (${fileConversionTime}ms)`);
|
|
|
|
// Quick validation of converted content
|
|
if (convertedXml && convertedXml.length > 100) {
|
|
console.log(` Converted content length: ${convertedXml.length} chars`);
|
|
|
|
// Check for XRechnung characteristics
|
|
const xrechnungMarkers = {
|
|
hasXrechnungId: convertedXml.includes('xrechnung') || convertedXml.includes('XRechnung'),
|
|
hasUblStructure: convertedXml.includes('Invoice') && convertedXml.includes('urn:oasis:names'),
|
|
hasGermanElements: convertedXml.includes('DE') || convertedXml.includes('EUR')
|
|
};
|
|
|
|
if (Object.values(xrechnungMarkers).some(Boolean)) {
|
|
console.log(` ✓ XRechnung characteristics detected`);
|
|
}
|
|
}
|
|
|
|
} else {
|
|
conversionErrors++;
|
|
console.log(`⚠ ${fileName}: Conversion returned no result`);
|
|
}
|
|
} catch (convError) {
|
|
conversionErrors++;
|
|
console.log(`⚠ ${fileName}: Conversion failed - ${convError.message}`);
|
|
}
|
|
} else {
|
|
conversionErrors++;
|
|
console.log(`⚠ ${fileName}: Failed to parse original ZUGFeRD`);
|
|
}
|
|
|
|
} catch (error) {
|
|
conversionErrors++;
|
|
const fileConversionTime = Date.now() - fileConversionStart;
|
|
totalConversionTime += fileConversionTime;
|
|
|
|
console.log(`✗ ${fileName}: Conversion failed - ${error.message}`);
|
|
}
|
|
}
|
|
|
|
// Calculate statistics
|
|
const successRate = processedFiles > 0 ? (successfulConversions / processedFiles) * 100 : 0;
|
|
const averageConversionTime = processedFiles > 0 ? totalConversionTime / processedFiles : 0;
|
|
|
|
console.log(`\nZUGFeRD to XRechnung Conversion Summary:`);
|
|
console.log(`- Files processed: ${processedFiles}`);
|
|
console.log(`- Successful conversions: ${successfulConversions} (${successRate.toFixed(1)}%)`);
|
|
console.log(`- Conversion errors: ${conversionErrors}`);
|
|
console.log(`- Average conversion time: ${averageConversionTime.toFixed(1)}ms`);
|
|
|
|
// Performance expectations
|
|
if (processedFiles > 0) {
|
|
expect(averageConversionTime).toBeLessThan(4000); // 4 seconds max per file
|
|
}
|
|
|
|
// We expect some conversions to work
|
|
if (processedFiles > 0) {
|
|
expect(successRate).toBeGreaterThan(0); // At least one conversion should work
|
|
}
|
|
|
|
} catch (error) {
|
|
console.log(`ZUGFeRD to XRechnung corpus testing failed: ${error.message}`);
|
|
throw error;
|
|
}
|
|
|
|
console.log(`ZUGFeRD to XRechnung corpus testing completed`);
|
|
});
|
|
|
|
// Performance summary test removed - PerformanceTracker not configured for these tests
|
|
|
|
export default tap.start(); |