From 2b763a914604bc06633151eebe8d781e3383c964 Mon Sep 17 00:00:00 2001 From: Jamie Bentham Date: Thu, 3 Aug 2023 11:36:37 +0100 Subject: [PATCH] LIME-771: Added additonal acceptance tests --- src/app/drivingLicence/fields.js | 8 +++++ src/app/drivingLicence/fieldsHelper.js | 3 +- src/app/drivingLicence/fieldsHelper.test.js | 18 ++++++++-- .../features/DVA_Driving_Licence.feature | 4 +-- .../features/DVLADrivingLicence.feature | 30 +++++++++++++++- test/browser/pages/DrivingLicencePage.js | 24 +++++++++++++ .../DrivingLicenceStepDefs.js | 36 +++++++++++++++++++ test/browser/util/TestDataCreator.js | 6 ++-- 8 files changed, 120 insertions(+), 9 deletions(-) diff --git a/src/app/drivingLicence/fields.js b/src/app/drivingLicence/fields.js index 92f56a31..f115c6cf 100644 --- a/src/app/drivingLicence/fields.js +++ b/src/app/drivingLicence/fields.js @@ -69,6 +69,10 @@ module.exports = { validate: [ "required", "date", + { + type: "before", + arguments: [], + }, { type: "beforeNow", fn: fields.beforeNow, @@ -83,6 +87,10 @@ module.exports = { validate: [ "required", "date", + { + type: "before", + arguments: [], + }, { type: "beforeNow", fn: fields.beforeNow, diff --git a/src/app/drivingLicence/fieldsHelper.js b/src/app/drivingLicence/fieldsHelper.js index 0747fb05..03120361 100644 --- a/src/app/drivingLicence/fieldsHelper.js +++ b/src/app/drivingLicence/fieldsHelper.js @@ -71,7 +71,8 @@ module.exports = { let dateFormat = 'YYYY-MM-DD'; let test = moment(_value, dateFormat); let comparator; - comparator = moment().subtract(timePeriod, timeUnit); + // 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 94d5b120..5b4ba07f 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", () => { @@ -102,7 +103,7 @@ describe("custom validation fields test", () => { }); it("should be false when licence issued greater than 10 years ago", () => { - const issueDate = "2013-08-01"; + const issueDate = moment().subtract(10, "years").subtract(1, "days").format("YYYY-MM-DD"); const validator = fields.beforeNow.bind({ values: { issueDate: issueDate, @@ -115,7 +116,20 @@ describe("custom validation fields test", () => { }); it("should be true when licence issued less than 10 years ago", () => { - const issueDate = "2013-08-04"; + 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, diff --git a/test/browser/features/DVA_Driving_Licence.feature b/test/browser/features/DVA_Driving_Licence.feature index ca5791dd..f498da85 100644 --- a/test/browser/features/DVA_Driving_Licence.feature +++ b/test/browser/features/DVA_Driving_Licence.feature @@ -247,13 +247,13 @@ Feature: DVA Driving licence CRI Error Validations |DVADrivingLicenceSubject |InvalidValidToDay|InvalidValidToMonth|InvalidValidToYear| |DrivingLicenceSubjectHappyBilly| 10 | 01 | 2010 | - @mock-api:dva-ConsentError @validation-regression @build @staging + @mock-api:dva-ConsentError @validation-regression @build @staging1 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 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..65919c3d 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,37 @@ 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..4485af4a 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,24 @@ 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 +164,15 @@ 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",