-
-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add suport for SWEDBANK_HABALV22 transaction date
- Loading branch information
Showing
3 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import d from 'date-fns'; | ||
|
||
import Fallback from './integration-bank.js'; | ||
|
||
/** @type {import('./bank.interface.js').IBank} */ | ||
export default { | ||
...Fallback, | ||
|
||
institutionIds: ['SWEDBANK_HABALV22'], | ||
|
||
accessValidForDays: 90, | ||
|
||
/** | ||
* The actual transaction date for card transactions is only available in the remittanceInformationUnstructured field when the transaction is booked. | ||
*/ | ||
normalizeTransaction(transaction, booked) { | ||
const dateMatch = transaction.remittanceInformationUnstructured?.match( | ||
/PIRKUMS [\d*]+ (\d{2}.\d{2}.\d{4})/, | ||
); | ||
|
||
if (dateMatch) { | ||
const extractedDate = d.parse(dateMatch[1], 'dd.MM.yyyy', new Date()); | ||
|
||
return Fallback.normalizeTransaction( | ||
{ ...transaction, bookingDate: d.format(extractedDate, 'yyyy-MM-dd') }, | ||
booked, | ||
); | ||
} | ||
|
||
return Fallback.normalizeTransaction(transaction, booked); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import SwedbankHabaLV22 from '../swedbank-habalv22.js'; | ||
|
||
describe('#normalizeTransaction', () => { | ||
const cardTransaction = { | ||
transactionId: '2024102900000000-1', | ||
bookingDate: '2024-10-29', | ||
valueDate: '2024-10-29', | ||
transactionAmount: { | ||
amount: '-22.99', | ||
currency: 'EUR', | ||
}, | ||
creditorName: 'SOME CREDITOR NAME', | ||
remittanceInformationUnstructured: | ||
'PIRKUMS 424242******4242 28.10.2024 22.99 EUR (111111) SOME CREDITOR NAME', | ||
bankTransactionCode: 'PMNT-CCRD-POSD', | ||
internalTransactionId: 'fa000f86afb2cc7678bcff0000000000', | ||
}; | ||
|
||
it('extracts card transaction date', () => { | ||
expect( | ||
SwedbankHabaLV22.normalizeTransaction(cardTransaction, true).bookingDate, | ||
).toEqual('2024-10-28'); | ||
|
||
expect( | ||
SwedbankHabaLV22.normalizeTransaction(cardTransaction, true).date, | ||
).toEqual('2024-10-28'); | ||
}); | ||
|
||
it('normalizes non-card transactions as usual', () => { | ||
const nonCardTransaction1 = { | ||
...cardTransaction, | ||
remittanceInformationUnstructured: 'Some info', | ||
}; | ||
expect( | ||
SwedbankHabaLV22.normalizeTransaction(nonCardTransaction1, true) | ||
.bookingDate, | ||
).toEqual('2024-10-29'); | ||
|
||
expect( | ||
SwedbankHabaLV22.normalizeTransaction(nonCardTransaction1, true).date, | ||
).toEqual('2024-10-29'); | ||
|
||
const nonCardTransaction2 = { | ||
...cardTransaction, | ||
remittanceInformationUnstructured: 'PIRKUMS xxx', | ||
}; | ||
expect( | ||
SwedbankHabaLV22.normalizeTransaction(nonCardTransaction2, true) | ||
.bookingDate, | ||
).toEqual('2024-10-29'); | ||
|
||
expect( | ||
SwedbankHabaLV22.normalizeTransaction(nonCardTransaction2, true).date, | ||
).toEqual('2024-10-29'); | ||
|
||
const nonCardTransaction3 = { | ||
...cardTransaction, | ||
remittanceInformationUnstructured: null, | ||
}; | ||
expect( | ||
SwedbankHabaLV22.normalizeTransaction(nonCardTransaction3, true) | ||
.bookingDate, | ||
).toEqual('2024-10-29'); | ||
|
||
expect( | ||
SwedbankHabaLV22.normalizeTransaction(nonCardTransaction3, true).date, | ||
).toEqual('2024-10-29'); | ||
}); | ||
}); |