All files / lib/validate-values-by-rules validate-values-by-rules.js

100% Statements 11/11
100% Branches 8/8
100% Functions 2/2
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 231x 1x 1x     18x 18x 18x           4x   14x 64x   14x     1x  
const isObject = require('lodash.isobject');
const isEmpty = require('lodash.isempty');
const validateValuesByRule = require('./validate-values-by-rule');
 
function validateValuesByRules(rules, item, key) {
  const errors = [];
  const values = isObject(item) && item.values;
  if (
    !Array.isArray(values)
    || isEmpty(values)
    || !Array.isArray(rules)
    || isEmpty(rules)
  ) {
    return errors;
  }
  rules.forEach((rule) => {
    errors.push(...validateValuesByRule(key, values, rule));
  });
  return errors;
}
 
module.exports = validateValuesByRules;