Skip to content

Commit 4e24b2c

Browse files
committed
fix tests
1 parent 1e79561 commit 4e24b2c

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

packages/server/tests/adapter/elysia.test.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ describe('Elysia adapter tests - rpc handler', () => {
1414
it('run hooks regular json', async () => {
1515
const { prisma, zodSchemas } = await loadSchema(schema);
1616

17-
const handler = await createElysiaApp(createElysiaHandler({ getPrisma: () => prisma, zodSchemas }));
17+
const handler = await createElysiaApp(
18+
createElysiaHandler({ getPrisma: () => prisma, zodSchemas, basePath: '/api' })
19+
);
1820

1921
let r = await handler(makeRequest('GET', makeUrl('/api/post/findMany', { where: { id: { equals: '1' } } })));
2022
expect(r.status).toBe(200);
@@ -88,6 +90,7 @@ describe('Elysia adapter tests - rpc handler', () => {
8890
const handler = await createElysiaApp(
8991
createElysiaHandler({
9092
getPrisma: () => prisma,
93+
basePath: '/api',
9194
modelMeta: require(path.join(projectDir, './zen/model-meta')).default,
9295
zodSchemas: require(path.join(projectDir, './zen/zod')),
9396
})
@@ -119,6 +122,7 @@ describe('Elysia adapter tests - rest handler', () => {
119122
const handler = await createElysiaApp(
120123
createElysiaHandler({
121124
getPrisma: () => prisma,
125+
basePath: '/api',
122126
handler: Rest({ endpoint: 'http://localhost/api' }),
123127
modelMeta,
124128
zodSchemas,
@@ -173,8 +177,15 @@ describe('Elysia adapter tests - rest handler', () => {
173177
});
174178

175179
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+
}
178189
}
179190

180191
async function unmarshal(r: Response, useSuperJson = false) {
@@ -186,4 +197,4 @@ async function createElysiaApp(middleware: (app: Elysia) => Promise<Elysia>) {
186197
const app = new Elysia();
187198
await middleware(app);
188199
return app.handle;
189-
}
200+
}

0 commit comments

Comments
 (0)