Handle cases where maximum and minimum are 0
This commit is contained in:
@@ -577,13 +577,13 @@ export const validateParam = (param, isXml) => {
|
|||||||
errors.push("Required field is not provided")
|
errors.push("Required field is not provided")
|
||||||
return errors
|
return errors
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maximum) {
|
if (maximum || maximum === 0) {
|
||||||
let err = validateMaximum(value, maximum)
|
let err = validateMaximum(value, maximum)
|
||||||
if (err) errors.push(err)
|
if (err) errors.push(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minimum) {
|
if (minimum || minimum === 0) {
|
||||||
let err = validateMinimum(value, minimum)
|
let err = validateMinimum(value, minimum)
|
||||||
if (err) errors.push(err)
|
if (err) errors.push(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* eslint-env mocha */
|
/* eslint-env mocha */
|
||||||
import expect from "expect"
|
import expect from "expect"
|
||||||
import { fromJS, OrderedMap } from "immutable"
|
import { fromJS, OrderedMap } from "immutable"
|
||||||
import {
|
import {
|
||||||
mapToList,
|
mapToList,
|
||||||
validateMinLength,
|
validateMinLength,
|
||||||
validateMaxLength,
|
validateMaxLength,
|
||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
validateInteger,
|
validateInteger,
|
||||||
validateParam,
|
validateParam,
|
||||||
validateFile,
|
validateFile,
|
||||||
validateMaximum,
|
validateMaximum,
|
||||||
validateMinimum,
|
validateMinimum,
|
||||||
fromJSOrdered,
|
fromJSOrdered,
|
||||||
getAcceptControllingResponse,
|
getAcceptControllingResponse,
|
||||||
@@ -97,11 +97,12 @@ describe("utils", function() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("returns a message for invalid input", function() {
|
it("returns a message for invalid input", function() {
|
||||||
|
expect(validateMaximum(1, 0)).toEqual(errorMessage)
|
||||||
expect(validateMaximum(10, 9)).toEqual(errorMessage)
|
expect(validateMaximum(10, 9)).toEqual(errorMessage)
|
||||||
expect(validateMaximum(20, 19)).toEqual(errorMessage)
|
expect(validateMaximum(20, 19)).toEqual(errorMessage)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("validateMinimum", function() {
|
describe("validateMinimum", function() {
|
||||||
let errorMessage = "Value must be greater than Minimum"
|
let errorMessage = "Value must be greater than Minimum"
|
||||||
|
|
||||||
@@ -111,6 +112,7 @@ describe("utils", function() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("returns a message for invalid input", function() {
|
it("returns a message for invalid input", function() {
|
||||||
|
expect(validateMinimum(-1, 0)).toEqual(errorMessage)
|
||||||
expect(validateMinimum(1, 2)).toEqual(errorMessage)
|
expect(validateMinimum(1, 2)).toEqual(errorMessage)
|
||||||
expect(validateMinimum(10, 20)).toEqual(errorMessage)
|
expect(validateMinimum(10, 20)).toEqual(errorMessage)
|
||||||
})
|
})
|
||||||
@@ -316,7 +318,7 @@ describe("utils", function() {
|
|||||||
result = validateParam( param, false )
|
result = validateParam( param, false )
|
||||||
expect( result ).toEqual( [] )
|
expect( result ).toEqual( [] )
|
||||||
})
|
})
|
||||||
|
|
||||||
it("validates required strings with min and max length", function() {
|
it("validates required strings with min and max length", function() {
|
||||||
// invalid string with max length
|
// invalid string with max length
|
||||||
param = fromJS({
|
param = fromJS({
|
||||||
@@ -606,7 +608,7 @@ describe("utils", function() {
|
|||||||
param = fromJS({
|
param = fromJS({
|
||||||
required: true,
|
required: true,
|
||||||
type: "number",
|
type: "number",
|
||||||
value: 10,
|
value: 10,
|
||||||
minimum: 5,
|
minimum: 5,
|
||||||
maximum: 99
|
maximum: 99
|
||||||
})
|
})
|
||||||
@@ -617,12 +619,32 @@ describe("utils", function() {
|
|||||||
param = fromJS({
|
param = fromJS({
|
||||||
required: true,
|
required: true,
|
||||||
type: "number",
|
type: "number",
|
||||||
value: -10,
|
value: -10,
|
||||||
minimum: -50,
|
minimum: -50,
|
||||||
maximum: -5
|
maximum: -5
|
||||||
})
|
})
|
||||||
result = validateParam( param, false )
|
result = validateParam( param, false )
|
||||||
expect( result ).toEqual( [] )
|
expect( result ).toEqual( [] )
|
||||||
|
|
||||||
|
// invalid number with maximum:0
|
||||||
|
param = fromJS({
|
||||||
|
required: true,
|
||||||
|
type: "number",
|
||||||
|
value: 1,
|
||||||
|
maximum: 0
|
||||||
|
})
|
||||||
|
result = validateParam( param, false )
|
||||||
|
expect( result ).toEqual( ["Value must be less than Maximum"] )
|
||||||
|
|
||||||
|
// invalid number with minimum:0
|
||||||
|
param = fromJS({
|
||||||
|
required: true,
|
||||||
|
type: "number",
|
||||||
|
value: -10,
|
||||||
|
minimum: 0
|
||||||
|
})
|
||||||
|
result = validateParam( param, false )
|
||||||
|
expect( result ).toEqual( ["Value must be greater than Minimum"] )
|
||||||
})
|
})
|
||||||
|
|
||||||
it("validates optional numbers", function() {
|
it("validates optional numbers", function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user