Sha256: 93bf2a084b11e0196afeaa05479f9f54a755273a5b82e3cb49ae073499beadc0

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

# encoding: UTF-8

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 '.' }
      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

3 entries across 3 versions & 1 rubygems

Version Path
vines-0.3.2 test/stanza/presence/probe_test.rb
vines-0.3.1 test/stanza/presence/probe_test.rb
vines-0.3.0 test/stanza/presence/probe_test.rb