Skip to content

Commit

Permalink
Fix RP creation bug (#2092)
Browse files Browse the repository at this point in the history
* Fix RP creation bug

https://eaflood.atlassian.net/browse/IWTF-4262

A recurring payment is being created for all permissions

* Amend generateRecurringPaymentRecord to set recurring flag to false when agreement id isn't present in transaction
  • Loading branch information
jaucourt authored Dec 12, 2024
1 parent 87fc755 commit 52ad3bb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,5 +326,17 @@ describe('recurring payments service', () => {

expect(() => generateRecurringPaymentRecord(sampleTransaction)).toThrow('Invalid dates provided for permission')
})

it('returns a false flag when agreementId is not present', () => {
const sampleTransaction = createFinalisedSampleTransaction(null, {
startDate: '2024-11-22T15:30:45.922Z',
issueDate: '2024-11-22T15:00:45.922Z',
endDate: '2025-11-21T23:59:59.999Z'
})

const rpRecord = generateRecurringPaymentRecord(sampleTransaction)

expect(rpRecord.payment.recurring).toBeFalsy()
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,24 @@ const getNextDueDate = (startDate, issueDate, endDate) => {
}

export const generateRecurringPaymentRecord = (transactionRecord, permission) => {
const [{ startDate, issueDate, endDate }] = transactionRecord.permissions
return {
payment: {
recurring: {
name: '',
nextDueDate: getNextDueDate(startDate, issueDate, endDate),
cancelledDate: null,
cancelledReason: null,
endDate,
agreementId: transactionRecord.agreementId,
status: 1
}
},
permissions: [permission]
if (transactionRecord.agreementId) {
const [{ startDate, issueDate, endDate }] = transactionRecord.permissions
return {
payment: {
recurring: {
name: '',
nextDueDate: getNextDueDate(startDate, issueDate, endDate),
cancelledDate: null,
cancelledReason: null,
endDate,
agreementId: transactionRecord.agreementId,
status: 1
}
},
permissions: [permission]
}
}
return { payment: { recurring: false } }
}

/**
Expand Down

0 comments on commit 52ad3bb

Please sign in to comment.