diff --git a/packages/operators/src/common/gt.js b/packages/operators/src/common/gt.js index ff0697b3e..9cbd47c46 100644 --- a/packages/operators/src/common/gt.js +++ b/packages/operators/src/common/gt.js @@ -31,13 +31,6 @@ function _gt({ params, location }) { )} at ${location}.` ); } - if (!type.isNumber(params[0]) || !type.isNumber(params[1])) { - throw new Error( - `Operator Error: _gt takes an array of 2 numbers. Received: ${JSON.stringify( - params - )} at ${location}.` - ); - } return params[0] > params[1]; } diff --git a/packages/operators/src/common/gte.js b/packages/operators/src/common/gte.js index c81eeb104..67ac07b8d 100644 --- a/packages/operators/src/common/gte.js +++ b/packages/operators/src/common/gte.js @@ -31,13 +31,6 @@ function _gte({ params, location }) { )} at ${location}.` ); } - if (!type.isNumber(params[0]) || !type.isNumber(params[1])) { - throw new Error( - `Operator Error: _gte takes an array of 2 numbers. Received: ${JSON.stringify( - params - )} at ${location}.` - ); - } return params[0] >= params[1]; } diff --git a/packages/operators/src/common/lt.js b/packages/operators/src/common/lt.js index 2fb040c55..303024f7b 100644 --- a/packages/operators/src/common/lt.js +++ b/packages/operators/src/common/lt.js @@ -31,13 +31,6 @@ function _lt({ params, location }) { )} at ${location}.` ); } - if (!type.isNumber(params[0]) || !type.isNumber(params[1])) { - throw new Error( - `Operator Error: _lt takes an array of 2 numbers. Received: ${JSON.stringify( - params - )} at ${location}.` - ); - } return params[0] < params[1]; } diff --git a/packages/operators/src/common/lte.js b/packages/operators/src/common/lte.js index 86055a2ee..990084aaa 100644 --- a/packages/operators/src/common/lte.js +++ b/packages/operators/src/common/lte.js @@ -31,13 +31,6 @@ function _lte({ params, location }) { )} at ${location}.` ); } - if (!type.isNumber(params[0]) || !type.isNumber(params[1])) { - throw new Error( - `Operator Error: _lte takes an array of 2 numbers. Received: ${JSON.stringify( - params - )} at ${location}.` - ); - } return params[0] <= params[1]; } diff --git a/packages/operators/test/common/gt.test.js b/packages/operators/test/common/gt.test.js index dd8be7bac..9b60c3cf4 100644 --- a/packages/operators/test/common/gt.test.js +++ b/packages/operators/test/common/gt.test.js @@ -1,43 +1,50 @@ import gt from '../../src/common/gt'; +const location = 'locationId'; + test('_gt param 0 greater than param 1', () => { - expect(gt({ params: [1, 0], location: 'locationId' })).toBe(true); - expect(gt({ params: [0, -1], location: 'locationId' })).toBe(true); - expect(gt({ params: [1, -1], location: 'locationId' })).toBe(true); - expect(gt({ params: [0.2, 0.1], location: 'locationId' })).toBe(true); + expect(gt({ params: [1, 0], location })).toBe(true); + expect(gt({ params: [0, -1], location })).toBe(true); + expect(gt({ params: [1, -1], location })).toBe(true); + expect(gt({ params: [0.2, 0.1], location })).toBe(true); + expect(gt({ params: [1, null], location })).toBe(true); + expect(gt({ params: [new Date(2), new Date(1)], location })).toBe(true); + expect(gt({ params: [new Date(2), null], location })).toBe(true); + expect(gt({ params: ['bbb', 'bb'], location })).toBe(true); }); test('_gt param 0 less than param 1', () => { - expect(gt({ params: [1, 1], location: 'locationId' })).toBe(false); - expect(gt({ params: [0, 1], location: 'locationId' })).toBe(false); - expect(gt({ params: [-1, 0], location: 'locationId' })).toBe(false); - expect(gt({ params: [-1, 1], location: 'locationId' })).toBe(false); - expect(gt({ params: [0.1, 0.2], location: 'locationId' })).toBe(false); + expect(gt({ params: [1, 1], location })).toBe(false); + expect(gt({ params: [0, 1], location })).toBe(false); + expect(gt({ params: [-1, 0], location })).toBe(false); + expect(gt({ params: [-1, 1], location })).toBe(false); + expect(gt({ params: [0.1, 0.2], location })).toBe(false); + expect(gt({ params: [null, 1], location })).toBe(false); + expect(gt({ params: [null, null], location })).toBe(false); + expect(gt({ params: [new Date(1), new Date(2)], location })).toBe(false); + expect(gt({ params: [null, new Date(2)], location })).toBe(false); + expect(gt({ params: [false, true], location })).toBe(false); + expect(gt({ params: ['a', 'b'], location })).toBe(false); + expect(gt({ params: ['aa', 'b'], location })).toBe(false); + expect(gt({ params: ['b', 'bb'], location })).toBe(false); + expect(gt({ params: [new Date(1), new Date(1)], location })).toBe(false); + expect(gt({ params: ['b', 'b'], location })).toBe(false); }); test('_gt params not an array', () => { - expect(() => gt({ params: '1, 0', location: 'locationId' })).toThrow( + expect(() => gt({ params: '1, 0', location })).toThrow( 'Operator Error: _gt takes an array type as input. Received: "1, 0" at locationId.' ); }); test('_gt params array with length 1', () => { - expect(() => gt({ params: [1], location: 'locationId' })).toThrow( + expect(() => gt({ params: [1], location })).toThrow( 'Operator Error: _gt takes an array of length 2 as input. Received: [1] at locationId.' ); }); test('_gt params array with length 3', () => { - expect(() => gt({ params: [1, 2, 3], location: 'locationId' })).toThrow( + expect(() => gt({ params: [1, 2, 3], location })).toThrow( 'Operator Error: _gt takes an array of length 2 as input. Received: [1,2,3] at locationId.' ); }); - -test('_gt params array with non numbers', () => { - expect(() => gt({ params: ['1', 1], location: 'locationId' })).toThrow( - 'Operator Error: _gt takes an array of 2 numbers. Received: ["1",1] at locationId.' - ); - expect(() => gt({ params: [1, '1'], location: 'locationId' })).toThrow( - 'Operator Error: _gt takes an array of 2 numbers. Received: [1,"1"] at locationId.' - ); -}); diff --git a/packages/operators/test/common/gte.test.js b/packages/operators/test/common/gte.test.js index 8f204779b..97aa4ad69 100644 --- a/packages/operators/test/common/gte.test.js +++ b/packages/operators/test/common/gte.test.js @@ -1,43 +1,50 @@ import gte from '../../src/common/gte'; +const location = 'locationId'; + test('_gte param 0 greater than param 1', () => { - expect(gte({ params: [1, 1], location: 'locationId' })).toBe(true); - expect(gte({ params: [1, 0], location: 'locationId' })).toBe(true); - expect(gte({ params: [0, -1], location: 'locationId' })).toBe(true); - expect(gte({ params: [1, -1], location: 'locationId' })).toBe(true); - expect(gte({ params: [0.2, 0.1], location: 'locationId' })).toBe(true); + expect(gte({ params: [1, 1], location })).toBe(true); + expect(gte({ params: [1, 0], location })).toBe(true); + expect(gte({ params: [0, -1], location })).toBe(true); + expect(gte({ params: [1, -1], location })).toBe(true); + expect(gte({ params: [0.2, 0.1], location })).toBe(true); + expect(gte({ params: [1, null], location })).toBe(true); + expect(gte({ params: [null, null], location })).toBe(true); + expect(gte({ params: [new Date(2), new Date(1)], location })).toBe(true); + expect(gte({ params: [new Date(2), null], location })).toBe(true); + expect(gte({ params: ['bbb', 'bb'], location })).toBe(true); + expect(gte({ params: ['b', 'b'], location })).toBe(true); + expect(gte({ params: [new Date(1), new Date(1)], location })).toBe(true); }); test('_gte param 0 less than param 1', () => { - expect(gte({ params: [0, 1], location: 'locationId' })).toBe(false); - expect(gte({ params: [-1, 0], location: 'locationId' })).toBe(false); - expect(gte({ params: [-1, 1], location: 'locationId' })).toBe(false); - expect(gte({ params: [0.1, 0.2], location: 'locationId' })).toBe(false); + expect(gte({ params: [0, 1], location })).toBe(false); + expect(gte({ params: [-1, 0], location })).toBe(false); + expect(gte({ params: [-1, 1], location })).toBe(false); + expect(gte({ params: [0.1, 0.2], location })).toBe(false); + expect(gte({ params: [null, 1], location })).toBe(false); + expect(gte({ params: [new Date(1), new Date(2)], location })).toBe(false); + expect(gte({ params: [null, new Date(2)], location })).toBe(false); + expect(gte({ params: [false, true], location })).toBe(false); + expect(gte({ params: ['a', 'b'], location })).toBe(false); + expect(gte({ params: ['aa', 'b'], location })).toBe(false); + expect(gte({ params: ['b', 'bb'], location })).toBe(false); }); test('_gte params not an array', () => { - expect(() => gte({ params: '1, 0', location: 'locationId' })).toThrow( + expect(() => gte({ params: '1, 0', location })).toThrow( 'Operator Error: _gte takes an array type as input. Received: "1, 0" at locationId.' ); }); test('_gte params array with length 1', () => { - expect(() => gte({ params: [1], location: 'locationId' })).toThrow( + expect(() => gte({ params: [1], location })).toThrow( 'Operator Error: _gte takes an array of length 2 as input. Received: [1] at locationId.' ); }); test('_gte params array with length 3', () => { - expect(() => gte({ params: [1, 2, 3], location: 'locationId' })).toThrow( + expect(() => gte({ params: [1, 2, 3], location })).toThrow( 'Operator Error: _gte takes an array of length 2 as input. Received: [1,2,3] at locationId.' ); }); - -test('_gte params array with non numbers', () => { - expect(() => gte({ params: ['1', 1], location: 'locationId' })).toThrow( - 'Operator Error: _gte takes an array of 2 numbers. Received: ["1",1] at locationId.' - ); - expect(() => gte({ params: [1, '1'], location: 'locationId' })).toThrow( - 'Operator Error: _gte takes an array of 2 numbers. Received: [1,"1"] at locationId.' - ); -}); diff --git a/packages/operators/test/common/lt.test.js b/packages/operators/test/common/lt.test.js index b6d2019df..2d9ce6267 100644 --- a/packages/operators/test/common/lt.test.js +++ b/packages/operators/test/common/lt.test.js @@ -1,43 +1,50 @@ import lt from '../../src/common/lt'; +const location = 'locationId'; + test('_lt param 0 less than param 1', () => { - expect(lt({ params: [0, 1], location: 'locationId' })).toBe(true); - expect(lt({ params: [-1, 0], location: 'locationId' })).toBe(true); - expect(lt({ params: [-1, 1], location: 'locationId' })).toBe(true); - expect(lt({ params: [0.1, 0.2], location: 'locationId' })).toBe(true); + expect(lt({ params: [0, 1], location })).toBe(true); + expect(lt({ params: [-1, 0], location })).toBe(true); + expect(lt({ params: [-1, 1], location })).toBe(true); + expect(lt({ params: [0.1, 0.2], location })).toBe(true); + expect(lt({ params: [null, 1], location })).toBe(true); + expect(lt({ params: [new Date(1), new Date(2)], location })).toBe(true); + expect(lt({ params: [null, new Date(2)], location })).toBe(true); + expect(lt({ params: [false, true], location })).toBe(true); + expect(lt({ params: ['a', 'b'], location })).toBe(true); + expect(lt({ params: ['aa', 'b'], location })).toBe(true); + expect(lt({ params: ['b', 'bb'], location })).toBe(true); }); test('_lt param 0 greater than param 1', () => { - expect(lt({ params: [1, 1], location: 'locationId' })).toBe(false); - expect(lt({ params: [1, 0], location: 'locationId' })).toBe(false); - expect(lt({ params: [0, -1], location: 'locationId' })).toBe(false); - expect(lt({ params: [1, -1], location: 'locationId' })).toBe(false); - expect(lt({ params: [0.2, 0.1], location: 'locationId' })).toBe(false); + expect(lt({ params: [1, 1], location })).toBe(false); + expect(lt({ params: [1, 0], location })).toBe(false); + expect(lt({ params: [0, -1], location })).toBe(false); + expect(lt({ params: [1, -1], location })).toBe(false); + expect(lt({ params: [0.2, 0.1], location })).toBe(false); + expect(lt({ params: [1, null], location })).toBe(false); + expect(lt({ params: [null, null], location })).toBe(false); + expect(lt({ params: [new Date(2), new Date(1)], location })).toBe(false); + expect(lt({ params: [new Date(2), null], location })).toBe(false); + expect(lt({ params: ['bbb', 'bb'], location })).toBe(false); + expect(lt({ params: ['b', 'b'], location })).toBe(false); + expect(lt({ params: [new Date(1), new Date(1)], location })).toBe(false); }); test('_lt params not an array', () => { - expect(() => lt({ params: '1, 0', location: 'locationId' })).toThrow( + expect(() => lt({ params: '1, 0', location })).toThrow( 'Operator Error: _lt takes an array type as input. Received: "1, 0" at locationId.' ); }); test('_lt params array with length 1', () => { - expect(() => lt({ params: [1], location: 'locationId' })).toThrow( + expect(() => lt({ params: [1], location })).toThrow( 'Operator Error: _lt takes an array of length 2 as input. Received: [1] at locationId.' ); }); test('_lt params array with length 3', () => { - expect(() => lt({ params: [1, 2, 3], location: 'locationId' })).toThrow( + expect(() => lt({ params: [1, 2, 3], location })).toThrow( 'Operator Error: _lt takes an array of length 2 as input. Received: [1,2,3] at locationId.' ); }); - -test('_lt params array with non numbers', () => { - expect(() => lt({ params: ['1', 1], location: 'locationId' })).toThrow( - 'Operator Error: _lt takes an array of 2 numbers. Received: ["1",1] at locationId.' - ); - expect(() => lt({ params: [1, '1'], location: 'locationId' })).toThrow( - 'Operator Error: _lt takes an array of 2 numbers. Received: [1,"1"] at locationId.' - ); -}); diff --git a/packages/operators/test/common/lte.test.js b/packages/operators/test/common/lte.test.js index fdecbeeec..cac2714f9 100644 --- a/packages/operators/test/common/lte.test.js +++ b/packages/operators/test/common/lte.test.js @@ -1,43 +1,50 @@ import lte from '../../src/common/lte'; +const location = 'locationId'; + test('_lte param 0 less than param 1', () => { - expect(lte({ params: [1, 1], location: 'locationId' })).toBe(true); - expect(lte({ params: [0, 1], location: 'locationId' })).toBe(true); - expect(lte({ params: [-1, 0], location: 'locationId' })).toBe(true); - expect(lte({ params: [-1, 1], location: 'locationId' })).toBe(true); - expect(lte({ params: [0.1, 0.2], location: 'locationId' })).toBe(true); + expect(lte({ params: [1, 1], location })).toBe(true); + expect(lte({ params: [0, 1], location })).toBe(true); + expect(lte({ params: [-1, 0], location })).toBe(true); + expect(lte({ params: [-1, 1], location })).toBe(true); + expect(lte({ params: [0.1, 0.2], location })).toBe(true); + expect(lte({ params: [null, 1], location })).toBe(true); + expect(lte({ params: [null, null], location })).toBe(true); + expect(lte({ params: [new Date(1), new Date(2)], location })).toBe(true); + expect(lte({ params: [new Date(1), new Date(1)], location })).toBe(true); + expect(lte({ params: [null, new Date(2)], location })).toBe(true); + expect(lte({ params: [false, true], location })).toBe(true); + expect(lte({ params: ['a', 'b'], location })).toBe(true); + expect(lte({ params: ['aa', 'b'], location })).toBe(true); + expect(lte({ params: ['b', 'bb'], location })).toBe(true); + expect(lte({ params: ['b', 'b'], location })).toBe(true); }); test('_lte param 0 greater than param 1', () => { - expect(lte({ params: [1, 0], location: 'locationId' })).toBe(false); - expect(lte({ params: [0, -1], location: 'locationId' })).toBe(false); - expect(lte({ params: [1, -1], location: 'locationId' })).toBe(false); - expect(lte({ params: [0.2, 0.1], location: 'locationId' })).toBe(false); + expect(lte({ params: [1, 0], location })).toBe(false); + expect(lte({ params: [0, -1], location })).toBe(false); + expect(lte({ params: [1, -1], location })).toBe(false); + expect(lte({ params: [0.2, 0.1], location })).toBe(false); + expect(lte({ params: [1, null], location })).toBe(false); + expect(lte({ params: [new Date(2), new Date(1)], location })).toBe(false); + expect(lte({ params: [new Date(2), null], location })).toBe(false); + expect(lte({ params: ['bbb', 'bb'], location })).toBe(false); }); test('_lte params not an array', () => { - expect(() => lte({ params: '1, 0', location: 'locationId' })).toThrow( + expect(() => lte({ params: '1, 0', location })).toThrow( 'Operator Error: _lte takes an array type as input. Received: "1, 0" at locationId.' ); }); test('_lte params array with length 1', () => { - expect(() => lte({ params: [1], location: 'locationId' })).toThrow( + expect(() => lte({ params: [1], location })).toThrow( 'Operator Error: _lte takes an array of length 2 as input. Received: [1] at locationId.' ); }); test('_lte params array with length 3', () => { - expect(() => lte({ params: [1, 2, 3], location: 'locationId' })).toThrow( + expect(() => lte({ params: [1, 2, 3], location })).toThrow( 'Operator Error: _lte takes an array of length 2 as input. Received: [1,2,3] at locationId.' ); }); - -test('_lte params array with non numbers', () => { - expect(() => lte({ params: ['1', 1], location: 'locationId' })).toThrow( - 'Operator Error: _lte takes an array of 2 numbers. Received: ["1",1] at locationId.' - ); - expect(() => lte({ params: [1, '1'], location: 'locationId' })).toThrow( - 'Operator Error: _lte takes an array of 2 numbers. Received: [1,"1"] at locationId.' - ); -});