All files / mongoose/lib/helpers/discriminator checkEmbeddedDiscriminatorKeyProjection.js

16.66% Statements 1/6
0% Branches 0/7
0% Functions 0/2
16.66% Lines 1/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    1x                    
'use strict';
 
module.exports = function checkEmbeddedDiscriminatorKeyProjection(userProjection, path, schema, selected, addedPaths) {
  const userProjectedInPath = Object.keys(userProjection).
    reduce((cur, key) => cur || key.startsWith(path + '.'), false);
  const _discriminatorKey = path + '.' + schema.options.discriminatorKey;
  if (!userProjectedInPath &&
      addedPaths.length === 1 &&
      addedPaths[0] === _discriminatorKey) {
    selected.splice(selected.indexOf(_discriminatorKey), 1);
  }
};