8000 Allow not passing parameters in socket calls by daffl · Pull Request #92 · feathersjs/feathers · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by ext 8000 ension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/providers/socket/commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ exports.setupMethodHandler = function setupMethodHandler (emitter, params, servi
if (typeof service[method] === 'function') {
emitter.on(name, function () {
var args = _.toArray(arguments);
// If the service is called with no parameter object
// insert an empty object
if(typeof args[position] === 'function') {
args.splice(position, 0, {});
}
args[position] = _.extend({ query: args[position] }, params);
service[method].apply(service, args);
});
Expand Down
17 changes: 17 additions & 0 deletions test/providers/primus.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ describe('Primus provider', function () {
});
});

it('missing parameters in socket call works (#88)', function(done) {
var service = app.lookup('todo');
var old = {
find: service.find
};

service.find = function(params) {
assert.deepEqual(_.omit(params, 'query'), socketParams, 'Handshake parameters passed on proper position');
old.find.apply(this, arguments);
};

socket.send('todo::find', function () {
_.extend(service, old);
done();
});
});

describe('CRUD', function () {
it('::find', function (done) {
socket.send('todo::find', {}, function (error, data) {
Expand Down
17 changes: 17 additions & 0 deletions test/providers/socketio.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ describe('SocketIO provider', function () {
});
});

it('missing parameters in socket call works (#88)', function(done) {
var service = app.lookup('todo');
var old = {
find: service.find
};

service.find = function(params) {
assert.deepEqual(_.omit(params, 'query'), socketParams, 'Handshake parameters passed on proper position');
old.find.apply(this, arguments);
};

socket.emit('todo::find', function () {
_.extend(service, old);
done();
});
});

describe('CRUD', function () {
it('::find', function (done) {
socket.emit('todo::find', {}, function (error, data) {
Expand Down
0