diff --git a/src/core/definer.test.ts b/src/core/definer.test.ts index c5633da..213860f 100644 --- a/src/core/definer.test.ts +++ b/src/core/definer.test.ts @@ -43,6 +43,46 @@ describe("defineRoute", () => { expect(response.status).toBe(200); }); + it("should pass Xquik search query parameters to a GET action", async () => { + const queryParams = z.object({ + q: z.string().min(1), + queryType: z.enum(["Latest", "Top"]).optional(), + limit: z.coerce.number().int().min(1).max(100).optional(), + }); + const route = defineRoute({ + operationId: "searchTweets", + method: "GET", + summary: "Search Tweets", + description: "Search public X posts", + tags: ["X"], + queryParams, + action: mockAction, + responses: { + 200: { description: "Search results" }, + }, + }); + const request = { + ...mockRequest, + url: "https://xquik.com/api/v1/x/tweets/search?q=openapi&queryType=Latest&limit=20", + }; + + mockAction.mockResolvedValue(new Response("Success")); + + const response = await route.GET(request as unknown as Request, { params: Promise.resolve({}) }); + + expect(mockAction).toHaveBeenCalledWith({ + pathParams: null, + queryParams: { + q: "openapi", + queryType: "Latest", + limit: 20, + }, + body: null, + }, request); + expect(response).toBeInstanceOf(Response); + expect(response.status).toBe(200); + }); + it("should handle a POST route with pathParams and body", async () => { const pathSchema = z.object({ id: z.string() }); const bodySchema = z.object({ name: z.string() });