Add breaking test (#931)

* add breaking test

* fix bug by replacing makeArguments
This commit is contained in:
Kévin Berthommier 2018-08-19 19:18:24 +02:00 committed by David Luecke
parent 1c066c76a1
commit 489792bbad
2 changed files with 36 additions and 2 deletions

View File

@ -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,
@ -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`);

View File

@ -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);
});
});
});