feat: 集成 AI 对话与只读查询工具
This commit is contained in:
39
apps/admin/src/components/AiChat/api.integration.test.ts
Normal file
39
apps/admin/src/components/AiChat/api.integration.test.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import api from '../../api';
|
||||
import { aiChatApi } from './api';
|
||||
|
||||
describe('AI chat API adapter', () => {
|
||||
afterEach(() => vi.restoreAllMocks());
|
||||
|
||||
it('unwraps the backend success/data response', async () => {
|
||||
vi.spyOn(api, 'get').mockResolvedValue({
|
||||
success: true,
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
title: '会话',
|
||||
createdAt: '2026-07-23T00:00:00.000Z',
|
||||
updatedAt: '2026-07-23T00:00:00.000Z',
|
||||
lastMessageAt: null,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await expect(aiChatApi.listConversations()).resolves.toMatchObject([{ id: 1, title: '会话' }]);
|
||||
});
|
||||
|
||||
it('loads every history page in chronological page order', async () => {
|
||||
vi.spyOn(api, 'get')
|
||||
.mockResolvedValueOnce({
|
||||
success: true,
|
||||
data: { items: [{ id: 1 }], total: 101, page: 1, limit: 100 },
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
success: true,
|
||||
data: { items: [{ id: 101 }], total: 101, page: 2, limit: 100 },
|
||||
});
|
||||
|
||||
const page = await aiChatApi.listMessages(3);
|
||||
expect(page.items.map((item) => item.id)).toEqual([1, 101]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user