|
| 1 | +import { describe, expect, it } from 'vitest' |
| 2 | +import { WealthboxBlock } from '@/blocks/blocks/wealthbox' |
| 3 | +import { wealthboxReadNoteTool } from '@/tools/wealthbox/read_note' |
| 4 | +import { wealthboxWriteTaskTool } from '@/tools/wealthbox/write_task' |
| 5 | + |
| 6 | +function mapParams(params: Record<string, unknown>, context?: { operation: string }) { |
| 7 | + const mapper = WealthboxBlock.tools.config?.params |
| 8 | + if (!mapper) throw new Error('Wealthbox block has no params mapper') |
| 9 | + return { ...params, ...mapper(params, context) } |
| 10 | +} |
| 11 | + |
| 12 | +function taskBody(params: Record<string, unknown>) { |
| 13 | + const body = wealthboxWriteTaskTool.request.body |
| 14 | + if (!body) throw new Error('Write task tool has no request body') |
| 15 | + return body(params as Parameters<typeof body>[0]) |
| 16 | +} |
| 17 | + |
| 18 | +describe('Wealthbox Write Task', () => { |
| 19 | + it('sends the block Content field as the task description', () => { |
| 20 | + const params = mapParams({ |
| 21 | + operation: 'write_task', |
| 22 | + oauthCredential: 'cred', |
| 23 | + title: 'Call client', |
| 24 | + dueDate: '2026-01-05 11:00 AM -0500', |
| 25 | + content: 'Review the portfolio', |
| 26 | + contactId: '42', |
| 27 | + }) |
| 28 | + |
| 29 | + expect(taskBody(params)).toMatchObject({ |
| 30 | + name: 'Call client', |
| 31 | + description: 'Review the portfolio', |
| 32 | + linked_to: [{ id: 42, type: 'Contact' }], |
| 33 | + }) |
| 34 | + }) |
| 35 | + |
| 36 | + it('keeps the model description on an agent tool call', () => { |
| 37 | + const params = mapParams( |
| 38 | + { |
| 39 | + oauthCredential: 'cred', |
| 40 | + title: 'Call client', |
| 41 | + dueDate: '2026-01-05 11:00 AM -0500', |
| 42 | + description: 'From the model', |
| 43 | + }, |
| 44 | + { operation: 'write_task' } |
| 45 | + ) |
| 46 | + |
| 47 | + expect(taskBody(params)).toMatchObject({ description: 'From the model' }) |
| 48 | + }) |
| 49 | +}) |
| 50 | + |
| 51 | +describe('Wealthbox Read Note without a note ID', () => { |
| 52 | + it('returns the listed notes from the status_updates array', async () => { |
| 53 | + const transform = wealthboxReadNoteTool.transformResponse |
| 54 | + if (!transform) throw new Error('Read note tool has no transformResponse') |
| 55 | + |
| 56 | + const notes = [{ id: 1, content: 'Spoke with the client' }] |
| 57 | + const result = await transform(Response.json({ status_updates: notes })) |
| 58 | + |
| 59 | + expect(result.output).toMatchObject({ notes, metadata: { totalItems: 1 } }) |
| 60 | + }) |
| 61 | +}) |
0 commit comments