import { tap, expect } from '@git.zone/tstest/tapbundle'; import { EInvoice } from '../../../ts/index.js'; import { InvoiceFormat } from '../../../ts/interfaces/common.js'; import { FormatDetector } from '../../../ts/formats/utils/format.detector.js'; import { CorpusLoader } from '../../helpers/corpus.loader.js'; import * as path from 'path'; /** * Test ID: CORP-05 * Test Description: FatturaPA Corpus Processing * Priority: Medium * * This test validates processing of Italian FatturaPA format files, * including structure validation and conversion capabilities. */ tap.test('CORP-05: FatturaPA Corpus Processing - should process Italian FatturaPA files', async () => { const fatturapaFiles = await CorpusLoader.loadCategory('FATTURAPA_OFFICIAL'); if (fatturapaFiles.length === 0) { console.log('⚠ No FatturaPA files found in corpus - skipping test'); return; } console.log(`Testing ${fatturapaFiles.length} FatturaPA files`); let detectedCount = 0; let unsupportedDecodeCount = 0; for (const file of fatturapaFiles) { const xmlBuffer = await CorpusLoader.loadFile(file.path); const xmlString = xmlBuffer.toString('utf-8'); const fileName = path.basename(file.path); const format = FormatDetector.detectFormat(xmlString); expect(format).toEqual(InvoiceFormat.FATTURAPA); detectedCount++; try { await EInvoice.fromXml(xmlString); expect(true).toBeFalse(); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); expect(errorMessage.includes('FatturaPA decoder not yet implemented')).toBeTrue(); unsupportedDecodeCount++; console.log(`✓ ${fileName}: Detection works and decode is explicitly unsupported`); } } expect(detectedCount).toEqual(fatturapaFiles.length); expect(unsupportedDecodeCount).toEqual(fatturapaFiles.length); }); tap.start();