require 'test_helper'
module SipgateIo
class XmlResponseTestTest < ActiveSupport::TestCase
test "hangup xml response without parameter" do
actual = SipgateIo::XmlResponse.hangup
expected = %Q[]
assert_equal sanitize_xml_for_test(actual), expected
end
test "hangup xml response with on_answer parameter" do
actual = SipgateIo::XmlResponse.hangup(callback: :on_answer)
expected = %Q[]
assert_equal sanitize_xml_for_test(actual), expected
end
test "hangup xml response with on_hangup parameter" do
actual = SipgateIo::XmlResponse.hangup(callback: :on_hangup)
expected = %Q[]
assert_equal sanitize_xml_for_test(actual), expected
end
test "reject without reason" do
actual = SipgateIo::XmlResponse.reject
expected = %Q[]
assert_equal sanitize_xml_for_test(actual), expected
end
test "reject with reason" do
actual = SipgateIo::XmlResponse.reject(reason: :busy)
expected = %Q[]
assert_equal sanitize_xml_for_test(actual), expected
actual = SipgateIo::XmlResponse.reject(reason: :rejected)
expected = %Q[]
assert_equal sanitize_xml_for_test(actual), expected
end
test "reject with reason and callback" do
actual = SipgateIo::XmlResponse.reject(reason: :busy, callback: :on_hangup)
expected = %Q[]
assert_equal sanitize_xml_for_test(actual), expected
actual = SipgateIo::XmlResponse.reject(reason: :rejected, callback: :on_answer)
expected = %Q[]
assert_equal sanitize_xml_for_test(actual), expected
end
test "play with url" do
actual = SipgateIo::XmlResponse.play(soundfile_url: "http://file.wav")
expected = %Q[http://file.wav]
assert_equal sanitize_xml_for_test(actual), expected
end
test "play with url and callback" do
actual = SipgateIo::XmlResponse.play(soundfile_url: "http://file.wav", callback: :on_hangup)
expected = %Q[http://file.wav]
assert_equal sanitize_xml_for_test(actual), expected
end
test "gather xml response without parameter" do
actual = SipgateIo::XmlResponse.gather
expected = %Q[]
assert_equal sanitize_xml_for_test(actual), expected
actual = SipgateIo::XmlResponse.gather()
expected = %Q[]
assert_equal sanitize_xml_for_test(actual), expected
end
test "gather xml response with callback" do
actual = SipgateIo::XmlResponse.gather(callback: :on_hangup)
expected = %Q[]
assert_equal sanitize_xml_for_test(actual), expected
end
test "gather xml response with parameter" do
actual = SipgateIo::XmlResponse.gather(soundfile_url: "http://file.wav")
expected = %Q[http://file.wav]
assert_equal sanitize_xml_for_test(actual), expected
actual = SipgateIo::XmlResponse.gather(soundfile_url: "http://file.wav", timeout: 5000)
expected = %Q[http://file.wav]
assert_equal sanitize_xml_for_test(actual), expected
end
test "gather xml response with parameter and callback" do
actual = SipgateIo::XmlResponse.gather(soundfile_url: "http://file.wav", callback: :on_hangup)
expected = %Q[http://file.wav]
assert_equal sanitize_xml_for_test(actual), expected
actual = SipgateIo::XmlResponse.gather(soundfile_url: "http://file.wav", max_digits: 5, callback: :on_answer)
expected = %Q[http://file.wav]
assert_equal sanitize_xml_for_test(actual), expected
end
test "call redirect to voicemail" do
actual = SipgateIo::XmlResponse.dial(target: :voicemail)
expected = %Q[]
assert_equal sanitize_xml_for_test(actual), expected
end
test "call redirect to number" do
actual = SipgateIo::XmlResponse.dial(target: "4915799912345")
expected = %Q[4915799912345]
assert_equal sanitize_xml_for_test(actual), expected
end
test "call redirect to number with anonymous" do
actual = SipgateIo::XmlResponse.dial(target: "4915799912345", clip: :anonymous)
expected = %Q[4915799912345]
assert_equal sanitize_xml_for_test(actual), expected
end
test "call redirect to number with clip" do
actual = SipgateIo::XmlResponse.dial(target: "4915799912345", clip: "4915799912345")
expected = %Q[4915799912345]
assert_equal sanitize_xml_for_test(actual), expected
end
test "call redirect to number with clip and callback" do
actual = SipgateIo::XmlResponse.dial(target: "4915799912345", clip: "4915799912345", callback: :on_answer)
expected = %Q[4915799912345]
assert_equal sanitize_xml_for_test(actual), expected
end
test "only on answer" do
actual = SipgateIo::XmlResponse.on_answer
expected = %Q[]
assert_equal sanitize_xml_for_test(actual), expected
end
test "only on hangup" do
actual = SipgateIo::XmlResponse.on_hangup
expected = %Q[]
assert_equal sanitize_xml_for_test(actual), expected
end
private
def sanitize_xml_for_test(xml)
xml.gsub(/(?<=\s{1})\s+/,"").gsub("\n", "")
end
end
end