Merge branch 'master' into bug/3271-fix-trim-with-non-json-parameters
This commit is contained in:
@@ -462,6 +462,12 @@ export const validateInteger = ( val ) => {
|
||||
}
|
||||
}
|
||||
|
||||
export const validateFile = ( val ) => {
|
||||
if ( val && !(val instanceof win.File) ) {
|
||||
return "Value must be a file"
|
||||
}
|
||||
}
|
||||
|
||||
// validation of parameters before execute
|
||||
export const validateParam = (param, isXml) => {
|
||||
let errors = []
|
||||
@@ -472,7 +478,9 @@ export const validateParam = (param, isXml) => {
|
||||
let stringCheck = type === "string" && !value
|
||||
let arrayCheck = type === "array" && Array.isArray(value) && !value.length
|
||||
let listCheck = type === "array" && Im.List.isList(value) && !value.count()
|
||||
if ( required && (stringCheck || arrayCheck || listCheck) ) {
|
||||
let fileCheck = type === "file" && !(value instanceof win.File)
|
||||
|
||||
if ( required && (stringCheck || arrayCheck || listCheck || fileCheck) ) {
|
||||
errors.push("Required field is not provided")
|
||||
return errors
|
||||
}
|
||||
@@ -505,7 +513,10 @@ export const validateParam = (param, isXml) => {
|
||||
errors.push({ index: index, error: err})
|
||||
}
|
||||
})
|
||||
|
||||
} else if ( type === "file" ) {
|
||||
let err = validateFile(value)
|
||||
if (!err) return errors
|
||||
errors.push(err)
|
||||
}
|
||||
|
||||
return errors
|
||||
|
||||
@@ -42,7 +42,8 @@ label
|
||||
input[type=text],
|
||||
input[type=password],
|
||||
input[type=search],
|
||||
input[type=email]
|
||||
input[type=email],
|
||||
input[type=file]
|
||||
{
|
||||
min-width: 100px;
|
||||
margin: 5px 0;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/* eslint-env mocha */
|
||||
import expect from "expect"
|
||||
import { fromJS } from "immutable"
|
||||
import { mapToList, validateNumber, validateInteger, validateParam } from "core/utils"
|
||||
import { mapToList, validateNumber, validateInteger, validateParam, validateFile } from "core/utils"
|
||||
import win from "core/window"
|
||||
|
||||
describe("utils", function(){
|
||||
|
||||
@@ -157,6 +158,19 @@ describe("utils", function(){
|
||||
})
|
||||
})
|
||||
|
||||
describe("validateFile", function() {
|
||||
let errorMessage = "Value must be a file"
|
||||
|
||||
it("validates against objects which are instances of 'File'", function() {
|
||||
let fileObj = new win.File([], "Test File")
|
||||
expect(validateFile(fileObj)).toBeFalsy()
|
||||
expect(validateFile(null)).toBeFalsy()
|
||||
expect(validateFile(undefined)).toBeFalsy()
|
||||
expect(validateFile(1)).toEqual(errorMessage)
|
||||
expect(validateFile("string")).toEqual(errorMessage)
|
||||
})
|
||||
})
|
||||
|
||||
describe("validateParam", function() {
|
||||
let param = null
|
||||
let result = null
|
||||
@@ -171,6 +185,16 @@ describe("utils", function(){
|
||||
expect( result ).toEqual( ["Required field is not provided"] )
|
||||
})
|
||||
|
||||
it("validates required files", function() {
|
||||
param = fromJS({
|
||||
required: true,
|
||||
type: "file",
|
||||
value: undefined
|
||||
})
|
||||
result = validateParam( param, false )
|
||||
expect( result ).toEqual( ["Required field is not provided"] )
|
||||
})
|
||||
|
||||
it("validates required arrays", function() {
|
||||
param = fromJS({
|
||||
required: true,
|
||||
|
||||
Reference in New Issue
Block a user