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

27 lines
661 B
JavaScript
Raw Normal View History

'use strict'
2018-04-25 12:48:05 +02:00
const {defaultValidators} = require('validate-fptf')
const anyOf = require('validate-fptf/lib/any-of')
const validators = require('./validators')
const create = (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
}
module.exports = create