cobot_client 4.0.0 → 6.0.0
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 +5 -5
- data/.github/workflows/ruby.yml +23 -0
- data/.github/workflows/test.yml +26 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +31 -0
- data/CHANGELOG.md +15 -3
- data/Gemfile +10 -0
- data/README.md +49 -11
- data/Rakefile +6 -2
- data/cobot_client.gemspec +18 -17
- data/lib/cobot_client/api_client.rb +31 -90
- data/lib/cobot_client/engine.rb +2 -0
- data/lib/cobot_client/errors.rb +47 -0
- data/lib/cobot_client/navigation_link.rb +11 -8
- data/lib/cobot_client/navigation_link_service.rb +11 -6
- data/lib/cobot_client/request.rb +89 -0
- data/lib/cobot_client/response.rb +45 -0
- data/lib/cobot_client/url_helper.rb +23 -20
- data/lib/cobot_client/version.rb +3 -1
- data/lib/cobot_client.rb +12 -3
- data/rbs_collection.yaml +20 -0
- data/sig/cobot_client/api_client.rbs +51 -0
- data/sig/cobot_client/errors.rbs +23 -0
- data/sig/cobot_client/navigation_link.rbs +11 -0
- data/sig/cobot_client/navigation_link_service.rbs +17 -0
- data/sig/cobot_client/request.rbs +39 -0
- data/sig/cobot_client/response.rbs +23 -0
- data/sig/cobot_client/url_helper.rbs +25 -0
- data/sig/cobot_client/version.rbs +3 -0
- data/sig/manifests.yaml +4 -0
- data/spec/cobot_client/api_client_spec.rb +183 -173
- data/spec/cobot_client/navigation_link_service_spec.rb +48 -23
- data/spec/cobot_client/url_helper_spec.rb +8 -6
- data/spec/spec_helper.rb +10 -0
- metadata +35 -67
- data/.travis.yml +0 -4
- data/lib/cobot_client/exceptions.rb +0 -17
|
@@ -1,133 +1,96 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe CobotClient::ApiClient do
|
|
4
|
-
let(:api_client) {
|
|
5
|
-
let(:default_response) {
|
|
6
|
-
|
|
7
|
-
before(:each) do
|
|
8
|
-
CobotClient::ApiClient.user_agent = 'test agent'
|
|
9
|
-
CobotClient::ApiClient.retry_time = 0
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
context 'listing resources' do
|
|
13
|
-
it 'calls rest client' do
|
|
14
|
-
expect(RestClient).to receive(:get).with('https://co-up.cobot.me/api/resources',
|
|
15
|
-
hash_including('Authorization' => 'Bearer token-123')) { default_response }
|
|
16
|
-
|
|
17
|
-
api_client.get_resources 'co-up'
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it 'returns the json' do
|
|
21
|
-
allow(RestClient).to receive(:get) { double(:response, body: [{id: 'resource-1'}].to_json) }
|
|
22
|
-
|
|
23
|
-
resources = api_client.get_resources 'co-up'
|
|
24
|
-
|
|
25
|
-
expect(resources).to eql([{id: 'resource-1'}])
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
context 'creating a booking' do
|
|
30
|
-
it 'calls rest client' do
|
|
31
|
-
expect(RestClient).to receive(:post).with(
|
|
32
|
-
'https://co-up.cobot.me/api/resources/res-1/bookings',
|
|
33
|
-
{title: 'meeting'}.to_json,
|
|
34
|
-
hash_including('Authorization' => 'Bearer token-123')) { default_response }
|
|
35
|
-
|
|
36
|
-
api_client.create_booking 'co-up', 'res-1', title: 'meeting'
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it 'returns the json' do
|
|
40
|
-
allow(RestClient).to receive(:post) { double(:response,
|
|
41
|
-
code: 201, body: {title: 'meeting'}.to_json) }
|
|
42
|
-
|
|
43
|
-
booking = api_client.create_booking 'co-up', 'res-1', title: 'meeting'
|
|
44
|
-
|
|
45
|
-
expect(booking).to eql({title: 'meeting'})
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
context 'updating a booking' do
|
|
50
|
-
it 'calls rest client' do
|
|
51
|
-
expect(RestClient).to receive(:put).with('https://co-up.cobot.me/api/bookings/booking-1',
|
|
52
|
-
{title: 'meeting'}.to_json,
|
|
53
|
-
hash_including('Authorization' => 'Bearer token-123')) { default_response }
|
|
54
|
-
|
|
55
|
-
api_client.update_booking 'co-up', 'booking-1', title: 'meeting'
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it 'returns the json' do
|
|
59
|
-
allow(RestClient).to receive(:put) { double(:response, code: 200,
|
|
60
|
-
body: {title: 'meeting'}.to_json) }
|
|
6
|
+
let(:api_client) { described_class.new('token-123') }
|
|
7
|
+
let(:default_response) { {status: 200, body: '{}'} }
|
|
61
8
|
|
|
62
|
-
|
|
9
|
+
def cobot_client_response(code:, body: '')
|
|
10
|
+
net_http_response = Net::HTTPResponse.new('1.1', code.to_s, nil)
|
|
11
|
+
net_http_response.body = body
|
|
12
|
+
net_http_response.instance_variable_set(:@read, true)
|
|
63
13
|
|
|
64
|
-
|
|
65
|
-
end
|
|
14
|
+
CobotClient::Response.new(net_http_response)
|
|
66
15
|
end
|
|
67
16
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
hash_including('Authorization' => 'Bearer token-123')) { default_response }
|
|
72
|
-
|
|
73
|
-
api_client.delete_booking 'co-up', 'booking-1'
|
|
74
|
-
end
|
|
17
|
+
before do
|
|
18
|
+
described_class.user_agent = 'test agent'
|
|
19
|
+
described_class.retry_time = 0
|
|
75
20
|
end
|
|
76
21
|
|
|
77
|
-
|
|
78
|
-
it '
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
22
|
+
describe '#put' do
|
|
23
|
+
it 'accepts a subdomain' do
|
|
24
|
+
request = stub_request(:put, 'https://co-up.cobot.me/api/invoices')
|
|
25
|
+
.with(
|
|
26
|
+
body: {id: '1'}.to_json,
|
|
27
|
+
headers: {
|
|
28
|
+
'Content-Type' => 'application/json',
|
|
29
|
+
'User-Agent' => 'test agent',
|
|
30
|
+
'Authorization' => 'Bearer token-123'
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
.and_return(default_response)
|
|
85
34
|
|
|
86
35
|
api_client.put 'co-up', '/invoices', {id: '1'}
|
|
36
|
+
|
|
37
|
+
expect(request).to have_been_made.once
|
|
87
38
|
end
|
|
88
39
|
|
|
89
40
|
it 'passes an array as body' do
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
41
|
+
request = stub_request(:put, 'https://co-up.cobot.me/api/invoices')
|
|
42
|
+
.with(
|
|
43
|
+
body: [{id: '1'}].to_json,
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type' => 'application/json',
|
|
46
|
+
'User-Agent' => 'test agent',
|
|
47
|
+
'Authorization' => 'Bearer token-123'
|
|
48
|
+
}
|
|
49
|
+
)
|
|
50
|
+
.and_return(default_response)
|
|
96
51
|
|
|
97
52
|
api_client.put 'co-up', '/invoices', [{id: '1'}]
|
|
53
|
+
|
|
54
|
+
expect(request).to have_been_made.once
|
|
98
55
|
end
|
|
99
56
|
|
|
100
57
|
it 'accepts a url' do
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
58
|
+
request = stub_request(:put, 'https://co-up.cobot.me/api/invoices')
|
|
59
|
+
.with(
|
|
60
|
+
body: {id: '1'}.to_json,
|
|
61
|
+
headers: {
|
|
62
|
+
'Content-Type' => 'application/json',
|
|
63
|
+
'User-Agent' => 'test agent',
|
|
64
|
+
'Authorization' => 'Bearer token-123'
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
.and_return(default_response)
|
|
107
68
|
|
|
108
69
|
api_client.put 'https://co-up.cobot.me/api/invoices', {id: '1'}
|
|
70
|
+
|
|
71
|
+
expect(request).to have_been_made.once
|
|
109
72
|
end
|
|
110
73
|
|
|
111
74
|
it 'returns the response json' do
|
|
112
|
-
|
|
75
|
+
allow_any_instance_of(CobotClient::Request).to receive(:submit) { cobot_client_response(code: 200, body: [{number: 1}].to_json) }
|
|
113
76
|
|
|
114
77
|
expect(api_client.put('co-up', '/invoices', {})).to eql([{number: 1}])
|
|
115
78
|
end
|
|
116
79
|
|
|
117
80
|
it 'returns nil when the status code is 204' do
|
|
118
|
-
|
|
81
|
+
allow_any_instance_of(CobotClient::Request).to receive(:submit) { cobot_client_response(body: '', code: 204) }
|
|
119
82
|
|
|
120
83
|
expect(api_client.put('co-up', '/invoices', {})).to be_nil
|
|
121
84
|
end
|
|
122
85
|
|
|
123
86
|
it 'retries a 502 error' do
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if
|
|
127
|
-
|
|
128
|
-
|
|
87
|
+
times = 0
|
|
88
|
+
allow_any_instance_of(CobotClient::Request).to receive(:submit) do
|
|
89
|
+
if times < 3
|
|
90
|
+
times += 1
|
|
91
|
+
cobot_client_response(code: 502)
|
|
129
92
|
else
|
|
130
|
-
|
|
93
|
+
cobot_client_response(code: 200, body: {success: true}.to_json)
|
|
131
94
|
end
|
|
132
95
|
end
|
|
133
96
|
|
|
@@ -135,49 +98,61 @@ describe CobotClient::ApiClient do
|
|
|
135
98
|
end
|
|
136
99
|
end
|
|
137
100
|
|
|
138
|
-
|
|
139
|
-
it '
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
101
|
+
describe '#patch' do
|
|
102
|
+
it 'accepts a subdomain' do
|
|
103
|
+
request = stub_request(:patch, 'https://co-up.cobot.me/api/invoices')
|
|
104
|
+
.with(
|
|
105
|
+
body: {id: '1'}.to_json,
|
|
106
|
+
headers: {
|
|
107
|
+
'Content-Type' => 'application/json',
|
|
108
|
+
'User-Agent' => 'test agent',
|
|
109
|
+
'Authorization' => 'Bearer token-123'
|
|
110
|
+
}
|
|
111
|
+
)
|
|
112
|
+
.and_return(default_response)
|
|
146
113
|
|
|
147
114
|
api_client.patch 'co-up', '/invoices', {id: '1'}
|
|
115
|
+
|
|
116
|
+
expect(request).to have_been_made.once
|
|
148
117
|
end
|
|
149
118
|
|
|
150
119
|
it 'accepts a url' do
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
120
|
+
request = stub_request(:patch, 'https://co-up.cobot.me/api/invoices')
|
|
121
|
+
.with(
|
|
122
|
+
body: {id: '1'}.to_json,
|
|
123
|
+
headers: {
|
|
124
|
+
'Content-Type' => 'application/json',
|
|
125
|
+
'User-Agent' => 'test agent',
|
|
126
|
+
'Authorization' => 'Bearer token-123'
|
|
127
|
+
}
|
|
128
|
+
)
|
|
129
|
+
.and_return(default_response)
|
|
157
130
|
|
|
158
131
|
api_client.patch 'https://co-up.cobot.me/api/invoices', {id: '1'}
|
|
132
|
+
|
|
133
|
+
expect(request).to have_been_made.once
|
|
159
134
|
end
|
|
160
135
|
|
|
161
136
|
it 'returns the response json' do
|
|
162
|
-
|
|
137
|
+
allow_any_instance_of(CobotClient::Request).to receive(:submit) { cobot_client_response(code: 200, body: [{number: 1}].to_json) }
|
|
163
138
|
|
|
164
139
|
expect(api_client.patch('co-up', '/invoices', {})).to eql([{number: 1}])
|
|
165
140
|
end
|
|
166
141
|
|
|
167
142
|
it 'returns nil when the status code is 204' do
|
|
168
|
-
|
|
143
|
+
allow_any_instance_of(CobotClient::Request).to receive(:submit) { cobot_client_response(body: '', code: 204) }
|
|
169
144
|
|
|
170
145
|
expect(api_client.patch('co-up', '/invoices', {})).to be_nil
|
|
171
146
|
end
|
|
172
147
|
|
|
173
148
|
it 'retries a 502 error' do
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if
|
|
177
|
-
|
|
178
|
-
|
|
149
|
+
times = 0
|
|
150
|
+
allow_any_instance_of(CobotClient::Request).to receive(:submit) do
|
|
151
|
+
if times < 3
|
|
152
|
+
times += 1
|
|
153
|
+
cobot_client_response(code: 502)
|
|
179
154
|
else
|
|
180
|
-
|
|
155
|
+
cobot_client_response(code: 200, body: {success: true}.to_json)
|
|
181
156
|
end
|
|
182
157
|
end
|
|
183
158
|
|
|
@@ -185,127 +160,162 @@ describe CobotClient::ApiClient do
|
|
|
185
160
|
end
|
|
186
161
|
end
|
|
187
162
|
|
|
188
|
-
|
|
189
|
-
it '
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
163
|
+
describe '#post' do
|
|
164
|
+
it 'accepts a subdomain' do
|
|
165
|
+
request = stub_request(:post, 'https://co-up.cobot.me/api/invoices')
|
|
166
|
+
.with(
|
|
167
|
+
body: {id: '1'}.to_json,
|
|
168
|
+
headers: {
|
|
169
|
+
'Content-Type' => 'application/json',
|
|
170
|
+
'User-Agent' => 'test agent',
|
|
171
|
+
'Authorization' => 'Bearer token-123'
|
|
172
|
+
}
|
|
173
|
+
)
|
|
174
|
+
.and_return(default_response)
|
|
196
175
|
|
|
197
176
|
api_client.post 'co-up', '/invoices', {id: '1'}
|
|
177
|
+
|
|
178
|
+
expect(request).to have_been_made.once
|
|
198
179
|
end
|
|
199
180
|
|
|
200
181
|
it 'accepts a url' do
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
182
|
+
request = stub_request(:post, 'https://co-up.cobot.me/api/invoices')
|
|
183
|
+
.with(
|
|
184
|
+
body: {id: '1'}.to_json,
|
|
185
|
+
headers: {
|
|
186
|
+
'Content-Type' => 'application/json',
|
|
187
|
+
'User-Agent' => 'test agent',
|
|
188
|
+
'Authorization' => 'Bearer token-123'
|
|
189
|
+
}
|
|
190
|
+
)
|
|
191
|
+
.and_return(default_response)
|
|
207
192
|
|
|
208
193
|
api_client.post 'https://co-up.cobot.me/api/invoices', {id: '1'}
|
|
194
|
+
|
|
195
|
+
expect(request).to have_been_made.once
|
|
209
196
|
end
|
|
210
197
|
|
|
211
198
|
it 'returns the response json' do
|
|
212
|
-
|
|
213
|
-
code: 201, body: [{number: 1}].to_json)
|
|
199
|
+
allow_any_instance_of(CobotClient::Request).to receive(:submit) {
|
|
200
|
+
cobot_client_response(code: 201, body: [{number: 1}].to_json)
|
|
201
|
+
}
|
|
214
202
|
|
|
215
203
|
expect(api_client.post('co-up', '/invoices', {})).to eql([{number: 1}])
|
|
216
204
|
end
|
|
217
205
|
|
|
218
206
|
it 'returns nil when the status code is 204' do
|
|
219
|
-
|
|
220
|
-
body: '')
|
|
207
|
+
allow_any_instance_of(CobotClient::Request).to receive(:submit) {
|
|
208
|
+
cobot_client_response(code: 204, body: '')
|
|
209
|
+
}
|
|
221
210
|
|
|
222
211
|
expect(api_client.post('co-up', '/invoices', {})).to be_nil
|
|
223
212
|
end
|
|
224
213
|
end
|
|
225
214
|
|
|
226
|
-
|
|
227
|
-
it '
|
|
228
|
-
|
|
229
|
-
|
|
215
|
+
describe '#get' do
|
|
216
|
+
it 'accepts a subdomain' do
|
|
217
|
+
request = stub_request(:get, 'https://co-up.cobot.me/api/invoices?from=2013-10-6&to=2013-10-12')
|
|
218
|
+
.with(headers:
|
|
219
|
+
{
|
|
220
|
+
'User-Agent' => 'test agent',
|
|
221
|
+
'Authorization' => 'Bearer token-123'
|
|
222
|
+
})
|
|
223
|
+
.and_return(default_response)
|
|
230
224
|
|
|
231
225
|
api_client.get 'co-up', '/invoices', {from: '2013-10-6', to: '2013-10-12'}
|
|
226
|
+
|
|
227
|
+
expect(request).to have_been_made.once
|
|
232
228
|
end
|
|
233
229
|
|
|
234
230
|
it 'accepts a url' do
|
|
235
|
-
|
|
236
|
-
|
|
231
|
+
request = stub_request(:get, 'https://co-up.cobot.me/api/invoices?from=2013-10-6&to=2013-10-12')
|
|
232
|
+
.with(headers:
|
|
233
|
+
{
|
|
234
|
+
'User-Agent' => 'test agent',
|
|
235
|
+
'Authorization' => 'Bearer token-123'
|
|
236
|
+
})
|
|
237
|
+
.and_return(default_response)
|
|
237
238
|
|
|
238
239
|
api_client.get 'https://co-up.cobot.me/api/invoices', {from: '2013-10-6', to: '2013-10-12'}
|
|
240
|
+
|
|
241
|
+
expect(request).to have_been_made.once
|
|
239
242
|
end
|
|
240
243
|
|
|
241
244
|
it 'returns the response json' do
|
|
242
|
-
|
|
245
|
+
allow_any_instance_of(CobotClient::Request).to receive(:submit) { cobot_client_response(code: 200, body: [{number: 1}].to_json) }
|
|
243
246
|
|
|
244
247
|
expect(api_client.get('co-up', '/invoices')).to eql([{number: 1}])
|
|
245
248
|
end
|
|
246
249
|
|
|
247
|
-
it 'converts a
|
|
248
|
-
|
|
250
|
+
it 'converts a net/http error into a cobot error' do
|
|
251
|
+
allow_any_instance_of(CobotClient::Request).to receive(:submit).and_raise(Timeout::Error.new)
|
|
249
252
|
|
|
250
253
|
expect do
|
|
251
254
|
api_client.get('co-up', '/invoices')
|
|
252
|
-
end.to raise_error(CobotClient::
|
|
255
|
+
end.to raise_error(CobotClient::ConnectionError)
|
|
253
256
|
end
|
|
254
257
|
|
|
255
|
-
it 'retries a
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
count += 1
|
|
260
|
-
fail RestClient::RequestTimeout
|
|
261
|
-
else
|
|
262
|
-
double(:response, body: '{}')
|
|
263
|
-
end
|
|
264
|
-
end
|
|
265
|
-
|
|
266
|
-
expect(RestClient).to receive(:get).exactly(2).times
|
|
258
|
+
it 'retries a Net::ReadTimeout' do
|
|
259
|
+
stub_request(:get, 'https://co-up.cobot.me/api/invoices')
|
|
260
|
+
.to_raise(Net::ReadTimeout.new)
|
|
261
|
+
.to_return(status: 200, body: '{}')
|
|
267
262
|
|
|
268
263
|
api_client.get('co-up', '/invoices')
|
|
264
|
+
|
|
265
|
+
expect(a_request(:get, 'https://co-up.cobot.me/api/invoices')).to have_been_made.twice
|
|
269
266
|
end
|
|
270
267
|
|
|
271
|
-
it 'converts a
|
|
272
|
-
|
|
268
|
+
it 'converts a Net::ReadTimeout into a CobotClient::ConnectionError' do
|
|
269
|
+
allow_any_instance_of(CobotClient::Request).to receive(:submit).and_raise(Net::ReadTimeout.new)
|
|
273
270
|
|
|
274
271
|
expect do
|
|
275
272
|
api_client.get('co-up', '/invoices')
|
|
276
|
-
end.to raise_error(CobotClient::
|
|
273
|
+
end.to raise_error(CobotClient::ConnectionError, /^Net::ReadTimeout: /)
|
|
277
274
|
end
|
|
278
275
|
|
|
279
276
|
it 'includes the response, http code and http body in the exception' do
|
|
280
|
-
response =
|
|
281
|
-
error =
|
|
282
|
-
|
|
277
|
+
response = cobot_client_response(code: 404, body: 'boom')
|
|
278
|
+
error = response.to_error
|
|
279
|
+
allow_any_instance_of(CobotClient::Request).to receive(:submit).and_raise(error)
|
|
283
280
|
|
|
284
281
|
begin
|
|
285
282
|
api_client.get('co-up', '/invoices')
|
|
286
|
-
rescue CobotClient::
|
|
283
|
+
rescue CobotClient::ResponseError => e
|
|
284
|
+
expect(e).to be_a(CobotClient::NotFound)
|
|
287
285
|
expect(e.response).to eql(response)
|
|
288
|
-
expect(e.http_code).to
|
|
286
|
+
expect(e.http_code).to be(404)
|
|
289
287
|
expect(e.http_body).to eql('boom')
|
|
290
288
|
end
|
|
291
289
|
end
|
|
292
290
|
end
|
|
293
291
|
|
|
294
|
-
|
|
295
|
-
it '
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
292
|
+
describe '#delete' do
|
|
293
|
+
it 'accepts a subdomain' do
|
|
294
|
+
request = stub_request(:delete, 'https://co-up.cobot.me/api/invoices/1')
|
|
295
|
+
.with(
|
|
296
|
+
headers: {
|
|
297
|
+
'User-Agent' => 'test agent',
|
|
298
|
+
'Authorization' => 'Bearer token-123'
|
|
299
|
+
}
|
|
300
|
+
).and_return(default_response)
|
|
299
301
|
|
|
300
302
|
api_client.delete 'co-up', '/invoices/1'
|
|
303
|
+
|
|
304
|
+
expect(request).to have_been_made.once
|
|
301
305
|
end
|
|
302
306
|
|
|
303
307
|
it 'accepts a url' do
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
308
|
+
request = stub_request(:delete, 'https://co-up.cobot.me/api/invoices/1')
|
|
309
|
+
.with(
|
|
310
|
+
headers: {
|
|
311
|
+
'User-Agent' => 'test agent',
|
|
312
|
+
'Authorization' => 'Bearer token-123'
|
|
313
|
+
}
|
|
314
|
+
).and_return(default_response)
|
|
307
315
|
|
|
308
316
|
api_client.delete 'https://co-up.cobot.me/api/invoices/1'
|
|
317
|
+
|
|
318
|
+
expect(request).to have_been_made.once
|
|
309
319
|
end
|
|
310
320
|
end
|
|
311
321
|
end
|
|
@@ -1,36 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
|
-
describe CobotClient::NavigationLinkService
|
|
4
|
-
let(:service) {
|
|
5
|
-
let(:api_client) {
|
|
5
|
+
describe CobotClient::NavigationLinkService do
|
|
6
|
+
let(:service) { described_class.new(api_client, 'co-up') }
|
|
7
|
+
let(:api_client) { CobotClient::ApiClient.new('access_token') }
|
|
6
8
|
|
|
7
9
|
context 'when there are links already' do
|
|
8
10
|
let(:existing_link) do
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
CobotClient::NavigationLink.new(
|
|
12
|
+
label: 'existing link',
|
|
13
|
+
section: 'admin/setup',
|
|
14
|
+
iframe_url: 'http://example.com/1'
|
|
15
|
+
)
|
|
11
16
|
end
|
|
12
17
|
let(:new_link) do
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
CobotClient::NavigationLink.new(
|
|
19
|
+
label: 'new link',
|
|
20
|
+
section: 'admin/setup',
|
|
21
|
+
iframe_url: 'http://example.com/2'
|
|
22
|
+
)
|
|
15
23
|
end
|
|
16
24
|
|
|
17
|
-
before
|
|
25
|
+
before do
|
|
18
26
|
allow(api_client).to receive(:get)
|
|
19
27
|
.with('co-up', '/navigation_links')
|
|
20
|
-
.and_return(
|
|
21
|
-
|
|
28
|
+
.and_return(
|
|
29
|
+
[
|
|
30
|
+
{
|
|
31
|
+
label: 'existing link',
|
|
32
|
+
section: 'admin/setup',
|
|
33
|
+
iframe_url: 'http://example.com/1'
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
)
|
|
22
37
|
end
|
|
23
38
|
|
|
24
39
|
it 'installs the missing links' do
|
|
25
40
|
expect(api_client).to receive(:post)
|
|
26
|
-
.with(
|
|
27
|
-
|
|
41
|
+
.with(
|
|
42
|
+
'co-up',
|
|
43
|
+
'/navigation_links',
|
|
44
|
+
hash_including(
|
|
45
|
+
label: 'new link',
|
|
46
|
+
section: 'admin/setup',
|
|
47
|
+
iframe_url: 'http://example.com/2'
|
|
48
|
+
)
|
|
49
|
+
).and_return({})
|
|
28
50
|
|
|
29
51
|
service.install_links [existing_link, new_link]
|
|
30
52
|
end
|
|
31
53
|
|
|
32
54
|
it 'returns all the links' do
|
|
33
|
-
allow(api_client).to receive(:post)
|
|
55
|
+
allow(api_client).to receive(:post).and_return({label: 'new link'})
|
|
34
56
|
|
|
35
57
|
expect(service.install_links([existing_link, new_link]).map(&:label)).to eql(['existing link', 'new link'])
|
|
36
58
|
end
|
|
@@ -38,28 +60,31 @@ describe CobotClient::NavigationLinkService, '#install_links' do
|
|
|
38
60
|
|
|
39
61
|
context 'when there are no links installed' do
|
|
40
62
|
let(:link) do
|
|
41
|
-
|
|
42
|
-
section: 'admin/manage',
|
|
43
|
-
|
|
63
|
+
CobotClient::NavigationLink.new(
|
|
64
|
+
section: 'admin/manage',
|
|
65
|
+
label: 'test link',
|
|
66
|
+
iframe_url: '/test',
|
|
67
|
+
user_editable: true
|
|
68
|
+
)
|
|
44
69
|
end
|
|
45
70
|
|
|
46
|
-
before
|
|
47
|
-
allow(api_client).to receive(:get).with('co-up', '/navigation_links')
|
|
71
|
+
before do
|
|
72
|
+
allow(api_client).to receive(:get).with('co-up', '/navigation_links').and_return([])
|
|
48
73
|
end
|
|
49
74
|
|
|
50
75
|
it 'installs the links' do
|
|
51
76
|
expect(api_client).to receive(:post)
|
|
52
77
|
.with('co-up', '/navigation_links',
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
78
|
+
section: 'admin/manage',
|
|
79
|
+
label: 'test link',
|
|
80
|
+
iframe_url: '/test',
|
|
81
|
+
user_editable: true).and_return({})
|
|
57
82
|
|
|
58
83
|
service.install_links [link]
|
|
59
84
|
end
|
|
60
85
|
|
|
61
86
|
it 'returns the links created' do
|
|
62
|
-
allow(api_client).to receive(:post)
|
|
87
|
+
allow(api_client).to receive(:post).and_return({label: 'test link'})
|
|
63
88
|
|
|
64
89
|
expect(service.install_links([link]).map(&:label)).to eql(['test link'])
|
|
65
90
|
end
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
|
-
describe CobotClient::UrlHelper
|
|
5
|
+
describe CobotClient::UrlHelper do
|
|
4
6
|
let(:helper) do
|
|
5
7
|
Object.new.tap do |o|
|
|
6
|
-
o.extend
|
|
8
|
+
o.extend described_class
|
|
7
9
|
end
|
|
8
10
|
end
|
|
9
11
|
|
|
10
|
-
after
|
|
11
|
-
|
|
12
|
+
after do
|
|
13
|
+
described_class.site = 'https://www.cobot.me'
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
it 'lets me change the site' do
|
|
15
|
-
|
|
17
|
+
described_class.site = 'https://www.cobot.com'
|
|
16
18
|
|
|
17
19
|
expect(helper.cobot_url).to eql('https://www.cobot.com/')
|
|
18
20
|
end
|
|
@@ -21,7 +23,7 @@ describe CobotClient::UrlHelper, 'cobot_url' do
|
|
|
21
23
|
expect(helper.cobot_url).to eql('https://www.cobot.me/')
|
|
22
24
|
end
|
|
23
25
|
|
|
24
|
-
it 'returns a url with a
|
|
26
|
+
it 'returns a url with a subdomain' do
|
|
25
27
|
expect(helper.cobot_url('co-up')).to eql('https://co-up.cobot.me/')
|
|
26
28
|
end
|
|
27
29
|
|
data/spec/spec_helper.rb
CHANGED