From 1421a222190e0e8a742aba1dcc4c45ed363090a8 Mon Sep 17 00:00:00 2001 From: kriptoburak Date: Thu, 2 Jul 2026 20:48:21 +0300 Subject: [PATCH] test: cover Xquik search fetcher generation --- .../src/generators/generateFetchers.test.ts | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/plugins/typescript/src/generators/generateFetchers.test.ts b/plugins/typescript/src/generators/generateFetchers.test.ts index d36a5a6..15bef65 100644 --- a/plugins/typescript/src/generators/generateFetchers.test.ts +++ b/plugins/typescript/src/generators/generateFetchers.test.ts @@ -111,6 +111,93 @@ describe("generateFetchers", () => { `); }); + it("should generate variables for the Xquik search query", async () => { + const writeFile = createWriteFileMock(); + const xquikDocument: OpenAPIObject = { + openapi: "3.0.0", + info: { + title: "Xquik API", + version: "1.0.0", + }, + components: { + securitySchemes: { + apiKey: { + type: "apiKey", + in: "header", + name: "x-api-key", + }, + }, + }, + paths: { + "/api/v1/x/tweets/search": { + get: { + operationId: "searchTweets", + description: "Search tweets", + security: [{ apiKey: [] }], + parameters: [ + { + name: "q", + in: "query", + required: true, + schema: { type: "string" }, + }, + { + name: "limit", + in: "query", + required: false, + schema: { type: "integer", minimum: 1, maximum: 100 }, + }, + ], + responses: { + "200": { + description: "Search results", + content: { + "application/json": { + schema: { + type: "object", + required: ["data"], + properties: { + data: { + type: "array", + items: { + type: "object", + required: ["id", "text"], + properties: { + id: { type: "string" }, + text: { type: "string" }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }; + + await generateFetchers( + { + openAPIDocument: xquikDocument, + writeFile, + readFile: async () => "", + existsFile: () => true, + }, + config + ); + + const output = writeFile.mock.calls[0][1]; + expect(output).toContain("export type SearchTweetsQueryParams = {"); + expect(output).toContain("export type SearchTweetsVariables = {"); + expect(output).toContain("queryParams: SearchTweetsQueryParams;"); + expect(output).toContain("q: string;"); + expect(output).toContain("limit?: number;"); + expect(output).toContain('url: "/api/v1/x/tweets/search"'); + }); + it("should generate fetchers without prefix", async () => { const writeFile = createWriteFileMock();