Skip to content

Commit

Permalink
Update order complete page RCP logic (#2096)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/IWTF-4265

Now that the recurring payment status is saved to the CRM, we can use that data to conditionally display content relating to recurring payments.
  • Loading branch information
irisfaraway authored Dec 23, 2024
1 parent e00aea1 commit 65976fb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('permission entity', () => {
defra_stagingid: '71ad9a25-2a03-406b-a0e3-f4ff37799374',
defra_datasource: 910400003,
defra_renewal: true,
defra_rcpagreement: false,
defra_licenceforyou: 1
},
optionSetData
Expand All @@ -32,6 +33,7 @@ describe('permission entity', () => {
stagingId: '71ad9a25-2a03-406b-a0e3-f4ff37799374',
dataSource: expect.objectContaining({ id: 910400003, label: 'Web Sales', description: 'Web Sales' }),
isRenewal: true,
isRecurringPayment: false,
isLicenceForYou: expect.objectContaining({ id: 1, label: 'Yes', description: 'Yes' })
}

Expand Down Expand Up @@ -76,6 +78,7 @@ describe('permission entity', () => {
permission.stagingId = '71ad9a25-2a03-406b-a0e3-f4ff37799374'
permission.dataSource = optionSetData.defra_datasource.options['910400003']
permission.isRenewal = true
permission.isRecurringPayment = false
permission.isLicenceForYou = optionSetData.defra_islicenceforyou.options['1']

permission.bindToEntity(Permission.definition.relationships.licensee, contact)
Expand All @@ -97,7 +100,8 @@ describe('permission entity', () => {
'[email protected]': `$${contact.uniqueContentId}`,
'[email protected]': `$${transaction.uniqueContentId}`,
'[email protected]': `$${poclFile.uniqueContentId}`,
defra_renewal: true
defra_renewal: true,
defra_rcpagreement: false
})
)
})
Expand Down
13 changes: 13 additions & 0 deletions packages/dynamics-lib/src/entities/permission.entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class Permission extends BaseEntity {
stagingId: { field: 'defra_stagingid', type: 'string' },
dataSource: { field: 'defra_datasource', type: 'optionset', ref: 'defra_datasource' },
isRenewal: { field: 'defra_renewal', type: 'boolean' },
isRecurringPayment: { field: 'defra_rcpagreement', type: 'boolean' },
isLicenceForYou: { field: 'defra_licenceforyou', type: 'optionset', ref: 'defra_islicenceforyou' }
},
relationships: {
Expand Down Expand Up @@ -127,6 +128,18 @@ export class Permission extends BaseEntity {
super._setState('isRenewal', isRenewal)
}

/**
* Whether the permission has a recurring payment agreement
* @type {boolean}
*/
get isRecurringPayment () {
return super._getState('isRecurringPayment')
}

set isRecurringPayment (isRecurringPayment) {
super._setState('isRecurringPayment', isRecurringPayment)
}

/*
* Whether the permission is for the user purchasing the licence or someone else
* @type {boolean}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { COMPLETION_STATUS, FEEDBACK_URI_DEFAULT } from '../../../../constants.j
import { displayStartTime } from '../../../../processors/date-and-time-display.js'
import { LICENCE_TYPE } from '../../../../processors/mapping-constants.js'
import { displayPrice } from '../../../../processors/price-display.js'
import { validForRecurringPayment } from '../../../../processors/recurring-pay-helper.js'

jest.mock('../../../../processors/recurring-pay-helper.js')
jest.mock('../../../../processors/date-and-time-display.js')
Expand Down Expand Up @@ -50,14 +49,16 @@ const getSamplePermission = ({
licenceType = LICENCE_TYPE['trout-and-coarse'],
isLicenceForYou = true,
licenceLength = '12M',
licensee = getSampleLicensee()
licensee = getSampleLicensee(),
isRecurringPayment = false
} = {}) => ({
startDate: '2019-12-14T00:00:00Z',
licensee,
isLicenceForYou,
licenceType,
referenceNumber,
licenceLength
licenceLength,
isRecurringPayment
})

const getSampleCompletionStatus = ({ agreed = true, posted = true, finalised = true, setUpPayment = true } = {}) => ({
Expand Down Expand Up @@ -203,27 +204,23 @@ describe('The order completion handler', () => {
expect(displayStartTime).toHaveBeenCalledWith(request, permission)
})

it('validForRecurringPayment is called with a permission', async () => {
const permission = getSamplePermission()

await getData(getSampleRequest({ permission }))

expect(validForRecurringPayment).toHaveBeenCalledWith(permission)
})

it.each`
agreement | valid | expected
${true} | ${true} | ${true}
${true} | ${false} | ${false}
${false} | ${false} | ${false}
${false} | ${true} | ${false}
show | recurring | expected
${true} | ${true} | ${true}
${true} | ${false} | ${false}
${false} | ${false} | ${false}
${false} | ${true} | ${false}
`(
'recurringPayment returns $expected when status for setup of recurring payment agreement is $agreement and valid for recurring payment is $valid',
async ({ agreement, valid, expected }) => {
validForRecurringPayment.mockReturnValueOnce(valid)
const completionStatus = getSampleCompletionStatus({ setUpPayment: agreement })
const { recurringPayment } = await getData(getSampleRequest({ completionStatus }))
'recurringPayment returns $expected when SHOW_RECURRING_PAYMENTS is $show and the permission recurring payment is $recurring',
async ({ show, recurring, expected }) => {
process.env.SHOW_RECURRING_PAYMENTS = show
const permission = getSamplePermission({ isRecurringPayment: recurring })
const request = getSampleRequest({ permission })
const { recurringPayment } = await getData(request)

expect(recurringPayment).toBe(expected)

delete process.env.SHOW_RECURRING_PAYMENTS
}
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pageRoute from '../../../routes/page-route.js'
import { validForRecurringPayment } from '../../../processors/recurring-pay-helper.js'
import Boom from '@hapi/boom'
import { COMPLETION_STATUS, FEEDBACK_URI_DEFAULT } from '../../../constants.js'
import { ORDER_COMPLETE, NEW_TRANSACTION, LICENCE_DETAILS } from '../../../uri.js'
Expand Down Expand Up @@ -42,7 +41,7 @@ export const getData = async request => {
digitalConfirmation: digital && permission.licensee.postalFulfilment,
digitalLicence: digital && !permission.licensee.postalFulfilment,
postalLicence: permission.licensee.postalFulfilment,
recurringPayment: isRecurringPayment(status, permission),
recurringPayment: isRecurringPayment(permission),
uri: {
feedback: process.env.FEEDBACK_URI || FEEDBACK_URI_DEFAULT,
licenceDetails: addLanguageCodeToUri(request, LICENCE_DETAILS.uri),
Expand All @@ -59,7 +58,7 @@ const postalFulfilment = permission => {
}
}

const isRecurringPayment = (status, permission) => validForRecurringPayment(permission) && status.permissions[0]['set-up-payment']
const isRecurringPayment = permission => process.env.SHOW_RECURRING_PAYMENTS?.toLowerCase() === 'true' && permission.isRecurringPayment

const digitalConfirmation = permission =>
permission.licensee.preferredMethodOfConfirmation === HOW_CONTACTED.email ||
Expand Down

0 comments on commit 65976fb

Please sign in to comment.