@@ -636,30 +636,47 @@ Deno.test("getEnhancedHandler with a faulty ctx.request.body", async () => {
636636 spyParseOakRequestBody . restore ( ) ;
637637} ) ;
638638
639- Deno . test ( "getEnhancedHandler with a faulty request method and content-type combination" , async ( ) => {
639+ Deno . test ( "getEnhancedHandler with a non-conventional request method and content-type combination" , async ( t ) => {
640+ const methodsToTest = [ "GET" , "HEAD" , "DELETE" ] ;
640641 const spyParseOakRequestBody = spy ( _internal , "parseOakReqBody" ) ;
641- function testHandler ( ) {
642- return "weird.method.content-type.combination.handled" ;
643- }
644- // deno-lint-ignore ban-types
645- const enhancedHandler : Function = _internal . getEnhancedHandler ( testHandler ) ;
646- const ctx = createMockContext ( {
647- method : "GET" ,
648- headers : [ [ "Content-Type" , "application/json" ] ] ,
649- } ) ;
650- Object . defineProperty ( ctx . request , "body" , {
651- get : ( ) => createMockRequestBody ( "json" , "Unexpected end of JSON input" ) ,
652- } ) ;
653- const spyCtxThrow = spy ( ) ;
654- Object . defineProperty ( ctx , "throw" , {
655- value : ( errorStatus : unknown , message ?: string , props ?: unknown ) => {
656- spyCtxThrow ( errorStatus , message , props ) ;
657- } ,
658- } ) ;
659- const retVal = await enhancedHandler ( ctx ) ;
660- assertSpyCalls ( spyCtxThrow , 0 ) ;
661- assertSpyCalls ( spyParseOakRequestBody , 1 ) ;
662- assertEquals ( retVal , "weird.method.content-type.combination.handled" ) ;
642+ await Promise . all ( methodsToTest . map ( ( method ) =>
643+ t . step ( {
644+ name : `testing content-type: application/json and ${ method } request` ,
645+ fn : async ( ) => {
646+ function testHandler ( ) {
647+ return `method ${ method } and Content-Type: application/json handled` ;
648+ }
649+ // deno-lint-ignore ban-types
650+ const enhancedHandler : Function = _internal . getEnhancedHandler (
651+ testHandler ,
652+ ) ;
653+ const ctx = createMockContext ( {
654+ method, // GET | HEAD | DELETE
655+ headers : [ [ "Content-Type" , "application/json" ] ] ,
656+ } ) ;
657+ Object . defineProperty ( ctx . request , "body" , {
658+ get : ( ) =>
659+ createMockRequestBody ( "json" , "Unexpected end of JSON input" ) ,
660+ } ) ;
661+ const spyCtxThrow = spy ( ) ;
662+ Object . defineProperty ( ctx , "throw" , {
663+ value : ( errorStatus : unknown , message ?: string , props ?: unknown ) => {
664+ spyCtxThrow ( errorStatus , message , props ) ;
665+ } ,
666+ } ) ;
667+ const retVal = await enhancedHandler ( ctx ) ;
668+ assertSpyCalls ( spyCtxThrow , 0 ) ;
669+ assertEquals (
670+ retVal ,
671+ `method ${ method } and Content-Type: application/json handled` ,
672+ ) ;
673+ } ,
674+ sanitizeOps : false ,
675+ sanitizeResources : false ,
676+ sanitizeExit : false ,
677+ } )
678+ ) ) ;
679+ assertSpyCalls ( spyParseOakRequestBody , methodsToTest . length ) ;
663680 spyParseOakRequestBody . restore ( ) ;
664681} ) ;
665682
0 commit comments