10BC0 Add breaking test by bertho-zero · Pull Request #931 · 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 extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ const {
getHooks,
processHooks,
enableHooks,
makeArguments,
ACTIVATE_HOOKS
} = hooks;

const makeArguments = (service, method, hookObject) => service.methods[ method ].reduce((result, value) => ([
...result,
hookObject[ value ]
]), []);

const withHooks = function withHooks ({
app,
service,
Expand Down Expand Up @@ -49,7 +53,7 @@ const withHooks = function withHooks ({
}

// Otherwise, call it with arguments created from the hook object
const promise = _super(...makeArguments(hookObject));
const promise = _super(...makeArguments(service, method, hookObject));

if (!isPromise(promise)) {
throw new Error(`Service method '${hookObject.method}' for '${hookObject.path}' service must return a promise`);
Expand Down
30 changes: 30 additions & 0 deletions test/hooks/hooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,34 @@ describe('hooks basics', () => {
});
});
});

it('context.data should not change arguments', () => {
const app = feathers().use('/dummy', {
methods: {
custom: ['id', 'params']
},
get () {},
custom (id, params) {
return Promise.resolve([id, params]);
}
});

app.service('dummy').hooks({
before: {
all (context) {
context.test = ['all::before'];
},
custom (context) {
context.data = { post: 'title' };
}
}
});

const args = [1, { provider: 'rest' }];

return app.service('dummy').custom(...args)
.then(result => {
assert.deepEqual(result, args);
});
});
});
0