Files
ims/tests/api/incidents/quality-check.test.ts
adminandClaude Haiku 4.5 4f75dd5887 feat(ai): switch from DeepSeek to local Ollama (qwen3:14b)
- Point AI client to localhost:11434/v1 (Ollama)
- Remove DeepSeek API key dependency
- Update model name to qwen3:14b across all routes
- Update test mocks to use createLocalLLMClient
- Removes need for DEEPSEEK_API_KEY setting

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 11:34:05 +08:00

72 lines
2.3 KiB
TypeScript

import { describe, it, expect, vi } from 'vitest'
const qualityOutput = { score: 8, passes: true, feedback: 'Clear description.', suggestions: [] }
vi.mock('@/lib/supabase/server', () => ({
createClient: vi.fn().mockResolvedValue({
auth: {
getUser: vi.fn().mockResolvedValue({ data: { user: { id: 'user-1' } }, error: null }),
},
from: vi.fn().mockReturnValue({
select: vi.fn().mockReturnThis(),
eq: vi.fn().mockReturnThis(),
gte: vi.fn().mockResolvedValue({ count: 0 }),
}),
rpc: vi.fn().mockResolvedValue({ error: null }),
}),
}))
vi.mock('@/lib/claude/client', () => ({
createLocalLLMClient: vi.fn().mockReturnValue({
chat: {
completions: {
create: vi.fn().mockResolvedValue({
choices: [{
message: {
tool_calls: [{
type: 'function',
function: {
name: 'assess_quality',
arguments: JSON.stringify(qualityOutput),
},
}],
},
}],
}),
},
},
}),
}))
describe('POST /api/incidents/ai/quality-check', () => {
it('returns 422 when description is missing', async () => {
const { POST } = await import('@/app/api/incidents/ai/quality-check/route')
const req = new Request('http://localhost/api/incidents/ai/quality-check', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ incident_type: 'injury' }),
})
const res = await POST(req as never)
expect(res.status).toBe(422)
})
it('returns quality assessment from local LLM', async () => {
const { POST } = await import('@/app/api/incidents/ai/quality-check/route')
const req = new Request('http://localhost/api/incidents/ai/quality-check', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
description: 'Forklift operator collided with racking in zone B at 14:30, injuring left arm.',
incident_type: 'injury',
}),
})
const res = await POST(req as never)
expect(res.status).toBe(200)
const body = await res.json()
expect(body).toHaveProperty('score')
expect(body).toHaveProperty('passes')
expect(body).toHaveProperty('feedback')
expect(body).toHaveProperty('suggestions')
})
})