~singpolyma/sgx-jmp

ref: fea0ffeb22d0f229d528b30f3844c425b5009ad9 sgx-jmp/test/test_customer_fwd.rb -rw-r--r-- 1.5 KiB
fea0ffebStephen Paul Weber Merge branch 'no-more-catapult' 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# frozen_string_literal: true

require "test_helper"
require "customer_fwd"

class Rantly
	def jid
		v = Blather::JID.new(Blather::JID.new(string, string).stripped.to_s)
		guard !v.to_s.to_s.empty?
		v
	end
end

class CustomerFwdTest < Minitest::Test
	def test_too_big_timeout
		fwd = CustomerFwd.for(uri: "xmpp:test@example.com", timeout: 500)
		assert_equal 300, fwd.timeout.to_i
	end

	property(:for_xmpp) { jid }
	def for_xmpp(jid)
		sip = "sip:#{ERB::Util.url_encode(jid.to_s)}@sip.cheogram.com"
		fwd = CustomerFwd.for(uri: "xmpp:#{jid}", timeout: 10)
		assert_kind_of CustomerFwd::XMPP, fwd
		assert_equal sip, fwd.to
	end

	property(:for_xmpp_sip) { jid }
	def for_xmpp_sip(jid)
		sip = "sip:#{ERB::Util.url_encode(jid.to_s)}@sip.cheogram.com"
		fwd = CustomerFwd.for(uri: sip, timeout: 10)
		assert_kind_of CustomerFwd::XMPP, fwd
		assert_equal sip, fwd.to
	end

	property(:for_tel) { sized(10) { "+1#{string(:digit)}" } }
	def for_tel(tel)
		fwd = CustomerFwd.for(uri: "tel:#{tel}", timeout: 10)
		assert_kind_of CustomerFwd::Tel, fwd
		assert_equal tel, fwd.to
	end

	def test_for_bad_tel
		assert_raises do
			CustomerFwd.for(uri: "tel:2261234567", timeout: 10)
		end
	end

	property(:for_sip) { "#{string(:alnum)}@#{string(:alnum)}.example.com" }
	def for_sip(sip)
		fwd = CustomerFwd.for(uri: "sip:#{sip}", timeout: 10)
		assert_kind_of CustomerFwd::SIP, fwd
		assert_equal "sip:#{sip}", fwd.to
	end

	property(:for_bogus) { string }
	def for_bogus(bogus)
		assert_raises(RuntimeError) do
			CustomerFwd.for(uri: "bogus:#{bogus}", timeout: 10)
		end
	end
end