sipgate_io 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,12 +2,145 @@ require 'test_helper'
2
2
 
3
3
  module SipgateIo
4
4
  class XmlResponseTestTest < ActiveSupport::TestCase
5
- # setup do
6
- # @routes = Engine.routes
7
- # end
8
- #
9
- # test "knows callback_url" do
10
- # puts SipgateIo::XmlResponse.gather()
11
- # end
5
+
6
+ test "hangup xml response without parameter" do
7
+ actual = SipgateIo::XmlResponse.hangup
8
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response><Hangup/></Response>]
9
+ assert_equal sanitize_xml_for_test(actual), expected
10
+ end
11
+
12
+ test "hangup xml response with on_answer parameter" do
13
+ actual = SipgateIo::XmlResponse.hangup(callback: :on_answer)
14
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response onAnswer="http://localhost:3000"><Hangup/></Response>]
15
+ assert_equal sanitize_xml_for_test(actual), expected
16
+ end
17
+
18
+ test "hangup xml response with on_hangup parameter" do
19
+ actual = SipgateIo::XmlResponse.hangup(callback: :on_hangup)
20
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response onHangup="http://localhost:3000"><Hangup/></Response>]
21
+ assert_equal sanitize_xml_for_test(actual), expected
22
+ end
23
+
24
+ test "reject without reason" do
25
+ actual = SipgateIo::XmlResponse.reject
26
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response><Reject/></Response>]
27
+ assert_equal sanitize_xml_for_test(actual), expected
28
+ end
29
+
30
+ test "reject with reason" do
31
+ actual = SipgateIo::XmlResponse.reject(reason: :busy)
32
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response><Reject reason="busy"/></Response>]
33
+ assert_equal sanitize_xml_for_test(actual), expected
34
+
35
+ actual = SipgateIo::XmlResponse.reject(reason: :rejected)
36
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response><Reject reason="rejected"/></Response>]
37
+ assert_equal sanitize_xml_for_test(actual), expected
38
+ end
39
+
40
+ test "reject with reason and callback" do
41
+ actual = SipgateIo::XmlResponse.reject(reason: :busy, callback: :on_hangup)
42
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response onHangup="http://localhost:3000"><Reject reason="busy"/></Response>]
43
+ assert_equal sanitize_xml_for_test(actual), expected
44
+
45
+ actual = SipgateIo::XmlResponse.reject(reason: :rejected, callback: :on_answer)
46
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response onAnswer="http://localhost:3000"><Reject reason="rejected"/></Response>]
47
+ assert_equal sanitize_xml_for_test(actual), expected
48
+ end
49
+
50
+ test "play with url" do
51
+ actual = SipgateIo::XmlResponse.play(soundfile_url: "http://file.wav")
52
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response><Play><Url>http://file.wav</Url></Play></Response>]
53
+ assert_equal sanitize_xml_for_test(actual), expected
54
+ end
55
+
56
+ test "play with url and callback" do
57
+ actual = SipgateIo::XmlResponse.play(soundfile_url: "http://file.wav", callback: :on_hangup)
58
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response onHangup="http://localhost:3000"><Play><Url>http://file.wav</Url></Play></Response>]
59
+ assert_equal sanitize_xml_for_test(actual), expected
60
+ end
61
+
62
+ test "gather xml response without parameter" do
63
+ actual = SipgateIo::XmlResponse.gather
64
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response><Gather onData="http://localhost:3000"></Gather></Response>]
65
+ assert_equal sanitize_xml_for_test(actual), expected
66
+
67
+ actual = SipgateIo::XmlResponse.gather()
68
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response><Gather onData="http://localhost:3000"></Gather></Response>]
69
+ assert_equal sanitize_xml_for_test(actual), expected
70
+ end
71
+
72
+ test "gather xml response with callback" do
73
+ actual = SipgateIo::XmlResponse.gather(callback: :on_hangup)
74
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response onHangup="http://localhost:3000"><Gather onData="http://localhost:3000"></Gather></Response>]
75
+ assert_equal sanitize_xml_for_test(actual), expected
76
+ end
77
+
78
+ test "gather xml response with parameter" do
79
+ actual = SipgateIo::XmlResponse.gather(soundfile_url: "http://file.wav")
80
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response><Gather onData="http://localhost:3000"><Play><Url>http://file.wav</Url></Play></Gather></Response>]
81
+ assert_equal sanitize_xml_for_test(actual), expected
82
+
83
+ actual = SipgateIo::XmlResponse.gather(soundfile_url: "http://file.wav", timeout: 5000)
84
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response><Gather onData="http://localhost:3000" timeout="5000"><Play><Url>http://file.wav</Url></Play></Gather></Response>]
85
+ assert_equal sanitize_xml_for_test(actual), expected
86
+ end
87
+
88
+ test "gather xml response with parameter and callback" do
89
+ actual = SipgateIo::XmlResponse.gather(soundfile_url: "http://file.wav", callback: :on_hangup)
90
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response onHangup="http://localhost:3000"><Gather onData="http://localhost:3000"><Play><Url>http://file.wav</Url></Play></Gather></Response>]
91
+ assert_equal sanitize_xml_for_test(actual), expected
92
+
93
+ actual = SipgateIo::XmlResponse.gather(soundfile_url: "http://file.wav", max_digits: 5, callback: :on_answer)
94
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response onAnswer="http://localhost:3000"><Gather onData="http://localhost:3000" maxDigits="5"><Play><Url>http://file.wav</Url></Play></Gather></Response>]
95
+ assert_equal sanitize_xml_for_test(actual), expected
96
+ end
97
+
98
+ test "call redirect to voicemail" do
99
+ actual = SipgateIo::XmlResponse.dial(target: :voicemail)
100
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Voicemail/></Dial></Response>]
101
+ assert_equal sanitize_xml_for_test(actual), expected
102
+ end
103
+
104
+ test "call redirect to number" do
105
+ actual = SipgateIo::XmlResponse.dial(target: "4915799912345")
106
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Number>4915799912345</Number></Dial></Response>]
107
+ assert_equal sanitize_xml_for_test(actual), expected
108
+ end
109
+
110
+ test "call redirect to number with anonymous" do
111
+ actual = SipgateIo::XmlResponse.dial(target: "4915799912345", clip: :anonymous)
112
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response><Dial anonymous="true"><Number>4915799912345</Number></Dial></Response>]
113
+ assert_equal sanitize_xml_for_test(actual), expected
114
+ end
115
+
116
+ test "call redirect to number with clip" do
117
+ actual = SipgateIo::XmlResponse.dial(target: "4915799912345", clip: "4915799912345")
118
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response><Dial callerId="4915799912345"><Number>4915799912345</Number></Dial></Response>]
119
+ assert_equal sanitize_xml_for_test(actual), expected
120
+ end
121
+
122
+ test "call redirect to number with clip and callback" do
123
+ actual = SipgateIo::XmlResponse.dial(target: "4915799912345", clip: "4915799912345", callback: :on_answer)
124
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response onAnswer="http://localhost:3000"><Dial callerId="4915799912345"><Number>4915799912345</Number></Dial></Response>]
125
+ assert_equal sanitize_xml_for_test(actual), expected
126
+ end
127
+
128
+ test "only on answer" do
129
+ actual = SipgateIo::XmlResponse.on_answer
130
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response onAnswer="http://localhost:3000"/>]
131
+ assert_equal sanitize_xml_for_test(actual), expected
132
+ end
133
+
134
+ test "only on hangup" do
135
+ actual = SipgateIo::XmlResponse.on_hangup
136
+ expected = %Q[<?xml version="1.0" encoding="UTF-8"?><Response onHangup="http://localhost:3000"/>]
137
+ assert_equal sanitize_xml_for_test(actual), expected
138
+ end
139
+
140
+ private
141
+
142
+ def sanitize_xml_for_test(xml)
143
+ xml.gsub(/(?<=\s{1})\s+/,"").gsub("\n", "")
144
+ end
12
145
  end
13
146
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sipgate_io
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Schmidt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-11 00:00:00.000000000 Z
11
+ date: 2016-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -116,6 +116,7 @@ files:
116
116
  - test/dummy/config/routes.rb
117
117
  - test/dummy/config/secrets.yml
118
118
  - test/dummy/db/development.sqlite3
119
+ - test/dummy/db/schema.rb
119
120
  - test/dummy/db/test.sqlite3
120
121
  - test/dummy/log/development.log
121
122
  - test/dummy/log/test.log
@@ -188,6 +189,7 @@ test_files:
188
189
  - test/dummy/config/secrets.yml
189
190
  - test/dummy/config.ru
190
191
  - test/dummy/db/development.sqlite3
192
+ - test/dummy/db/schema.rb
191
193
  - test/dummy/db/test.sqlite3
192
194
  - test/dummy/log/development.log
193
195
  - test/dummy/log/test.log