Skip to content

Commit

Permalink
Pass connection in params (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Aug 22, 2018
1 parent 35c792b commit 9057849
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/transport-commons/lib/socket/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ exports.runMethod = function (app, connection, path, method, args) {
const query = methodArgs[position] || {};
// `params` have to be re-mapped to the query
// and added with the route
const params = Object.assign({ query, route }, connection);
const params = Object.assign({ query, route, connection }, connection);

methodArgs[position] = params;

Expand Down
10 changes: 7 additions & 3 deletions packages/transport-commons/test/socket/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ describe('@feathersjs/transport-commons', () => {
id: 10,
params: Object.assign({
query: {},
route: {}
route: {},
connection
}, connection)
});
done();
Expand All @@ -82,7 +83,8 @@ describe('@feathersjs/transport-commons', () => {
try {
const params = Object.assign({
query: { fromQuery: true },
route: {}
route: {},
connection
}, connection);

assert.ok(!error);
Expand All @@ -107,6 +109,7 @@ describe('@feathersjs/transport-commons', () => {
assert.deepEqual(result, {
id: 10,
params: Object.assign({
connection,
query: {},
route: {}
}, connection)
Expand All @@ -131,7 +134,8 @@ describe('@feathersjs/transport-commons', () => {
}, (error, result) => {
const params = Object.assign({
query: { fromQuery: true },
route: {}
route: {},
connection
}, connection);

try {
Expand Down
30 changes: 30 additions & 0 deletions packages/transport-commons/test/socket/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,36 @@ describe('socket commons utils', () => {
runMethod(app, {}, 'myservice', 'get', [ 10, {}, callback ]);
});

it('merges params with connection and passes connection', done => {
const connection = {
testing: true
};
const callback = (error, result) => {
if (error) {
return done(error);
}

assert.deepEqual(result, {
id: 10,
params: {
connection,
query: {},
route: {},
testing: true
}
});
done();
};

app.use('/otherservice', {
get (id, params) {
return Promise.resolve({ id, params });
}
});

runMethod(app, connection, 'otherservice', 'get', [ 10, {}, callback ]);
});

it('with params missing', done => {
const callback = (error, result) => {
if (error) {
Expand Down

0 comments on commit 9057849

Please sign in to comment.