This commit is contained in:
Bastian Wagner
2026-06-18 17:12:59 +02:00
parent 85a43d1b08
commit 63ee20bcd8
2 changed files with 196 additions and 3 deletions

View File

@@ -12,6 +12,9 @@ describe('AssistantService', () => {
let listRealtimeService: {
publishSnapshot: jest.Mock;
};
let listsService: {
listLists: jest.Mock;
};
let service: AssistantService;
beforeEach(() => {
@@ -25,9 +28,13 @@ describe('AssistantService', () => {
listRealtimeService = {
publishSnapshot: jest.fn(),
};
listsService = {
listLists: jest.fn(),
};
service = new AssistantService(
chatLogsRepository as never,
listRealtimeService as never,
listsService as never,
);
});
@@ -114,6 +121,82 @@ describe('AssistantService', () => {
);
});
it('answers open list read requests locally without calling Mistral', async () => {
listsService.listLists.mockResolvedValue([
{
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',
},
{
id: 'item-2',
title: 'Brot',
required: true,
checked: true,
position: 1,
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',
},
{
id: 'list-2',
ownerId: 'user-1',
accessRole: 'owner',
name: 'Fertig',
kind: 'todo',
items: [
{
id: 'item-3',
title: 'Done',
required: true,
checked: true,
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 result = await service.chat('user-1', {
messages: [{ role: 'user', content: 'Zeige mir meine offenen Listen' }],
});
expect(global.fetch).not.toHaveBeenCalled();
expect(result.message.content).toContain('Du hast 1 offene Liste');
expect(result.message.content).toContain('**Einkauf**');
expect(result.message.content).toContain('Milch');
expect(result.message.content).not.toContain('Fertig');
expect(chatLogsRepository.save).toHaveBeenCalledWith(
expect.objectContaining({
userId: 'user-1',
provider: 'listify',
endpoint: 'local:listLists',
agentId: null,
statusCode: 200,
assistantContent: expect.stringContaining('Einkauf'),
}),
);
});
it('adds a normalized list context system message when context is present', async () => {
const providerResponse = {
choices: [