Skip to content

Commit

Permalink
fix: Error on bank accounts without connection relationship
Browse files Browse the repository at this point in the history
Some old bank accounts, without any associated running connector, may
have no "connection" relationship.

Adding a protection against this.
  • Loading branch information
doubleface authored and doubleface committed Dec 9, 2022
1 parent dbc6200 commit f7c46ab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/cozy-doctypes/src/banking/BankAccount.js
Expand Up @@ -64,7 +64,9 @@ class BankAccount extends Document {
matchedAccountIds[localAccount._id]
)
const newAccountId =
replacedCozyAccountIds[localAccount.relationships.connection.data._id]
replacedCozyAccountIds[
localAccount?.relationships?.connection?.data?._id
]
if (foundInMatchedAccounts || !newAccountId) {
continue
}
Expand Down
17 changes: 16 additions & 1 deletion packages/cozy-doctypes/src/banking/BankAccount.spec.js
@@ -1,7 +1,7 @@
const BankAccount = require('./BankAccount')

describe('account reconciliation', () => {
it('should update relationship of disabled accounts associated to the same relationship as updated anabled accounts', () => {
it('should update relationship of disabled accounts associated to the same relationship as updated anabled accounts even with accounts without connection relationship', () => {
const newAccounts = [
{
number: '1',
Expand Down Expand Up @@ -51,6 +51,21 @@ describe('account reconciliation', () => {
metadata: {
updatedAt: '2020-11-30'
}
},
{
_id: 'oldaccountnorelationship',
number: '10',
balance: 0,
relationships: {
other: {
data: {
some: 'data'
}
}
},
metadata: {
updatedAt: '2012-11-30'
}
}
]
const matchedAccounts = BankAccount.reconciliate(
Expand Down

0 comments on commit f7c46ab

Please sign in to comment.