'use strict'; const test = require('node:test'); const assert = require('node:assert/strict'); const { attachChatToOpportunity } = require('../src/chat-log'); test('chat-log: attaches full conversation as opportunity note', async () => { const calls = []; const client = { async getMessages() { return [ { id: 1, sender_type: 'contact', text_content: 'I want 500 rings', private: false }, { id: 2, sender_type: 'agent', text_content: '

Sure, here are options.

', private: false }, ]; }, }; const twenty = { async createNote(text) { calls.push(['note', text]); return 'note-1'; }, async linkNoteToOpportunity(note, opp) { calls.push(['link', note, opp]); }, }; const id = await attachChatToOpportunity({ client, twenty, convUuid: 'c1', opportunityId: 'o1' }); assert.equal(id, 'note-1'); assert.match(calls[0][1], /Customer\] I want 500 rings/); assert.match(calls[0][1], /Agent\] Sure, here are options/); assert.deepEqual(calls[1], ['link', 'note-1', 'o1']); });