Skip to content

Commit 8ba3780

Browse files
committed
test: update definer tests
1 parent f0418b6 commit 8ba3780

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

src/core/definer.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,4 +346,62 @@ describe("defineRoute", () => {
346346
expect(await response.text()).toBe("Middleware success");
347347
expect(mockMiddleware).toHaveBeenCalled();
348348
});
349+
350+
it("should handle undefined context", async () => {
351+
const route = defineRoute({
352+
operationId: "noContextExample",
353+
method: "GET",
354+
summary: "No Context Example",
355+
description: "Example route without context",
356+
tags: ["example"],
357+
action: mockAction,
358+
responses: {
359+
200: { description: "OK" },
360+
},
361+
});
362+
363+
mockAction.mockResolvedValue(new Response("Success"));
364+
365+
const nextJsRouteHandler = route.GET;
366+
const response = await nextJsRouteHandler(mockRequest as unknown as Request, undefined as unknown as {
367+
params: Promise<unknown>,
368+
});
369+
370+
expect(mockAction).toHaveBeenCalledWith({
371+
pathParams: null,
372+
queryParams: null,
373+
body: null,
374+
}, mockRequest);
375+
376+
expect(response).toBeInstanceOf(Response);
377+
expect(response.status).toBe(200);
378+
});
379+
380+
it("should handle null context params", async () => {
381+
const route = defineRoute({
382+
operationId: "nullParamsExample",
383+
method: "GET",
384+
summary: "Null Params Example",
385+
description: "Example route with null context params",
386+
tags: ["example"],
387+
action: mockAction,
388+
responses: {
389+
200: { description: "OK" },
390+
},
391+
});
392+
393+
mockAction.mockResolvedValue(new Response("Success"));
394+
395+
const nextJsRouteHandler = route.GET;
396+
const response = await nextJsRouteHandler(mockRequest as unknown as Request, { params: Promise.resolve(null) });
397+
398+
expect(mockAction).toHaveBeenCalledWith({
399+
pathParams: null,
400+
queryParams: null,
401+
body: null,
402+
}, mockRequest);
403+
404+
expect(response).toBeInstanceOf(Response);
405+
expect(response.status).toBe(200);
406+
});
349407
});

0 commit comments

Comments
 (0)