---
phase: 18-api-route-tests
plan: 03
type: execute
---
Add tests for generate API route covering Gemini provider path.
Purpose: Test image generation with Gemini, the default and most common path.
Output: Tests for /api/generate Gemini path with mocked GoogleGenAI SDK.
~/.claude/get-shit-done/workflows/execute-phase.md
~/.claude/get-shit-done/templates/summary.md
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md
**Route to test:**
@src/app/api/generate/route.ts
**Test patterns from previous plans:**
@src/app/api/llm/__tests__/route.test.ts
Task 1: Create generate route tests for Gemini provider
src/app/api/generate/__tests__/route.test.ts
Create tests for /api/generate route Gemini (default) path:
- POST: Generates image successfully with prompt only
- POST: Generates image with prompt and input images
- POST: Applies aspect ratio config
- POST: Applies resolution config for nano-banana-pro model
- POST: Applies Google Search tool for nano-banana-pro
- POST: Rejects missing prompt (when no images/dynamicInputs)
- POST: Returns 500 when API key missing
- POST: Returns 429 on rate limit errors
- POST: Handles no candidates in response
- POST: Handles text-only response (no image)
Mock @google/genai GoogleGenAI class:
```typescript
vi.mock("@google/genai", () => ({
GoogleGenAI: vi.fn().mockImplementation(() => ({
models: {
generateContent: vi.fn().mockResolvedValue({
candidates: [{
content: {
parts: [{
inlineData: {
mimeType: "image/png",
data: "base64ImageData",
},
}],
},
}],
}),
},
})),
}));
```
Test default model selection (nano-banana-pro when not specified).
Test X-Gemini-API-Key header takes precedence over env var.
Test response structure matches GenerateResponse type.
npm test -- src/app/api/generate/__tests__/route.test.ts --testNamePattern="Gemini"
Gemini provider tests pass covering success, config options, and error paths
Task 2: Add generate route validation and edge case tests
src/app/api/generate/__tests__/route.test.ts
Add validation and edge case tests to existing test file:
- POST: Accepts request with only images (image-to-image)
- POST: Accepts request with dynamicInputs containing prompt
- POST: Accepts request with dynamicInputs containing image frames
- POST: Handles large response payloads (warns but succeeds)
- POST: Extracts MIME type from data URL correctly
- POST: Falls back to image/png for raw base64
Test provider routing:
- POST: Routes to Gemini when no selectedModel provided
- POST: Routes to Gemini when selectedModel.provider is "gemini"
Test the getInputMappingFromSchema helper (if exported or through behavior):
- Verify schema parsing maps generic names to model-specific params
- Test array detection for multi-image inputs
Do NOT test Replicate/fal paths in this plan - those are in 18-04.
npm test -- src/app/api/generate/__tests__/route.test.ts
All Gemini path tests pass including validation and edge cases
Before declaring plan complete:
- [ ] `npm test -- src/app/api/generate/__tests__/route.test.ts` passes
- [ ] Tests cover Gemini provider path only (Replicate/fal in next plan)
- [ ] Config options tested (aspectRatio, resolution, googleSearch)
- [ ] Error handling tested
- [ ] No TypeScript errors
- All tasks completed
- All verification checks pass
- Gemini path thoroughly tested
- Input validation tested