fixed a previous bug, written a test for it

This commit is contained in:
Theodor Diaconu 2016-10-26 10:34:36 +03:00
parent 01f86f1f48
commit 52de82ed6f
2 changed files with 6 additions and 1 deletions

View file

@ -52,7 +52,7 @@ function cleanOptions(options, restrictedFields) {
if (options.fields) {
cleanObject(options.fields, restrictedFields);
if (_.keys(options.fields) === 0) {
if (_.keys(options.fields).length === 0) {
_.extend(options.fields, {_id: 1})
}
} else {

View file

@ -86,6 +86,11 @@ describe('Unit Tests', function () {
assert.isDefined(filters.$or[0].$and[0].test);
assert.isUndefined(filters.$or[0].$and[0].shouldRestrict);
assert.isUndefined(filters.$or[0].$and[0]['shouldRestrict.this']);
let options2 = {fields: {test: 1}};
restrictFields({}, options2, ['test']);
assert.isUndefined(options2.fields.test);
assert.isDefined(options2.fields._id);
});
it('Should restrict links # getLinks', function () {