All files / src/helpers ensure-obj-props-valid.ts

100% Statements 7/7
100% Branches 7/7
100% Functions 2/2
100% Lines 6/6

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  1x   1x         277x 290x   277x 26x            
 
import { BadRequest } from '@feathersjs/errors';
 
export default function ensureObjPropsValid (
  obj: Record<string, unknown>,
  props: string[],
  allowNone?: boolean
): void {
  const keys = Object.keys(obj);
  const valid = keys.every(key => props.includes(key) && typeof obj[key] === 'string');
 
  if (!valid || (keys.length === 0 && !allowNone)) {
    throw new BadRequest(
      'User info is not valid. (authLocalMgnt)',
      { errors: { $className: 'badParams' } }
    );
  }
}