-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathclient_spec.rb
More file actions
107 lines (86 loc) · 3.49 KB
/
client_spec.rb
File metadata and controls
107 lines (86 loc) · 3.49 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# frozen_string_literal: true
require 'spec_helper'
module Intercom
describe Client do
let(:token) { 'my_access_token' }
let(:client) do
Client.new(
token: token,
handle_rate_limit: true
)
end
it 'should set the base url' do
_(client.base_url).must_equal('https://api.intercom.io')
end
it 'should have handle_rate_limit set' do
_(client.handle_rate_limit).must_equal(true)
end
it 'should be able to change the base url' do
prev = client.options(Intercom::Client.set_base_url('https://mymockintercom.io'))
_(client.base_url).must_equal('https://mymockintercom.io')
client.options(prev)
_(client.base_url).must_equal('https://api.intercom.io')
end
it 'should be able to change the timeouts' do
prev = client.options(Intercom::Client.set_timeouts(open_timeout: 10, read_timeout: 15))
_(client.timeouts).must_equal(open_timeout: 10, read_timeout: 15)
client.options(prev)
_(client.timeouts).must_equal(open_timeout: 30, read_timeout: 90)
end
it 'should be able to change the open timeout individually' do
prev = client.options(Intercom::Client.set_timeouts(open_timeout: 50))
_(client.timeouts).must_equal(open_timeout: 50, read_timeout: 90)
client.options(prev)
_(client.timeouts).must_equal(open_timeout: 30, read_timeout: 90)
end
it 'should be able to change the read timeout individually' do
prev = client.options(Intercom::Client.set_timeouts(read_timeout: 50))
_(client.timeouts).must_equal(open_timeout: 30, read_timeout: 50)
client.options(prev)
_(client.timeouts).must_equal(open_timeout: 30, read_timeout: 90)
end
it 'should raise on nil credentials' do
_(proc { Client.new(token: nil) }).must_raise MisconfiguredClientError
end
describe 'API version' do
it 'does not set the api version by default' do
assert_nil(client.api_version)
end
it 'allows api version to be provided' do
_(Client.new(token: token, api_version: '2.0').api_version).must_equal('2.0')
end
it 'allows api version to be nil' do
# matches default behavior, and will honor version set in the Developer Hub
assert_nil(Client.new(token: token, api_version: nil).api_version)
end
it 'allows api version to be Unstable' do
_(Client.new(token: token, api_version: 'Unstable').api_version).must_equal('Unstable')
end
it 'raises on invalid api version' do
_(proc { Client.new(token: token, api_version: '0.2') }).must_raise MisconfiguredClientError
end
it 'raises on empty api version' do
_(proc { Client.new(token: token, api_version: '') }).must_raise MisconfiguredClientError
end
it 'assigns works' do
stub_request(:any, 'https://api.intercom.io/contacts?id=123').to_return(
status: [200, 'OK'],
headers: { 'X-RateLimit-Reset' => Time.now.utc + 10 },
body: { "test": 'testing' }.to_json
)
client.get('/contacts', id: '123')
end
it 'sets rate limit details to empty hash' do
stub_request(:any, "https://api.intercom.io/test").to_raise(StandardError)
expect { client.get('/test', {}) }.must_raise(StandardError)
client.rate_limit_details.must_equal({})
end
end
describe 'OAuth clients' do
it 'supports "token"' do
client = Client.new(token: 'foo')
_(client.token).must_equal('foo')
end
end
end
end