Skip to content

Commit

Permalink
Add test case for invalid date and date validation to handle it
Browse files Browse the repository at this point in the history
  • Loading branch information
lnagel committed Jan 10, 2025
1 parent bb0b4c0 commit c3f5c5d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/app-gocardless/banks/lhv-lhvbee22.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import d from 'date-fns';

import Fallback from './integration-bank.js';

/** @type {import('./bank.interface.js').IBank} */
Expand All @@ -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'),
};
}
}
Expand Down
1 change: 1 addition & 0 deletions src/app-gocardless/banks/tests/lhv-lhvbee22.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c3f5c5d

Please sign in to comment.