This commit is contained in:
Bastian Wagner
2026-06-18 19:02:49 +02:00
parent 63ee20bcd8
commit f86416e8bc
2 changed files with 193 additions and 1 deletions

View File

@@ -14,6 +14,7 @@ describe('AssistantService', () => {
};
let listsService: {
listLists: jest.Mock;
addItem: jest.Mock;
};
let service: AssistantService;
@@ -30,6 +31,7 @@ describe('AssistantService', () => {
};
listsService = {
listLists: jest.fn(),
addItem: jest.fn(),
};
service = new AssistantService(
chatLogsRepository as never,
@@ -210,7 +212,7 @@ describe('AssistantService', () => {
mockMistralResponse(providerResponse);
await service.chat('user-1', {
messages: [{ role: 'user', content: 'Fuege hier Brot hinzu' }],
messages: [{ role: 'user', content: 'Was ist hier wichtig?' }],
context: {
page: 'list_detail',
route: '/lists/list-1',
@@ -283,6 +285,84 @@ describe('AssistantService', () => {
});
});
it('adds list items locally when the user writes onto the current list', async () => {
const updatedList = {
id: 'list-1',
ownerId: 'user-1',
accessRole: 'owner',
name: 'Einkauf',
kind: 'shopping',
items: [
{
id: 'item-1',
title: 'Brot',
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',
};
listsService.addItem.mockResolvedValue(updatedList);
const result = await service.chat('user-1', {
messages: [{ role: 'user', content: 'Fuege hier Brot hinzu' }],
context: {
page: 'list_detail',
route: '/lists/list-1',
list: {
id: 'list-1',
ownerId: 'user-1',
accessRole: 'owner',
name: 'Einkauf',
kind: 'shopping',
items: [],
collaborators: [],
createdAt: '2026-06-12T00:00:00.000Z',
updatedAt: '2026-06-12T00:00:00.000Z',
},
},
});
expect(global.fetch).not.toHaveBeenCalled();
expect(listsService.addItem).toHaveBeenCalledWith('user-1', 'list-1', {
title: 'Brot',
});
expect(result).toEqual({
message: {
role: 'assistant',
content: 'Ich habe **Brot** zu **Einkauf** hinzugefuegt.',
},
actions: [
{
type: 'list.item_added',
listId: 'list-1',
itemTitle: 'Brot',
list: updatedList,
},
],
});
expect(listRealtimeService.publishSnapshot).toHaveBeenCalledWith(
'user-1',
updatedList,
);
expect(chatLogsRepository.save).toHaveBeenCalledWith(
expect.objectContaining({
provider: 'listify',
endpoint: 'local:addItem',
requestPayload: expect.objectContaining({
intent: 'list.add_item',
listId: 'list-1',
itemTitle: 'Brot',
}),
}),
);
});
it('logs full failed provider responses before throwing', async () => {
const providerResponse = {
message: 'connector failed',