Skip to content

Commit f7c46ab

Browse files
doublefacedoubleface
doubleface
authored andcommittedDec 9, 2022
fix: Error on bank accounts without connection relationship
Some old bank accounts, without any associated running connector, may have no "connection" relationship. Adding a protection against this.

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed
 

‎packages/cozy-doctypes/src/banking/BankAccount.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ class BankAccount extends Document {
6464
matchedAccountIds[localAccount._id]
6565
)
6666
const newAccountId =
67-
replacedCozyAccountIds[localAccount.relationships.connection.data._id]
67+
replacedCozyAccountIds[
68+
localAccount?.relationships?.connection?.data?._id
69+
]
6870
if (foundInMatchedAccounts || !newAccountId) {
6971
continue
7072
}

‎packages/cozy-doctypes/src/banking/BankAccount.spec.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const BankAccount = require('./BankAccount')
22

33
describe('account reconciliation', () => {
4-
it('should update relationship of disabled accounts associated to the same relationship as updated anabled accounts', () => {
4+
it('should update relationship of disabled accounts associated to the same relationship as updated anabled accounts even with accounts without connection relationship', () => {
55
const newAccounts = [
66
{
77
number: '1',
@@ -51,6 +51,21 @@ describe('account reconciliation', () => {
5151
metadata: {
5252
updatedAt: '2020-11-30'
5353
}
54+
},
55+
{
56+
_id: 'oldaccountnorelationship',
57+
number: '10',
58+
balance: 0,
59+
relationships: {
60+
other: {
61+
data: {
62+
some: 'data'
63+
}
64+
}
65+
},
66+
metadata: {
67+
updatedAt: '2012-11-30'
68+
}
5469
}
5570
]
5671
const matchedAccounts = BankAccount.reconciliate(

0 commit comments

Comments
 (0)
Please sign in to comment.