diff --git a/src/app/drivingLicence/fields.js b/src/app/drivingLicence/fields.js index f115c6cf..6a7cfb8e 100644 --- a/src/app/drivingLicence/fields.js +++ b/src/app/drivingLicence/fields.js @@ -76,7 +76,7 @@ module.exports = { { type: "beforeNow", fn: fields.beforeNow, - arguments: [10, "years"] + arguments: [10, "years"], }, ], dependent: { field: "issuerDependent", value: "DVLA" }, @@ -88,13 +88,13 @@ module.exports = { "required", "date", { - type: "before", - arguments: [], + type: "before", + arguments: [], }, { type: "beforeNow", fn: fields.beforeNow, - arguments: [10, "years"] + arguments: [10, "years"], }, ], dependent: { field: "issuerDependent", value: "DVA" }, diff --git a/src/app/drivingLicence/fieldsHelper.js b/src/app/drivingLicence/fieldsHelper.js index 03120361..df1e5ce0 100644 --- a/src/app/drivingLicence/fieldsHelper.js +++ b/src/app/drivingLicence/fieldsHelper.js @@ -1,5 +1,5 @@ const { validators } = require("hmpo-form-wizard/lib/validation"); -const moment = require('moment'); +const moment = require("moment"); module.exports = { firstNameMiddleNameLengthValidator( @@ -63,17 +63,15 @@ module.exports = { return secondCheck && thirdCheck && fourthCheck; }, - beforeNow( - _value, - timePeriod, - timeUnit, - ) { - let dateFormat = 'YYYY-MM-DD'; - let test = moment(_value, dateFormat); - let comparator; - // One additional day subtracted so that the check is inclusive of the current date minus X time - comparator = moment().subtract(timePeriod, timeUnit).subtract(1, "days"); + beforeNow(_value, timePeriod, timeUnit) { + let dateFormat = "YYYY-MM-DD"; + let test = moment(_value, dateFormat); + let comparator; + // One additional day subtracted so that the check is inclusive of the current date minus X time + comparator = moment().subtract(timePeriod, timeUnit).subtract(1, "days"); - return _value === '' || validators.date(_value) && test.isAfter(comparator); - } + return ( + _value === "" || (validators.date(_value) && test.isAfter(comparator)) + ); + }, }; diff --git a/src/app/drivingLicence/fieldsHelper.test.js b/src/app/drivingLicence/fieldsHelper.test.js index 5b4ba07f..73d8bbcb 100644 --- a/src/app/drivingLicence/fieldsHelper.test.js +++ b/src/app/drivingLicence/fieldsHelper.test.js @@ -1,5 +1,5 @@ const fields = require("./fieldsHelper"); -const moment = require('moment'); +const moment = require("moment"); describe("custom validation fields test", () => { it("should be false when first and middle name combined greater than 30 characters", () => { @@ -103,44 +103,44 @@ describe("custom validation fields test", () => { }); it("should be false when licence issued greater than 10 years ago", () => { - const issueDate = moment().subtract(10, "years").subtract(1, "days").format("YYYY-MM-DD"); + const issueDate = moment() + .subtract(10, "years") + .subtract(1, "days") + .format("YYYY-MM-DD"); const validator = fields.beforeNow.bind({ values: { issueDate: issueDate, }, }); - expect( - validator(issueDate, 10, "years") - ).to.be.false; + expect(validator(issueDate, 10, "years")).to.be.false; }); - it("should be true when licence issued less than 10 years ago", () => { - const issueDate = moment().subtract(10, "years").add(1, "days").format("YYYY-MM-DD"); - const validator = fields.beforeNow.bind({ - values: { - issueDate: issueDate, - }, - }); - - expect( - validator(issueDate, 10, "years") - ).to.be.true; + it("should be true when licence issued less than 10 years ago", () => { + const issueDate = moment() + .subtract(10, "years") + .add(1, "days") + .format("YYYY-MM-DD"); + const validator = fields.beforeNow.bind({ + values: { + issueDate: issueDate, + }, }); - it("should be true when licence issued is issued exactly 10 years ago", () => { - const issueDate = moment().subtract(10, "years").format("YYYY-MM-DD"); - const validator = fields.beforeNow.bind({ - values: { - issueDate: issueDate, - }, - }); - - expect( - validator(issueDate, 10, "years") - ).to.be.true; + expect(validator(issueDate, 10, "years")).to.be.true; + }); + + it("should be true when licence issued is issued exactly 10 years ago", () => { + const issueDate = moment().subtract(10, "years").format("YYYY-MM-DD"); + const validator = fields.beforeNow.bind({ + values: { + issueDate: issueDate, + }, }); + expect(validator(issueDate, 10, "years")).to.be.true; + }); + it("should be true when licence number does match DOB date kenneth", () => { const licenceNo = "DECER607085K99LN"; const validator = fields.dvlaValidator.bind({ diff --git a/test/browser/features/DVA_Driving_Licence.feature b/test/browser/features/DVA_Driving_Licence.feature index f498da85..0bde289e 100644 --- a/test/browser/features/DVA_Driving_Licence.feature +++ b/test/browser/features/DVA_Driving_Licence.feature @@ -247,7 +247,7 @@ Feature: DVA Driving licence CRI Error Validations |DVADrivingLicenceSubject |InvalidValidToDay|InvalidValidToMonth|InvalidValidToYear| |DrivingLicenceSubjectHappyBilly| 10 | 01 | 2010 | - @mock-api:dva-ConsentError @validation-regression @build @staging1 + @mock-api:dva-ConsentError @validation-regression @build @staging Scenario Outline: DVA Driving Licence error validation when DVA consent checkbox is unselected Given User enters DVA data as a And DVA consent checkbox is unselected diff --git a/test/browser/pages/DrivingLicencePage.js b/test/browser/pages/DrivingLicencePage.js index 65919c3d..fb152ef7 100644 --- a/test/browser/pages/DrivingLicencePage.js +++ b/test/browser/pages/DrivingLicencePage.js @@ -1,5 +1,5 @@ const { expect: expect } = require("chai"); -const moment = require('moment'); +const moment = require("moment"); const TestDataCreator = require("../util/TestDataCreator"); exports.DrivingLicencePage = class PlaywrightDevPage { @@ -230,7 +230,9 @@ exports.DrivingLicencePage = class PlaywrightDevPage { } async userReEntersDayOfIssueAsCurrentDateMinus(days) { - await this.licenceIssueDay.fill(moment().subtract(days, "days").format("DD")); + await this.licenceIssueDay.fill( + moment().subtract(days, "days").format("DD") + ); } async userReEntersDayOfIssueAsCurrentDatePlus(days) { @@ -242,7 +244,9 @@ exports.DrivingLicencePage = class PlaywrightDevPage { } async userReEntersMonthOfIssueAsCurrentDateMinus(months) { - await this.licenceIssueMonth.fill(moment().subtract(months, "months").format("MM")); + await this.licenceIssueMonth.fill( + moment().subtract(months, "months").format("MM") + ); } async userReEntersYearOfIssue(InvalidYearOfIssue) { @@ -250,14 +254,15 @@ exports.DrivingLicencePage = class PlaywrightDevPage { } async userReEntersYearOfIssueAsCurrentDateMinus(years) { - await this.licenceIssueYear.fill(moment().subtract(years, "years").format("YYYY")); + await this.licenceIssueYear.fill( + moment().subtract(years, "years").format("YYYY") + ); } async userReEntersIssueDateAsCurrentDate() { await this.licenceIssueYear.fill(moment().format("YYYY")); await this.licenceIssueMonth.fill(moment().format("MM")); await this.licenceIssueDay.fill(moment().format("DD")); - } async userReEntersValidToDay(InvalidValidToDay) { diff --git a/test/browser/step_definitions/DrivingLicenceStepDefs.js b/test/browser/step_definitions/DrivingLicenceStepDefs.js index 4485af4a..4bc7902c 100644 --- a/test/browser/step_definitions/DrivingLicenceStepDefs.js +++ b/test/browser/step_definitions/DrivingLicenceStepDefs.js @@ -133,7 +133,9 @@ Then( { timeout: 2 * 5000 }, async function (daysToSubtract) { const drivingLicencePage = new DrivingLicencePage(this.page); - await drivingLicencePage.userReEntersDayOfIssueAsCurrentDateMinus(daysToSubtract); + await drivingLicencePage.userReEntersDayOfIssueAsCurrentDateMinus( + daysToSubtract + ); } ); @@ -169,7 +171,9 @@ Then( { timeout: 2 * 5000 }, async function (yearsToSubtract) { const drivingLicencePage = new DrivingLicencePage(this.page); - await drivingLicencePage.userReEntersYearOfIssueAsCurrentDateMinus(yearsToSubtract); + await drivingLicencePage.userReEntersYearOfIssueAsCurrentDateMinus( + yearsToSubtract + ); } );