@@ -6,6 +6,7 @@ const expect = require('chai').expect // Assertion library
6
6
const api = require ( '../index' ) ( { version : 'v1.0' , logger : false } )
7
7
const api2 = require ( '../index' ) ( { version : 'v1.0' , logger : false } )
8
8
const api3 = require ( '../index' ) ( { version : 'v1.0' , logger : false } )
9
+ const api4 = require ( '../index' ) ( { version : 'v1.0' , logger : false } )
9
10
10
11
let event = {
11
12
httpMethod : 'get' ,
@@ -222,6 +223,32 @@ api3.METHOD([1,'DELETE'],'/multimethod/badtype', (req,res) => {
222
223
res . status ( 200 ) . json ( { method : req . method , path : '/multimethod/badtype' } )
223
224
} )
224
225
226
+
227
+ api4 . get ( '/*' , ( req , res ) => {
228
+ res . status ( 200 ) . header ( 'wildcard' , true ) . json ( { method : req . method , path : req . path } )
229
+ } )
230
+
231
+ api4 . get ( '/test/*' , ( req , res ) => {
232
+ res . status ( 200 ) . header ( 'wildcard' , true ) . json ( { method : req . method , path : req . path , nested : "true" } )
233
+ } )
234
+
235
+ api4 . options ( '/test/*' , ( req , res ) => {
236
+ res . status ( 200 ) . header ( 'wildcard' , true ) . json ( { method : req . method , path : req . path , nested : "true" } )
237
+ } )
238
+
239
+ api4 . options ( '/test/test/*' , ( req , res ) => {
240
+ res . status ( 200 ) . header ( 'wildcard' , true ) . json ( { method : req . method , path : req . path , nested : "true" } )
241
+ } )
242
+
243
+ api4 . post ( '/*' , ( req , res ) => {
244
+ res . status ( 200 ) . header ( 'wildcard' , true ) . json ( { method : req . method , path : req . path } )
245
+ } )
246
+
247
+ api4 . post ( '/test/*' , ( req , res ) => {
248
+ res . status ( 200 ) . header ( 'wildcard' , true ) . json ( { method : req . method , path : req . path , nested : "true" } )
249
+ } )
250
+
251
+
225
252
/******************************************************************************/
226
253
/*** BEGIN TESTS ***/
227
254
/******************************************************************************/
@@ -320,6 +347,28 @@ describe('Route Tests:', function() {
320
347
expect ( result ) . to . deep . equal ( { headers : { 'content-type' : 'application/json' } , statusCode : 404 , body : '{"error":"Route not found"}' , isBase64Encoded : false } )
321
348
} ) // end it
322
349
350
+ it ( 'Wildcard: /*' , async function ( ) {
351
+ let _event = Object . assign ( { } , event , { path : '/foo/bar' } )
352
+ let result = await new Promise ( r => api4 . run ( _event , { } , ( e , res ) => { r ( res ) } ) )
353
+ expect ( result ) . to . deep . equal ( {
354
+ headers : { 'content-type' : 'application/json' , 'wildcard' : true } ,
355
+ statusCode : 200 ,
356
+ body : '{"method":"GET","path":"/foo/bar"}' ,
357
+ isBase64Encoded : false
358
+ } )
359
+ } ) // end it
360
+
361
+ it ( 'Wildcard: /test/*' , async function ( ) {
362
+ let _event = Object . assign ( { } , event , { path : '/test/foo/bar' } )
363
+ let result = await new Promise ( r => api4 . run ( _event , { } , ( e , res ) => { r ( res ) } ) )
364
+ expect ( result ) . to . deep . equal ( {
365
+ headers : { 'content-type' : 'application/json' , 'wildcard' : true } ,
366
+ statusCode : 200 ,
367
+ body : '{"method":"GET","path":"/test/foo/bar","nested":"true"}' ,
368
+ isBase64Encoded : false
369
+ } )
370
+ } ) // end it
371
+
323
372
} ) // end GET tests
324
373
325
374
@@ -486,6 +535,28 @@ describe('Route Tests:', function() {
486
535
expect ( result ) . to . deep . equal ( { headers : { 'content-type' : 'application/json' } , statusCode : 404 , body : '{"error":"Route not found"}' , isBase64Encoded : false } )
487
536
} ) // end it
488
537
538
+ it ( 'Wildcard: /*' , async function ( ) {
539
+ let _event = Object . assign ( { } , event , { path : '/foo/bar' , httpMethod : 'post' } )
540
+ let result = await new Promise ( r => api4 . run ( _event , { } , ( e , res ) => { r ( res ) } ) )
541
+ expect ( result ) . to . deep . equal ( {
542
+ headers : { 'content-type' : 'application/json' , 'wildcard' : true } ,
543
+ statusCode : 200 ,
544
+ body : '{"method":"POST","path":"/foo/bar"}' ,
545
+ isBase64Encoded : false
546
+ } )
547
+ } ) // end it
548
+
549
+ it ( 'Wildcard: /test/*' , async function ( ) {
550
+ let _event = Object . assign ( { } , event , { path : '/test/foo/bar' , httpMethod : 'post' } )
551
+ let result = await new Promise ( r => api4 . run ( _event , { } , ( e , res ) => { r ( res ) } ) )
552
+ expect ( result ) . to . deep . equal ( {
553
+ headers : { 'content-type' : 'application/json' , 'wildcard' : true } ,
554
+ statusCode : 200 ,
555
+ body : '{"method":"POST","path":"/test/foo/bar","nested":"true"}' ,
556
+ isBase64Encoded : false
557
+ } )
558
+ } ) // end it
559
+
489
560
} ) // end POST tests
490
561
491
562
@@ -702,6 +773,28 @@ describe('Route Tests:', function() {
702
773
expect ( result ) . to . deep . equal ( { headers : { 'content-type' : 'application/json' } , statusCode : 404 , body : '{"error":"Route not found"}' , isBase64Encoded : false } )
703
774
} ) // end it
704
775
776
+ it ( 'Wildcard: /test/*' , async function ( ) {
777
+ let _event = Object . assign ( { } , event , { path : '/test/foo/bar' , httpMethod : 'options' } )
778
+ let result = await new Promise ( r => api4 . run ( _event , { } , ( e , res ) => { r ( res ) } ) )
779
+ expect ( result ) . to . deep . equal ( {
780
+ headers : { 'content-type' : 'application/json' , 'wildcard' : true } ,
781
+ statusCode : 200 ,
782
+ body : '{"method":"OPTIONS","path":"/test/foo/bar","nested":"true"}' ,
783
+ isBase64Encoded : false
784
+ } )
785
+ } ) // end it
786
+
787
+ it ( 'Wildcard: /test/test/* (higher level matching)' , async function ( ) {
788
+ let _event = Object . assign ( { } , event , { path : '/test/test/foo/bar' , httpMethod : 'options' } )
789
+ let result = await new Promise ( r => api4 . run ( _event , { } , ( e , res ) => { r ( res ) } ) )
790
+ expect ( result ) . to . deep . equal ( {
791
+ headers : { 'content-type' : 'application/json' , 'wildcard' : true } ,
792
+ statusCode : 200 ,
793
+ body : '{"method":"OPTIONS","path":"/test/test/foo/bar","nested":"true"}' ,
794
+ isBase64Encoded : false
795
+ } )
796
+ } ) // end it
797
+
705
798
} ) // end OPTIONS tests
706
799
707
800
0 commit comments