diff --git a/src/app/drivingLicence/fields.js b/src/app/drivingLicence/fields.js index 465342a2..6a7cfb8e 100644 --- a/src/app/drivingLicence/fields.js +++ b/src/app/drivingLicence/fields.js @@ -73,6 +73,11 @@ module.exports = { type: "before", arguments: [], }, + { + type: "beforeNow", + fn: fields.beforeNow, + arguments: [10, "years"], + }, ], dependent: { field: "issuerDependent", value: "DVLA" }, }, @@ -86,6 +91,11 @@ module.exports = { type: "before", arguments: [], }, + { + type: "beforeNow", + fn: fields.beforeNow, + arguments: [10, "years"], + }, ], dependent: { field: "issuerDependent", value: "DVA" }, }, diff --git a/src/app/drivingLicence/fieldsHelper.js b/src/app/drivingLicence/fieldsHelper.js index a46cb3aa..df1e5ce0 100644 --- a/src/app/drivingLicence/fieldsHelper.js +++ b/src/app/drivingLicence/fieldsHelper.js @@ -1,4 +1,5 @@ const { validators } = require("hmpo-form-wizard/lib/validation"); +const moment = require("moment"); module.exports = { firstNameMiddleNameLengthValidator( @@ -62,4 +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"); + + 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 02d2c424..73d8bbcb 100644 --- a/src/app/drivingLicence/fieldsHelper.test.js +++ b/src/app/drivingLicence/fieldsHelper.test.js @@ -1,4 +1,5 @@ const fields = require("./fieldsHelper"); +const moment = require("moment"); describe("custom validation fields test", () => { it("should be false when first and middle name combined greater than 30 characters", () => { @@ -101,6 +102,45 @@ describe("custom validation fields test", () => { ).to.be.false; }); + 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 validator = fields.beforeNow.bind({ + values: { + issueDate: issueDate, + }, + }); + + 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 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 ca5791dd..0bde289e 100644 --- a/test/browser/features/DVA_Driving_Licence.feature +++ b/test/browser/features/DVA_Driving_Licence.feature @@ -253,7 +253,7 @@ Feature: DVA Driving licence CRI Error Validations And DVA consent checkbox is unselected When User clicks on continue Then I can see the DVA consent error summary as You must give your consent to continue - And I can see the DVA consent error on the checkbox as Error: You must give your consent to continue + And I can see the DVA consent error on the checkbox as You must give your consent to continue And I check the page Title Error: Enter your details exactly as they appear on your UK driving licence – Prove your identity – GOV.UK Examples: |DVADrivingLicenceSubject | diff --git a/test/browser/features/DVLADrivingLicence.feature b/test/browser/features/DVLADrivingLicence.feature index ab94361b..59b2819e 100644 --- a/test/browser/features/DVLADrivingLicence.feature +++ b/test/browser/features/DVLADrivingLicence.feature @@ -258,6 +258,34 @@ Feature: DVLA Driving licence CRI Error Validations |DrivingLicenceSubjectHappyPeter| & | ^% | £$ ^ | |DrivingLicenceSubjectHappyPeter| | | | + @mock-api:dl-success @validation-regression @build @staging + Scenario: DVLA Driving Licence Issue date that is greater than 10 years old date error validation + Given User enters DVLA data as a DrivingLicenceSubjectHappyPeter + Then User enters date of issue as current date + And User enters year of issue as current year minus 10 + And User enters day of issue as current day minus 1 + When User clicks on continue + Then I see issue date error in summary as Enter the date as it appears on your driving licence + And I see invalid issue date field error as Enter the date as it appears on your driving licence + And I check the page Title Error: Enter your details exactly as they appear on your UK driving licence – Prove your identity – GOV.UK + + @mock-api:dl-success @validation-regression @build @staging + Scenario: DVLA Driving Licence Issue date that is exactly 10 years old date error validation + Given User enters DVLA data as a DrivingLicenceSubjectHappyPeter + Then User enters date of issue as current date + And User enters year of issue as current year minus 10 + When User clicks on continue + Then Proper error message is displayed as We could not find your details + + @mock-api:dl-success @validation-regression @build @staging + Scenario: DVLA Driving Licence Issue date that is 1 day under 10 years old date error validation + Given User enters DVLA data as a DrivingLicenceSubjectHappyPeter + Then User enters date of issue as current date + And User enters year of issue as current year minus 10 + And User enters day of issue as current day plus 1 + When User clicks on continue + Then Proper error message is displayed as We could not find your details + @mock-api:dl-success @validation-regression @build @staging Scenario Outline: DVLA Driving Licence Issue date in the future error validation Given User enters DVLA data as a @@ -308,7 +336,7 @@ Feature: DVLA Driving licence CRI Error Validations Given User enters DVLA data as a And DVLA consent checkbox is unselected When User clicks on continue - And I can see the DVLA consent error on the checkbox as Error: You must give your consent to continue + And I can see the DVLA consent error on the checkbox as You must give your consent to continue Then I can see the DVLA consent error summary as You must give your consent to continue And I check the page Title Error: Enter your details exactly as they appear on your UK driving licence – Prove your identity – GOV.UK Examples: diff --git a/test/browser/pages/DrivingLicencePage.js b/test/browser/pages/DrivingLicencePage.js index bbeefe52..fb152ef7 100644 --- a/test/browser/pages/DrivingLicencePage.js +++ b/test/browser/pages/DrivingLicencePage.js @@ -1,4 +1,5 @@ const { expect: expect } = require("chai"); +const moment = require("moment"); const TestDataCreator = require("../util/TestDataCreator"); exports.DrivingLicencePage = class PlaywrightDevPage { @@ -228,14 +229,42 @@ exports.DrivingLicencePage = class PlaywrightDevPage { await this.licenceIssueDay.fill(InvalidDayOfIssue); } + async userReEntersDayOfIssueAsCurrentDateMinus(days) { + await this.licenceIssueDay.fill( + moment().subtract(days, "days").format("DD") + ); + } + + async userReEntersDayOfIssueAsCurrentDatePlus(days) { + await this.licenceIssueDay.fill(moment().add(days, "days").format("DD")); + } + async userReEntersMonthOfIssue(InvalidMonthOfIssue) { await this.licenceIssueMonth.fill(InvalidMonthOfIssue); } + async userReEntersMonthOfIssueAsCurrentDateMinus(months) { + await this.licenceIssueMonth.fill( + moment().subtract(months, "months").format("MM") + ); + } + async userReEntersYearOfIssue(InvalidYearOfIssue) { await this.licenceIssueYear.fill(InvalidYearOfIssue); } + async userReEntersYearOfIssueAsCurrentDateMinus(years) { + 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) { await this.licenceValidToDay.fill(InvalidValidToDay); } diff --git a/test/browser/step_definitions/DrivingLicenceStepDefs.js b/test/browser/step_definitions/DrivingLicenceStepDefs.js index 2b5d47d8..4bc7902c 100644 --- a/test/browser/step_definitions/DrivingLicenceStepDefs.js +++ b/test/browser/step_definitions/DrivingLicenceStepDefs.js @@ -110,6 +110,15 @@ Then( } ); +Then( + /^User enters date of issue as current date$/, + { timeout: 2 * 5000 }, + async function () { + const drivingLicencePage = new DrivingLicencePage(this.page); + await drivingLicencePage.userReEntersIssueDateAsCurrentDate(); + } +); + Then( /^User re-enters day of issue as (.*)$/, { timeout: 2 * 5000 }, @@ -119,6 +128,26 @@ Then( } ); +Then( + /^User enters day of issue as current day minus (.*)$/, + { timeout: 2 * 5000 }, + async function (daysToSubtract) { + const drivingLicencePage = new DrivingLicencePage(this.page); + await drivingLicencePage.userReEntersDayOfIssueAsCurrentDateMinus( + daysToSubtract + ); + } +); + +Then( + /^User enters day of issue as current day plus (.*)$/, + { timeout: 2 * 5000 }, + async function (daysToAdd) { + const drivingLicencePage = new DrivingLicencePage(this.page); + await drivingLicencePage.userReEntersDayOfIssueAsCurrentDatePlus(daysToAdd); + } +); + Then( /^User re-enters month of issue as (.*)$/, { timeout: 2 * 5000 }, @@ -137,6 +166,17 @@ Then( } ); +Then( + /^User enters year of issue as current year minus (.*)$/, + { timeout: 2 * 5000 }, + async function (yearsToSubtract) { + const drivingLicencePage = new DrivingLicencePage(this.page); + await drivingLicencePage.userReEntersYearOfIssueAsCurrentDateMinus( + yearsToSubtract + ); + } +); + Then( /^User re-enters valid to day as (.*)$/, { timeout: 2 * 5000 }, diff --git a/test/browser/util/TestDataCreator.js b/test/browser/util/TestDataCreator.js index 2e2f4dc7..08b1cde1 100644 --- a/test/browser/util/TestDataCreator.js +++ b/test/browser/util/TestDataCreator.js @@ -13,7 +13,7 @@ exports.getDVLATestUserFromMap = function ( birthYear: "1962", licenceIssueDay: "23", licenceIssueMonth: "05", - licenceIssueYear: "1982", + licenceIssueYear: "2018", issueNumber: "12", consentDVLACheckbox: "true", middleNames: "BENJAMIN", @@ -32,7 +32,7 @@ exports.getDVLATestUserFromMap = function ( birthYear: "1965", licenceIssueDay: "19", licenceIssueMonth: "04", - licenceIssueYear: "2001", + licenceIssueYear: "2018", issueNumber: "23", consentDVLACheckbox: "true", middleNames: " ", @@ -67,7 +67,7 @@ exports.getDVATestUserFromMap = function ( birthYear: "1981", licenceIssueDay: "19", licenceIssueMonth: "04", - licenceIssueYear: "2001", + licenceIssueYear: "2018", consentDVACheckbox: "true", middleNames: "", lastName: "BATSON",