/** * Tests for Tavus Recording Configuration * * Tests that recording properties are correctly included in conversation creation. */ import { TavusClient, TavusConfig, ConversationRequest } from '../libs/shared/utils/src/api-clients/tavus-client'; // Mock fetch for testing const mockFetch = jest.fn(); global.fetch = mockFetch; describe('Tavus Recording Configuration', () => { let tavusClient: TavusClient; let mockConfig: TavusConfig; beforeEach(() => { // Reset mocks mockFetch.mockClear(); // Create mock config mockConfig = { apiKey: 'test-api-key-123', debug: true, }; // Create client instance tavusClient = new TavusClient(mockConfig); }); describe('Conversation Creation with Recording', () => { beforeEach(async () => { // Mock successful initialization mockFetch.mockResolvedValueOnce({ ok: true, status: 200, json: async () => ({ replicas: [] }), }); await tavusClient.initialize(); }); it('should include recording properties by default', async () => { const mockConversationResponse = { conversation_id: 'c123456', conversation_url: 'https://tavus.daily.co/c123456', status: 'active', replica_id: 'rf4703150052', persona_id: 'p48fdf065d6b', created_at: '2024-01-01T00:00:00Z', }; mockFetch.mockResolvedValueOnce({ ok: true, status: 200, json: async () => mockConversationResponse, }); const conversationRequest: ConversationRequest = { replicaId: 'rf4703150052', personaId: 'p48fdf065d6b', }; await tavusClient.createConversation(conversationRequest); expect(mockFetch).toHaveBeenCalledWith( 'https://tavusapi.com/v2/conversations', expect.objectContaining({ method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': 'test-api-key-123', }, body: JSON.stringify({ replica_id: 'rf4703150052', persona_id: 'p48fdf065d6b', properties: { enable_recording: true, aws_assume_role_arn: "arn:aws:iam::803663093034:role/CVIRecordingRole", recording_s3_bucket_region: "eu-north-1", recording_s3_bucket_name: "buzztrail-tavus-main" }, }), }) ); }); it('should merge custom properties with recording properties', async () => { const mockConversationResponse = { conversation_id: 'c123456', conversation_url: 'https://tavus.daily.co/c123456', status: 'active', replica_id: 'rf4703150052', persona_id: 'p48fdf065d6b', created_at: '2024-01-01T00:00:00Z', }; mockFetch.mockResolvedValueOnce({ ok: true, status: 200, json: async () => mockConversationResponse, }); const conversationRequest: ConversationRequest = { replicaId: 'rf4703150052', personaId: 'p48fdf065d6b', properties: { max_call_duration: 30, language: 'english', enableVideo: true, enableAudio: true, }, }; await tavusClient.createConversation(conversationRequest); expect(mockFetch).toHaveBeenCalledWith( 'https://tavusapi.com/v2/conversations', expect.objectContaining({ method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': 'test-api-key-123', }, body: JSON.stringify({ replica_id: 'rf4703150052', persona_id: 'p48fdf065d6b', properties: { enable_recording: true, aws_assume_role_arn: "arn:aws:iam::803663093034:role/CVIRecordingRole", recording_s3_bucket_region: "eu-north-1", recording_s3_bucket_name: "buzztrail-tavus-main", max_call_duration: 30, language: 'english', enableVideo: true, enableAudio: true, }, }), }) ); }); it('should allow custom properties to override recording properties', async () => { const mockConversationResponse = { conversation_id: 'c123456', conversation_url: 'https://tavus.daily.co/c123456', status: 'active', replica_id: 'rf4703150052', persona_id: 'p48fdf065d6b', created_at: '2024-01-01T00:00:00Z', }; mockFetch.mockResolvedValueOnce({ ok: true, status: 200, json: async () => mockConversationResponse, }); const conversationRequest: ConversationRequest = { replicaId: 'rf4703150052', personaId: 'p48fdf065d6b', properties: { enable_recording: false, // Override default recording_s3_bucket_name: "custom-bucket", // Override default max_call_duration: 60, }, }; await tavusClient.createConversation(conversationRequest); expect(mockFetch).toHaveBeenCalledWith( 'https://tavusapi.com/v2/conversations', expect.objectContaining({ method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': 'test-api-key-123', }, body: JSON.stringify({ replica_id: 'rf4703150052', persona_id: 'p48fdf065d6b', properties: { enable_recording: false, // Should be overridden aws_assume_role_arn: "arn:aws:iam::803663093034:role/CVIRecordingRole", recording_s3_bucket_region: "eu-north-1", recording_s3_bucket_name: "custom-bucket", // Should be overridden max_call_duration: 60, }, }), }) ); }); }); });