db-vendo-client/test/e2e/lib/validate-fptf-with.js

28 lines
700 B
JavaScript
Raw Normal View History

2022-05-07 16:17:37 +02:00
import validateFptf from 'validate-fptf'
const {defaultValidators} = validateFptf
import anyOf from 'validate-fptf/lib/any-of.js'
2022-05-07 16:17:37 +02:00
import validators from './validators.js'
2018-04-25 12:48:05 +02:00
2022-05-07 16:17:37 +02:00
const createValidateFptfWith = (cfg, customValidators = {}) => {
2018-04-25 12:48:05 +02:00
const val = Object.assign({}, defaultValidators)
for (let key of Object.keys(validators)) {
2018-04-25 12:48:05 +02:00
val[key] = validators[key](cfg)
}
2018-04-25 12:48:05 +02:00
Object.assign(val, customValidators)
const validateFptfWith = (t, item, allowedTypes, name) => {
2020-05-22 16:09:25 +02:00
if ('string' === typeof allowedTypes) {
val[allowedTypes](val, item, name)
} else {
anyOf(allowedTypes, val, item, name)
}
2020-05-22 16:09:25 +02:00
t.pass(name + ' is valid')
}
return validateFptfWith
}
2022-05-07 16:17:37 +02:00
export {
createValidateFptfWith,
}