From 75f3bccdd7a1c5b1977ceceec40d07e585be0981 Mon Sep 17 00:00:00 2001 From: Toon Willems Date: Thu, 30 Nov 2023 18:51:39 +0100 Subject: [PATCH] Add workaround for non-unique transactionIds for Belfius bank (#283) Co-authored-by: Toon Willems --- src/app-gocardless/bank-factory.js | 2 ++ src/app-gocardless/banks/belfius_gkccbebb.js | 29 +++++++++++++++++++ .../banks/tests/belfius_gkccbebb.spec.js | 21 ++++++++++++++ src/app-gocardless/tests/bank-factory.spec.js | 8 +++++ upcoming-release-notes/283.md | 6 ++++ 5 files changed, 66 insertions(+) create mode 100644 src/app-gocardless/banks/belfius_gkccbebb.js create mode 100644 src/app-gocardless/banks/tests/belfius_gkccbebb.spec.js create mode 100644 upcoming-release-notes/283.md diff --git a/src/app-gocardless/bank-factory.js b/src/app-gocardless/bank-factory.js index 59113bb2c..cd0be5626 100644 --- a/src/app-gocardless/bank-factory.js +++ b/src/app-gocardless/bank-factory.js @@ -7,6 +7,7 @@ import SandboxfinanceSfin0000 from './banks/sandboxfinance-sfin0000.js'; import FintroBeGebabebb from './banks/fintro-be-gebabebb.js'; import DanskeBankDabNO22 from './banks/danskebank-dabno22.js'; import SparNordSpNoDK22 from './banks/sparnord-spnodk22.js'; +import Belfius from './banks/belfius_gkccbebb.js'; const banks = [ AmericanExpressAesudef1, @@ -17,6 +18,7 @@ const banks = [ FintroBeGebabebb, DanskeBankDabNO22, SparNordSpNoDK22, + Belfius, ]; export default (institutionId) => diff --git a/src/app-gocardless/banks/belfius_gkccbebb.js b/src/app-gocardless/banks/belfius_gkccbebb.js new file mode 100644 index 000000000..488f71327 --- /dev/null +++ b/src/app-gocardless/banks/belfius_gkccbebb.js @@ -0,0 +1,29 @@ +import Fallback from './integration-bank.js'; + +/** @type {import('./bank.interface.js').IBank} */ +export default { + institutionIds: ['BELFIUS_GKCCBEBB'], + + normalizeAccount(account) { + return Fallback.normalizeAccount(account); + }, + + // The problem is that we have transaction with duplicated transaction ids. + // This is not expected and the nordigen api has a work-around for some backs + // They will set an internalTransactionId which is unique + normalizeTransaction(transaction, _booked) { + return { + ...transaction, + transactionId: transaction.internalTransactionId, + date: transaction.bookingDate || transaction.valueDate, + }; + }, + + sortTransactions(transactions = []) { + return Fallback.sortTransactions(transactions); + }, + + calculateStartingBalance(sortedTransactions = [], balances = []) { + return Fallback.calculateStartingBalance(sortedTransactions, balances); + }, +}; diff --git a/src/app-gocardless/banks/tests/belfius_gkccbebb.spec.js b/src/app-gocardless/banks/tests/belfius_gkccbebb.spec.js new file mode 100644 index 000000000..25291a6a8 --- /dev/null +++ b/src/app-gocardless/banks/tests/belfius_gkccbebb.spec.js @@ -0,0 +1,21 @@ +import Belfius from '../belfius_gkccbebb.js'; +import { mockTransactionAmount } from '../../services/tests/fixtures.js'; + +describe('Belfius', () => { + describe('#normalizeTransaction', () => { + it('returns the internalTransactionId as transactionId', () => { + const transaction = { + transactionId: 'non-unique-id', + internalTransactionId: 'D202301180000003', + transactionAmount: mockTransactionAmount, + }; + const normalizedTransaction = Belfius.normalizeTransaction( + transaction, + true, + ); + expect(normalizedTransaction.transactionId).toEqual( + transaction.internalTransactionId, + ); + }); + }); +}); diff --git a/src/app-gocardless/tests/bank-factory.spec.js b/src/app-gocardless/tests/bank-factory.spec.js index efe73e50b..93484b225 100644 --- a/src/app-gocardless/tests/bank-factory.spec.js +++ b/src/app-gocardless/tests/bank-factory.spec.js @@ -3,6 +3,7 @@ import MbankRetailBrexplpw from '../banks/mbank-retail-brexplpw.js'; import SandboxfinanceSfin0000 from '../banks/sandboxfinance-sfin0000.js'; import IngPlIngbplpw from '../banks/ing-pl-ingbplpw.js'; import IntegrationBank from '../banks/integration-bank.js'; +import Belfius from '../banks/belfius_gkccbebb.js'; describe('BankFactory', () => { it('should return MbankRetailBrexplpw when institutionId is mbank-retail-brexplpw', () => { @@ -26,6 +27,13 @@ describe('BankFactory', () => { expect(result.institutionIds).toContain(institutionId); }); + it('should return Belfius when institutionId is BELFIUS_GKCCBEBB', () => { + const institutionId = Belfius.institutionIds[0]; + const result = BankFactory(institutionId); + + expect(result.institutionIds).toContain(institutionId); + }); + it('should return IntegrationBank when institutionId is not found', () => { const institutionId = IntegrationBank.institutionIds[0]; const result = BankFactory(institutionId); diff --git a/upcoming-release-notes/283.md b/upcoming-release-notes/283.md new file mode 100644 index 000000000..505f647db --- /dev/null +++ b/upcoming-release-notes/283.md @@ -0,0 +1,6 @@ +--- +category: Bugfix +authors: [Nudded] +--- + +Fix: non-unique transactionId values for Belfius bank causing missing data.