File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed
Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -202,7 +202,7 @@ module.exports = function(registry) {
202202 this . _runWhenAttachedToApp ( function ( app ) {
203203 var remotes = app . remotes ( ) ;
204204 remotes . before ( className + '.' + name , function ( ctx , next ) {
205- fn ( ctx , ctx . result , next ) ;
205+ return fn ( ctx , ctx . result , next ) ;
206206 } ) ;
207207 } ) ;
208208 } ;
@@ -213,7 +213,7 @@ module.exports = function(registry) {
213213 this . _runWhenAttachedToApp ( function ( app ) {
214214 var remotes = app . remotes ( ) ;
215215 remotes . after ( className + '.' + name , function ( ctx , next ) {
216- fn ( ctx , ctx . result , next ) ;
216+ return fn ( ctx , ctx . result , next ) ;
217217 } ) ;
218218 } ) ;
219219 } ;
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ var loopback = require('../');
1010var ACL = loopback . ACL ;
1111var defineModelTestsWithDataSource = require ( './util/model-tests' ) ;
1212var PersistedModel = loopback . PersistedModel ;
13+ var Promise = require ( 'bluebird' ) ;
1314var sinonChai = require ( 'sinon-chai' ) ;
1415chai . use ( sinonChai ) ;
1516
@@ -308,6 +309,32 @@ describe.onServer('Remote Methods', function() {
308309 done ( ) ;
309310 } ) ;
310311 } ) ;
312+
313+ it ( 'Does not stop the hook chain after returning a promise' , function ( done ) {
314+ var hooksCalled = [ ] ;
315+
316+ User . beforeRemote ( 'create' , function ( ) {
317+ hooksCalled . push ( 'first' ) ;
318+ return Promise . resolve ( ) ;
319+ } ) ;
320+
321+ User . beforeRemote ( 'create' , function ( ctx , user , next ) {
322+ hooksCalled . push ( 'second' ) ;
323+ next ( ) ;
324+ } ) ;
325+
326+ // invoke save
327+ request ( app )
328+ . post ( '/users' )
329+ . send ( { data : { first : 'foo' , last : 'bar' } } )
330+ . expect ( 'Content-Type' , / j s o n / )
331+ . expect ( 200 )
332+ . end ( function ( err , res ) {
333+ if ( err ) return done ( err ) ;
334+ expect ( hooksCalled ) . to . eql ( [ 'first' , 'second' ] ) ;
335+ done ( ) ;
336+ } ) ;
337+ } ) ;
311338 } ) ;
312339
313340 describe ( 'Model.afterRemote(name, fn)' , function ( ) {
You can’t perform that action at this time.
0 commit comments