Sha256: 34be2897515c73ae66e1b64d623e0c76eb4de32e364da798ddf17befe0eb27b7

Contents?: true

Size: 1.35 KB

Versions: 6

Compression:

Stored size: 1.35 KB

Contents

# encoding: UTF-8

require 'tmpdir'
require 'vines'
require 'ext/nokogiri'
require 'minitest/autorun'

class ProbeTest < MiniTest::Unit::TestCase
  def setup
    @alice = Vines::JID.new('alice@wonderland.lit/tea')
    @stream = MiniTest::Mock.new
    @config = Vines::Config.new do
      host 'wonderland.lit' do
        storage(:fs) { dir Dir.tmpdir }
      end
    end
  end

  def test_missing_to_address_raises
    node = node(%q{<presence id="42" type="probe"/>})
    stanza = Vines::Stanza::Presence::Probe.new(node, @stream)
    def stanza.inbound?; false; end

    @stream.expect(:user, Vines::User.new(jid: @alice))

    assert_raises(Vines::StanzaErrors::BadRequest) { stanza.process }
    assert @stream.verify
  end

  def test_to_remote_address_routes
    node = node(%q{<presence id="42" to="romeo@verona.lit" type="probe"/>})
    stanza = Vines::Stanza::Presence::Probe.new(node, @stream)
    def stanza.inbound?; false; end

    expected = node(%Q{<presence id="42" to="romeo@verona.lit" type="probe" from="#{@alice}"/>})
    router = MiniTest::Mock.new
    router.expect(:route, nil, [expected])

    @stream.expect(:router, router)
    @stream.expect(:user, Vines::User.new(jid: @alice))
    @stream.expect(:config, @config)

    stanza.process
    assert @stream.verify
    assert router.verify
  end

  private

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
vines-0.4.5 test/stanza/presence/probe_test.rb
vines-0.4.4 test/stanza/presence/probe_test.rb
vines-0.4.3 test/stanza/presence/probe_test.rb
vines-0.4.2 test/stanza/presence/probe_test.rb
vines-0.4.1 test/stanza/presence/probe_test.rb
vines-0.4.0 test/stanza/presence/probe_test.rb