@@ -12,6 +12,7 @@ import {
1212 Controller ,
1313 ControllerMethodArgs ,
1414 Get ,
15+ Patch ,
1516 Post ,
1617 Put ,
1718 useOakServer ,
@@ -23,11 +24,12 @@ const spyTemplate = {
2324 handler1 ( ..._ : unknown [ ] ) { } ,
2425 handler2 ( ..._ : unknown [ ] ) { } ,
2526 handler3 ( ..._ : unknown [ ] ) { } ,
27+ handler4 ( ..._ : unknown [ ] ) { } ,
2628 catchAll ( ..._ : unknown [ ] ) { } ,
2729} ;
2830
2931@Controller ( "/test" )
30- class TestController {
32+ class TestController1 {
3133 @Get ( "/handler1/:bar" )
3234 @Get ( "/handler1/bar" )
3335 @Post ( "/handler1/par" )
@@ -70,10 +72,41 @@ class TestController {
7072 spyTemplate . handler3 ( method , reqPath , regPath , { ...param } ) ;
7173 return { method, reqPath, regPath, param, body } ;
7274 }
75+
76+ @Patch ( "/handler4" )
77+ @ControllerMethodArgs ( "body" , "param" )
78+ handler4 (
79+ body : Record < string , unknown > ,
80+ param : Record < string , unknown > ,
81+ ctx : Context ,
82+ ) {
83+ const method = ctx . request . method ;
84+ const reqPath = ctx . request . url . pathname ;
85+ const regPath = ctx . state . _oakRoutingCtrl_regPath ;
86+ spyTemplate . handler4 ( method , reqPath , regPath , { ...param } ) ;
87+ return { method, reqPath, regPath, param, body } ;
88+ }
89+ }
90+
91+ @Controller ( "/test" )
92+ class TestController2 {
93+ @Patch ( "/handler4/:bar" )
94+ @ControllerMethodArgs ( "body" , "param" )
95+ handler4 (
96+ body : Record < string , unknown > ,
97+ param : Record < string , unknown > ,
98+ ctx : Context ,
99+ ) {
100+ const method = ctx . request . method ;
101+ const reqPath = ctx . request . url . pathname ;
102+ const regPath = ctx . state . _oakRoutingCtrl_regPath ;
103+ spyTemplate . handler4 ( method , reqPath , regPath , { ...param } ) ;
104+ return { method, reqPath, regPath, param, body } ;
105+ }
73106}
74107
75108const app = new Application ( ) ;
76- useOakServer ( app , [ TestController ] ) ;
109+ useOakServer ( app , [ TestController1 , TestController2 ] ) ;
77110app . use ( ( ctx ) => {
78111 spyTemplate . catchAll (
79112 "catch-all middleware invoked for" ,
@@ -282,3 +315,59 @@ Deno.test("Similar paths that do not actually overlap - path 2", async () => {
282315 body : { charlie : true } ,
283316 } ) ;
284317} ) ;
318+
319+ Deno . test ( "[PATCH] /test/handler4" , async ( ) => {
320+ const handler4Spy = spy ( spyTemplate , "handler4" ) ;
321+ const catchAllSpy = spy ( spyTemplate , "catchAll" ) ;
322+
323+ const req = await superoak ( app ) ;
324+ const res = await req . patch ( "/test/handler4" ) ;
325+
326+ assertSpyCalls ( handler4Spy , 1 ) ;
327+ assertSpyCallArgs ( handler4Spy , 0 , [
328+ "PATCH" ,
329+ "/test/handler4" ,
330+ "/test/handler4" ,
331+ { } ,
332+ ] ) ;
333+ assertSpyCalls ( catchAllSpy , 1 ) ;
334+
335+ handler4Spy . restore ( ) ;
336+ catchAllSpy . restore ( ) ;
337+
338+ assertEquals ( res . body , {
339+ method : "PATCH" ,
340+ reqPath : "/test/handler4" ,
341+ regPath : "/test/handler4" ,
342+ param : { } ,
343+ body : { } ,
344+ } ) ;
345+ } ) ;
346+
347+ Deno . test ( "[PATCH] /test/handler4/:bar" , async ( ) => {
348+ const handler4Spy = spy ( spyTemplate , "handler4" ) ;
349+ const catchAllSpy = spy ( spyTemplate , "catchAll" ) ;
350+
351+ const req = await superoak ( app ) ;
352+ const res = await req . patch ( "/test/handler4/bob" ) . send ( { bob : true } ) ;
353+
354+ assertSpyCalls ( handler4Spy , 1 ) ;
355+ assertSpyCallArgs ( handler4Spy , 0 , [
356+ "PATCH" ,
357+ "/test/handler4/bob" ,
358+ "/test/handler4/:bar" ,
359+ { bar : "bob" } ,
360+ ] ) ;
361+ assertSpyCalls ( catchAllSpy , 1 ) ;
362+
363+ handler4Spy . restore ( ) ;
364+ catchAllSpy . restore ( ) ;
365+
366+ assertEquals ( res . body , {
367+ method : "PATCH" ,
368+ reqPath : "/test/handler4/bob" ,
369+ regPath : "/test/handler4/:bar" ,
370+ param : { bar : "bob" } ,
371+ body : { bob : true } ,
372+ } ) ;
373+ } ) ;
0 commit comments