1# frozen_string_literal: true
 2
 3require "test_helper"
 4require "customer_fwd"
 5
 6class Rantly
 7	def jid
 8		v = Blather::JID.new(Blather::JID.new(string, string).stripped.to_s)
 9		guard !v.to_s.to_s.empty?
10		v
11	end
12end
13
14class CustomerFwdTest < Minitest::Test
15	def test_too_big_timeout
16		fwd = CustomerFwd.for(uri: "xmpp:test@example.com", timeout: 500)
17		assert_equal 300, fwd.timeout.to_i
18	end
19
20	property(:for_xmpp) { jid }
21	def for_xmpp(jid)
22		sip = "sip:#{ERB::Util.url_encode(jid.to_s)}@sip.cheogram.com"
23		fwd = CustomerFwd.for(uri: "xmpp:#{jid}", timeout: 10)
24		assert_kind_of CustomerFwd::XMPP, fwd
25		assert_equal sip, fwd.to
26	end
27
28	property(:for_xmpp_sip) { jid }
29	def for_xmpp_sip(jid)
30		sip = "sip:#{ERB::Util.url_encode(jid.to_s)}@sip.cheogram.com"
31		fwd = CustomerFwd.for(uri: sip, timeout: 10)
32		assert_kind_of CustomerFwd::XMPP, fwd
33		assert_equal sip, fwd.to
34	end
35
36	property(:for_tel) { sized(10) { "+1#{string(:digit)}" } }
37	def for_tel(tel)
38		fwd = CustomerFwd.for(uri: "tel:#{tel}", timeout: 10)
39		assert_kind_of CustomerFwd::Tel, fwd
40		assert_equal tel, fwd.to
41	end
42
43	def test_for_bad_tel
44		assert_raises do
45			CustomerFwd.for(uri: "tel:2261234567", timeout: 10)
46		end
47	end
48
49	property(:for_sip) { "#{string(:alnum)}@#{string(:alnum)}.example.com" }
50	def for_sip(sip)
51		fwd = CustomerFwd.for(uri: "sip:#{sip}", timeout: 10)
52		assert_kind_of CustomerFwd::SIP, fwd
53		assert_equal "sip:#{sip}", fwd.to
54	end
55
56	property(:for_bogus) { string }
57	def for_bogus(bogus)
58		assert_raises(RuntimeError) do
59			CustomerFwd.for(uri: "bogus:#{bogus}", timeout: 10)
60		end
61	end
62
63	def test_for_empty
64		assert_raises(RuntimeError) do
65			CustomerFwd.for(uri: "", timeout: 10)
66		end
67	end
68end