ruvector/studio/lib/api/rate.test.ts
rUv 814f595995 feat(studio): Add complete RuVector Studio application
Major additions:
- Complete Next.js studio application with 1600+ components
- Docker support (Dockerfile.combined, docker-compose.yml)
- GCP deployment documentation and benchmarks
- SQL benchmark scripts for performance testing
- Sentry integration for monitoring
- Comprehensive test suite and mocks

Studio features:
- Dashboard and admin interfaces
- Data visualization components
- Authentication and user management
- API integration with RuVector backend
- Static data and public assets

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-06 23:04:48 +00:00

74 lines
1.7 KiB
TypeScript

import { expect, test, vi } from 'vitest'
// End of third-party imports
import rate from '../../pages/api/ai/feedback/rate'
import { sanitizeMessagePart } from '../ai/tools/tool-sanitizer'
vi.mock('../ai/tools/tool-sanitizer', () => ({
sanitizeMessagePart: vi.fn((part) => part),
}))
test('rate calls the tool sanitizer', async () => {
const mockReq = {
method: 'POST',
headers: {
authorization: 'Bearer test-token',
},
body: {
rating: 'negative',
messages: [
{
role: 'assistant',
parts: [
{
type: 'tool-execute_sql',
state: 'output-available',
output: 'test output',
},
],
},
],
messageId: 'test-message-id',
projectRef: 'test-project',
orgSlug: 'test-org',
reason: 'The response was not helpful',
},
on: vi.fn(),
}
const mockRes = {
status: vi.fn(() => mockRes),
json: vi.fn(() => mockRes),
setHeader: vi.fn(() => mockRes),
}
vi.mock('lib/ai/org-ai-details', () => ({
getOrgAIDetails: vi.fn().mockResolvedValue({
aiOptInLevel: 'schema_and_log_and_data',
isLimited: false,
}),
}))
vi.mock('lib/ai/model', () => ({
getModel: vi.fn().mockResolvedValue({
model: {},
error: null,
}),
}))
vi.mock('ai', () => ({
generateObject: vi.fn().mockResolvedValue({
object: {
category: 'sql_generation',
},
}),
}))
vi.mock('components/ui/AIAssistantPanel/Message.utils', () => ({
rateMessageResponseSchema: {},
}))
await rate(mockReq as any, mockRes as any)
expect(sanitizeMessagePart).toHaveBeenCalled()
})