diff --git a/src/camtParser.ts b/src/camtParser.ts index 74b3702..4e286dd 100644 --- a/src/camtParser.ts +++ b/src/camtParser.ts @@ -352,6 +352,9 @@ export class CamtParser { if (typeof current === 'string' || typeof current === 'number') { return String(current); } + if (Array.isArray(current)) { + return String(current.join('')); + } if (current && typeof current === 'object' && current !== null && '#text' in current) { return String((current as { '#text': unknown })['#text']); } diff --git a/src/tests/camtParser.test.ts b/src/tests/camtParser.test.ts index 84b44db..f745f63 100644 --- a/src/tests/camtParser.test.ts +++ b/src/tests/camtParser.test.ts @@ -728,4 +728,200 @@ describe('CamtParser', () => { expect(transaction.purpose).toBe('Payment with party structure'); expect(transaction.amount).toBe(200.0); }); + + it('should handle multiple entries in RmtInf (Ustrd)', () => { + const camtXml = ` + + + + 52D20260106T1009246445830N000000000 + 2026-01-06T10:09:24.0+01:00 + + + 0752D522026010610092464000001000 + + 1 + true + + 000000000 + 2026-01-06T10:09:24.0+01:00 + + + DE06940594210000027227 + + EUR + + John Doe + + + + BANKABC1XXX + ABC Bank + + DE 123456789 + UmsStId + + + + + + + + OPBD + + + 27.31 + DBIT +
+
2026-01-05
+ +
+ + + + CLBD + + + 234.81 + DBIT +
+
2026-01-05
+ +
+ + 179.46 + DBIT + + BOOK + + +
2026-01-05
+
+ +
2026-01-05
+
+ TXN003 + + + PMNT + + ICDT + ESCT + + + + NTRF+116+02089 + DK + + + + + + test msgid + VG 2025 QUARTAL IV 12345678 + VG 2025 QUARTAL IV + + 179.46 + + + PMNT + + ICDT + ESCT + + + + NTRF+116+02189 + DK + + + + + + DOE + + + + + DE12345678901234567890 + + + + + ABC Bank + + + + + DE12345678901234567891 + + + + + + + BANKABC1XXX + + + + + 28,65EUR EREF: VG 2025 QUARTAL IV IBAN + : DE12345678901234567891 BIC: BANKABC1XXX + + + + ENTGELT gem. Vereinbarung +
+
+
+
`; + + const parser = new CamtParser(camtXml); + const statements = parser.parse(); + + expect(statements).toHaveLength(1); + const statement = statements[0]; + expect(statement.transactions).toHaveLength(1); + + const transaction = statement.transactions[0]; + + // Check all Transaction fields filled by the parser + expect(transaction.amount).toBe(-179.46); + expect(transaction.customerReference).toBe('VG 2025 QUARTAL IV'); + expect(transaction.bankReference).toBe('TXN003'); + expect(transaction.purpose).toBe( + '28,65EUR EREF: VG 2025 QUARTAL IV IBAN: DE12345678901234567891 BIC: BANKABC1XXX', + ); + expect(transaction.remoteName).toBe('ABC Bank'); + expect(transaction.remoteAccountNumber).toBe('DE12345678901234567891'); + expect(transaction.remoteBankId).toBe('BANKABC1XXX'); + expect(transaction.e2eReference).toBe('VG 2025 QUARTAL IV'); + + // Check date fields + expect(transaction.valueDate).toBeInstanceOf(Date); + expect(transaction.valueDate.getFullYear()).toBe(2026); + expect(transaction.valueDate.getMonth()).toBe(0); // November (0-based) + expect(transaction.valueDate.getDate()).toBe(5); + expect(transaction.entryDate).toBeInstanceOf(Date); + expect(transaction.entryDate.getFullYear()).toBe(2026); + expect(transaction.entryDate.getMonth()).toBe(0); // November (0-based) + expect(transaction.entryDate.getDate()).toBe(5); + + // Check transaction type and code fields + expect(transaction.fundsCode).toBe('PMNT'); + expect(transaction.transactionType).toBe('ICDT'); + expect(transaction.transactionCode).toBe('ESCT'); + + // Check additional information fields + expect(transaction.additionalInformation).toBe('ENTGELT gem. Vereinbarung'); + expect(transaction.bookingText).toBe('ENTGELT gem. Vereinbarung'); // Should match additionalInformation + + // Verify optional fields not set in this test + expect(transaction.primeNotesNr).toBeUndefined(); + expect(transaction.remoteIdentifier).toBeUndefined(); + expect(transaction.client).toBeUndefined(); + expect(transaction.textKeyExtension).toBeUndefined(); + }); });