Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/core/definer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() });
Expand Down