From f6fc6aa7d298dff64574fa410a69bf249a3441b9 Mon Sep 17 00:00:00 2001 From: gsavoie Date: Wed, 21 Feb 2018 22:48:52 -0500 Subject: [PATCH] https://github.com/feathersjs-ecosystem/feathers-authentication-hooks/issues/41 (#42) --- src/has-role-or-restrict.js | 4 ++-- test/has-role-or-restrict.test.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/has-role-or-restrict.js b/src/has-role-or-restrict.js index 5fd4441..95352b5 100644 --- a/src/has-role-or-restrict.js +++ b/src/has-role-or-restrict.js @@ -53,7 +53,7 @@ export default function (options = {}) { return hook; } - return hook.service.find({ query }, params).then(results => { + return hook.service.find(Object.assign({}, params, { query })).then(results => { if (hook.method === 'get' && Array.isArray(results) && results.length === 1) { hook.result = results[0]; return hook; @@ -131,7 +131,7 @@ export default function (options = {}) { return hook; } - return hook.service.find({ query }, params).then(results => { + return hook.service.find(Object.assign({}, params, { query })).then(results => { if (hook.method === 'get' && Array.isArray(results) && results.length === 1) { hook.result = results[0]; return hook; diff --git a/test/has-role-or-restrict.test.js b/test/has-role-or-restrict.test.js index f7fd92a..e606d53 100644 --- a/test/has-role-or-restrict.test.js +++ b/test/has-role-or-restrict.test.js @@ -93,7 +93,7 @@ describe('hasRoleOrRestrict', () => { }; hasRoleOrRestrict({ roles: ['admin'], restrict: {approved: true} }).call(mockService, hook); - expect(mockFind).to.be.calledWith({ query: {author: 'James', approved: true} }, { provider: undefined, query: { author: 'James' } }); + expect(mockFind).to.be.calledWith({ provider: undefined, query: {author: 'James', approved: true} }); }); it('if hook.id is set, merge the restriction and the id into the query and call find', () => { @@ -111,7 +111,7 @@ describe('hasRoleOrRestrict', () => { }; hasRoleOrRestrict({roles: ['admin'], restrict: {approved: true}, idField: '_id'}).call(mockService, hook); - expect(mockFind).to.be.calledWith({ query: {'_id': '525235', approved: true} }, { provider: undefined }); + expect(mockFind).to.be.calledWith({ provider: undefined, query: {'_id': '525235', approved: true} }); }); }); @@ -184,7 +184,7 @@ describe('hasRoleOrRestrict', () => { }; hasRoleOrRestrict({ roles: ['admin'], restrict: {approved: true} }).call(mockService, hook); - expect(mockFind).to.be.calledWith({ query: {author: 'James', approved: true} }, { provider: undefined, query: { author: 'James' } }); + expect(mockFind).to.be.calledWith({ provider: undefined, query: {author: 'James', approved: true} }); }); it('if hook.id is set, merge the restriction and the id into the query and call find', () => { @@ -202,7 +202,7 @@ describe('hasRoleOrRestrict', () => { }; hasRoleOrRestrict({roles: ['admin'], restrict: {approved: true}, idField: '_id'}).call(mockService, hook); - expect(mockFind).to.be.calledWith({ query: {'_id': '525235', approved: true} }, { provider: undefined }); + expect(mockFind).to.be.calledWith({ provider: undefined, query: {'_id': '525235', approved: true} }); }); describe('when owner option enabled', () => {