Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
fix: change the error message, and the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MitanOmar committed Mar 30, 2023
1 parent 979e411 commit 6ca6185
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app/validators/moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function validateMoment(options = { gt: null, lt: null }) {
}
let valid = !!newValue && newValue._isValid;
if (!valid) {
return "false";
return "The given value is not a valid value";
}

if (options.gt) {
Expand All @@ -35,7 +35,7 @@ export default function validateMoment(options = { gt: null, lt: null }) {
getDateTimeIfValid(get(content, options.gt)) ||
moment();
if (newValue <= gtVal) {
valid = "false";
valid = `The value is smaller than ${options.gt}`;
}
}
if (options.lt) {
Expand All @@ -45,7 +45,7 @@ export default function validateMoment(options = { gt: null, lt: null }) {
moment();

if (newValue >= ltVal) {
valid = "false";
valid = `The valus is larger than ${options.lt}`;
}
}
return valid;
Expand Down
9 changes: 6 additions & 3 deletions tests/unit/validators/moment-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import validateMoment from "timed/validators/moment";

module("Unit | Validator | moment", function () {
test("works without value", function (assert) {
assert.strictEqual(validateMoment()("key", null, null, {}, {}), "false");
assert.strictEqual(
validateMoment()("key", null, null, {}, {}),
"The given value is not a valid value"
);
assert.true(validateMoment()("key", moment(), null, {}, {}));
});

Expand All @@ -27,7 +30,7 @@ module("Unit | Validator | moment", function () {
{},
{ otherKey: moment().add(1, "second") }
),
"false"
"The value is smaller than otherKey"
);
});

Expand All @@ -50,7 +53,7 @@ module("Unit | Validator | moment", function () {
{},
{ otherKey: moment().add(-1, "second") }
),
"false"
"The valus is larger than otherKey"
);
});

Expand Down

0 comments on commit 6ca6185

Please sign in to comment.