Skip to content

Commit 6716e4c

Browse files
aaronbrezelclaude
andcommitted
fix: remove as-any cast in callGeminiAPI, use CONFIG.MODEL_NAME in test
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c6934e3 commit 6716e4c

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

__tests__/api.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// ── Import after mocks ─────────────────────────────────────────
1515

1616
import { buildGeminiPayload, callGeminiAPI } from "../src/server/api";
17+
import { CONFIG } from "../src/server/config";
1718
import type { GeminiRequest } from "../src/shared/types";
1819

1920
// ── Helpers ────────────────────────────────────────────────────
@@ -124,6 +125,6 @@ describe("callGeminiAPI", () => {
124125
mockFetchResponse({ candidates: [{ content: { parts: [{ text: "ok" }] } }] });
125126
callGeminiAPI(baseReq);
126127
const url = (UrlFetchApp.fetch as jest.Mock).mock.calls[0][0];
127-
expect(url).toContain("gemini-2.0-flash");
128+
expect(url).toContain(CONFIG.MODEL_NAME);
128129
});
129130
});

src/server/api.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,8 @@ export function callGeminiAPI(req: GeminiRequest): string {
6161
const json = JSON.parse(response.getContentText()) as Record<string, unknown>;
6262

6363
if (json.error) throw new Error((json.error as { message: string }).message);
64-
return (json.candidates as any)?.[0]?.content?.parts?.[0]?.text ?? "No response.";
64+
const candidates = json.candidates as
65+
| Array<{ content: { parts: Array<{ text: string }> } }>
66+
| undefined;
67+
return candidates?.[0]?.content?.parts?.[0]?.text ?? "No response.";
6568
}

0 commit comments

Comments
 (0)