Files
gongxue-base/apps/admin/src/components/AiChat/api.integration.test.ts

40 lines
1.1 KiB
TypeScript

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]);
});
});