Files
makelore/tests/unit/coding-projects-facade.test.ts

54 lines
2.0 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest';
const hostApiFetch = vi.hoisted(() => vi.fn());
vi.mock('@/lib/host-api', () => ({ hostApiFetch }));
describe('coding project Host facade', () => {
beforeEach(() => vi.clearAllMocks());
it('uses only the vendor-neutral project metadata routes', async () => {
hostApiFetch
.mockResolvedValueOnce({ projects: [], activeProjectId: null })
.mockResolvedValueOnce({ snapshot: { project: { id: 'project/a' }, config: {} } })
.mockResolvedValueOnce({ conversations: [] })
.mockResolvedValueOnce({ conversation: { id: 'conversation-1' } })
.mockResolvedValueOnce({ conversation: { id: 'conversation-1', title: 'Renamed' } })
.mockResolvedValueOnce({});
const {
createCodingProjectConversation,
getCodingProjectConfig,
listCodingProjectConversations,
listCodingProjects,
patchCodingProjectConversation,
deleteCodingProjectConversation,
} = await import('@/lib/coding-projects');
await listCodingProjects();
await getCodingProjectConfig('project/a');
await listCodingProjectConversations('project/a');
await createCodingProjectConversation({
projectId: 'project/a',
agentId: 'agent-1',
title: '新对话',
});
await patchCodingProjectConversation('conversation/1', { title: 'Renamed', unread: true });
await deleteCodingProjectConversation('conversation/1');
expect(hostApiFetch.mock.calls).toEqual([
['/api/coding/projects'],
['/api/coding/projects/config?projectId=project%2Fa'],
['/api/coding/projects/conversations?projectId=project%2Fa'],
['/api/coding/projects/conversations', {
method: 'POST',
body: JSON.stringify({ projectId: 'project/a', agentId: 'agent-1', title: '新对话' }),
}],
['/api/coding/conversations/conversation%2F1', {
method: 'PATCH',
body: JSON.stringify({ title: 'Renamed', unread: true }),
}],
['/api/coding/conversations/conversation%2F1', { method: 'DELETE' }],
]);
});
});