532 lines
18 KiB
TypeScript
532 lines
18 KiB
TypeScript
|
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||
|
import * as plugins from '../../../ts/plugins.ts';
|
||
|
import { EInvoice } from '../../../ts/classes.xinvoice.ts';
|
||
|
import { CorpusLoader } from '../../helpers/corpus.loader.ts';
|
||
|
import { PerformanceTracker } from '../../helpers/performance.tracker.ts';
|
||
|
|
||
|
const testTimeout = 300000; // 5 minutes timeout for corpus processing
|
||
|
|
||
|
// VAL-10: Business Level Validation
|
||
|
// Tests business logic validation including invoice totals, tax calculations,
|
||
|
// payment terms, and business rule compliance
|
||
|
|
||
|
tap.test('VAL-10: Business Level Validation - Invoice Totals Consistency', async (tools) => {
|
||
|
const startTime = Date.now();
|
||
|
|
||
|
const totalConsistencyTests = [
|
||
|
{
|
||
|
name: 'Correct Total Calculation',
|
||
|
xml: `<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
|
||
|
<ID>TEST-001</ID>
|
||
|
<IssueDate>2024-01-01</IssueDate>
|
||
|
<InvoiceTypeCode>380</InvoiceTypeCode>
|
||
|
<DocumentCurrencyCode>EUR</DocumentCurrencyCode>
|
||
|
<InvoiceLine>
|
||
|
<ID>1</ID>
|
||
|
<InvoicedQuantity unitCode="C62">2</InvoicedQuantity>
|
||
|
<LineExtensionAmount currencyID="EUR">100.00</LineExtensionAmount>
|
||
|
<Price>
|
||
|
<PriceAmount currencyID="EUR">50.00</PriceAmount>
|
||
|
</Price>
|
||
|
</InvoiceLine>
|
||
|
<TaxTotal>
|
||
|
<TaxAmount currencyID="EUR">19.00</TaxAmount>
|
||
|
<TaxSubtotal>
|
||
|
<TaxableAmount currencyID="EUR">100.00</TaxableAmount>
|
||
|
<TaxAmount currencyID="EUR">19.00</TaxAmount>
|
||
|
<TaxCategory>
|
||
|
<Percent>19.00</Percent>
|
||
|
</TaxCategory>
|
||
|
</TaxSubtotal>
|
||
|
</TaxTotal>
|
||
|
<LegalMonetaryTotal>
|
||
|
<LineExtensionAmount currencyID="EUR">100.00</LineExtensionAmount>
|
||
|
<TaxExclusiveAmount currencyID="EUR">100.00</TaxExclusiveAmount>
|
||
|
<TaxInclusiveAmount currencyID="EUR">119.00</TaxInclusiveAmount>
|
||
|
<PayableAmount currencyID="EUR">119.00</PayableAmount>
|
||
|
</LegalMonetaryTotal>
|
||
|
</Invoice>`,
|
||
|
valid: true
|
||
|
},
|
||
|
{
|
||
|
name: 'Incorrect Line Total',
|
||
|
xml: `<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
|
||
|
<ID>TEST-001</ID>
|
||
|
<IssueDate>2024-01-01</IssueDate>
|
||
|
<InvoiceTypeCode>380</InvoiceTypeCode>
|
||
|
<DocumentCurrencyCode>EUR</DocumentCurrencyCode>
|
||
|
<InvoiceLine>
|
||
|
<ID>1</ID>
|
||
|
<InvoicedQuantity unitCode="C62">2</InvoicedQuantity>
|
||
|
<LineExtensionAmount currencyID="EUR">150.00</LineExtensionAmount>
|
||
|
<Price>
|
||
|
<PriceAmount currencyID="EUR">50.00</PriceAmount>
|
||
|
</Price>
|
||
|
</InvoiceLine>
|
||
|
<LegalMonetaryTotal>
|
||
|
<LineExtensionAmount currencyID="EUR">150.00</LineExtensionAmount>
|
||
|
<TaxExclusiveAmount currencyID="EUR">150.00</TaxExclusiveAmount>
|
||
|
<PayableAmount currencyID="EUR">150.00</PayableAmount>
|
||
|
</LegalMonetaryTotal>
|
||
|
</Invoice>`,
|
||
|
valid: false
|
||
|
}
|
||
|
];
|
||
|
|
||
|
for (const test of totalConsistencyTests) {
|
||
|
try {
|
||
|
const invoice = new EInvoice();
|
||
|
const parseResult = await invoice.fromXmlString(test.xml);
|
||
|
|
||
|
if (parseResult) {
|
||
|
const validationResult = await invoice.validate();
|
||
|
|
||
|
if (test.valid) {
|
||
|
expect(validationResult.valid).toBe(true);
|
||
|
tools.log(`✓ ${test.name}: Valid business logic accepted`);
|
||
|
} else {
|
||
|
expect(validationResult.valid).toBe(false);
|
||
|
tools.log(`✓ ${test.name}: Invalid business logic rejected`);
|
||
|
}
|
||
|
} else if (!test.valid) {
|
||
|
tools.log(`✓ ${test.name}: Invalid invoice rejected at parse time`);
|
||
|
}
|
||
|
} catch (error) {
|
||
|
if (!test.valid) {
|
||
|
tools.log(`✓ ${test.name}: Invalid business logic properly rejected: ${error.message}`);
|
||
|
} else {
|
||
|
throw error;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const duration = Date.now() - startTime;
|
||
|
PerformanceTracker.recordMetric('business-validation-totals', duration);
|
||
|
});
|
||
|
|
||
|
tap.test('VAL-10: Business Level Validation - Tax Calculation Consistency', async (tools) => {
|
||
|
const startTime = Date.now();
|
||
|
|
||
|
const taxCalculationTests = [
|
||
|
{
|
||
|
name: 'Standard VAT Calculation (19%)',
|
||
|
baseAmount: 100.00,
|
||
|
taxRate: 19.00,
|
||
|
expectedTax: 19.00,
|
||
|
valid: true
|
||
|
},
|
||
|
{
|
||
|
name: 'Zero VAT Calculation',
|
||
|
baseAmount: 100.00,
|
||
|
taxRate: 0.00,
|
||
|
expectedTax: 0.00,
|
||
|
valid: true
|
||
|
},
|
||
|
{
|
||
|
name: 'Reduced VAT Calculation (7%)',
|
||
|
baseAmount: 100.00,
|
||
|
taxRate: 7.00,
|
||
|
expectedTax: 7.00,
|
||
|
valid: true
|
||
|
},
|
||
|
{
|
||
|
name: 'Incorrect Tax Amount',
|
||
|
baseAmount: 100.00,
|
||
|
taxRate: 19.00,
|
||
|
expectedTax: 20.00,
|
||
|
valid: false
|
||
|
},
|
||
|
{
|
||
|
name: 'Rounding Edge Case',
|
||
|
baseAmount: 33.33,
|
||
|
taxRate: 19.00,
|
||
|
expectedTax: 6.33, // Should round correctly
|
||
|
valid: true
|
||
|
}
|
||
|
];
|
||
|
|
||
|
for (const test of taxCalculationTests) {
|
||
|
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
|
||
|
<ID>TEST-TAX-${test.taxRate}</ID>
|
||
|
<IssueDate>2024-01-01</IssueDate>
|
||
|
<InvoiceTypeCode>380</InvoiceTypeCode>
|
||
|
<DocumentCurrencyCode>EUR</DocumentCurrencyCode>
|
||
|
<TaxTotal>
|
||
|
<TaxAmount currencyID="EUR">${test.expectedTax.toFixed(2)}</TaxAmount>
|
||
|
<TaxSubtotal>
|
||
|
<TaxableAmount currencyID="EUR">${test.baseAmount.toFixed(2)}</TaxableAmount>
|
||
|
<TaxAmount currencyID="EUR">${test.expectedTax.toFixed(2)}</TaxAmount>
|
||
|
<TaxCategory>
|
||
|
<Percent>${test.taxRate.toFixed(2)}</Percent>
|
||
|
</TaxCategory>
|
||
|
</TaxSubtotal>
|
||
|
</TaxTotal>
|
||
|
<LegalMonetaryTotal>
|
||
|
<TaxExclusiveAmount currencyID="EUR">${test.baseAmount.toFixed(2)}</TaxExclusiveAmount>
|
||
|
<TaxInclusiveAmount currencyID="EUR">${(test.baseAmount + test.expectedTax).toFixed(2)}</TaxInclusiveAmount>
|
||
|
<PayableAmount currencyID="EUR">${(test.baseAmount + test.expectedTax).toFixed(2)}</PayableAmount>
|
||
|
</LegalMonetaryTotal>
|
||
|
</Invoice>`;
|
||
|
|
||
|
try {
|
||
|
const invoice = new EInvoice();
|
||
|
const parseResult = await invoice.fromXmlString(xml);
|
||
|
|
||
|
if (parseResult) {
|
||
|
const validationResult = await invoice.validate();
|
||
|
|
||
|
if (test.valid) {
|
||
|
// For valid tests, we expect successful validation or minor rounding tolerance
|
||
|
if (!validationResult.valid) {
|
||
|
// Check if it's just a rounding issue
|
||
|
const errors = validationResult.errors || [];
|
||
|
const hasOnlyRoundingErrors = errors.every(error =>
|
||
|
error.message.toLowerCase().includes('rounding') ||
|
||
|
error.message.toLowerCase().includes('precision')
|
||
|
);
|
||
|
|
||
|
if (!hasOnlyRoundingErrors) {
|
||
|
tools.log(`Validation failed for ${test.name}: ${errors.map(e => e.message).join(', ')}`);
|
||
|
}
|
||
|
}
|
||
|
tools.log(`✓ ${test.name}: Tax calculation processed`);
|
||
|
} else {
|
||
|
expect(validationResult.valid).toBe(false);
|
||
|
tools.log(`✓ ${test.name}: Invalid tax calculation rejected`);
|
||
|
}
|
||
|
}
|
||
|
} catch (error) {
|
||
|
if (!test.valid) {
|
||
|
tools.log(`✓ ${test.name}: Invalid calculation properly rejected: ${error.message}`);
|
||
|
} else {
|
||
|
tools.log(`⚠ ${test.name}: Unexpected error: ${error.message}`);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const duration = Date.now() - startTime;
|
||
|
PerformanceTracker.recordMetric('business-validation-tax', duration);
|
||
|
});
|
||
|
|
||
|
tap.test('VAL-10: Business Level Validation - Payment Terms Validation', async (tools) => {
|
||
|
const startTime = Date.now();
|
||
|
|
||
|
const paymentTermsTests = [
|
||
|
{
|
||
|
name: 'Valid Due Date (30 days)',
|
||
|
issueDate: '2024-01-01',
|
||
|
dueDate: '2024-01-31',
|
||
|
paymentTerms: 'Net 30 days',
|
||
|
valid: true
|
||
|
},
|
||
|
{
|
||
|
name: 'Due Date Before Issue Date',
|
||
|
issueDate: '2024-01-31',
|
||
|
dueDate: '2024-01-01',
|
||
|
paymentTerms: 'Immediate',
|
||
|
valid: false
|
||
|
},
|
||
|
{
|
||
|
name: 'Same Day Payment',
|
||
|
issueDate: '2024-01-01',
|
||
|
dueDate: '2024-01-01',
|
||
|
paymentTerms: 'Due on receipt',
|
||
|
valid: true
|
||
|
},
|
||
|
{
|
||
|
name: 'Extended Payment Terms (90 days)',
|
||
|
issueDate: '2024-01-01',
|
||
|
dueDate: '2024-03-31',
|
||
|
paymentTerms: 'Net 90 days',
|
||
|
valid: true
|
||
|
}
|
||
|
];
|
||
|
|
||
|
for (const test of paymentTermsTests) {
|
||
|
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
|
||
|
<ID>TEST-PAYMENT-${Date.now()}</ID>
|
||
|
<IssueDate>${test.issueDate}</IssueDate>
|
||
|
<DueDate>${test.dueDate}</DueDate>
|
||
|
<InvoiceTypeCode>380</InvoiceTypeCode>
|
||
|
<DocumentCurrencyCode>EUR</DocumentCurrencyCode>
|
||
|
<PaymentTerms>
|
||
|
<Note>${test.paymentTerms}</Note>
|
||
|
</PaymentTerms>
|
||
|
<LegalMonetaryTotal>
|
||
|
<PayableAmount currencyID="EUR">100.00</PayableAmount>
|
||
|
</LegalMonetaryTotal>
|
||
|
</Invoice>`;
|
||
|
|
||
|
try {
|
||
|
const invoice = new EInvoice();
|
||
|
const parseResult = await invoice.fromXmlString(xml);
|
||
|
|
||
|
if (parseResult) {
|
||
|
const validationResult = await invoice.validate();
|
||
|
|
||
|
if (test.valid) {
|
||
|
// Valid payment terms should be accepted
|
||
|
tools.log(`✓ ${test.name}: Valid payment terms accepted`);
|
||
|
} else {
|
||
|
expect(validationResult.valid).toBe(false);
|
||
|
tools.log(`✓ ${test.name}: Invalid payment terms rejected`);
|
||
|
}
|
||
|
}
|
||
|
} catch (error) {
|
||
|
if (!test.valid) {
|
||
|
tools.log(`✓ ${test.name}: Invalid payment terms properly rejected: ${error.message}`);
|
||
|
} else {
|
||
|
tools.log(`⚠ ${test.name}: Unexpected error: ${error.message}`);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const duration = Date.now() - startTime;
|
||
|
PerformanceTracker.recordMetric('business-validation-payment', duration);
|
||
|
});
|
||
|
|
||
|
tap.test('VAL-10: Business Level Validation - Business Rules Compliance', async (tools) => {
|
||
|
const startTime = Date.now();
|
||
|
|
||
|
// Test EN16931 business rules at business level
|
||
|
const businessRuleTests = [
|
||
|
{
|
||
|
name: 'BR-01: Invoice must have an identifier',
|
||
|
xml: `<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
|
||
|
<ID>INV-2024-001</ID>
|
||
|
<IssueDate>2024-01-01</IssueDate>
|
||
|
<InvoiceTypeCode>380</InvoiceTypeCode>
|
||
|
</Invoice>`,
|
||
|
valid: true
|
||
|
},
|
||
|
{
|
||
|
name: 'BR-01 Violation: Missing invoice identifier',
|
||
|
xml: `<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
|
||
|
<IssueDate>2024-01-01</IssueDate>
|
||
|
<InvoiceTypeCode>380</InvoiceTypeCode>
|
||
|
</Invoice>`,
|
||
|
valid: false
|
||
|
},
|
||
|
{
|
||
|
name: 'BR-02: Invoice must have an issue date',
|
||
|
xml: `<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
|
||
|
<ID>INV-2024-001</ID>
|
||
|
<IssueDate>2024-01-01</IssueDate>
|
||
|
<InvoiceTypeCode>380</InvoiceTypeCode>
|
||
|
</Invoice>`,
|
||
|
valid: true
|
||
|
},
|
||
|
{
|
||
|
name: 'BR-02 Violation: Missing issue date',
|
||
|
xml: `<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
|
||
|
<ID>INV-2024-001</ID>
|
||
|
<InvoiceTypeCode>380</InvoiceTypeCode>
|
||
|
</Invoice>`,
|
||
|
valid: false
|
||
|
}
|
||
|
];
|
||
|
|
||
|
for (const test of businessRuleTests) {
|
||
|
try {
|
||
|
const invoice = new EInvoice();
|
||
|
const parseResult = await invoice.fromXmlString(test.xml);
|
||
|
|
||
|
if (parseResult) {
|
||
|
const validationResult = await invoice.validate();
|
||
|
|
||
|
if (test.valid) {
|
||
|
expect(validationResult.valid).toBe(true);
|
||
|
tools.log(`✓ ${test.name}: Business rule compliance verified`);
|
||
|
} else {
|
||
|
expect(validationResult.valid).toBe(false);
|
||
|
tools.log(`✓ ${test.name}: Business rule violation detected`);
|
||
|
}
|
||
|
} else if (!test.valid) {
|
||
|
tools.log(`✓ ${test.name}: Invalid invoice rejected at parse time`);
|
||
|
}
|
||
|
} catch (error) {
|
||
|
if (!test.valid) {
|
||
|
tools.log(`✓ ${test.name}: Business rule violation properly caught: ${error.message}`);
|
||
|
} else {
|
||
|
throw error;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const duration = Date.now() - startTime;
|
||
|
PerformanceTracker.recordMetric('business-validation-rules', duration);
|
||
|
});
|
||
|
|
||
|
tap.test('VAL-10: Business Level Validation - Multi-Line Invoice Logic', async (tools) => {
|
||
|
const startTime = Date.now();
|
||
|
|
||
|
// Test complex multi-line invoice business logic
|
||
|
const multiLineXml = `<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
|
||
|
<ID>MULTI-LINE-001</ID>
|
||
|
<IssueDate>2024-01-01</IssueDate>
|
||
|
<InvoiceTypeCode>380</InvoiceTypeCode>
|
||
|
<DocumentCurrencyCode>EUR</DocumentCurrencyCode>
|
||
|
<InvoiceLine>
|
||
|
<ID>1</ID>
|
||
|
<InvoicedQuantity unitCode="C62">2</InvoicedQuantity>
|
||
|
<LineExtensionAmount currencyID="EUR">100.00</LineExtensionAmount>
|
||
|
<Item>
|
||
|
<Name>Product A</Name>
|
||
|
<ClassifiedTaxCategory>
|
||
|
<Percent>19.00</Percent>
|
||
|
</ClassifiedTaxCategory>
|
||
|
</Item>
|
||
|
<Price>
|
||
|
<PriceAmount currencyID="EUR">50.00</PriceAmount>
|
||
|
</Price>
|
||
|
</InvoiceLine>
|
||
|
<InvoiceLine>
|
||
|
<ID>2</ID>
|
||
|
<InvoicedQuantity unitCode="C62">1</InvoicedQuantity>
|
||
|
<LineExtensionAmount currencyID="EUR">75.00</LineExtensionAmount>
|
||
|
<Item>
|
||
|
<Name>Product B</Name>
|
||
|
<ClassifiedTaxCategory>
|
||
|
<Percent>7.00</Percent>
|
||
|
</ClassifiedTaxCategory>
|
||
|
</Item>
|
||
|
<Price>
|
||
|
<PriceAmount currencyID="EUR">75.00</PriceAmount>
|
||
|
</Price>
|
||
|
</InvoiceLine>
|
||
|
<TaxTotal>
|
||
|
<TaxAmount currencyID="EUR">24.25</TaxAmount>
|
||
|
<TaxSubtotal>
|
||
|
<TaxableAmount currencyID="EUR">100.00</TaxableAmount>
|
||
|
<TaxAmount currencyID="EUR">19.00</TaxAmount>
|
||
|
<TaxCategory>
|
||
|
<Percent>19.00</Percent>
|
||
|
</TaxCategory>
|
||
|
</TaxSubtotal>
|
||
|
<TaxSubtotal>
|
||
|
<TaxableAmount currencyID="EUR">75.00</TaxableAmount>
|
||
|
<TaxAmount currencyID="EUR">5.25</TaxAmount>
|
||
|
<TaxCategory>
|
||
|
<Percent>7.00</Percent>
|
||
|
</TaxCategory>
|
||
|
</TaxSubtotal>
|
||
|
</TaxTotal>
|
||
|
<LegalMonetaryTotal>
|
||
|
<LineExtensionAmount currencyID="EUR">175.00</LineExtensionAmount>
|
||
|
<TaxExclusiveAmount currencyID="EUR">175.00</TaxExclusiveAmount>
|
||
|
<TaxInclusiveAmount currencyID="EUR">199.25</TaxInclusiveAmount>
|
||
|
<PayableAmount currencyID="EUR">199.25</PayableAmount>
|
||
|
</LegalMonetaryTotal>
|
||
|
</Invoice>`;
|
||
|
|
||
|
try {
|
||
|
const invoice = new EInvoice();
|
||
|
const parseResult = await invoice.fromXmlString(multiLineXml);
|
||
|
|
||
|
expect(parseResult).toBeTruthy();
|
||
|
|
||
|
const validationResult = await invoice.validate();
|
||
|
|
||
|
// Multi-line business logic should be valid
|
||
|
if (!validationResult.valid) {
|
||
|
tools.log(`Multi-line validation issues: ${validationResult.errors?.map(e => e.message).join(', ')}`);
|
||
|
}
|
||
|
|
||
|
tools.log(`✓ Multi-line invoice business logic validation completed`);
|
||
|
|
||
|
} catch (error) {
|
||
|
tools.log(`Multi-line invoice test failed: ${error.message}`);
|
||
|
throw error;
|
||
|
}
|
||
|
|
||
|
const duration = Date.now() - startTime;
|
||
|
PerformanceTracker.recordMetric('business-validation-multiline', duration);
|
||
|
});
|
||
|
|
||
|
tap.test('VAL-10: Business Level Validation - Corpus Business Logic', { timeout: testTimeout }, async (tools) => {
|
||
|
const startTime = Date.now();
|
||
|
let processedFiles = 0;
|
||
|
let validBusinessLogic = 0;
|
||
|
let businessLogicErrors = 0;
|
||
|
|
||
|
try {
|
||
|
const ciiFiles = await CorpusLoader.getFiles('CII_XML_RECHNUNG');
|
||
|
|
||
|
for (const filePath of ciiFiles.slice(0, 8)) { // Process first 8 files
|
||
|
try {
|
||
|
const invoice = new EInvoice();
|
||
|
const parseResult = await invoice.fromFile(filePath);
|
||
|
processedFiles++;
|
||
|
|
||
|
if (parseResult) {
|
||
|
const validationResult = await invoice.validate();
|
||
|
|
||
|
if (validationResult.valid) {
|
||
|
validBusinessLogic++;
|
||
|
} else {
|
||
|
// Check for business logic specific errors
|
||
|
const businessErrorTypes = ['total', 'calculation', 'tax', 'payment', 'rule'];
|
||
|
const hasBusinessErrors = validationResult.errors?.some(error =>
|
||
|
businessErrorTypes.some(type => error.message.toLowerCase().includes(type))
|
||
|
);
|
||
|
|
||
|
if (hasBusinessErrors) {
|
||
|
businessLogicErrors++;
|
||
|
tools.log(`Business logic errors in ${plugins.path.basename(filePath)}`);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
} catch (error) {
|
||
|
tools.log(`Failed to process ${plugins.path.basename(filePath)}: ${error.message}`);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const businessLogicSuccessRate = processedFiles > 0 ? (validBusinessLogic / processedFiles) * 100 : 0;
|
||
|
const businessErrorRate = processedFiles > 0 ? (businessLogicErrors / processedFiles) * 100 : 0;
|
||
|
|
||
|
tools.log(`Business logic validation completed:`);
|
||
|
tools.log(`- Processed: ${processedFiles} files`);
|
||
|
tools.log(`- Valid business logic: ${validBusinessLogic} files (${businessLogicSuccessRate.toFixed(1)}%)`);
|
||
|
tools.log(`- Business logic errors: ${businessLogicErrors} files (${businessErrorRate.toFixed(1)}%)`);
|
||
|
|
||
|
// Business logic should have reasonable success rate
|
||
|
expect(businessLogicSuccessRate).toBeGreaterThan(60);
|
||
|
|
||
|
} catch (error) {
|
||
|
tools.log(`Corpus business validation failed: ${error.message}`);
|
||
|
throw error;
|
||
|
}
|
||
|
|
||
|
const totalDuration = Date.now() - startTime;
|
||
|
PerformanceTracker.recordMetric('business-validation-corpus', totalDuration);
|
||
|
|
||
|
expect(totalDuration).toBeLessThan(120000); // 2 minutes max
|
||
|
tools.log(`Business validation performance: ${totalDuration}ms total`);
|
||
|
});
|
||
|
|
||
|
tap.test('VAL-10: Performance Summary', async (tools) => {
|
||
|
const operations = [
|
||
|
'business-validation-totals',
|
||
|
'business-validation-tax',
|
||
|
'business-validation-payment',
|
||
|
'business-validation-rules',
|
||
|
'business-validation-multiline',
|
||
|
'business-validation-corpus'
|
||
|
];
|
||
|
|
||
|
for (const operation of operations) {
|
||
|
const summary = await PerformanceTracker.getSummary(operation);
|
||
|
if (summary) {
|
||
|
tools.log(`${operation}: avg=${summary.average}ms, min=${summary.min}ms, max=${summary.max}ms, p95=${summary.p95}ms`);
|
||
|
}
|
||
|
}
|
||
|
});
|