Skip to content

Commit

Permalink
LIME-771: fixed linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gds-jbentham committed Aug 3, 2023
1 parent 2b763a9 commit 682e3ee
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 52 deletions.
8 changes: 4 additions & 4 deletions src/app/drivingLicence/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = {
{
type: "beforeNow",
fn: fields.beforeNow,
arguments: [10, "years"]
arguments: [10, "years"],
},
],
dependent: { field: "issuerDependent", value: "DVLA" },
Expand All @@ -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" },
Expand Down
24 changes: 11 additions & 13 deletions src/app/drivingLicence/fieldsHelper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { validators } = require("hmpo-form-wizard/lib/validation");
const moment = require('moment');
const moment = require("moment");

module.exports = {
firstNameMiddleNameLengthValidator(
Expand Down Expand Up @@ -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))
);
},
};
54 changes: 27 additions & 27 deletions src/app/drivingLicence/fieldsHelper.test.js
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion test/browser/features/DVA_Driving_Licence.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 <DVADrivingLicenceSubject>
And DVA consent checkbox is unselected
Expand Down
15 changes: 10 additions & 5 deletions test/browser/pages/DrivingLicencePage.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -242,22 +244,25 @@ 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) {
await this.licenceIssueYear.fill(InvalidYearOfIssue);
}

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) {
Expand Down
8 changes: 6 additions & 2 deletions test/browser/step_definitions/DrivingLicenceStepDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
);

Expand Down Expand Up @@ -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
);
}
);

Expand Down

0 comments on commit 682e3ee

Please sign in to comment.