Skip to content

Commit

Permalink
Merge pull request #2 from livechat/API-4316/fix-non-negative-validation
Browse files Browse the repository at this point in the history
Fix nonNegative validation rule
  • Loading branch information
Neob91 authored Sep 23, 2019
2 parents 9093c8c + 5d60284 commit 0c55173
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/express-validate.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions lib/validator.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"email": "[email protected]"
}
],
"version": "0.1.15",
"version": "0.1.16",
"homepage": "https://github.com/livechat/express-validate",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion src/validator.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Validator.addRule 'lowerThan',
Validator.addRule 'nonNegative',
message: "%s must be non-negative"
test: (str) ->
return @rules.between.test str, {low: -1, high: Infinity}
return @rules.between.test str, {low: 0, high: Infinity}

Validator.addRule 'positive',
message: "%s must be positive"
Expand Down
12 changes: 12 additions & 0 deletions test/test_validator.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ describe "Validator", ()->
validator.testInternal({key: "1"}, "integer", "key").should.be.false
validator.testInternal({key: "0"}, "integer", "key").should.be.false

it "non-negative rule", () ->
validator.testInternal({key: "-1"}, "nonNegative", "key").should.not.be.false
validator.testInternal({key: -1}, "nonNegative", "key").should.not.be.false
validator.testInternal({key: -2}, "nonNegative", "key").should.not.be.false
validator.testInternal({key: -223572357235}, "nonNegative", "key").should.not.be.false

validator.testInternal({key: "0"}, "nonNegative", "key").should.be.false
validator.testInternal({key: 0}, "nonNegative", "key").should.be.false
validator.testInternal({key: 1}, "nonNegative", "key").should.be.false
validator.testInternal({key: 2}, "nonNegative", "key").should.be.false
validator.testInternal({key: 9235472346}, "nonNegative", "key").should.be.false

describe "validate", ->
it "should validate simple object", () ->
validator.validate({key: "value"}, {key: "required"}).length.should.equal 0
Expand Down

0 comments on commit 0c55173

Please sign in to comment.