Skip to content

Commit

Permalink
Add validations for maximum and minimum
Browse files Browse the repository at this point in the history
  • Loading branch information
bsonntag committed Nov 18, 2019
1 parent 466789f commit 2f897a2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/utils/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
40 changes: 40 additions & 0 deletions test/src/utils/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
});
});
});

0 comments on commit 2f897a2

Please sign in to comment.