@@ -59,29 +59,86 @@ describe('Wealthbox Write Task', () => {
5959} )
6060
6161describe ( 'Wealthbox Read Note without a note ID' , ( ) => {
62- it ( 'returns the listed notes from the status_updates array ' , async ( ) => {
62+ it ( 'returns the listed notes and keeps the raw list body under note ' , async ( ) => {
6363 const transform = wealthboxReadNoteTool . transformResponse
6464 if ( ! transform ) throw new Error ( 'Read note tool has no transformResponse' )
6565
6666 const notes = [ { id : 1 , content : 'Spoke with the client' } ]
6767 const result = await transform ( Response . json ( { status_updates : notes } ) )
6868
69- expect ( result . output ) . toMatchObject ( { notes, metadata : { totalItems : 1 } } )
69+ expect ( result . output ) . toMatchObject ( {
70+ notes,
71+ note : { status_updates : notes } ,
72+ metadata : { totalItems : 1 } ,
73+ } )
7074 } )
7175} )
7276
73- describe ( 'Wealthbox canvas reads without an ID' , ( ) => {
74- it ( 'lists tasks when Read Task has no task ID' , ( ) => {
75- const params = mapParams ( { operation : 'read_task' , oauthCredential : 'cred' , taskId : '' } )
76- const url = wealthboxReadTaskTool . request . url as ( p : Record < string , unknown > ) => string
77+ function readUrl (
78+ tool : typeof wealthboxReadTaskTool ,
79+ operation : 'read_task' | 'read_contact' ,
80+ params : Record < string , unknown >
81+ ) {
82+ const url = tool . request . url
83+ if ( typeof url !== 'function' ) throw new Error ( 'Read tool has no URL builder' )
84+ const id = ( value : unknown ) => ( typeof value === 'string' ? value : undefined )
85+ return url ( {
86+ accessToken : 'token' ,
87+ operation,
88+ taskId : id ( params . taskId ) ,
89+ contactId : id ( params . contactId ) ,
90+ } )
91+ }
92+
93+ describe ( 'Wealthbox reads without an ID' , ( ) => {
94+ it ( 'still requires a task ID on the canvas' , ( ) => {
95+ expect ( ( ) =>
96+ mapParams ( { operation : 'read_task' , oauthCredential : 'cred' , taskId : '' } )
97+ ) . toThrow ( 'Task ID is required' )
98+ } )
99+
100+ it ( 'still requires a contact ID on the canvas' , ( ) => {
101+ expect ( ( ) =>
102+ mapParams ( { operation : 'read_contact' , oauthCredential : 'cred' , contactId : '' } )
103+ ) . toThrow ( 'Contact ID is required' )
104+ } )
105+
106+ it ( 'lists tasks on an agent call with no task ID' , ( ) => {
107+ const params = mapParams ( { oauthCredential : 'cred' } , { operation : 'read_task' } )
108+
109+ expect ( readUrl ( wealthboxReadTaskTool , 'read_task' , params ) ) . toBe (
110+ 'https://api.crmworkspace.com/v1/tasks'
111+ )
112+ } )
113+
114+ it ( 'lists contacts on an agent call with no contact ID' , ( ) => {
115+ const params = mapParams ( { oauthCredential : 'cred' } , { operation : 'read_contact' } )
77116
78- expect ( url ( params ) ) . toBe ( 'https://api.crmworkspace.com/v1/tasks' )
117+ expect ( readUrl ( wealthboxReadContactTool , 'read_contact' , params ) ) . toBe (
118+ 'https://api.crmworkspace.com/v1/contacts'
119+ )
79120 } )
121+ } )
80122
81- it ( 'lists contacts when Read Contact has no contact ID' , ( ) => {
82- const params = mapParams ( { operation : 'read_contact' , oauthCredential : 'cred' , contactId : '' } )
83- const url = wealthboxReadContactTool . request . url as ( p : Record < string , unknown > ) => string
123+ describe ( 'Wealthbox Write Task with a stale Read Task ID' , ( ) => {
124+ it ( 'creates the task instead of posting to the stale task path' , ( ) => {
125+ const params = mapParams ( {
126+ operation : 'write_task' ,
127+ oauthCredential : 'cred' ,
128+ title : 'Call client' ,
129+ dueDate : '2026-01-05 11:00 AM -0500' ,
130+ contactId : '42' ,
131+ taskId : '999' ,
132+ } )
133+ const url = wealthboxWriteTaskTool . request . url
134+ if ( typeof url !== 'function' ) throw new Error ( 'Write task tool has no URL builder' )
84135
85- expect ( url ( params ) ) . toBe ( 'https://api.crmworkspace.com/v1/contacts' )
136+ expect (
137+ url ( {
138+ accessToken : 'token' ,
139+ operation : 'write_task' ,
140+ taskId : typeof params . taskId === 'string' ? params . taskId : undefined ,
141+ } )
142+ ) . toBe ( 'https://api.crmworkspace.com/v1/tasks' )
86143 } )
87144} )
0 commit comments