require 'spec_helper' require 'blather/client/dsl' module MockFileReceiver def post_init end def receive_data(data) end def unbind end end def si_xml <<-XML XML end describe Blather::FileTransfer do before do @host = 'host.name' @client = Blather::Client.setup Blather::JID.new('n@d/r'), 'pass' end it 'can select ibb' do iq = Blather::XMPPNode.import(parse_stanza(si_xml).root) @client.stubs(:write).with do |answer| answer.si.feature.x.field('stream-method').value.must_equal Blather::Stanza::Iq::Ibb::NS_IBB true end transfer = Blather::FileTransfer.new(@client, iq) transfer.allow_s5b = false transfer.allow_ibb = true transfer.accept(MockFileReceiver) end it 'can select s5b' do iq = Blather::XMPPNode.import(parse_stanza(si_xml).root) @client.stubs(:write).with do |answer| answer.si.feature.x.field('stream-method').value.must_equal Blather::Stanza::Iq::S5b::NS_S5B true end transfer = Blather::FileTransfer.new(@client, iq) transfer.allow_s5b = true transfer.allow_ibb = false transfer.accept(MockFileReceiver) end it 'can response no-valid-streams' do iq = Blather::XMPPNode.import(parse_stanza(si_xml).root) @client.stubs(:write).with do |answer| answer.find_first('error')['type'].must_equal "cancel" answer.find_first('.//ns:no-valid-streams', :ns => 'http://jabber.org/protocol/si').wont_be_nil true end transfer = Blather::FileTransfer.new(@client, iq) transfer.allow_s5b = false transfer.allow_ibb = false transfer.accept(MockFileReceiver) end it 'can decline transfer' do iq = Blather::XMPPNode.import(parse_stanza(si_xml).root) @client.stubs(:write).with do |answer| answer.find_first('error')['type'].must_equal "cancel" answer.find_first('.//ns:forbidden', :ns => 'urn:ietf:params:xml:ns:xmpp-stanzas').wont_be_nil answer.find_first('.//ns:text', :ns => 'urn:ietf:params:xml:ns:xmpp-stanzas').content.must_equal "Offer declined" true end transfer = Blather::FileTransfer.new(@client, iq) transfer.decline end end