@@ -17,9 +17,21 @@ let event = {
17
17
}
18
18
}
19
19
20
+ api . use ( function ( req , res , next ) {
21
+ console . log ( 'HELLO FROM MIDDLEWARE' )
22
+ req . testMiddleware = "123" ;
23
+ next ( ) ;
24
+ } ) ;
25
+
20
26
/******************************************************************************/
21
27
/*** DEFINE TEST ROUTES ***/
22
28
/******************************************************************************/
29
+ api . get ( "/" , function ( req , res ) {
30
+ res . status ( 200 ) . json ( {
31
+ testMiddleware : req . testMiddleware ,
32
+ } )
33
+ } ) ;
34
+
23
35
api . get ( '/test' , function ( req , res ) {
24
36
res . status ( 200 ) . json ( { method : 'get' , status : 'ok' } )
25
37
} )
@@ -40,6 +52,12 @@ api.get('/test/test2/test3', function(req,res) {
40
52
41
53
describe ( 'Base Path Tests:' , function ( ) {
42
54
55
+ it ( 'should return testMiddleware: 123 when calling the root path' , async function ( ) {
56
+ let _event = Object . assign ( { } , event , { path : '/v1' } )
57
+ let result = await new Promise ( r => api . run ( _event , { } , ( e , res ) => { r ( res ) } ) )
58
+ expect ( result ) . toEqual ( { multiValueHeaders : { 'content-type' : [ 'application/json' ] } , statusCode : 200 , body : '{"method":"get","status":"ok"}' , isBase64Encoded : false } )
59
+ } )
60
+
43
61
it ( 'Simple path with base: /v1/test' , async function ( ) {
44
62
let _event = Object . assign ( { } , event , { path : '/v1/test' } )
45
63
let result = await new Promise ( r => api . run ( _event , { } , ( e , res ) => { r ( res ) } ) )
0 commit comments