From 2f897a2b0ddcf07ed447f8fb47ee4ad86a949d4b Mon Sep 17 00:00:00 2001 From: Benjamim Sonntag Date: Mon, 18 Nov 2019 11:48:06 +0000 Subject: [PATCH] Add validations for maximum and minimum --- src/utils/validate.js | 2 ++ test/src/utils/validate.test.js | 40 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/utils/validate.js b/src/utils/validate.js index 8ef552b..00fa514 100644 --- a/src/utils/validate.js +++ b/src/utils/validate.js @@ -41,9 +41,11 @@ function getPropertyName(error: Object): string { function getErrorArgs(error) { switch (error.keyword) { case 'maxLength': + case 'maximum': return { max: error.params.limit }; case 'minLength': + case 'minimum': return { min: error.params.limit }; default: diff --git a/test/src/utils/validate.test.js b/test/src/utils/validate.test.js index dc5144e..b85027a 100644 --- a/test/src/utils/validate.test.js +++ b/test/src/utils/validate.test.js @@ -108,4 +108,44 @@ describe('validate', () => { } }); }); + + it('should return errors with the `maximum` rule', () => { + const result = validate({ + properties: { + foo: { + maximum: 1, + type: 'number' + } + } + }, { + foo: 2 + }); + + expect(result).toEqual({ + foo: { + args: { max: 1 }, + rule: 'maximum' + } + }); + }); + + it('should return errors with the `minimum` rule', () => { + const result = validate({ + properties: { + foo: { + minimum: 2, + type: 'number' + } + } + }, { + foo: 1 + }); + + expect(result).toEqual({ + foo: { + args: { min: 2 }, + rule: 'minimum' + } + }); + }); });