Sha256: 049f65d9744aaa98e2738dc56199d0442ec7ef685531f697cbb3ede9fd9ed158

Contents?: true

Size: 1.31 KB

Versions: 19

Compression:

Stored size: 1.31 KB

Contents

# encoding: UTF-8

require 'test_helper'

describe Vines::Stream::Http::Start do
  before do
    @stream = MiniTest::Mock.new
    @state = Vines::Stream::Http::Start.new(@stream)
  end

  def test_missing_body_raises_error
    node = node('<presence type="unavailable"/>')
    assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
  end

  def test_body_with_missing_namespace_raises_error
    node = node('<body rid="42" sid="12"/>')
    assert_raises(Vines::StreamErrors::NotAuthorized) { @state.node(node) }
  end

  def test_missing_session_starts_stream
    EM.run do
      node = node('<body xmlns="http://jabber.org/protocol/httpbind" rid="42" sid="12"/>')
      @stream.expect(:start, nil, [node])
      @stream.expect(:advance, nil, [Vines::Stream::Http::Auth.new(@stream)])
      @state.node(node)
      assert @stream.verify
      EM.stop
    end
  end

  def test_valid_session_resumes_stream
    EM.run do
      node = node('<body xmlns="http://jabber.org/protocol/httpbind" rid="42" sid="123"/>')
      session = MiniTest::Mock.new
      session.expect(:resume, nil, [@stream, node])
      Vines::Stream::Http::Sessions['123'] = session
      @state.node(node)
      assert @stream.verify
      assert session.verify
      EM.stop
    end
  end

  private

  def node(xml)
    Nokogiri::XML(xml).root
  end
end

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
diaspora-vines-0.2.0.develop.4 test/stream/http/start_test.rb
diaspora-vines-0.2.0.develop.3 test/stream/http/start_test.rb
diaspora-vines-0.2.0.develop.2 test/stream/http/start_test.rb
diaspora-vines-0.2.0.develop.1 test/stream/http/start_test.rb
diaspora-vines-0.1.28 test/stream/http/start_test.rb
lygneo-vines-0.1.5 test/stream/http/start_test.rb
lygneo-vines-0.1.1 test/stream/http/start_test.rb
diaspora-vines-0.1.27 test/stream/http/start_test.rb
diaspora-vines-0.1.26 test/stream/http/start_test.rb
diaspora-vines-0.1.25 test/stream/http/start_test.rb
diaspora-vines-0.1.24 test/stream/http/start_test.rb
vines-0.4.10 test/stream/http/start_test.rb
diaspora-vines-0.1.22 test/stream/http/start_test.rb
diaspora-vines-0.1.21 test/stream/http/start_test.rb
diaspora-vines-0.1.2 test/stream/http/start_test.rb
vines-0.4.9 test/stream/http/start_test.rb
vines-0.4.8 test/stream/http/start_test.rb
vines-0.4.7 test/stream/http/start_test.rb
vines-0.4.6 test/stream/http/start_test.rb