@@ -9,6 +9,7 @@ const api3 = require('../index')({ version: 'v1.0', logger: false })
9
9
const api4 = require ( '../index' ) ( { version : 'v1.0' , logger : false } )
10
10
const api5 = require ( '../index' ) ( { version : 'v1.0' , logger : false } )
11
11
const api6 = require ( '../index' ) ( { version : 'v1.0' , logger : false } )
12
+ const api7 = require ( '../index' ) ( { version : 'v1.0' , logger : false } )
12
13
13
14
let event = {
14
15
httpMethod : 'get' ,
@@ -207,6 +208,10 @@ api.head('/head/*', (req,res) => {
207
208
res . status ( 200 ) . header ( 'wildcard' , true ) . json ( { } )
208
209
} )
209
210
211
+ api . get ( '/methodNotAllowed' , ( req , res ) => {
212
+ res . send ( { status : 'OK' } )
213
+ } )
214
+
210
215
// Multi methods
211
216
api3 . METHOD ( 'get,post' , '/multimethod/test' , ( req , res ) => {
212
217
res . status ( 200 ) . json ( { method : req . method , path : '/multimethod/test' } )
@@ -258,6 +263,10 @@ api6.get('/test', function testHandler(req,res) {
258
263
res . send ( { status : 'ok' } )
259
264
} )
260
265
266
+ api7 . get ( function ( req , res ) {
267
+ res . status ( 200 ) . json ( { method : 'get' , status : 'ok' } )
268
+ } )
269
+
261
270
262
271
/******************************************************************************/
263
272
/*** BEGIN TESTS ***/
@@ -392,6 +401,25 @@ describe('Route Tests:', function() {
392
401
expect ( result ) . to . deep . equal ( { multiValueHeaders : { 'content-type' : [ 'application/json' ] } , statusCode : 200 , body : '{"method":"get","status":"ok"}' , isBase64Encoded : false } )
393
402
} ) // end it
394
403
404
+ it ( 'Method not allowed' , async function ( ) {
405
+ let _event = Object . assign ( { } , event , { path : '/methodNotAllowed' , httpMethod : 'post' } )
406
+ let result = await new Promise ( r => api . run ( _event , { } , ( e , res ) => { r ( res ) } ) )
407
+ expect ( result ) . to . deep . equal ( { multiValueHeaders : { 'content-type' : [ 'application/json' ] } , statusCode : 405 , body : '{"error":"Method not allowed"}' , isBase64Encoded : false } )
408
+ } ) // end it
409
+
410
+
411
+ it ( 'Method not allowed (/* path - valid method)' , async function ( ) {
412
+ let _event = Object . assign ( { } , event , { path : '/methodNotAllowedStar' , httpMethod : 'get' } )
413
+ let result = await new Promise ( r => api7 . run ( _event , { } , ( e , res ) => { r ( res ) } ) )
414
+ expect ( result ) . to . deep . equal ( { multiValueHeaders : { 'content-type' : [ 'application/json' ] } , statusCode : 200 , body : '{"method":"get","status":"ok"}' , isBase64Encoded : false } )
415
+ } ) // end it
416
+
417
+ it ( 'Method not allowed (/* path)' , async function ( ) {
418
+ let _event = Object . assign ( { } , event , { path : '/methodNotAllowedStar' , httpMethod : 'post' } )
419
+ let result = await new Promise ( r => api7 . run ( _event , { } , ( e , res ) => { r ( res ) } ) )
420
+ expect ( result ) . to . deep . equal ( { multiValueHeaders : { 'content-type' : [ 'application/json' ] } , statusCode : 405 , body : '{"error":"Method not allowed"}' , isBase64Encoded : false } )
421
+ } ) // end it
422
+
395
423
} ) // end GET tests
396
424
397
425
0 commit comments