diff --git a/packages/dynamics-lib/src/entities/__tests__/permission.entity.spec.js b/packages/dynamics-lib/src/entities/__tests__/permission.entity.spec.js index 975b1ed6c4..4edd6658b1 100644 --- a/packages/dynamics-lib/src/entities/__tests__/permission.entity.spec.js +++ b/packages/dynamics-lib/src/entities/__tests__/permission.entity.spec.js @@ -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 @@ -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' }) } @@ -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) @@ -97,7 +100,8 @@ describe('permission entity', () => { 'defra_ContactId@odata.bind': `$${contact.uniqueContentId}`, 'defra_Transaction@odata.bind': `$${transaction.uniqueContentId}`, 'defra_POCLFileId@odata.bind': `$${poclFile.uniqueContentId}`, - defra_renewal: true + defra_renewal: true, + defra_rcpagreement: false }) ) }) diff --git a/packages/dynamics-lib/src/entities/permission.entity.js b/packages/dynamics-lib/src/entities/permission.entity.js index 0f94497938..71d5b86848 100755 --- a/packages/dynamics-lib/src/entities/permission.entity.js +++ b/packages/dynamics-lib/src/entities/permission.entity.js @@ -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: { @@ -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} diff --git a/packages/gafl-webapp-service/src/pages/order-complete/order-complete/__tests__/order-complete.spec.js b/packages/gafl-webapp-service/src/pages/order-complete/order-complete/__tests__/order-complete.spec.js index 155ea1a09b..f0f0340dbc 100644 --- a/packages/gafl-webapp-service/src/pages/order-complete/order-complete/__tests__/order-complete.spec.js +++ b/packages/gafl-webapp-service/src/pages/order-complete/order-complete/__tests__/order-complete.spec.js @@ -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') @@ -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 } = {}) => ({ @@ -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 } ) diff --git a/packages/gafl-webapp-service/src/pages/order-complete/order-complete/route.js b/packages/gafl-webapp-service/src/pages/order-complete/order-complete/route.js index e86243f8f9..17deb1c2fe 100644 --- a/packages/gafl-webapp-service/src/pages/order-complete/order-complete/route.js +++ b/packages/gafl-webapp-service/src/pages/order-complete/order-complete/route.js @@ -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' @@ -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), @@ -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 ||