Skip to content

Commit

Permalink
fix: Normalize params to object even when it is falsy (#1012)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Sep 21, 2018
1 parent 1b866ea commit af97818
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
7 changes: 5 additions & 2 deletions packages/feathers/lib/hooks/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ const { _ } = require('@feathersjs/commons');
const assignArguments = context => {
const { service, method } = context;
const parameters = service.methods[method];

const argsObject = context.arguments.reduce((result, value, index) => {
result[parameters[index]] = value;
return result;
}, { params: {} });
}, {});

if (!argsObject.params) {
argsObject.params = {};
}

Object.assign(context, argsObject);

Expand Down
23 changes: 19 additions & 4 deletions packages/feathers/test/hooks/hooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ describe('hooks basics', () => {

it('invalid type in .hooks throws error', () => {
const app = feathers().use('/dummy', {
get (id, params, callback) {
callback(null, { id, params });
get (id, params) {
return Promise.resolve({ id, params });
}
});

Expand All @@ -117,8 +117,8 @@ describe('hooks basics', () => {

it('invalid hook method throws error', () => {
const app = feathers().use('/dummy', {
get (id, params, callback) {
callback(null, { id, params });
get (id, params) {
return Promise.resolve({ id, params });
}
});

Expand Down Expand Up @@ -342,4 +342,19 @@ describe('hooks basics', () => {
assert.deepEqual(result, args);
});
});

it('normalizes params to object even when it is falsy (#1001)', () => {
const app = feathers().use('/dummy', {
get (id, params) {
return Promise.resolve({ id, params });
}
});

return app.service('dummy').get('test', null).then(result => {
assert.deepEqual(result, {
id: 'test',
params: {}
});
});
});
});

0 comments on commit af97818

Please sign in to comment.