# frozen_string_literal: true require 'spec_helper' RSpec.describe TwilioBase::Routers::Voice::DirectDial do include Rails.application.routes.url_helpers describe '#route' do context 'protocol is PSTN' do it 'returns dial Twiml' do protocol = TwilioBase::Protocols::Voice::Pstn.new( to: '+1234567890', params: { action_url: 'https://someurl.com', status_callback_url: 'https://somestatusurl.com' } ) direct_dial = described_class.new(protocol: protocol) expected_result = dial_twiml( params: { action_url: protocol.action_url, caller_id: protocol.caller_uuid, endpoint: protocol.endpoint, protocol: protocol.name, status_callback_events: protocol.status_callback_events, status_callback_url: protocol.status_callback_url } ) expect(direct_dial.route).to eq(expected_result) end context 'with yield block' do it 'returns direct diall Twiml using yield block' do protocol = TwilioBase::Protocols::Voice::Pstn.new( params: { action_url: 'https://someurl.com', status_callback_url: 'https://somestatusurl.com' }, to: '+1234567890' ) direct_dial = described_class.new(protocol: protocol) voice_response = Twilio::TwiML::VoiceResponse.new expected_result = dial_twiml( params: { action_url: protocol.action_url, caller_id: protocol.caller_uuid, endpoint: protocol.endpoint, play_urls: '/audio.wav', protocol: protocol.name, status_callback_events: protocol.status_callback_events, status_callback_url: protocol.status_callback_url } ) result = direct_dial.route { voice_response.play(url: '/audio.wav') } expect(result).to eq(expected_result) end end end context 'protocol is Sip' do it 'returns sip dial Twiml' do protocol = TwilioBase::Protocols::Voice::Sip.new( params: { action_url: 'https://someurl.com', sip_endpoint: '124@abc.net', status_callback_url: 'https://somestatusurl.com' }, to: '+442039605098' ) direct_dial = described_class.new(protocol: protocol) expected_result = dial_twiml( params: { action_url: protocol.action_url, caller_id: protocol.caller_uuid, endpoint: protocol.endpoint, protocol: protocol.name, status_callback_url: protocol.status_callback_url, status_callback_events: protocol.status_callback_events } ) expect(direct_dial.route).to eq(expected_result) end end end end