diff --git a/packages/gafl-webapp-service/src/pages/recurring-payments/choose-payment/__tests__/result-function.spec.js b/packages/gafl-webapp-service/src/pages/recurring-payments/choose-payment/__tests__/result-function.spec.js index 4d7084b5c8..c7fd4c23c8 100644 --- a/packages/gafl-webapp-service/src/pages/recurring-payments/choose-payment/__tests__/result-function.spec.js +++ b/packages/gafl-webapp-service/src/pages/recurring-payments/choose-payment/__tests__/result-function.spec.js @@ -27,7 +27,7 @@ describe('choose payment > result function', () => { expect(result).toBe(CommonResults.OK) }) - it.only('returns common result as recurring when payment is recurring payment', async () => { + it('returns common result as recurring when payment is recurring payment', async () => { const mockRequest = getMockRequest({ payload: { 'recurring-payment': 'yes' } }) const result = await resultFunction(mockRequest) diff --git a/packages/gafl-webapp-service/src/pages/recurring-payments/set-up-payment/__tests__/__snapshots__/route.spec.js.snap b/packages/gafl-webapp-service/src/pages/recurring-payments/set-up-payment/__tests__/__snapshots__/route.spec.js.snap new file mode 100644 index 0000000000..c1e2c7db87 --- /dev/null +++ b/packages/gafl-webapp-service/src/pages/recurring-payments/set-up-payment/__tests__/__snapshots__/route.spec.js.snap @@ -0,0 +1,21 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`route getData returns expected values 1`] = ` +Object { + "cost": Symbol(cost value), + "errorMap": Object { + "agree": Object { + "any.required": Object { + "ref": "#agree", + "text": "recurring payment error", + }, + }, + }, + "reminder": Symbol(reminder value), + "type": Symbol(type value), + "uri": Object { + "single": Symbol(uri value), + "terms": Symbol(uri value), + }, +} +`; diff --git a/packages/gafl-webapp-service/src/pages/recurring-payments/set-up-payment/__tests__/route.spec.js b/packages/gafl-webapp-service/src/pages/recurring-payments/set-up-payment/__tests__/route.spec.js index a6a13014f9..d7b99afa88 100644 --- a/packages/gafl-webapp-service/src/pages/recurring-payments/set-up-payment/__tests__/route.spec.js +++ b/packages/gafl-webapp-service/src/pages/recurring-payments/set-up-payment/__tests__/route.spec.js @@ -13,7 +13,7 @@ jest.mock('../../../../processors/uri-helper.js') jest.mock('../../../../processors/recurring-pay-reminder-display.js') jest.mock('../../../../processors/price-display.js') -const getSampleRequest = (permission = {}, catalog = {}) => ({ +const getSampleRequest = (permission = {}, catalog = getCatalog()) => ({ cache: () => ({ helpers: { transaction: { @@ -26,6 +26,10 @@ const getSampleRequest = (permission = {}, catalog = {}) => ({ } }) +const getCatalog = () => ({ + recurring_payment_set_up_error: 'recurring payment error' +}) + describe('route', () => { describe('validator', () => { it('validator should validate "yes" as a valid choice', () => { @@ -46,79 +50,32 @@ describe('route', () => { }) describe('getData', () => { - it('cost equals return of displayPermissionPrice', async () => { - const returnValue = Symbol('return value') - displayPermissionPrice.mockReturnValueOnce(returnValue) + it('returns expected values', async () => { + const cost = Symbol('cost value') + const type = Symbol('type value') + const reminder = Symbol('reminder value') + const uri = Symbol('uri value') - const result = await getData(getSampleRequest()) - - expect(result.cost).toEqual(returnValue) - }) - - it('displayPermissionPrice is called with permission and getCatalog', async () => { - const catalog = Symbol('mock catalog') - const permission = Symbol('mock permission') - const request = getSampleRequest(permission, catalog) - - await getData(request) - - expect(displayPermissionPrice).toHaveBeenCalledWith(permission, catalog) - }) - - it('type equals return of recurringLicenceTypeDisplay', async () => { - const returnValue = Symbol('return value') - recurringLicenceTypeDisplay.mockReturnValueOnce(returnValue) + displayPermissionPrice.mockReturnValueOnce(cost) + recurringLicenceTypeDisplay.mockReturnValueOnce(type) + recurringPayReminderDisplay.mockReturnValueOnce(reminder) + addLanguageCodeToUri.mockReturnValue(uri) const result = await getData(getSampleRequest()) - expect(result.type).toEqual(returnValue) + expect(result).toMatchSnapshot() }) - it('recurringLicenceTypeDisplay is called with permission and getCatalog', async () => { - const catalog = Symbol('mock catalog') - const permission = Symbol('mock permission') + it.each([ + [displayPermissionPrice, Symbol('mock catalog'), Symbol('mock permission')], + [recurringLicenceTypeDisplay, Symbol('mock catalog'), Symbol('mock permission')], + [recurringPayReminderDisplay, Symbol('mock catalog'), Symbol('mock permission')] + ])('%s is called with permission and getCatalog', async (func, catalog, permission) => { const request = getSampleRequest(permission, catalog) await getData(request) - expect(recurringLicenceTypeDisplay).toHaveBeenCalledWith(permission, catalog) - }) - - it('reminder equals return of recurringPayReminderDisplay', async () => { - const returnValue = Symbol('return value') - recurringPayReminderDisplay.mockReturnValueOnce(returnValue) - - const result = await getData(getSampleRequest()) - - expect(result.reminder).toEqual(returnValue) - }) - - it('recurringPayReminderDisplay is called with permission and getCatalog', async () => { - const catalog = Symbol('mock catalog') - const permission = Symbol('mock permission') - const request = getSampleRequest(permission, catalog) - - await getData(request) - - expect(recurringPayReminderDisplay).toHaveBeenCalledWith(permission, catalog) - }) - - it('single equals return of addLanguageCodeToUri with choose payment', async () => { - const returnValue = Symbol('return value') - addLanguageCodeToUri.mockReturnValue(returnValue) - - const result = await getData(getSampleRequest()) - - expect(result.uri.single).toEqual(returnValue) - }) - - it('terms equals return of addLanguageCodeToUri with terms and conditions', async () => { - const returnValue = Symbol('return value') - addLanguageCodeToUri.mockReturnValue(returnValue) - - const result = await getData(getSampleRequest()) - - expect(result.uri.single).toEqual(returnValue) + expect(func).toHaveBeenCalledWith(permission, catalog) }) it.each([[CHOOSE_PAYMENT.uri], [TERMS_AND_CONDITIONS.uri] diff --git a/packages/gafl-webapp-service/src/pages/recurring-payments/set-up-payment/route.js b/packages/gafl-webapp-service/src/pages/recurring-payments/set-up-payment/route.js index ff3178d15b..0c5465fe8d 100644 --- a/packages/gafl-webapp-service/src/pages/recurring-payments/set-up-payment/route.js +++ b/packages/gafl-webapp-service/src/pages/recurring-payments/set-up-payment/route.js @@ -13,8 +13,14 @@ export const validator = Joi.object({ export const getData = async request => { const permission = await request.cache().helpers.transaction.getCurrentPermission() + const errorMsg = request.i18n.getCatalog().recurring_payment_set_up_error return { + errorMap: { + agree: { + 'any.required': { ref: '#agree', text: errorMsg } + } + }, cost: displayPermissionPrice(permission, request.i18n.getCatalog()), type: recurringLicenceTypeDisplay(permission, request.i18n.getCatalog()), reminder: recurringPayReminderDisplay(permission, request.i18n.getCatalog()), diff --git a/packages/gafl-webapp-service/src/pages/recurring-payments/set-up-payment/set-up-payment.njk b/packages/gafl-webapp-service/src/pages/recurring-payments/set-up-payment/set-up-payment.njk index 3a4799c89e..395f8862e3 100644 --- a/packages/gafl-webapp-service/src/pages/recurring-payments/set-up-payment/set-up-payment.njk +++ b/packages/gafl-webapp-service/src/pages/recurring-payments/set-up-payment/set-up-payment.njk @@ -8,20 +8,11 @@ {% set title = mssgs.recurring_payment_set_up_title %} {% block pageTitle %}{{ title }}{{ mssgs.gov_uk }}{% endblock %} -{% set errorMsg = mssgs.recurring_payment_set_up_error %} - -{% set errorMap = { - 'agree': { - 'any.required': { ref: '#agree', text: errorMsg } - } - } -%} - {% block content %}