fix(compliance): improve compliance

This commit is contained in:
Philipp Kunz 2025-05-28 11:31:31 +00:00
parent 0140267eb2
commit a5b2d435d4
5 changed files with 157 additions and 4 deletions

View File

@ -0,0 +1,39 @@
import { PerformanceTracker as StaticPerformanceTracker } from './performance.tracker.js';
/**
* Instance-based wrapper for PerformanceTracker to provide the API expected by tests
*/
export class PerformanceTracker {
constructor(private name: string) {}
/**
* Measure an async operation
*/
async measureAsync<T>(operation: string, fn: () => Promise<T>): Promise<T> {
const fullOperation = `${this.name} - ${operation}`;
const { result } = await StaticPerformanceTracker.track(fullOperation, fn);
return result;
}
/**
* Measure a sync operation (convert to async)
*/
measure<T>(operation: string, fn: () => T): T {
const fullOperation = `${this.name} - ${operation}`;
const result = fn();
// Track sync operations as completed instantly
const startTime = performance.now();
const endTime = performance.now();
// We can't use the static tracker for sync operations directly,
// so we'll just return the result
return result;
}
/**
* Get summary statistics for operations under this tracker
*/
async getSummary(operation?: string): Promise<any> {
const fullOperation = operation ? `${this.name} - ${operation}` : this.name;
return StaticPerformanceTracker.getSummary(fullOperation);
}
}

View File

@ -313,7 +313,8 @@ tap.test('CONV-09: Round-Trip - ZUGFeRD format preservation', async () => {
// Test ZUGFeRD format preservation
const zugferdInvoice = `<?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: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#conformant#urn:zugferd.de:2p1:basic</ram:ID>
@ -322,6 +323,9 @@ tap.test('CONV-09: Round-Trip - ZUGFeRD format preservation', async () => {
<rsm:ExchangedDocument>
<ram:ID>ZF-RT-001</ram:ID>
<ram:TypeCode>380</ram:TypeCode>
<ram:IssueDateTime>
<udt:DateTimeString format="102">20240123</udt:DateTimeString>
</ram:IssueDateTime>
</rsm:ExchangedDocument>
<rsm:SupplyChainTradeTransaction>
<ram:ApplicableHeaderTradeAgreement>
@ -347,6 +351,28 @@ tap.test('CONV-09: Round-Trip - ZUGFeRD format preservation', async () => {
</ram:PostalTradeAddress>
</ram:BuyerTradeParty>
</ram:ApplicableHeaderTradeAgreement>
<ram:ApplicableHeaderTradeDelivery/>
<ram:IncludedSupplyChainTradeLineItem>
<ram:AssociatedDocumentLineDocument>
<ram:LineID>1</ram:LineID>
</ram:AssociatedDocumentLineDocument>
<ram:SpecifiedTradeProduct>
<ram:Name>ZUGFeRD Test Product</ram:Name>
</ram:SpecifiedTradeProduct>
<ram:SpecifiedLineTradeDelivery>
<ram:BilledQuantity unitCode="C62">3</ram:BilledQuantity>
</ram:SpecifiedLineTradeDelivery>
<ram:SpecifiedLineTradeSettlement>
<ram:ApplicableTradeTax>
<ram:TypeCode>VAT</ram:TypeCode>
<ram:CategoryCode>S</ram:CategoryCode>
<ram:RateApplicablePercent>19</ram:RateApplicablePercent>
</ram:ApplicableTradeTax>
<ram:SpecifiedTradeSettlementLineMonetarySummation>
<ram:LineTotalAmount>1259.40</ram:LineTotalAmount>
</ram:SpecifiedTradeSettlementLineMonetarySummation>
</ram:SpecifiedLineTradeSettlement>
</ram:IncludedSupplyChainTradeLineItem>
<ram:ApplicableHeaderTradeSettlement>
<ram:InvoiceCurrencyCode>EUR</ram:InvoiceCurrencyCode>
<ram:SpecifiedTradeSettlementPaymentMeans>

View File

@ -32,6 +32,14 @@ tap.test('CONV-12: Performance - should measure single XML load/export performan
<cac:PartyName>
<cbc:Name>UBL Performance Test Seller</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:StreetName>Test Street 1</cbc:StreetName>
<cbc:CityName>Test City</cbc:CityName>
<cbc:PostalZone>12345</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>DE</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
</cac:Party>
</cac:AccountingSupplierParty>
<cac:AccountingCustomerParty>
@ -39,6 +47,14 @@ tap.test('CONV-12: Performance - should measure single XML load/export performan
<cac:PartyName>
<cbc:Name>UBL Performance Test Buyer</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:StreetName>Buyer Street 10</cbc:StreetName>
<cbc:CityName>Buyer City</cbc:CityName>
<cbc:PostalZone>54321</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>DE</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
</cac:Party>
</cac:AccountingCustomerParty>
<cac:InvoiceLine>
@ -69,18 +85,50 @@ tap.test('CONV-12: Performance - should measure single XML load/export performan
</ram:IssueDateTime>
</rsm:ExchangedDocument>
<rsm:SupplyChainTradeTransaction>
<ram:IncludedSupplyChainTradeLineItem>
<ram:AssociatedDocumentLineDocument>
<ram:LineID>1</ram:LineID>
</ram:AssociatedDocumentLineDocument>
<ram:SpecifiedTradeProduct>
<ram:Name>Product</ram:Name>
</ram:SpecifiedTradeProduct>
<ram:SpecifiedLineTradeDelivery>
<ram:BilledQuantity unitCode="EA">2</ram:BilledQuantity>
</ram:SpecifiedLineTradeDelivery>
<ram:SpecifiedLineTradeSettlement>
<ram:SpecifiedTradeSettlementLineMonetarySummation>
<ram:LineTotalAmount>200.00</ram:LineTotalAmount>
</ram:SpecifiedTradeSettlementLineMonetarySummation>
</ram:SpecifiedLineTradeSettlement>
</ram:IncludedSupplyChainTradeLineItem>
<ram:ApplicableHeaderTradeAgreement>
<ram:SellerTradeParty>
<ram:Name>CII Performance Test Seller</ram:Name>
<ram:PostalTradeAddress>
<ram:LineOne>Test Street 1</ram:LineOne>
<ram:CityName>Test City</ram:CityName>
<ram:PostcodeCode>12345</ram:PostcodeCode>
<ram:CountryID>DE</ram:CountryID>
</ram:PostalTradeAddress>
</ram:SellerTradeParty>
<ram:BuyerTradeParty>
<ram:Name>CII Performance Test Buyer</ram:Name>
<ram:PostalTradeAddress>
<ram:LineOne>Buyer Street 10</ram:LineOne>
<ram:CityName>Buyer City</ram:CityName>
<ram:PostcodeCode>54321</ram:PostcodeCode>
<ram:CountryID>DE</ram:CountryID>
</ram:PostalTradeAddress>
</ram:BuyerTradeParty>
</ram:ApplicableHeaderTradeAgreement>
<ram:ApplicableHeaderTradeDelivery/>
<ram:ApplicableHeaderTradeSettlement>
<ram:InvoiceCurrencyCode>EUR</ram:InvoiceCurrencyCode>
<ram:SpecifiedTradeSettlementHeaderMonetarySummation>
<ram:TaxBasisTotalAmount>200.00</ram:TaxBasisTotalAmount>
<ram:TaxTotalAmount currencyID="EUR">38.00</ram:TaxTotalAmount>
<ram:GrandTotalAmount>238.00</ram:GrandTotalAmount>
<ram:DuePayableAmount>238.00</ram:DuePayableAmount>
</ram:SpecifiedTradeSettlementHeaderMonetarySummation>
</ram:ApplicableHeaderTradeSettlement>
</rsm:SupplyChainTradeTransaction>
@ -270,6 +318,14 @@ tap.test('CONV-12: Performance - should analyze memory usage during operations',
<cac:PartyName>
<cbc:Name>Memory Test Seller</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:StreetName>Memory Street 1</cbc:StreetName>
<cbc:CityName>Memory City</cbc:CityName>
<cbc:PostalZone>10000</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>DE</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
</cac:Party>
</cac:AccountingSupplierParty>
<cac:AccountingCustomerParty>
@ -277,6 +333,14 @@ tap.test('CONV-12: Performance - should analyze memory usage during operations',
<cac:PartyName>
<cbc:Name>Memory Test Buyer</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:StreetName>Buyer Street 5</cbc:StreetName>
<cbc:CityName>Buyer City</cbc:CityName>
<cbc:PostalZone>20000</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>DE</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
</cac:Party>
</cac:AccountingCustomerParty>
${Array.from({ length: size }, (_, i) => `
@ -355,6 +419,14 @@ tap.test('CONV-12: Performance - should handle concurrent operations', async ()
<cac:PartyName>
<cbc:Name>Concurrent Seller</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:StreetName>Seller Street 1</cbc:StreetName>
<cbc:CityName>Seller City</cbc:CityName>
<cbc:PostalZone>11111</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>DE</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
</cac:Party>
</cac:AccountingSupplierParty>
<cac:AccountingCustomerParty>
@ -362,8 +434,24 @@ tap.test('CONV-12: Performance - should handle concurrent operations', async ()
<cac:PartyName>
<cbc:Name>Concurrent Buyer</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:StreetName>Buyer Street 1</cbc:StreetName>
<cbc:CityName>Buyer City</cbc:CityName>
<cbc:PostalZone>22222</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>DE</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
</cac:Party>
</cac:AccountingCustomerParty>
<cac:InvoiceLine>
<cbc:ID>1</cbc:ID>
<cbc:InvoicedQuantity unitCode="C62">10</cbc:InvoicedQuantity>
<cbc:LineExtensionAmount currencyID="EUR">1000.00</cbc:LineExtensionAmount>
<cac:Item>
<cbc:Name>Test Product</cbc:Name>
</cac:Item>
</cac:InvoiceLine>
<cac:LegalMonetaryTotal>
<cbc:PayableAmount currencyID="EUR">1100.00</cbc:PayableAmount>
</cac:LegalMonetaryTotal>

View File

@ -2,4 +2,4 @@
* Simple performance tracker for test suite
*/
export { PerformanceTracker } from '../helpers/performance.tracker.js';
export { PerformanceTracker } from '../helpers/performance.tracker.instance.js';

View File

@ -75,12 +75,12 @@ export class EN16931Validator {
}
// BR-08: Seller postal address is mandatory
if (!invoice.from?.address?.city || !invoice.from?.address?.postalCode || !invoice.from?.address?.countryCode) {
if (!invoice.from?.address?.city || !invoice.from?.address?.postalCode || (!invoice.from?.address?.countryCode && !invoice.from?.address?.country)) {
errors.push('BR-08: Seller postal address (city, postal code, country) is mandatory');
}
// BR-10: Buyer postal address is mandatory
if (!invoice.to?.address?.city || !invoice.to?.address?.postalCode || !invoice.to?.address?.countryCode) {
if (!invoice.to?.address?.city || !invoice.to?.address?.postalCode || (!invoice.to?.address?.countryCode && !invoice.to?.address?.country)) {
errors.push('BR-10: Buyer postal address (city, postal code, country) is mandatory');
}