From c3f5c5d975ddd41e533a252c7c77b44d33f007ba Mon Sep 17 00:00:00 2001 From: Lenno Nagel Date: Thu, 9 Jan 2025 11:03:17 +0200 Subject: [PATCH] Add test case for invalid date and date validation to handle it --- src/app-gocardless/banks/lhv-lhvbee22.js | 8 ++++++-- src/app-gocardless/banks/tests/lhv-lhvbee22.spec.js | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/app-gocardless/banks/lhv-lhvbee22.js b/src/app-gocardless/banks/lhv-lhvbee22.js index 43e7e075..f8d34bc2 100644 --- a/src/app-gocardless/banks/lhv-lhvbee22.js +++ b/src/app-gocardless/banks/lhv-lhvbee22.js @@ -1,3 +1,5 @@ +import d from 'date-fns'; + import Fallback from './integration-bank.js'; /** @type {import('./bank.interface.js').IBank} */ @@ -20,15 +22,17 @@ export default { ); if (cardTxMatch) { + const extractedDate = d.parse(cardTxMatch[2], 'yyyy-MM-dd', new Date()); + transaction = { ...transaction, creditorName: cardTxMatch[4].split('\\')[0].trim(), }; - if (booked) { + if (booked && d.isValid(extractedDate)) { transaction = { ...transaction, - bookingDate: cardTxMatch[2], + bookingDate: d.format(extractedDate, 'yyyy-MM-dd'), }; } } diff --git a/src/app-gocardless/banks/tests/lhv-lhvbee22.spec.js b/src/app-gocardless/banks/tests/lhv-lhvbee22.spec.js index 571bdeb8..72e61fb3 100644 --- a/src/app-gocardless/banks/tests/lhv-lhvbee22.spec.js +++ b/src/app-gocardless/banks/tests/lhv-lhvbee22.spec.js @@ -37,6 +37,7 @@ describe('#normalizeTransaction', () => { ['regular text', 'Some info'], ['partial card text', 'PIRKUMS xxx'], ['null value', null], + ['invalid date', '(..1234) 2025-13-45 09:32 Merchant\\Address'], ])('normalizes non-card transaction with %s', (_, remittanceInfo) => { const transaction = { ...bookedCardTransaction,