~singpolyma/sgx-jmp

ref: 2f7a1b60192a14c86ef9a1f727ea9369cfedc2c6 sgx-jmp/test/test_customer_fwd.rb -rw-r--r-- 1.4 KiB
2f7a1b60Stephen Paul Weber Merge branch 'more-tel-selection-coverage' 2 years 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
# 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) { "+#{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

	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