All files / lib validate-config.js

100% Statements 17/17
100% Branches 5/5
100% Functions 4/4
100% Lines 16/16

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 23 24 251x 1x 1x 1x 1x     3x 1x   2x 2x 8x   2x 18x 18x 18x     17x     1x  
const isObject = require('lodash.isobject');
const validateRule = require('./validate-rule');
const validateItem = require('./validate-item');
const validateValues = require('./validate-values');
const validateValuesByRules = require('./validate-values-by-rules/validate-values-by-rules');
 
function validateConfig({ config, rules = [] }) {
  if (!isObject(config) || Object.keys(config).length === 0) {
    throw new Error('options.config must be an object containing flipr config');
  }
  const errors = [];
  rules.forEach((rule) => {
    errors.push(...validateRule(rule));
  });
  Object.keys(config).forEach((key) => {
    errors.push(...validateItem(config[key], key));
    errors.push(...validateValues(config[key], key));
    errors.push(...validateValuesByRules(rules, config[key], key));
  });
  // compact, remove falsey values
  return errors.filter((error) => !!error);
}
 
module.exports = validateConfig;