spec/punchblock/translator/asterisk/call_spec.rb in punchblock-2.7.1 vs spec/punchblock/translator/asterisk/call_spec.rb in punchblock-2.7.2
- old
+ new
@@ -834,15 +834,15 @@
let :command do
Punchblock::Command::Join.new call_uri: other_call_id
end
- let :ami_event do
+ let :second_ami_event do
RubyAMI::Event.new 'BridgeEnter',
'Privilege' => "call,all",
'BridgeUniqueid' => bridge_uniqueid,
- 'Channel' => call_channel
+ 'Channel' => other_channel
end
let :expected_joined do
Punchblock::Event::Joined.new target_call_id: subject.id,
call_uri: other_call_id
@@ -852,31 +852,53 @@
Punchblock::Event::Joined.new target_call_id: other_call_id,
call_uri: subject.id
end
before do
- translator.bridges[bridge_uniqueid] = other_channel
+ translator.register_call subject
translator.register_call other_call
-
- other_call.pending_joins[channel] = command
command.request!
expect(subject).to receive(:execute_agi_command).and_return code: 200
subject.execute_command command
+ translator.handle_ami_event ami_event
end
it 'sends the correct Joined events' do
expect(translator).to receive(:handle_pb_event).with expected_joined
expect(translator).to receive(:handle_pb_event).with expected_joined_other
- subject.process_ami_event ami_event
+ translator.handle_ami_event second_ami_event
expect(command.response(0.5)).to eq(true)
end
+
+ context 'out of order' do
+ let :ami_event do
+ RubyAMI::Event.new 'BridgeEnter',
+ 'Privilege' => "call,all",
+ 'BridgeUniqueid' => bridge_uniqueid,
+ 'Channel' => other_channel
+ end
+
+ let :second_ami_event do
+ RubyAMI::Event.new 'BridgeEnter',
+ 'Privilege' => "call,all",
+ 'BridgeUniqueid' => bridge_uniqueid,
+ 'Channel' => call_channel
+ end
+
+ it 'sends the correct Joined events' do
+ expect(translator).to receive(:handle_pb_event).with expected_joined
+ expect(translator).to receive(:handle_pb_event).with expected_joined_other
+ translator.handle_ami_event second_ami_event
+ expect(command.response(0.5)).to eq(true)
+ end
+ end
end
end
context 'with a BridgeLeave event' do
let(:bridge_uniqueid) { "1234-5678" }
- let(:call_channel) { "SIP/foo-1234" }
+ let(:call_channel) { "SIP/foo" }
let :ami_event do
RubyAMI::Event.new 'BridgeLeave',
'Privilege' => "call,all",
'BridgeUniqueid' => bridge_uniqueid,
'Channel' => call_channel
@@ -894,15 +916,15 @@
let :other_call do
Call.new other_channel, translator, ami_client, connection
end
let(:other_call_id) { other_call.id }
- let :ami_event do
+ let :second_ami_event do
RubyAMI::Event.new 'BridgeLeave',
'Privilege' => "call,all",
'BridgeUniqueid' => bridge_uniqueid,
- 'Channel' => call_channel
+ 'Channel' => other_channel
end
let :expected_unjoined do
Punchblock::Event::Unjoined.new target_call_id: subject.id,
call_uri: other_call_id
@@ -912,17 +934,40 @@
Punchblock::Event::Unjoined.new target_call_id: other_call_id,
call_uri: subject.id
end
before do
- translator.bridges[bridge_uniqueid + '_leave'] = other_channel
+ translator.register_call subject
translator.register_call other_call
+ translator.handle_ami_event ami_event
end
it 'sends the correct Unjoined events' do
expect(translator).to receive(:handle_pb_event).with expected_unjoined
expect(translator).to receive(:handle_pb_event).with expected_unjoined_other
- subject.process_ami_event ami_event
+ translator.handle_ami_event second_ami_event
+ end
+
+ context 'out of order' do
+ let :ami_event do
+ RubyAMI::Event.new 'BridgeLeave',
+ 'Privilege' => "call,all",
+ 'BridgeUniqueid' => bridge_uniqueid,
+ 'Channel' => other_channel
+ end
+
+ let :second_ami_event do
+ RubyAMI::Event.new 'BridgeLeave',
+ 'Privilege' => "call,all",
+ 'BridgeUniqueid' => bridge_uniqueid,
+ 'Channel' => call_channel
+ end
+
+ it 'sends the correct Unjoined events' do
+ expect(translator).to receive(:handle_pb_event).with expected_unjoined
+ expect(translator).to receive(:handle_pb_event).with expected_unjoined_other
+ translator.handle_ami_event second_ami_event
+ end
end
end
end
context 'with a BridgeExec event' do