forked from dimitrisnijder/ringcentral-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathringcentral_spec.rb
More file actions
81 lines (69 loc) · 2.79 KB
/
ringcentral_spec.rb
File metadata and controls
81 lines (69 loc) · 2.79 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
require 'ringcentral'
RSpec.describe 'RingCentral' do
describe 'ringcentral' do
it 'test_class_variables' do
expect('https://platform.devtest.ringcentral.com').to eq(RingCentral.SANDBOX_SERVER)
expect('https://platform.ringcentral.com').to eq(RingCentral.PRODUCTION_SERVER)
end
it 'test_initializer' do
rc = RingCentral.new('app_key', 'app_secret', RingCentral.SANDBOX_SERVER)
expect('app_key').to eq(rc.app_key)
expect('app_secret').to eq(rc.app_secret)
expect('https://platform.devtest.ringcentral.com').to eq(rc.server)
expect(true).to eq(rc.auto_refresh)
end
it 'test_authorize_uri' do
rc = RingCentral.new('app_key', 'app_secret', RingCentral.SANDBOX_SERVER)
expect(RingCentral.SANDBOX_SERVER + '/restapi/oauth/authorize?client_id=app_secret&redirect_uri=https%3A%2F%2Fexample.com&response_type=code&state=mystate').to eq(rc.authorize_uri('https://example.com', 'mystate'))
end
it 'test_password_flow' do
Dotenv.load
rc = RingCentral.new(ENV['appKey'], ENV['appSecret'], ENV['server'])
expect(rc.token).to be_nil
# create token
rc.authorize(username: ENV['username'], extension: ENV['extension'], password: ENV['password'])
expect(rc.token).not_to be_nil
# refresh token
rc.refresh
expect(rc.token).not_to be_nil
# revoke token
rc.revoke
expect(rc.token).to be_nil
end
it 'test_http_methods' do
Dotenv.load
rc = RingCentral.new(ENV['appKey'], ENV['appSecret'], ENV['server'])
rc.authorize(username: ENV['username'], extension: ENV['extension'], password: ENV['password'])
# get
r = rc.get('/restapi/v1.0/account/~/extension/~')
expect(r).not_to be_nil
expect('101').to eq(JSON.parse(r.body)['extensionNumber'])
# post
r = rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
to: [{phoneNumber: ENV['receiver']}],
from: {phoneNumber: ENV['username']},
text: 'Hello world'
})
expect(r).not_to be_nil
message = JSON.parse(r.body)
expect('SMS').to eq(message['type'])
messageUrl = "/restapi/v1.0/account/~/extension/~/message-store/#{message['id']}"
# put
r = rc.put(messageUrl, payload: { readStatus: 'Unread' })
expect(r).not_to be_nil
message = JSON.parse(r.body)
expect('Unread').to eq(message['readStatus'])
r = rc.put(messageUrl, payload: { readStatus: 'Read' })
expect(r).not_to be_nil
message = JSON.parse(r.body)
expect('Read').to eq(message['readStatus'])
# delete
r = rc.delete(messageUrl)
expect(r).not_to be_nil
r = rc.get(messageUrl)
expect(r).not_to be_nil
message = JSON.parse(r.body)
expect('Deleted').to eq(message['availability'])
end
end
end