7e8f4859cd
- Add ADR-036 unified OCR architecture (typhoon-ocr via Ollama) - Extend AI execution profiles for OCR sandbox configuration - Add comprehensive frontend test coverage (components, hooks, services) - Add backend test coverage for document-numbering services - Update OCR sidecar with typhoon-ocr integration - Add AI policy service and execution profile management - Update AGENTS.md and architecture documentation
51 lines
2.3 KiB
TypeScript
51 lines
2.3 KiB
TypeScript
// File: frontend/lib/services/__tests__/search.service.test.ts
|
|
// Change Log:
|
|
// - 2026-06-13: Initial creation - test coverage for searchService
|
|
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import apiClient from '@/lib/api/client';
|
|
import { searchService } from '../search.service';
|
|
|
|
describe('searchService', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
describe('search', () => {
|
|
it('ควรส่งคำขอ GET /search พร้อมข้อมูลการค้นหาสำเร็จ', async () => {
|
|
const mockResult = { items: [{ publicId: '019505a1-7c3e-7000-8000-doc111111111', title: 'Test doc' }] };
|
|
vi.mocked(apiClient.get).mockResolvedValue({ data: mockResult });
|
|
const query = { q: 'test', limit: 10, offset: 0 };
|
|
const result = await searchService.search(query);
|
|
expect(apiClient.get).toHaveBeenCalledWith('/search', { params: query });
|
|
expect(result).toEqual(mockResult);
|
|
});
|
|
});
|
|
|
|
describe('suggest', () => {
|
|
it('ควรดึงข้อมูล suggest และแกะค่า items ออกมาสำเร็จ', async () => {
|
|
const mockResult = { items: ['test1', 'test2'] };
|
|
vi.mocked(apiClient.get).mockResolvedValue({ data: mockResult });
|
|
const result = await searchService.suggest('test');
|
|
expect(apiClient.get).toHaveBeenCalledWith('/search', { params: { q: 'test', limit: 5 } });
|
|
expect(result).toEqual(['test1', 'test2']);
|
|
});
|
|
|
|
it('ควรคืนค่า raw response ใน suggest หากไม่มีฟิลด์ items', async () => {
|
|
const mockResult = ['test1', 'test2'];
|
|
vi.mocked(apiClient.get).mockResolvedValue({ data: mockResult });
|
|
const result = await searchService.suggest('test');
|
|
expect(result).toEqual(['test1', 'test2']);
|
|
});
|
|
});
|
|
|
|
describe('reindex', () => {
|
|
it('ควรส่งคำขอ POST เพื่อสั่ง reindex สำเร็จ', async () => {
|
|
vi.mocked(apiClient.post).mockResolvedValue({ data: { success: true } });
|
|
const result = await searchService.reindex('correspondence');
|
|
expect(apiClient.post).toHaveBeenCalledWith('/search/reindex', { type: 'correspondence' });
|
|
expect(result).toEqual({ success: true });
|
|
});
|
|
});
|
|
});
|