mcp
This commit is contained in:
@@ -9,6 +9,9 @@ describe('AssistantService', () => {
|
||||
create: jest.Mock;
|
||||
save: jest.Mock;
|
||||
};
|
||||
let listRealtimeService: {
|
||||
publishSnapshot: jest.Mock;
|
||||
};
|
||||
let service: AssistantService;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -19,7 +22,13 @@ describe('AssistantService', () => {
|
||||
create: jest.fn((input) => input),
|
||||
save: jest.fn(async (input) => input),
|
||||
};
|
||||
service = new AssistantService(chatLogsRepository as never);
|
||||
listRealtimeService = {
|
||||
publishSnapshot: jest.fn(),
|
||||
};
|
||||
service = new AssistantService(
|
||||
chatLogsRepository as never,
|
||||
listRealtimeService as never,
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -86,6 +95,7 @@ describe('AssistantService', () => {
|
||||
},
|
||||
actions: [],
|
||||
});
|
||||
expect(listRealtimeService.publishSnapshot).not.toHaveBeenCalled();
|
||||
expect(chatLogsRepository.save).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
userId: 'user-1',
|
||||
@@ -129,6 +139,27 @@ describe('AssistantService', () => {
|
||||
});
|
||||
|
||||
it('extracts the final assistant message from multi-completion responses', async () => {
|
||||
const updatedList = {
|
||||
id: 'list-1',
|
||||
ownerId: 'user-1',
|
||||
accessRole: 'owner',
|
||||
name: 'Einkauf',
|
||||
kind: 'shopping',
|
||||
items: [
|
||||
{
|
||||
id: 'item-1',
|
||||
title: 'Milch',
|
||||
required: true,
|
||||
checked: false,
|
||||
position: 0,
|
||||
createdAt: '2026-06-12T00:00:00.000Z',
|
||||
updatedAt: '2026-06-12T00:00:00.000Z',
|
||||
},
|
||||
],
|
||||
collaborators: [],
|
||||
createdAt: '2026-06-12T00:00:00.000Z',
|
||||
updatedAt: '2026-06-12T00:00:00.000Z',
|
||||
};
|
||||
const providerResponse = {
|
||||
id: 'chatcmpl-test',
|
||||
object: 'chat.multi_completion',
|
||||
@@ -144,8 +175,8 @@ describe('AssistantService', () => {
|
||||
id: 'call-1',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'listify_list_existing_lists',
|
||||
arguments: '{"includeItems": false}',
|
||||
name: 'listify_add_list_item',
|
||||
arguments: '{"listId": "list-1", "title": "Milch"}',
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -154,6 +185,14 @@ describe('AssistantService', () => {
|
||||
role: 'tool',
|
||||
index: 1,
|
||||
content: [{ type: 'text', text: '{"lists":[]}' }],
|
||||
tool_call_id: 'call-1',
|
||||
metadata: {
|
||||
mcp_meta: {
|
||||
structuredContent: {
|
||||
list: updatedList,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
@@ -172,6 +211,18 @@ describe('AssistantService', () => {
|
||||
});
|
||||
|
||||
expect(result.message.content).toBe('Hier sind deine bestehenden Listen.');
|
||||
expect(result.actions).toEqual([
|
||||
{
|
||||
type: 'list.item_added',
|
||||
listId: 'list-1',
|
||||
itemTitle: 'Milch',
|
||||
list: updatedList,
|
||||
},
|
||||
]);
|
||||
expect(listRealtimeService.publishSnapshot).toHaveBeenCalledWith(
|
||||
'user-1',
|
||||
updatedList,
|
||||
);
|
||||
expect(chatLogsRepository.save).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
responsePayload: providerResponse,
|
||||
|
||||
Reference in New Issue
Block a user