diff --git a/packages/gafl-webapp-service/src/pages/concessions/date-of-birth/__tests__/route.spec.js b/packages/gafl-webapp-service/src/pages/concessions/date-of-birth/__tests__/route.spec.js index 1d664b221..7dc8cd1fc 100644 --- a/packages/gafl-webapp-service/src/pages/concessions/date-of-birth/__tests__/route.spec.js +++ b/packages/gafl-webapp-service/src/pages/concessions/date-of-birth/__tests__/route.spec.js @@ -2,7 +2,7 @@ import { getData } from '../route' import pageRoute from '../../../../routes/page-route.js' import { nextPage } from '../../../../routes/next-page.js' import { DATE_OF_BIRTH, LICENCE_FOR } from '../../../../uri.js' -import { dateOfBirthValidator, getErrorFlags } from '../../../../schema/validators/validators.js' +import { dateOfBirthValidator, getDateErrorFlags } from '../../../../schema/validators/validators.js' jest.mock('../../../../routes/next-page.js') jest.mock('../../../../routes/page-route.js') @@ -83,7 +83,7 @@ describe('name > route', () => { it('adds return value of getErrorFlags to the page data', async () => { const errorFlags = { unique: Symbol('error-flags') } - getErrorFlags.mockReturnValueOnce(errorFlags) + getDateErrorFlags.mockReturnValueOnce(errorFlags) const result = await getData(mockRequest()) expect(result).toEqual(expect.objectContaining(errorFlags)) }) @@ -91,7 +91,7 @@ describe('name > route', () => { it('passes error to getErrorFlags', async () => { const error = Symbol('error') await getData(mockRequest({ pageGet: async () => ({ error }) })) - expect(getErrorFlags).toHaveBeenCalledWith(error) + expect(getDateErrorFlags).toHaveBeenCalledWith(error) }) it('passes correct page name when getting page cache', async () => { diff --git a/packages/gafl-webapp-service/src/pages/concessions/date-of-birth/route.js b/packages/gafl-webapp-service/src/pages/concessions/date-of-birth/route.js index 891383603..1e0b00bc1 100644 --- a/packages/gafl-webapp-service/src/pages/concessions/date-of-birth/route.js +++ b/packages/gafl-webapp-service/src/pages/concessions/date-of-birth/route.js @@ -2,7 +2,7 @@ import { DATE_OF_BIRTH, LICENCE_FOR } from '../../../uri.js' import pageRoute from '../../../routes/page-route.js' import { nextPage } from '../../../routes/next-page.js' import GetDataRedirect from '../../../handlers/get-data-redirect.js' -import { dateOfBirthValidator, getErrorFlags } from '../../../schema/validators/validators.js' +import { dateOfBirthValidator, getDateErrorFlags } from '../../../schema/validators/validators.js' const redirectToStartOfJourney = status => { if (!status[LICENCE_FOR.page]) { @@ -14,7 +14,7 @@ export const getData = async request => { const { isLicenceForYou } = await request.cache().helpers.transaction.getCurrentPermission() const status = await request.cache().helpers.status.getCurrentPermission() const page = await request.cache().helpers.page.getCurrentPermission(DATE_OF_BIRTH.page) - const pageData = { isLicenceForYou, ...getErrorFlags(page?.error) } + const pageData = { isLicenceForYou, ...getDateErrorFlags(page?.error) } redirectToStartOfJourney(status) diff --git a/packages/gafl-webapp-service/src/pages/licence-details/licence-to-start/__tests__/route.spec.js b/packages/gafl-webapp-service/src/pages/licence-details/licence-to-start/__tests__/route.spec.js index d2d0990cb..11519e4f0 100644 --- a/packages/gafl-webapp-service/src/pages/licence-details/licence-to-start/__tests__/route.spec.js +++ b/packages/gafl-webapp-service/src/pages/licence-details/licence-to-start/__tests__/route.spec.js @@ -2,7 +2,7 @@ import pageRoute from '../../../../routes/page-route.js' import { nextPage } from '../../../../routes/next-page.js' import { getData } from '../route' import { LICENCE_TO_START } from '../../../../uri.js' -import { startDateValidator, getErrorFlags } from '../../../../schema/validators/validators.js' +import { startDateValidator, getDateErrorFlags } from '../../../../schema/validators/validators.js' jest.mock('../../../../routes/next-page.js') jest.mock('../../../../routes/page-route.js') @@ -34,7 +34,7 @@ describe('licence-to-start > route', () => { describe('getData', () => { beforeEach(() => { - getErrorFlags.mockClear() + getDateErrorFlags.mockClear() }) it('should return isLicenceForYou as true, if isLicenceForYou is true on the transaction cache', async () => { @@ -74,7 +74,7 @@ describe('licence-to-start > route', () => { it('adds return value of getErrorFlags to the page data', async () => { const errorFlags = { unique: Symbol('error-flags') } - getErrorFlags.mockReturnValueOnce(errorFlags) + getDateErrorFlags.mockReturnValueOnce(errorFlags) const result = await getData(getMockRequest()) expect(result).toEqual(expect.objectContaining(errorFlags)) }) @@ -82,7 +82,7 @@ describe('licence-to-start > route', () => { it('passes error to getErrorFlags', async () => { const error = Symbol('error') await getData(getMockRequest(undefined, async () => ({ error }))) - expect(getErrorFlags).toHaveBeenCalledWith(error) + expect(getDateErrorFlags).toHaveBeenCalledWith(error) }) }) diff --git a/packages/gafl-webapp-service/src/pages/licence-details/licence-to-start/route.js b/packages/gafl-webapp-service/src/pages/licence-details/licence-to-start/route.js index 1d8755b1f..6e063b488 100644 --- a/packages/gafl-webapp-service/src/pages/licence-details/licence-to-start/route.js +++ b/packages/gafl-webapp-service/src/pages/licence-details/licence-to-start/route.js @@ -3,7 +3,7 @@ import { START_AFTER_PAYMENT_MINUTES, ADVANCED_PURCHASE_MAX_DAYS, SERVICE_LOCAL_ import { LICENCE_TO_START } from '../../../uri.js' import pageRoute from '../../../routes/page-route.js' import { nextPage } from '../../../routes/next-page.js' -import { getErrorFlags, startDateValidator } from '../../../schema/validators/validators.js' +import { getDateErrorFlags, startDateValidator } from '../../../schema/validators/validators.js' export const getData = async request => { const fmt = 'DD MM YYYY' @@ -16,7 +16,7 @@ export const getData = async request => { maxStartDate: moment().tz(SERVICE_LOCAL_TIME).add(ADVANCED_PURCHASE_MAX_DAYS, 'days').format(fmt), advancedPurchaseMaxDays: ADVANCED_PURCHASE_MAX_DAYS, startAfterPaymentMinutes: START_AFTER_PAYMENT_MINUTES, - ...getErrorFlags(page?.error) + ...getDateErrorFlags(page?.error) } if (page?.error) { diff --git a/packages/gafl-webapp-service/src/pages/renewals/identify/__tests__/route.spec.js b/packages/gafl-webapp-service/src/pages/renewals/identify/__tests__/route.spec.js index 6a3689070..afe14fdae 100644 --- a/packages/gafl-webapp-service/src/pages/renewals/identify/__tests__/route.spec.js +++ b/packages/gafl-webapp-service/src/pages/renewals/identify/__tests__/route.spec.js @@ -2,7 +2,7 @@ import pageRoute from '../../../../routes/page-route.js' import { addLanguageCodeToUri } from '../../../../processors/uri-helper.js' import { getData, validator } from '../route.js' import { IDENTIFY, NEW_TRANSACTION } from '../../../../uri.js' -import { dateOfBirthValidator, getErrorFlags } from '../../../../schema/validators/validators.js' +import { dateOfBirthValidator, getDateErrorFlags } from '../../../../schema/validators/validators.js' jest.mock('../../../../routes/page-route.js', () => jest.fn()) jest.mock('../../../../uri.js', () => ({ @@ -50,7 +50,7 @@ describe('getData', () => { it('adds return value of getErrorFlags to the page data', async () => { const errorFlags = { unique: Symbol('error-flags') } - getErrorFlags.mockReturnValueOnce(errorFlags) + getDateErrorFlags.mockReturnValueOnce(errorFlags) const result = await getData(getMockRequest()) expect(result).toEqual(expect.objectContaining(errorFlags)) }) @@ -58,7 +58,7 @@ describe('getData', () => { it('passes error to getErrorFlags', async () => { const error = Symbol('error') await getData(getMockRequest(undefined, async () => ({ error }))) - expect(getErrorFlags).toHaveBeenCalledWith(error) + expect(getDateErrorFlags).toHaveBeenCalledWith(error) }) it('passes correct page name when getting page cache', async () => { diff --git a/packages/gafl-webapp-service/src/pages/renewals/identify/route.js b/packages/gafl-webapp-service/src/pages/renewals/identify/route.js index 7d86e1b79..234176ae1 100644 --- a/packages/gafl-webapp-service/src/pages/renewals/identify/route.js +++ b/packages/gafl-webapp-service/src/pages/renewals/identify/route.js @@ -4,7 +4,7 @@ import Joi from 'joi' import { validation } from '@defra-fish/business-rules-lib' import { addLanguageCodeToUri } from '../../../processors/uri-helper.js' import GetDataRedirect from '../../../handlers/get-data-redirect.js' -import { dateOfBirthValidator, getErrorFlags } from '../../../schema/validators/validators.js' +import { dateOfBirthValidator, getDateErrorFlags } from '../../../schema/validators/validators.js' export const getData = async request => { // If we are supplied a permission number, validate it or throw 400 @@ -26,7 +26,7 @@ export const getData = async request => { uri: { new: addLanguageCodeToUri(request, NEW_TRANSACTION.uri) }, - ...getErrorFlags(page?.error) + ...getDateErrorFlags(page?.error) } } diff --git a/packages/gafl-webapp-service/src/schema/validators/__tests__/validators.spec.js b/packages/gafl-webapp-service/src/schema/validators/__tests__/validators.spec.js index 0cdc53471..95ef43e7c 100644 --- a/packages/gafl-webapp-service/src/schema/validators/__tests__/validators.spec.js +++ b/packages/gafl-webapp-service/src/schema/validators/__tests__/validators.spec.js @@ -1,5 +1,5 @@ import Joi from 'joi' -import { dateOfBirthValidator, startDateValidator, getErrorFlags } from '../validators.js' +import { dateOfBirthValidator, startDateValidator, getDateErrorFlags } from '../validators.js' import moment from 'moment-timezone' const dateSchema = require('../../date.schema.js') @@ -183,7 +183,7 @@ describe('startDate validator', () => { describe('getErrorFlags', () => { it('sets all error flags to be false when there are no errors', () => { - const result = getErrorFlags() + const result = getDateErrorFlags() expect(result).toEqual({ isDayError: false, isMonthError: false, isYearError: false }) }) @@ -201,7 +201,7 @@ describe('getErrorFlags', () => { ])('when error is %s, should set %o in flags', (errorKey, expected) => { const error = { [errorKey]: 'anything.at.all' } - const result = getErrorFlags(error) + const result = getDateErrorFlags(error) expect(result).toEqual(expect.objectContaining(expected)) }) diff --git a/packages/gafl-webapp-service/src/schema/validators/validators.js b/packages/gafl-webapp-service/src/schema/validators/validators.js index 6c3437cd2..70fefe6d2 100644 --- a/packages/gafl-webapp-service/src/schema/validators/validators.js +++ b/packages/gafl-webapp-service/src/schema/validators/validators.js @@ -43,7 +43,7 @@ export const startDateValidator = payload => { } } -export const getErrorFlags = error => { +export const getDateErrorFlags = error => { const errorFlags = { isDayError: false, isMonthError: false, isYearError: false } const commonErrors = ['full-date', 'invalid-date', 'date-range', 'non-numeric']