From 52de82ed6fb4bebc2378a7e0578a0d77290bad06 Mon Sep 17 00:00:00 2001 From: Theodor Diaconu Date: Wed, 26 Oct 2016 10:34:36 +0300 Subject: [PATCH] fixed a previous bug, written a test for it --- lib/exposure/lib/restrictFields.js | 2 +- lib/exposure/testing/units/units.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/exposure/lib/restrictFields.js b/lib/exposure/lib/restrictFields.js index 4ea573d..edebc1f 100644 --- a/lib/exposure/lib/restrictFields.js +++ b/lib/exposure/lib/restrictFields.js @@ -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 { diff --git a/lib/exposure/testing/units/units.js b/lib/exposure/testing/units/units.js index b62f354..6d244cc 100644 --- a/lib/exposure/testing/units/units.js +++ b/lib/exposure/testing/units/units.js @@ -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 () {