# encoding: utf-8 require 'spec_helper' module Punchblock module Component module Asterisk module AMI describe Action do it 'registers itself' do expect(RayoNode.class_from_registration(:action, 'urn:xmpp:rayo:asterisk:ami:1')).to eq(described_class) end describe "from a stanza" do let :stanza do <<-MESSAGE MESSAGE end subject { RayoNode.from_xml parse_stanza(stanza).root, '9f00061', '1' } it { should be_instance_of described_class } it_should_behave_like 'event' describe '#name' do subject { super().name } it { should be == 'Originate' } end describe '#params' do subject { super().params } it { should be == { 'Channel' => 'SIP/101test', 'Context' => 'default', 'Exten' => '8135551212', 'Priority' => '1', 'Callerid' => '3125551212', 'Timeout' => '30000', 'Variable' => 'var1=23|var2=24|var3=25', 'Async' => '1'} } end end describe "testing equality" do context "with the same name and params" do it "should be equal" do expect(Action.new(:name => 'Originate', :params => { :channel => 'SIP/101test' })).to eq(Action.new(:name => 'Originate', :params => { :channel => 'SIP/101test' })) end end context "with the same name and different params" do it "should be equal" do expect(Action.new(:name => 'Originate', :params => { :channel => 'SIP/101' })).not_to eq(Action.new(:name => 'Originate', :params => { :channel => 'SIP/101test' })) end end context "with a different name and the same params" do it "should be equal" do expect(Action.new(:name => 'Hangup', :params => { :channel => 'SIP/101test' })).not_to eq(Action.new(:name => 'Originate', :params => { :channel => 'SIP/101test' })) end end end describe "when setting options in initializer" do subject do described_class.new :name => 'Originate', :params => { 'Channel' => 'SIP/101test' } end describe '#name' do subject { super().name } it { should be == 'Originate' } end describe '#params' do subject { super().params } it { should be == { 'Channel' => 'SIP/101test' } } end describe "exporting to Rayo" do it "should export to XML that can be understood by its parser" do new_instance = RayoNode.from_xml subject.to_rayo expect(new_instance).to be_instance_of described_class expect(new_instance.name).to eq('Originate') expect(new_instance.params).to eq({ 'Channel' => 'SIP/101test' }) end it "should render to a parent node if supplied" do doc = Nokogiri::XML::Document.new parent = Nokogiri::XML::Node.new 'foo', doc doc.root = parent rayo_doc = subject.to_rayo(parent) expect(rayo_doc).to eq(parent) end end end class Action class Complete describe Success do let :stanza do <<-MESSAGE Originate successfully queued Some thing happened MESSAGE end subject { RayoNode.from_xml(parse_stanza(stanza).root).reason } it { should be_instance_of described_class } describe '#name' do subject { super().name } it { should be == :success } end describe '#message' do subject { super().message } it { should be == "Originate successfully queued" } end describe '#text_body' do subject { super().text_body } it { should be == 'Some thing happened' } end describe '#headers' do subject { super().headers } it { should be == {'Channel' => 'SIP/101-3f3f', 'State' => 'Ring'} } end describe '#attributes' do subject { super().attributes } it { should be == {'Channel' => 'SIP/101-3f3f', 'State' => 'Ring'} } end # For BC describe "when setting options in initializer" do subject do described_class.new message: 'Originate successfully queued', text_body: 'Some thing happened', headers: {'Channel' => 'SIP/101-3f3f', 'State' => 'Ring'} end describe '#message' do subject { super().message } it { should be == 'Originate successfully queued' } end describe '#text_body' do subject { super().text_body } it { should be == 'Some thing happened' } end describe '#headers' do subject { super().headers } it { should be == {'Channel' => 'SIP/101-3f3f', 'State' => 'Ring'} } end describe '#attributes' do subject { super().attributes } it { should be == {'Channel' => 'SIP/101-3f3f', 'State' => 'Ring'} } end # For BC end end end end end end end end end