@@ -368,6 +368,42 @@ describe('@feathersjs/express/rest provider', () => {
368
368
. then ( ( ) => server . close ( ) ) ;
369
369
} ) ;
370
370
371
+ it ( 'allows middleware arrays before and after a service' , ( ) => {
372
+ const app = expressify ( feathers ( ) ) ;
373
+
374
+ app . configure ( rest ( ) )
375
+ . use ( expressify . json ( ) )
376
+ . use ( '/todo' , [ function ( req , res , next ) {
377
+ req . body . before = [ 'before first' ] ;
378
+ next ( ) ;
379
+ } , function ( req , res , next ) {
380
+ req . body . before . push ( 'before second' ) ;
381
+ next ( ) ;
382
+ } ] , {
383
+ create ( data ) {
384
+ return Promise . resolve ( data ) ;
385
+ }
386
+ } , [ function ( req , res , next ) {
387
+ res . data . after = [ 'after first' ] ;
388
+ next ( ) ;
389
+ } ] , function ( req , res , next ) {
390
+ res . data . after . push ( 'after second' ) ;
391
+ next ( ) ;
392
+ } ) ;
393
+
394
+ const server = app . listen ( 4776 ) ;
395
+
396
+ return axios . post ( 'http://localhost:4776/todo' , { text : 'Do dishes' } )
397
+ . then ( res => {
398
+ assert . deepStrictEqual ( res . data , {
399
+ text : 'Do dishes' ,
400
+ before : [ 'before first' , 'before second' ] ,
401
+ after : [ 'after first' , 'after second' ]
402
+ } ) ;
403
+ } )
404
+ . then ( ( ) => server . close ( ) ) ;
405
+ } ) ;
406
+
371
407
it ( 'allows an array of middleware without a service' , ( ) => {
372
408
const app = expressify ( feathers ( ) ) ;
373
409
const middlewareArray = [
0 commit comments