@@ -14,7 +14,9 @@ describe('Elysia adapter tests - rpc handler', () => {
14
14
it ( 'run hooks regular json' , async ( ) => {
15
15
const { prisma, zodSchemas } = await loadSchema ( schema ) ;
16
16
17
- const handler = await createElysiaApp ( createElysiaHandler ( { getPrisma : ( ) => prisma , zodSchemas } ) ) ;
17
+ const handler = await createElysiaApp (
18
+ createElysiaHandler ( { getPrisma : ( ) => prisma , zodSchemas, basePath : '/api' } )
19
+ ) ;
18
20
19
21
let r = await handler ( makeRequest ( 'GET' , makeUrl ( '/api/post/findMany' , { where : { id : { equals : '1' } } } ) ) ) ;
20
22
expect ( r . status ) . toBe ( 200 ) ;
@@ -88,6 +90,7 @@ describe('Elysia adapter tests - rpc handler', () => {
88
90
const handler = await createElysiaApp (
89
91
createElysiaHandler ( {
90
92
getPrisma : ( ) => prisma ,
93
+ basePath : '/api' ,
91
94
modelMeta : require ( path . join ( projectDir , './zen/model-meta' ) ) . default ,
92
95
zodSchemas : require ( path . join ( projectDir , './zen/zod' ) ) ,
93
96
} )
@@ -119,6 +122,7 @@ describe('Elysia adapter tests - rest handler', () => {
119
122
const handler = await createElysiaApp (
120
123
createElysiaHandler ( {
121
124
getPrisma : ( ) => prisma ,
125
+ basePath : '/api' ,
122
126
handler : Rest ( { endpoint : 'http://localhost/api' } ) ,
123
127
modelMeta,
124
128
zodSchemas,
@@ -173,8 +177,15 @@ describe('Elysia adapter tests - rest handler', () => {
173
177
} ) ;
174
178
175
179
function makeRequest ( method : string , path : string , body ?: any ) {
176
- const payload = body ? JSON . stringify ( body ) : undefined ;
177
- return new Request ( `http://localhost${ path } ` , { method, body : payload } ) ;
180
+ if ( body ) {
181
+ return new Request ( `http://localhost${ path } ` , {
182
+ method,
183
+ body : JSON . stringify ( body ) ,
184
+ headers : { 'Content-Type' : 'application/json' } ,
185
+ } ) ;
186
+ } else {
187
+ return new Request ( `http://localhost${ path } ` , { method } ) ;
188
+ }
178
189
}
179
190
180
191
async function unmarshal ( r : Response , useSuperJson = false ) {
@@ -186,4 +197,4 @@ async function createElysiaApp(middleware: (app: Elysia) => Promise<Elysia>) {
186
197
const app = new Elysia ( ) ;
187
198
await middleware ( app ) ;
188
199
return app . handle ;
189
- }
200
+ }
0 commit comments