spec/punchblock/translator/asterisk/call_spec.rb in punchblock-1.9.0 vs spec/punchblock/translator/asterisk/call_spec.rb in punchblock-1.9.1
- old
+ new
@@ -849,10 +849,31 @@
it "should send an EXEC RINGING AGI command and set the command's response" do
subject.wrapped_object.should_receive(:execute_agi_command).with('EXEC RINGING').and_return code: 200
subject.execute_command command
command.response(0.5).should be true
end
+
+ context "when the AMI commannd raises an error" do
+ let(:message) { 'Some error' }
+ let(:error) { RubyAMI::Error.new.tap { |e| e.message = message } }
+
+ before { subject.wrapped_object.should_receive(:execute_agi_command).and_raise error }
+
+ it "should return an error with the message" do
+ subject.execute_command command
+ command.response(0.5).should be == ProtocolError.new.setup('error', message, subject.id)
+ end
+
+ context "with message 'No such channel'" do
+ let(:message) { 'No such channel' }
+
+ it "should return an :item_not_found event for the call" do
+ subject.execute_command command
+ command.response(0.5).should be == ProtocolError.new.setup(:item_not_found, "Could not find a call with ID #{subject.id}", subject.id)
+ end
+ end
+ end
end
context 'with a reject command' do
let(:command) { Command::Reject.new }
@@ -874,28 +895,91 @@
command.reason = :error
subject.wrapped_object.should_receive(:execute_agi_command).with('EXEC Congestion').and_return code: 200
subject.execute_command command
command.response(0.5).should be true
end
+
+ context "when the AMI commannd raises an error" do
+ let(:message) { 'Some error' }
+ let(:error) { RubyAMI::Error.new.tap { |e| e.message = message } }
+
+ before { subject.wrapped_object.should_receive(:execute_agi_command).and_raise error }
+
+ it "should return an error with the message" do
+ subject.execute_command command
+ command.response(0.5).should be == ProtocolError.new.setup('error', message, subject.id)
+ end
+
+ context "with message 'No such channel'" do
+ let(:message) { 'No such channel' }
+
+ it "should return an :item_not_found event for the call" do
+ subject.execute_command command
+ command.response(0.5).should be == ProtocolError.new.setup(:item_not_found, "Could not find a call with ID #{subject.id}", subject.id)
+ end
+ end
+ end
end
context 'with an answer command' do
let(:command) { Command::Answer.new }
it "should send an ANSWER AGI command and set the command's response" do
subject.wrapped_object.should_receive(:execute_agi_command).with('ANSWER').and_return code: 200
subject.execute_command command
command.response(0.5).should be true
end
+
+ context "when the AMI commannd raises an error" do
+ let(:message) { 'Some error' }
+ let(:error) { RubyAMI::Error.new.tap { |e| e.message = message } }
+
+ before { subject.wrapped_object.should_receive(:execute_agi_command).and_raise error }
+
+ it "should return an error with the message" do
+ subject.execute_command command
+ command.response(0.5).should be == ProtocolError.new.setup('error', message, subject.id)
+ end
+
+ context "with message 'No such channel'" do
+ let(:message) { 'No such channel' }
+
+ it "should return an :item_not_found event for the call" do
+ subject.execute_command command
+ command.response(0.5).should be == ProtocolError.new.setup(:item_not_found, "Could not find a call with ID #{subject.id}", subject.id)
+ end
+ end
+ end
end
context 'with a hangup command' do
let(:command) { Command::Hangup.new }
it "should send a Hangup AMI command and set the command's response" do
ami_client.should_receive(:send_action).once.with('Hangup', 'Channel' => channel, 'Cause' => 16).and_return RubyAMI::Response.new
subject.execute_command command
command.response(0.5).should be true
+ end
+
+ context "when the AMI commannd raises an error" do
+ let(:message) { 'Some error' }
+ let(:error) { RubyAMI::Error.new.tap { |e| e.message = message } }
+
+ before { ami_client.should_receive(:send_action).and_raise error }
+
+ it "should return an error with the message" do
+ subject.execute_command command
+ command.response(0.5).should be == ProtocolError.new.setup('error', message, subject.id)
+ end
+
+ context "with message 'No such channel'" do
+ let(:message) { 'No such channel' }
+
+ it "should return an :item_not_found event for the call" do
+ subject.execute_command command
+ command.response(0.5).should be == ProtocolError.new.setup(:item_not_found, "Could not find a call with ID #{subject.id}", subject.id)
+ end
+ end
end
end
context 'with an AGI command component' do
let :command do