@@ -14,6 +14,19 @@ class TestMastraServer extends MastraServer<any, any, any> {
1414 registerContextMiddleware = vi . fn ( ) ;
1515 registerAuthMiddleware = vi . fn ( ) ;
1616 registerHttpLoggingMiddleware = vi . fn ( ) ;
17+
18+ buildCustomRouteHandlerForTest ( ) {
19+ return this . buildCustomRouteHandler ( ) ;
20+ }
21+
22+ handleCustomRouteRequestForTest (
23+ url : string ,
24+ method : string ,
25+ headers : Record < string , string | string [ ] | undefined > ,
26+ body : unknown ,
27+ ) {
28+ return this . handleCustomRouteRequest ( url , method , headers , body ) ;
29+ }
1730}
1831
1932function createMockFGAProvider ( authorized = true ) : IFGAProvider {
@@ -24,6 +37,45 @@ function createMockFGAProvider(authorized = true): IFGAProvider {
2437 } ;
2538}
2639
40+ describe ( 'custom route forwarding' , ( ) => {
41+ it ( 'should forward DELETE JSON bodies to custom routes' , async ( ) => {
42+ const mastra = new Mastra ( {
43+ logger : false ,
44+ server : {
45+ apiRoutes : [
46+ {
47+ path : '/items/:id' ,
48+ method : 'DELETE' ,
49+ handler : async c => {
50+ const body = await c . req . json ( ) ;
51+ const { id } = c . req . param ( ) ;
52+
53+ return c . json ( { deleted : id , reason : body . reason } ) ;
54+ } ,
55+ } ,
56+ ] ,
57+ } ,
58+ } ) ;
59+ const adapter = new TestMastraServer ( { app : { } , mastra } ) ;
60+
61+ await expect ( adapter . buildCustomRouteHandlerForTest ( ) ) . resolves . toBe ( true ) ;
62+
63+ const response = await adapter . handleCustomRouteRequestForTest (
64+ 'http://localhost/items/123' ,
65+ 'DELETE' ,
66+ { 'content-type' : 'application/json' } ,
67+ { reason : 'no longer needed' } ,
68+ ) ;
69+
70+ expect ( response ) . not . toBeNull ( ) ;
71+ expect ( response ! . status ) . toBe ( 200 ) ;
72+ await expect ( response ! . json ( ) ) . resolves . toEqual ( {
73+ deleted : '123' ,
74+ reason : 'no longer needed' ,
75+ } ) ;
76+ } ) ;
77+ } ) ;
78+
2779describe ( 'FGA Middleware - checkRouteFGA' , ( ) => {
2880 let checkRouteFGA : (
2981 mastra : any ,
0 commit comments