Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotorres97 authored and jspranger committed Nov 16, 2021
1 parent 3bc9bf7 commit 835b5de
Show file tree
Hide file tree
Showing 11 changed files with 606 additions and 652 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.eslintcache
coverage
node_modules
21 changes: 9 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
],
"main": "./src/index.js",
"scripts": {
"changelog": "github_changelog_generator --header-label='# Changelog' --future-release=v$npm_config_future_release && sed -i '' -e :a -e '$d;N;2,4ba' -e 'P;D' CHANGELOG.md",
"coverage": "yarn test --coverage",
"lint": "eslint src test",
"test": "jest",
"version": "npm run changelog --future-release=$npm_package_version && git add -A CHANGELOG.md"
"changelog": "uphold-scripts changelog $npm_package_version",
"lint": "uphold-scripts lint",
"release": "uphold-scripts release",
"test": "uphold-scripts test --coverage",
"version": "uphold-scripts version"
},
"dependencies": {
"lodash": "^4.17.21",
Expand All @@ -46,22 +46,19 @@
"abavalidator": "^2.0.1",
"bignumber.js": "^9.0.0",
"creditcard": "^0.1.2",
"eslint": "^6.8.0",
"eslint-config-uphold": "^1.0.1",
"google-libphonenumber": "^1.0.18",
"iban": "0.0.6",
"isoc": "0.0.1",
"jest": "^27.3.1",
"moment": "^2.13.0",
"prettier": "^1.18.2",
"sinon": "^1.15.4",
"moment": "^2.29.1",
"sinon": "^11.1.1",
"tin-validator": "^1.0.0",
"uk-modulus-checking": "0.0.3",
"uphold-scripts": "^0.5.0",
"urijs": "^1.17.1",
"validator": "^13.7.0"
},
"engines": {
"node": ">=10"
"node": ">=12"
},
"optionalPeerDependencies": {
"abavalidator": ">=2 <3",
Expand Down
4 changes: 2 additions & 2 deletions src/asserts/callback-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const expression = /^[a-zA-Z]+$/;
* Export `CallbackAssert`.
*/

module.exports = function(fn, customClass) {
module.exports = function (fn, customClass) {
/**
* Class name.
*/
Expand All @@ -42,7 +42,7 @@ module.exports = function(fn, customClass) {
* Validation algorithm.
*/

this.validate = function(value) {
this.validate = function (value) {
let result;

try {
Expand Down
2 changes: 1 addition & 1 deletion src/asserts/taxpayer-identification-number-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = function taxpayerIdentificationNumberAssert() {
* Validation algorithm.
*/

this.validate = function(value) {
this.validate = function (value) {
if (typeof value !== 'string') {
throw new Violation(this, value, { value: Validator.errorCode.must_be_a_string });
}
Expand Down
7 changes: 1 addition & 6 deletions src/asserts/us-subdivision-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,7 @@ module.exports = function usSubdivisionAssert({ categories: categories = keys, a
code = value.substr(-2);
}

const result = chain(subdivisions)
.pick(this.categories)
.values()
.flatten()
.includes(code)
.value();
const result = chain(subdivisions).pick(this.categories).values().flatten().includes(code).value();

if (result !== true) {
throw new Violation(this, value);
Expand Down
2 changes: 1 addition & 1 deletion src/asserts/us-zip-code-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = function usZipCodeAssert() {
* Validation algorithm.
*/

this.validate = function(value) {
this.validate = function (value) {
if (typeof value !== 'string') {
throw new Violation(this, value, { value: Validator.errorCode.must_be_a_string });
}
Expand Down
14 changes: 7 additions & 7 deletions test/asserts/date-diff-greater-than-assert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('DateDiffGreaterThanAssert', () => {
});

it('should throw an error if the diff between `now` and input date is equal to `threshold`', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

try {
Assert.dateDiffGreaterThan(0).validate(new Date('1970-01-01'));
Expand All @@ -97,7 +97,7 @@ describe('DateDiffGreaterThanAssert', () => {
});

it('should throw an error if the `absolute` diff between `now` and input date is equal to `threshold`', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

try {
Assert.dateDiffGreaterThan(24 * 60 * 60 * 1000, { absolute: true }).validate(new Date('1970-01-02'));
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('DateDiffGreaterThanAssert', () => {
});

it('should throw an error if the diff between `now` and input date is less than the `threshold`', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

try {
Assert.dateDiffGreaterThan(24 * 60 * 60 * 1000).validate(new Date('1970-01-01'));
Expand Down Expand Up @@ -164,7 +164,7 @@ describe('DateDiffGreaterThanAssert', () => {
});

it('should expose `assert` equal to `DateDiffGreaterThanAssert`', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

try {
Assert.dateDiffGreaterThan(24 * 60 * 60 * 1000).validate(new Date('1970-01-01'));
Expand All @@ -178,7 +178,7 @@ describe('DateDiffGreaterThanAssert', () => {
});

it('should expose `absolute`, `asFloat`, `diff`, `fromDate`, `threshold` and `unit` on the violation', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

try {
Assert.dateDiffGreaterThan(24 * 60 * 60 * 1000).validate(new Date('1970-01-01'));
Expand Down Expand Up @@ -245,15 +245,15 @@ describe('DateDiffGreaterThanAssert', () => {
});

it('should accept a date whose diff from `now` is greater than the threshold', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

Assert.dateDiffGreaterThan(24 * 60 * 60 * 1000).validate(new Date('1969-12-30'));

clock.restore();
});

it('should accept a date whose `absolute` diff from `now` is greater than the threshold', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

Assert.dateDiffGreaterThan(24 * 60 * 60 * 1000, { absolute: true }).validate(new Date('1970-01-03'));

Expand Down
14 changes: 7 additions & 7 deletions test/asserts/date-diff-greater-than-or-equal-to-assert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('DateDiffGreaterThanOrEqualToAssert', () => {
});

it('should throw an error if the diff between `now` and input date is less than the `threshold`', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

try {
Assert.dateDiffGreaterThanOrEqualTo(24 * 60 * 60 * 1000).validate(new Date('1970-01-01'));
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('DateDiffGreaterThanOrEqualToAssert', () => {
});

it('should expose `assert` equal to `DateDiffGreaterThanOrEqualToAssert`', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

try {
Assert.dateDiffGreaterThanOrEqualTo(24 * 60 * 60 * 1000).validate(new Date('1970-01-01'));
Expand All @@ -124,7 +124,7 @@ describe('DateDiffGreaterThanOrEqualToAssert', () => {
});

it('should expose `absolute`, `asFloat`, `diff`, `fromDate`, `threshold` and `unit` on the violation', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

try {
Assert.dateDiffGreaterThanOrEqualTo(24 * 60 * 60 * 1000).validate(new Date('1970-01-01'));
Expand Down Expand Up @@ -192,31 +192,31 @@ describe('DateDiffGreaterThanOrEqualToAssert', () => {
});

it('should accept a date whose diff from `now` is equal to the threshold', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

Assert.dateDiffGreaterThanOrEqualTo(24 * 60 * 60 * 1000).validate(new Date('1969-12-31'));

clock.restore();
});

it('should accept a date whose diff from `now` is greater than the threshold', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

Assert.dateDiffGreaterThanOrEqualTo(24 * 60 * 60 * 1000).validate(new Date('1969-12-30'));

clock.restore();
});

it('should accept a date whose `absolute` diff from `now` is equal to the threshold', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

Assert.dateDiffGreaterThanOrEqualTo(24 * 60 * 60 * 1000, { absolute: true }).validate(new Date('1970-01-02'));

clock.restore();
});

it('should accept a date whose `absolute` diff from `now` is greater than the threshold', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

Assert.dateDiffGreaterThanOrEqualTo(24 * 60 * 60 * 1000, { absolute: true }).validate(new Date('1970-01-03'));

Expand Down
14 changes: 7 additions & 7 deletions test/asserts/date-diff-less-than-assert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('DateDiffLessThanAssert', () => {
});

it('should throw an error if the diff between `now` and input date is equal to `threshold`', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

try {
Assert.dateDiffLessThan(0).validate(new Date('1970-01-01'));
Expand All @@ -97,7 +97,7 @@ describe('DateDiffLessThanAssert', () => {
});

it('should throw an error if the `absolute` diff between `now` and input date is equal to `threshold`', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

try {
Assert.dateDiffLessThan(24 * 60 * 60 * 1000, { absolute: true }).validate(new Date('1970-01-02'));
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('DateDiffLessThanAssert', () => {
});

it('should throw an error if the diff between `now` and input date is greater than the `threshold`', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

try {
Assert.dateDiffLessThan(24 * 60 * 60 * 1000).validate(new Date('1969-12-30'));
Expand All @@ -151,7 +151,7 @@ describe('DateDiffLessThanAssert', () => {
});

it('should throw an error if the `absolute` diff between `now` and input date is greater than the `threshold`', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

try {
Assert.dateDiffLessThan(24 * 60 * 60 * 1000, { absolute: true }).validate(new Date('1970-01-03'));
Expand Down Expand Up @@ -192,7 +192,7 @@ describe('DateDiffLessThanAssert', () => {
});

it('should expose `assert` equal to `DateDiffLessThanAssert`', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

try {
Assert.dateDiffLessThan(24 * 60 * 60 * 1000).validate(new Date('1969-12-31'));
Expand All @@ -206,7 +206,7 @@ describe('DateDiffLessThanAssert', () => {
});

it('should expose `absolute`, `asFloat`, `diff`, `fromDate`, `threshold` and `unit` on the violation', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

try {
Assert.dateDiffLessThan(24 * 60 * 60 * 1000).validate(new Date('1969-12-31'));
Expand Down Expand Up @@ -267,7 +267,7 @@ describe('DateDiffLessThanAssert', () => {
});

it('should accept a date whose diff from `now` is less than the threshold', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

Assert.dateDiffLessThan(24 * 60 * 60 * 1000).validate(new Date('1969-12-31 11:00:00Z'));

Expand Down
16 changes: 8 additions & 8 deletions test/asserts/date-diff-less-than-or-equal-to-assert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('DateDiffLessThanOrEqualToAssert', () => {
});

it('should throw an error if the diff between `now` and input date is greater than the `threshold`', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

try {
Assert.dateDiffLessThanOrEqualTo(24 * 60 * 60 * 1000).validate(new Date('1969-12-30'));
Expand All @@ -97,7 +97,7 @@ describe('DateDiffLessThanOrEqualToAssert', () => {
});

it('should throw an error if the `absolute` diff between `now` and input date is greater than the `threshold`', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

try {
Assert.dateDiffLessThanOrEqualTo(24 * 60 * 60 * 1000, { absolute: true }).validate(new Date('1970-01-03'));
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('DateDiffLessThanOrEqualToAssert', () => {
});

it('should expose `assert` equal to `DateDiffLessThanOrEqualToAssert`', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

try {
Assert.dateDiffLessThanOrEqualTo(24 * 60 * 60 * 1000).validate(new Date('1969-12-30'));
Expand All @@ -153,7 +153,7 @@ describe('DateDiffLessThanOrEqualToAssert', () => {
});

it('should expose `absolute`, `asFloat`, `diff`, `fromDate`, `threshold` and `unit` on the violation', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

try {
Assert.dateDiffLessThanOrEqualTo(24 * 60 * 60 * 1000).validate(new Date('1969-12-30'));
Expand Down Expand Up @@ -214,31 +214,31 @@ describe('DateDiffLessThanOrEqualToAssert', () => {
});

it('should accept a date whose diff from `now` is equal to the threshold', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

Assert.dateDiffLessThanOrEqualTo(24 * 60 * 60 * 1000).validate(new Date('1969-12-31'));

clock.restore();
});

it('should accept a date whose diff from `now` is less than the threshold', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

Assert.dateDiffLessThanOrEqualTo(24 * 60 * 60 * 1000).validate(new Date('1969-12-31 11:00:00Z'));

clock.restore();
});

it('should accept a date whose `absolute` diff from `now` is equal to the threshold', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

Assert.dateDiffLessThanOrEqualTo(24 * 60 * 60 * 1000, { absolute: true }).validate(new Date('1970-01-02'));

clock.restore();
});

it('should accept a date whose `absolute` diff from `now` is less than the threshold', () => {
const clock = sinon.useFakeTimers(0, 'Date');
const clock = sinon.useFakeTimers({ now: 0, toFake: ['Date'] });

Assert.dateDiffLessThanOrEqualTo(24 * 60 * 60 * 1000, { absolute: true }).validate(
new Date('1970-01-01 11:00:00Z')
Expand Down
Loading

0 comments on commit 835b5de

Please sign in to comment.