All files / lib validate-values.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 191x     18x 18x 3x   15x 24x 1x 23x 1x   24x       1x  
const isObject = require('lodash.isobject');
 
function validateValues(item, key) {
  const values = item && item.values;
  if (!Array.isArray(values)) {
    return [];
  }
  return values.reduce((errors, value) => {
    if (!isObject(value)) {
      errors.push(new Error(`items inside values must be objects for key "${key}"`));
    } else if (!Object.prototype.hasOwnProperty.call(value, 'value')) {
      errors.push(new Error(`items inside values must have a value property for key "${key}"`));
    }
    return errors;
  }, []);
}
 
module.exports = validateValues;