Skip to content

Commit

Permalink
Add workaround for non-unique transactionIds for Belfius bank (actual…
Browse files Browse the repository at this point in the history
…budget#283)

Co-authored-by: Toon Willems <[email protected]>
  • Loading branch information
2 people authored and MMichotte committed Sep 9, 2024
1 parent 787ddc6 commit 75f3bcc
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app-gocardless/bank-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -17,6 +18,7 @@ const banks = [
FintroBeGebabebb,
DanskeBankDabNO22,
SparNordSpNoDK22,
Belfius,
];

export default (institutionId) =>
Expand Down
29 changes: 29 additions & 0 deletions src/app-gocardless/banks/belfius_gkccbebb.js
Original file line number Diff line number Diff line change
@@ -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);
},
};
21 changes: 21 additions & 0 deletions src/app-gocardless/banks/tests/belfius_gkccbebb.spec.js
Original file line number Diff line number Diff line change
@@ -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,
);
});
});
});
8 changes: 8 additions & 0 deletions src/app-gocardless/tests/bank-factory.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/283.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [Nudded]
---

Fix: non-unique transactionId values for Belfius bank causing missing data.

0 comments on commit 75f3bcc

Please sign in to comment.