spec/punchblock/translator/asterisk/component/output_spec.rb in punchblock-2.6.0 vs spec/punchblock/translator/asterisk/component/output_spec.rb in punchblock-2.7.0
- old
+ new
@@ -28,10 +28,12 @@
let :command_options do
{ :render_document => {:value => ssml_doc}, renderer: renderer }
end
+ let(:ast13mode) { false }
+
subject { Output.new original_command, mock_call }
def expect_answered(value = true)
allow(mock_call).to receive(:answered?).and_return(value)
end
@@ -931,14 +933,19 @@
end
end
describe 'interrupt_on' do
def ami_event_for_dtmf(digit, position)
- RubyAMI::Event.new 'DTMF',
- 'Digit' => digit.to_s,
- 'Start' => position == :start ? 'Yes' : 'No',
- 'End' => position == :end ? 'Yes' : 'No'
+ if ast13mode
+ RubyAMI::Event.new 'DTMF' + (position == :start ? 'Begin' : '') + (position == :end ? 'End' : ''),
+ 'Digit' => digit.to_s
+ else
+ RubyAMI::Event.new 'DTMF',
+ 'Digit' => digit.to_s,
+ 'Start' => position == :start ? 'Yes' : 'No',
+ 'End' => position == :end ? 'Yes' : 'No'
+ end
end
def send_ami_events_for_dtmf(digit)
mock_call.process_ami_event ami_event_for_dtmf(digit, :start)
mock_call.process_ami_event ami_event_for_dtmf(digit, :end)
@@ -1662,14 +1669,19 @@
end
end
describe 'interrupt_on' do
def ami_event_for_dtmf(digit, position)
- RubyAMI::Event.new 'DTMF',
- 'Digit' => digit.to_s,
- 'Start' => position == :start ? 'Yes' : 'No',
- 'End' => position == :end ? 'Yes' : 'No'
+ if ast13mode
+ RubyAMI::Event.new 'DTMF' + (position == :start ? 'Begin' : '') + (position == :end ? 'End' : ''),
+ 'Digit' => digit.to_s
+ else
+ RubyAMI::Event.new 'DTMF',
+ 'Digit' => digit.to_s,
+ 'Start' => position == :start ? 'Yes' : 'No',
+ 'End' => position == :end ? 'Yes' : 'No'
+ end
end
def send_ami_events_for_dtmf(digit)
mock_call.process_ami_event ami_event_for_dtmf(digit, :start)
mock_call.process_ami_event ami_event_for_dtmf(digit, :end)
@@ -1734,27 +1746,38 @@
expect_answered
expect(mock_call).to receive(:execute_agi_command).once.with('EXEC Playback', audio_filename)
expect(subject).to receive(:send_finish).and_return nil
end
+ def send_correct_complete_event
+ expect(mock_call).to receive :redirect_back
+ subject.execute
+ expect(original_command.response(0.1)).to be_a Ref
+ expect(original_command).not_to be_complete
+ send_ami_events_for_dtmf 1
+ mock_call.process_ami_event ami_event
+ sleep 0.2
+ expect(original_command).to be_complete
+ expect(reason).to be_a Punchblock::Component::Output::Complete::Finish
+ end
+
context "when a DTMF digit is received" do
it "sends the correct complete event" do
- expect(mock_call).to receive :redirect_back
- subject.execute
- expect(original_command.response(0.1)).to be_a Ref
- expect(original_command).not_to be_complete
- send_ami_events_for_dtmf 1
- mock_call.process_ami_event ami_event
- sleep 0.2
- expect(original_command).to be_complete
- expect(reason).to be_a Punchblock::Component::Output::Complete::Finish
+ send_correct_complete_event
end
it "redirects the call back to async AGI" do
expect(mock_call).to receive(:redirect_back).once
subject.execute
expect(original_command.response(0.1)).to be_a Ref
send_ami_events_for_dtmf 1
+ end
+
+ context 'with an Asterisk 13 DTMFEnd event' do
+ let(:ast13mode) { true }
+ it "sends the correct complete event" do
+ send_correct_complete_event
+ end
end
end
end
context "set to :voice" do