check_mobi 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +15 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +1 -0
- data/Gemfile +4 -0
- data/Guardfile +42 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +11 -0
- data/check_mobi.gemspec +31 -0
- data/lib/check_mobi/client.rb +65 -0
- data/lib/check_mobi/configuration.rb +44 -0
- data/lib/check_mobi/core_ext/hash.rb +11 -0
- data/lib/check_mobi/core_ext/string.rb +15 -0
- data/lib/check_mobi/errors/required_field_error.rb +3 -0
- data/lib/check_mobi/resource.rb +37 -0
- data/lib/check_mobi/resources/check_number.rb +20 -0
- data/lib/check_mobi/resources/country_list.rb +19 -0
- data/lib/check_mobi/resources/my_account.rb +17 -0
- data/lib/check_mobi/resources/phone_validation/request_validation.rb +22 -0
- data/lib/check_mobi/resources/phone_validation/validation_status.rb +21 -0
- data/lib/check_mobi/resources/phone_validation/verify_pin.rb +23 -0
- data/lib/check_mobi/resources/prefixes.rb +17 -0
- data/lib/check_mobi/resources/sms/details.rb +23 -0
- data/lib/check_mobi/resources/sms/send.rb +23 -0
- data/lib/check_mobi/resources/voice/actions/hangup.rb +17 -0
- data/lib/check_mobi/resources/voice/actions/play.rb +21 -0
- data/lib/check_mobi/resources/voice/actions/send_dtmf.rb +22 -0
- data/lib/check_mobi/resources/voice/actions/speak.rb +22 -0
- data/lib/check_mobi/resources/voice/actions/wait.rb +22 -0
- data/lib/check_mobi/resources/voice/call.rb +26 -0
- data/lib/check_mobi/resources/voice/call_details.rb +24 -0
- data/lib/check_mobi/resources/voice/events.rb +32 -0
- data/lib/check_mobi/resources/voice/hangup_call.rb +24 -0
- data/lib/check_mobi/response.rb +22 -0
- data/lib/check_mobi/shared/class_with_attributes.rb +102 -0
- data/lib/check_mobi/version.rb +3 -0
- data/lib/check_mobi.rb +45 -0
- data/test/check_mobi/check_mobi_test.rb +7 -0
- data/test/check_mobi/client_test.rb +64 -0
- data/test/check_mobi/configuration_test.rb +55 -0
- data/test/check_mobi/core_ext/hash_test.rb +7 -0
- data/test/check_mobi/core_ext/string_test.rb +27 -0
- data/test/check_mobi/resources/check_number_test.rb +35 -0
- data/test/check_mobi/resources/country_test.rb +14 -0
- data/test/check_mobi/resources/my_account_test.rb +15 -0
- data/test/check_mobi/resources/phone_validation/request_validation_test.rb +47 -0
- data/test/check_mobi/resources/phone_validation/validation_status_test.rb +24 -0
- data/test/check_mobi/resources/phone_validation/verify_pin_test.rb +27 -0
- data/test/check_mobi/resources/prefix_test.rb +15 -0
- data/test/check_mobi/resources/sms/detail_test.rb +24 -0
- data/test/check_mobi/resources/sms/send_test.rb +57 -0
- data/test/check_mobi/resources/voice/actions/hangup_action_test.rb +42 -0
- data/test/check_mobi/resources/voice/actions/play_action_test.rb +25 -0
- data/test/check_mobi/resources/voice/actions/send_dtmf_action_test.rb +29 -0
- data/test/check_mobi/resources/voice/actions/speak_action_test.rb +76 -0
- data/test/check_mobi/resources/voice/actions/wait_action_test.rb +26 -0
- data/test/check_mobi/resources/voice/call_details_test.rb +16 -0
- data/test/check_mobi/resources/voice/call_test.rb +147 -0
- data/test/check_mobi/resources/voice/hangup_call_test.rb +16 -0
- data/test/check_mobi/shared/class_with_attributes_test.rb +136 -0
- data/test/helper.rb +42 -0
- metadata +271 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe CheckMobi::Resources::SMS::Send do
|
4
|
+
describe 'sms sending should fail' do
|
5
|
+
before do
|
6
|
+
@endpoint = 'https://api.checkmobi.com/v1/sms/send'
|
7
|
+
CheckMobi.api_key = ENV['API_KEY']
|
8
|
+
stub_post_request(@endpoint)
|
9
|
+
@text = 'hi there!'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'for invalid sender field' do
|
13
|
+
@client = CheckMobi::Resources::SMS::Send.new(text: @text)
|
14
|
+
@client.perform
|
15
|
+
assert_requested(:post,
|
16
|
+
@endpoint,
|
17
|
+
headers: headers_with_authorization,
|
18
|
+
body: {text: @text,
|
19
|
+
to: nil,
|
20
|
+
notification_callback: nil,
|
21
|
+
platform: 'web'
|
22
|
+
},
|
23
|
+
times: 1)
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
it 'for invalid text field' do
|
28
|
+
@client = CheckMobi::Resources::SMS::Send.new(to: ENV['PHONE_NUMBER'])
|
29
|
+
@client.perform
|
30
|
+
assert_requested(:post,
|
31
|
+
@endpoint,
|
32
|
+
headers: headers_with_authorization,
|
33
|
+
body: {text: nil,
|
34
|
+
to: ENV['PHONE_NUMBER'],
|
35
|
+
notification_callback: nil,
|
36
|
+
platform: 'web'
|
37
|
+
},
|
38
|
+
times: 1)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'sms sending should be successful' do
|
42
|
+
|
43
|
+
@client = CheckMobi::Resources::SMS::Send.new(to: ENV['PHONE_NUMBER'], text: @text)
|
44
|
+
@client.perform
|
45
|
+
assert_requested(:post,
|
46
|
+
@endpoint,
|
47
|
+
headers: headers_with_authorization,
|
48
|
+
body: {text: @text,
|
49
|
+
to: ENV['PHONE_NUMBER'],
|
50
|
+
notification_callback: nil,
|
51
|
+
platform: 'web'
|
52
|
+
},
|
53
|
+
times: 1)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe CheckMobi::Resources::Voice::Actions::Hangup do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@endpoint = 'https://api.checkmobi.com/v1/call'
|
7
|
+
|
8
|
+
CheckMobi.api_key = ENV['API_KEY']
|
9
|
+
|
10
|
+
@resource = CheckMobi::Resources::Voice::Call.new(
|
11
|
+
to: ENV['PHONE_NUMBER'],
|
12
|
+
platform: 'android'
|
13
|
+
)
|
14
|
+
|
15
|
+
@hangup_action = CheckMobi::Resources::Voice::Actions::Hangup.new(reason: 'rejected')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should set action name implicitly' do
|
19
|
+
@hangup_action.action.must_equal 'hangup'
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should not allow setting action name' do
|
23
|
+
@hangup_action.respond_to?(:action=).must_equal false
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should request properly' do
|
27
|
+
stub_post_request(@endpoint)
|
28
|
+
@resource.events << @hangup_action
|
29
|
+
@resource.perform
|
30
|
+
assert_requested(:post, @endpoint,
|
31
|
+
body: {
|
32
|
+
from: nil,
|
33
|
+
to: ENV['PHONE_NUMBER'],
|
34
|
+
notification_callback: nil, platform: 'android',
|
35
|
+
events: [{action: 'hangup', reason: 'rejected'}]
|
36
|
+
},
|
37
|
+
headers: headers_with_authorization,
|
38
|
+
times: 1
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe CheckMobi::Resources::Voice::Actions::Play do
|
4
|
+
before do
|
5
|
+
CheckMobi.configure do |c|
|
6
|
+
c.api_key = ENV['API_KEY']
|
7
|
+
end
|
8
|
+
|
9
|
+
@resource = CheckMobi::Resources::Voice::Call.new(
|
10
|
+
to: ENV['PHONE_NUMBER'],
|
11
|
+
from: ENV['PHONE_NUMBER']
|
12
|
+
)
|
13
|
+
|
14
|
+
@play_action = CheckMobi::Resources::Voice::Actions::Play.new
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should set action name implicitly' do
|
18
|
+
@play_action.action.must_equal 'play'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should not allow setting action name' do
|
22
|
+
@play_action.respond_to?(:action=).must_equal false
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe CheckMobi::Resources::Voice::Actions::SendDTMF do
|
4
|
+
describe 'SendDTMF functions' do
|
5
|
+
before do
|
6
|
+
CheckMobi.configure do |c|
|
7
|
+
c.api_key = ENV['API_KEY']
|
8
|
+
end
|
9
|
+
|
10
|
+
@resource = CheckMobi::Resources::Voice::Call.new(
|
11
|
+
to: ENV['PHONE_NUMBER'],
|
12
|
+
from: ENV['PHONE_NUMBER']
|
13
|
+
)
|
14
|
+
|
15
|
+
@send_dtmf = CheckMobi::Resources::Voice::Actions::SendDTMF.new
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should set default values' do
|
19
|
+
@send_dtmf.action.must_equal 'send_dtmf'
|
20
|
+
@send_dtmf.async.must_equal true
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should not allow setting action name' do
|
24
|
+
@send_dtmf.respond_to?(:action=).must_equal false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe CheckMobi::Resources::Voice::Actions::Speak do
|
4
|
+
before do
|
5
|
+
@endpoint = 'https://api.checkmobi.com/v1/call'
|
6
|
+
|
7
|
+
CheckMobi.configure do |c|
|
8
|
+
c.api_key = ENV['API_KEY']
|
9
|
+
end
|
10
|
+
|
11
|
+
@resource = CheckMobi::Resources::Voice::Call.new(
|
12
|
+
to: ENV['PHONE_NUMBER'],
|
13
|
+
from: ENV['PHONE_NUMBER']
|
14
|
+
)
|
15
|
+
|
16
|
+
@speak_action = CheckMobi::Resources::Voice::Actions::Speak.new
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should set default values' do
|
20
|
+
@speak_action.action.must_equal 'speak'
|
21
|
+
@speak_action.loop.must_equal 1
|
22
|
+
@speak_action.voice.must_equal 'WOMAN'
|
23
|
+
@speak_action.language.must_equal 'en-US'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should not allow setting action name' do
|
27
|
+
@speak_action.respond_to?(:action=).must_equal false
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should add speak event correctly' do
|
31
|
+
@resource.events << @speak_action
|
32
|
+
@resource.events.length.must_equal 1
|
33
|
+
@resource.events.first.action.must_equal @speak_action.class.name.split('::').last.underscore!
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should build hashes correctly' do
|
37
|
+
@resource.events << @speak_action
|
38
|
+
hash = @resource.to_hash
|
39
|
+
hash.keys.must_include(:events)
|
40
|
+
hash[:events].must_be_instance_of Array
|
41
|
+
hash[:events].first.must_be_instance_of Hash
|
42
|
+
hash[:events].first[:action].must_equal @speak_action.class.name.split('::').last.underscore!
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should request without text' do
|
46
|
+
stub_post_request(@endpoint).to_return(status: 400, body: {code: 10, error: 'Invalid request Payload'}.to_json)
|
47
|
+
@resource.events << @speak_action
|
48
|
+
response = @resource.perform
|
49
|
+
response.status_code.must_equal '400'
|
50
|
+
response.code.must_equal 10
|
51
|
+
assert_requested(:post,
|
52
|
+
@endpoint,
|
53
|
+
body: @resource.to_hash,
|
54
|
+
headers: headers_with_authorization,
|
55
|
+
times: 1)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should pass with text' do
|
59
|
+
stub_post_request(@endpoint).to_return(status: 200)
|
60
|
+
@speak_action.text = 'sample text'
|
61
|
+
@resource.events << @speak_action
|
62
|
+
response = @resource.perform
|
63
|
+
response.status_code.must_equal '200'
|
64
|
+
assert_requested(:post,
|
65
|
+
@endpoint,
|
66
|
+
body: {
|
67
|
+
from: ENV['PHONE_NUMBER'], to: ENV['PHONE_NUMBER'], notification_callback: nil, platform: 'web',
|
68
|
+
events:[
|
69
|
+
{text: 'sample text', loop: 1,voice: 'WOMAN',language: 'en-US',action: 'speak'}
|
70
|
+
]
|
71
|
+
},
|
72
|
+
headers: headers_with_authorization,
|
73
|
+
times: 1)
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe CheckMobi::Resources::Voice::Actions::Wait do
|
4
|
+
before do
|
5
|
+
CheckMobi.configure do |c|
|
6
|
+
c.api_key = ENV['API_KEY']
|
7
|
+
end
|
8
|
+
|
9
|
+
@resource = CheckMobi::Resources::Voice::Call.new(
|
10
|
+
to: ENV['PHONE_NUMBER'],
|
11
|
+
from: ENV['PHONE_NUMBER']
|
12
|
+
)
|
13
|
+
|
14
|
+
@wait_action = CheckMobi::Resources::Voice::Actions::Wait.new
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should set default values' do
|
18
|
+
@wait_action.action.must_equal 'wait'
|
19
|
+
@wait_action.length.must_equal 1
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should not allow setting action name' do
|
23
|
+
@wait_action.respond_to?(:action=).must_equal false
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe CheckMobi::Resources::Voice::CallDetails do
|
4
|
+
before do
|
5
|
+
CheckMobi.api_key = ENV['API_KEY']
|
6
|
+
@id = '1234567890'
|
7
|
+
@endpoint = "https://api.checkmobi.com/v1/call/#{@id}"
|
8
|
+
stub_get_request(@endpoint)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should request properly' do
|
12
|
+
resource = CheckMobi::Resources::Voice::CallDetails.new(id: @id)
|
13
|
+
resource.perform
|
14
|
+
assert_requested(:get, @endpoint, headers: headers_with_authorization)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe CheckMobi::Resources::Voice::Call do
|
4
|
+
|
5
|
+
describe 'object buildings test' do
|
6
|
+
before do
|
7
|
+
@resource = CheckMobi::Resources::Voice::Call.new
|
8
|
+
@speak_action = CheckMobi::Resources::Voice::Actions::Speak.new
|
9
|
+
@play_action = CheckMobi::Resources::Voice::Actions::Play.new
|
10
|
+
@send_dtmf = CheckMobi::Resources::Voice::Actions::SendDTMF.new
|
11
|
+
@wait_action = CheckMobi::Resources::Voice::Actions::Wait.new
|
12
|
+
@hangup_action = CheckMobi::Resources::Voice::Actions::Hangup.new
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should set default values when not specified' do
|
16
|
+
@resource.events.must_equal []
|
17
|
+
@resource.platform.must_equal CheckMobi::Configuration::DEFAULT_PLATFORM
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should set events as sent during initialization' do
|
21
|
+
resource = CheckMobi::Resources::Voice::Call.new(events: [1])
|
22
|
+
resource.events.must_equal [1]
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should set events after initialization' do
|
26
|
+
@resource.events << {key: 'value'}
|
27
|
+
@resource.events.must_equal [{key: 'value'}]
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should add speak event correctly' do
|
31
|
+
@resource.events << @speak_action
|
32
|
+
@resource.events.length.must_equal 1
|
33
|
+
@resource.events.first.action.must_equal @speak_action.class.name.split('::').last.underscore!
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should add play event correctly' do
|
37
|
+
@resource.events << @play_action
|
38
|
+
@resource.events.length.must_equal 1
|
39
|
+
@resource.events.first.action.must_equal @play_action.class.name.split('::').last.underscore!
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should add send_dtmf event correctly' do
|
43
|
+
@resource.events << @send_dtmf
|
44
|
+
@resource.events.length.must_equal 1
|
45
|
+
@resource.events.first.action.must_equal @send_dtmf.class.name.split('::').last.underscore!
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should add hangup event correctly' do
|
49
|
+
@resource.events << @hangup_action
|
50
|
+
@resource.events.length.must_equal 1
|
51
|
+
@resource.events.first.action.must_equal @hangup_action.class.name.split('::').last.underscore!
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should add wait event correctly' do
|
55
|
+
@resource.events << @wait_action
|
56
|
+
@resource.events.length.must_equal 1
|
57
|
+
@resource.events.first.action.must_equal @wait_action.class.name.split('::').last.underscore!
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should add multiple events correctly' do
|
61
|
+
@resource.events << @speak_action
|
62
|
+
@resource.events.length.must_equal 1
|
63
|
+
@resource.events << @play_action
|
64
|
+
@resource.events.length.must_equal 2
|
65
|
+
@resource.events << @send_dtmf
|
66
|
+
@resource.events.length.must_equal 3
|
67
|
+
@resource.events.concat [@hangup_action, @wait_action]
|
68
|
+
@resource.events.length.must_equal 5
|
69
|
+
@resource.events.each {|event| event.action.must_equal event.class.name.split('::').last.underscore!}
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should have attributes' do
|
73
|
+
@resource.must_respond_to :attributes
|
74
|
+
@resource.attributes.must_be_instance_of Array
|
75
|
+
@resource.attributes.must_include :events
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
describe 'api interaction test' do
|
82
|
+
before do
|
83
|
+
@endpoint = 'https://api.checkmobi.com/v1/call'
|
84
|
+
CheckMobi.configure do |c|
|
85
|
+
c.api_key = ENV['API_KEY']
|
86
|
+
end
|
87
|
+
|
88
|
+
@resource = CheckMobi::Resources::Voice::Call.new(
|
89
|
+
to: ENV['PHONE_NUMBER']
|
90
|
+
)
|
91
|
+
|
92
|
+
@speak_action = CheckMobi::Resources::Voice::Actions::Speak.new
|
93
|
+
@play_action = CheckMobi::Resources::Voice::Actions::Play.new
|
94
|
+
@send_dtmf = CheckMobi::Resources::Voice::Actions::SendDTMF.new
|
95
|
+
@wait_action = CheckMobi::Resources::Voice::Actions::Wait.new
|
96
|
+
@hangup_action = CheckMobi::Resources::Voice::Actions::Hangup.new
|
97
|
+
|
98
|
+
stub_post_request(@endpoint)
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
it 'should request without any events' do
|
103
|
+
@resource.perform
|
104
|
+
assert_requested(:post,
|
105
|
+
@endpoint,
|
106
|
+
headers: headers_with_authorization,
|
107
|
+
body: {from: nil, to: ENV['PHONE_NUMBER'], events: [], notification_callback: nil, platform: 'web'})
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should request with from number' do
|
111
|
+
@resource.from = ENV['PHONE_NUMBER']
|
112
|
+
@resource.perform
|
113
|
+
assert_requested(:post,
|
114
|
+
@endpoint,
|
115
|
+
headers: headers_with_authorization,
|
116
|
+
body: {
|
117
|
+
from: ENV['PHONE_NUMBER'], to: ENV['PHONE_NUMBER'], events: [],
|
118
|
+
notification_callback: nil, platform: 'web'
|
119
|
+
})
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should pass with valid events' do
|
123
|
+
@speak_action.update_attributes(text: 'You are the best', loop: 2)
|
124
|
+
@play_action.update_attributes(url: 'http://www.tonycuffe.com/mp3/tailtoddle_lo.mp3')
|
125
|
+
@send_dtmf.update_attributes(digits: '1W2', async: false)
|
126
|
+
@wait_action.length = 4
|
127
|
+
speak_action2 = CheckMobi::Resources::Voice::Actions::Speak.new(text: 'We are done.')
|
128
|
+
@resource.events << @speak_action << @play_action << @send_dtmf << @wait_action << speak_action2 << @hangup_action
|
129
|
+
@resource.perform
|
130
|
+
assert_requested(:post,
|
131
|
+
@endpoint,
|
132
|
+
headers: headers_with_authorization,
|
133
|
+
body: {
|
134
|
+
from: nil, to: ENV['PHONE_NUMBER'],
|
135
|
+
notification_callback: nil, platform: 'web',
|
136
|
+
events: [
|
137
|
+
{ action: "speak", text: "You are the best", loop: 2, language: "en-US", voice: 'WOMAN' },
|
138
|
+
{ action: "play", url: "http://www.tonycuffe.com/mp3/tailtoddle_lo.mp3", loop: 1 },
|
139
|
+
{ action: "send_dtmf", digits: "1W2", async: false },
|
140
|
+
{ action: "wait", length: 4 },
|
141
|
+
{ action: "speak", text: "We are done.", loop: 1, voice: 'WOMAN', language: "en-US" },
|
142
|
+
{ action: "hangup", reason: nil }
|
143
|
+
]
|
144
|
+
})
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe CheckMobi::Resources::Voice::HangupCall do
|
4
|
+
before do
|
5
|
+
CheckMobi.api_key = ENV['API_KEY']
|
6
|
+
@req_id = '1234567890'
|
7
|
+
@endpoint = "https://api.checkmobi.com/v1/call/#{@req_id}"
|
8
|
+
stub_delete_request(@endpoint)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should request properly' do
|
12
|
+
resource = CheckMobi::Resources::Voice::HangupCall.new(req_id: @req_id)
|
13
|
+
resource.perform
|
14
|
+
assert_requested(:delete, @endpoint, headers: headers_with_authorization)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require_relative '../../../lib/check_mobi/shared/class_with_attributes'
|
3
|
+
|
4
|
+
describe ClassWithAttributes do
|
5
|
+
|
6
|
+
describe 'it should set attributes properly' do
|
7
|
+
|
8
|
+
class Parent
|
9
|
+
include ClassWithAttributes
|
10
|
+
attributes :a, :b, :c
|
11
|
+
readonly_attributes :d, :e, :f
|
12
|
+
attribute :g, default: []
|
13
|
+
attribute :h, default: Time.new
|
14
|
+
readonly_attribute :i, default: String.new
|
15
|
+
end
|
16
|
+
|
17
|
+
class ChildA < Parent
|
18
|
+
attribute :j, default: %w(A B C)
|
19
|
+
end
|
20
|
+
|
21
|
+
class AnotherClass
|
22
|
+
include ClassWithAttributes
|
23
|
+
attribute :k, default: 'value_of_k'
|
24
|
+
end
|
25
|
+
|
26
|
+
class ClassWithoutAttributes
|
27
|
+
attr_accessor :l
|
28
|
+
|
29
|
+
def initialize(l)
|
30
|
+
@l = l
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should set attr_accessors' do
|
35
|
+
p = Parent.new
|
36
|
+
p.must_respond_to(:a)
|
37
|
+
p.must_respond_to(:a=)
|
38
|
+
p.must_respond_to(:b)
|
39
|
+
p.must_respond_to(:b=)
|
40
|
+
p.must_respond_to(:c)
|
41
|
+
p.must_respond_to(:c=)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should set attr_readers' do
|
45
|
+
p = Parent.new
|
46
|
+
p.must_respond_to(:d)
|
47
|
+
p.wont_respond_to(:d=)
|
48
|
+
p.must_respond_to(:e)
|
49
|
+
p.wont_respond_to(:e=)
|
50
|
+
p.must_respond_to(:f)
|
51
|
+
p.wont_respond_to(:f=)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should set default attributes' do
|
55
|
+
p = Parent.new
|
56
|
+
p.must_respond_to(:g)
|
57
|
+
p.must_respond_to(:g=)
|
58
|
+
p.g.must_equal []
|
59
|
+
p.h.must_be_instance_of Time
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should set default readonly attributes' do
|
63
|
+
p = Parent.new
|
64
|
+
p.must_respond_to(:i)
|
65
|
+
p.wont_respond_to(:i=)
|
66
|
+
p.i.must_be_instance_of String
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should initialize properly with attributes' do
|
70
|
+
p = Parent.new(a: 1, b: 'init_b', d: 'init_d', g: Hash.new, i: Object.new)
|
71
|
+
p.a.must_equal 1
|
72
|
+
p.b.must_equal 'init_b'
|
73
|
+
p.d.must_equal nil
|
74
|
+
p.g.must_be_instance_of Hash
|
75
|
+
p.i.must_be_instance_of String
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should update attributes properly' do
|
79
|
+
p = Parent.new(a: 1, b: 'init_b', d: 'init_d', g: Hash.new, i: Object.new)
|
80
|
+
p.update_attributes(a: 3, b: 'updated_b', d: 'updated_d', g: Time.new, i: Array.new)
|
81
|
+
p.a.must_equal 3
|
82
|
+
p.b.must_equal 'updated_b'
|
83
|
+
p.d.must_equal nil
|
84
|
+
p.g.must_be_instance_of Time
|
85
|
+
p.i.must_be_instance_of String
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'it should build' do
|
90
|
+
class AnotherParent
|
91
|
+
include ClassWithAttributes
|
92
|
+
attributes :a, :b, :c, :f
|
93
|
+
readonly_attributes :d
|
94
|
+
attribute :h, default: Hash.new
|
95
|
+
readonly_attribute :i, default: String.new
|
96
|
+
end
|
97
|
+
|
98
|
+
class ChildB < AnotherParent
|
99
|
+
attribute :j, default: %w(A B C)
|
100
|
+
end
|
101
|
+
|
102
|
+
class AnotherClass
|
103
|
+
include ClassWithAttributes
|
104
|
+
attribute :k, default: 'value_of_k'
|
105
|
+
end
|
106
|
+
|
107
|
+
class ClassWithoutAttributes
|
108
|
+
attr_accessor :l
|
109
|
+
|
110
|
+
def initialize(l)
|
111
|
+
@l = l
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'hash properly' do
|
116
|
+
child_b = ChildB.new
|
117
|
+
another_class_object = AnotherClass.new
|
118
|
+
class_without_attributes = ClassWithoutAttributes.new('not gonna converted to hash')
|
119
|
+
value_of_f = [another_class_object, another_class_object]
|
120
|
+
p = AnotherParent.new(a: child_b, b: another_class_object, c: class_without_attributes, f: value_of_f)
|
121
|
+
output_hash = p.to_hash
|
122
|
+
expected_hash = {
|
123
|
+
a: {j: %w(A B C)},
|
124
|
+
b: {k: 'value_of_k'},
|
125
|
+
c: class_without_attributes,
|
126
|
+
f: [{k: 'value_of_k'}, {k: 'value_of_k'}],
|
127
|
+
d: nil,
|
128
|
+
h: {},
|
129
|
+
i: ''
|
130
|
+
}
|
131
|
+
|
132
|
+
output_hash.must_equal expected_hash
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'check_mobi'
|
2
|
+
# Dir['check_mobi/*.rb'].each { |file| require file }
|
3
|
+
# Dir['check_mobi/resources/**/*.rb'].each { |file| require file }
|
4
|
+
require 'minitest/spec'
|
5
|
+
require 'minitest/autorun'
|
6
|
+
require "minitest/focus"
|
7
|
+
require 'webmock/minitest'
|
8
|
+
require 'vcr'
|
9
|
+
require 'coveralls'
|
10
|
+
|
11
|
+
Coveralls.wear!
|
12
|
+
|
13
|
+
VCR.configure do |config|
|
14
|
+
config.cassette_library_dir = 'fixtures/vcr_cassettes'
|
15
|
+
config.hook_into :webmock
|
16
|
+
config.filter_sensitive_data('<API_KEY>') { ENV['API_KEY'] }
|
17
|
+
end
|
18
|
+
|
19
|
+
WebMock.disable_net_connect!
|
20
|
+
|
21
|
+
def stub_get_request(url)
|
22
|
+
stub_request(:get, url)
|
23
|
+
end
|
24
|
+
|
25
|
+
def stub_delete_request(url)
|
26
|
+
stub_request(:delete, url)
|
27
|
+
end
|
28
|
+
|
29
|
+
def stub_post_request(url)
|
30
|
+
stub_request(:post, url)
|
31
|
+
end
|
32
|
+
|
33
|
+
def headers_without_authorization
|
34
|
+
{
|
35
|
+
'Accept': 'application/json',
|
36
|
+
'Content-Type': 'application/json'
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def headers_with_authorization
|
41
|
+
headers_without_authorization.merge!({'Authorization': ENV['API_KEY']})
|
42
|
+
end
|