-
-
Notifications
You must be signed in to change notification settings - Fork 655
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bank handler for
VIRGIN_NRNBGB22
(Virgin Money) (#360)
- Loading branch information
Showing
4 changed files
with
112 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,65 @@ | ||
import Virgin from '../virgin_nrnbgb22.js'; | ||
import { mockTransactionAmount } from '../../services/tests/fixtures.js'; | ||
|
||
describe('Virgin', () => { | ||
describe('#normalizeTransaction', () => { | ||
it('does not alter simple payee information', () => { | ||
const transaction = { | ||
bookingDate: '2024-01-01T00:00:00Z', | ||
remittanceInformationUnstructured: 'DIRECT DEBIT PAYMENT', | ||
transactionAmount: mockTransactionAmount, | ||
}; | ||
|
||
const normalizedTransaction = Virgin.normalizeTransaction( | ||
transaction, | ||
true, | ||
); | ||
|
||
expect(normalizedTransaction.creditorName).toEqual( | ||
'DIRECT DEBIT PAYMENT', | ||
); | ||
expect(normalizedTransaction.debtorName).toEqual('DIRECT DEBIT PAYMENT'); | ||
expect(normalizedTransaction.remittanceInformationUnstructured).toEqual( | ||
'DIRECT DEBIT PAYMENT', | ||
); | ||
}); | ||
|
||
it('formats bank transfer payee and references', () => { | ||
const transaction = { | ||
bookingDate: '2024-01-01T00:00:00Z', | ||
remittanceInformationUnstructured: 'FPS, Joe Bloggs, Food', | ||
transactionAmount: mockTransactionAmount, | ||
}; | ||
|
||
const normalizedTransaction = Virgin.normalizeTransaction( | ||
transaction, | ||
true, | ||
); | ||
|
||
expect(normalizedTransaction.creditorName).toEqual('Joe Bloggs'); | ||
expect(normalizedTransaction.debtorName).toEqual('Joe Bloggs'); | ||
expect(normalizedTransaction.remittanceInformationUnstructured).toEqual( | ||
'Food', | ||
); | ||
}); | ||
|
||
it('removes method information from payee name', () => { | ||
const transaction = { | ||
bookingDate: '2024-01-01T00:00:00Z', | ||
remittanceInformationUnstructured: 'Card 99, Tesco Express', | ||
transactionAmount: mockTransactionAmount, | ||
}; | ||
|
||
const normalizedTransaction = Virgin.normalizeTransaction( | ||
transaction, | ||
true, | ||
); | ||
|
||
expect(normalizedTransaction.creditorName).toEqual('Tesco Express'); | ||
expect(normalizedTransaction.debtorName).toEqual('Tesco Express'); | ||
expect(normalizedTransaction.remittanceInformationUnstructured).toEqual( | ||
'Card 99, Tesco Express', | ||
); | ||
}); | ||
}); | ||
}); |
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,39 @@ | ||
import Fallback from './integration-bank.js'; | ||
|
||
/** @type {import('./bank.interface.js').IBank} */ | ||
export default { | ||
...Fallback, | ||
|
||
institutionIds: ['VIRGIN_NRNBGB22'], | ||
|
||
accessValidForDays: 90, | ||
|
||
normalizeTransaction(transaction, booked) { | ||
const transferPrefixes = ['MOB', 'FPS']; | ||
const methodRegex = /^(Card|WLT)\s\d+/; | ||
|
||
const parts = transaction.remittanceInformationUnstructured.split(', '); | ||
|
||
if (transferPrefixes.includes(parts[0])) { | ||
// Transfer remittance information begins with either "MOB" or "FPS" | ||
// the second field contains the payee and the third contains the | ||
// reference | ||
|
||
transaction.creditorName = parts[1]; | ||
transaction.debtorName = parts[1]; | ||
transaction.remittanceInformationUnstructured = parts[2]; | ||
} else if (parts[0].match(methodRegex)) { | ||
// The payee is prefixed with the payment method, eg "Card 11, {payee}" | ||
|
||
transaction.creditorName = parts[1]; | ||
transaction.debtorName = parts[1]; | ||
} else { | ||
// Simple payee name | ||
|
||
transaction.creditorName = transaction.remittanceInformationUnstructured; | ||
transaction.debtorName = transaction.remittanceInformationUnstructured; | ||
} | ||
|
||
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,6 @@ | ||
--- | ||
category: Enhancements | ||
authors: [matt-fidd] | ||
--- | ||
|
||
Add bank handler for VIRGIN_NRNBGB22 (Virgin Money) for more accurate payees |