rdstation-ruby-client 1.2.0 → 2.3.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.
Files changed (47) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE/rdsm-ruby-client-issue-template.md +49 -0
  3. data/.rspec +2 -0
  4. data/CHANGELOG.md +163 -0
  5. data/README.md +243 -43
  6. data/lib/rdstation-ruby-client.rb +6 -0
  7. data/lib/rdstation.rb +19 -0
  8. data/lib/rdstation/api_response.rb +3 -3
  9. data/lib/rdstation/authentication.rb +32 -3
  10. data/lib/rdstation/authorization.rb +24 -0
  11. data/lib/rdstation/builder/field.rb +70 -0
  12. data/lib/rdstation/client.rb +17 -70
  13. data/lib/rdstation/contacts.rb +21 -16
  14. data/lib/rdstation/error.rb +22 -15
  15. data/lib/rdstation/error/format.rb +21 -3
  16. data/lib/rdstation/error/formatter.rb +53 -7
  17. data/lib/rdstation/error_handler.rb +29 -26
  18. data/lib/rdstation/error_handler/bad_request.rb +30 -0
  19. data/lib/rdstation/error_handler/unauthorized.rb +17 -9
  20. data/lib/rdstation/events.rb +7 -19
  21. data/lib/rdstation/fields.rb +31 -7
  22. data/lib/rdstation/retryable_request.rb +35 -0
  23. data/lib/rdstation/version.rb +1 -1
  24. data/lib/rdstation/webhooks.rb +25 -17
  25. data/rdstation-ruby-client.gemspec +4 -1
  26. data/spec/lib/rdstation-ruby-client_spec.rb +1 -1
  27. data/spec/lib/rdstation/api_response_spec.rb +34 -0
  28. data/spec/lib/rdstation/authentication_spec.rb +164 -0
  29. data/spec/lib/rdstation/authorization_spec.rb +24 -0
  30. data/spec/lib/rdstation/builder/field_spec.rb +69 -0
  31. data/spec/lib/rdstation/client_spec.rb +37 -0
  32. data/spec/lib/rdstation/contacts_spec.rb +54 -41
  33. data/spec/lib/rdstation/error/format_spec.rb +46 -0
  34. data/spec/lib/rdstation/error/formatter_spec.rb +83 -0
  35. data/spec/lib/rdstation/error_handler/unauthorized_spec.rb +0 -29
  36. data/spec/lib/rdstation/error_handler_spec.rb +153 -26
  37. data/spec/lib/rdstation/events_spec.rb +20 -9
  38. data/spec/lib/rdstation/fields_spec.rb +10 -3
  39. data/spec/lib/rdstation/retryable_request_spec.rb +142 -0
  40. data/spec/lib/rdstation/webhooks_spec.rb +41 -13
  41. data/spec/lib/rdstation_spec.rb +18 -0
  42. metadata +40 -13
  43. data/Gemfile.lock +0 -59
  44. data/lib/rdstation/error_handler/default.rb +0 -15
  45. data/lib/rdstation/error_handler/resource_not_found.rb +0 -24
  46. data/spec/lib/rdstation/error_handler/default_spec.rb +0 -14
  47. data/spec/lib/rdstation/error_handler/resource_not_found_spec.rb +0 -54
@@ -18,12 +18,15 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.required_ruby_version = '>= 2.0.0'
22
+
23
+ spec.add_development_dependency "bundler", "> 1.3"
22
24
  spec.add_development_dependency "rake"
23
25
  spec.add_development_dependency 'rspec'
24
26
  spec.add_development_dependency 'webmock', '~> 2.1'
25
27
  spec.add_development_dependency 'turn'
26
28
  spec.add_development_dependency 'rspec_junit_formatter'
29
+ spec.add_development_dependency 'pry'
27
30
 
28
31
  spec.add_dependency "httparty", "~> 0.12"
29
32
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe RDStation do
4
4
  let(:rdstation_client) { RDStation::Client.new('token','private' ) }
5
5
  let(:lead_email) { "iginosms@gmail.com" }
6
- let(:amount) { 300}
6
+ let(:amount) { 300 }
7
7
 
8
8
 
9
9
  context "#change_lead_status" do
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RDStation::ApiResponse do
4
+ describe ".build" do
5
+ context "when the response HTTP status is 2xx" do
6
+ let(:response) { OpenStruct.new(code: 200, body: '{}') }
7
+
8
+ it "returns the response body" do
9
+ expect(RDStation::ApiResponse.build(response)).to eq({})
10
+ end
11
+ end
12
+
13
+ shared_examples_for 'call_error_handler' do
14
+ it "calls error handler" do
15
+ error_handler = instance_double(RDStation::ErrorHandler)
16
+ allow(error_handler).to receive(:raise_error)
17
+ expect(RDStation::ErrorHandler).to receive(:new).with(response).and_return(error_handler)
18
+ RDStation::ApiResponse.build(response)
19
+ end
20
+ end
21
+
22
+ context "when the response is not in the 2xx range" do
23
+ let(:response) { OpenStruct.new(code: 404, body: '{}') }
24
+
25
+ it_behaves_like 'call_error_handler'
26
+ end
27
+
28
+ context "when the response body is not JSON-parseable" do
29
+ let(:response) { OpenStruct.new(code: 504, body: '<html><head></head><body></body></html>') }
30
+
31
+ it_behaves_like 'call_error_handler'
32
+ end
33
+ end
34
+ end
@@ -88,6 +88,34 @@ RSpec.describe RDStation::Authentication do
88
88
 
89
89
  let(:authentication) { described_class.new('client_id', 'client_secret') }
90
90
 
91
+ describe '#auth_url' do
92
+ let(:configuration_client_id) { 'configuration_client_id' }
93
+ let(:configuration_client_secret) { 'configuration_client_secret' }
94
+ let(:redirect_url) { 'redirect_url' }
95
+ before do
96
+ RDStation.configure do |config|
97
+ config.client_id = configuration_client_id
98
+ config.client_secret = configuration_client_secret
99
+ end
100
+ end
101
+
102
+ context 'when client_id and client_secret are specified in initialization' do
103
+ it 'uses those specified in initialization' do
104
+ auth = described_class.new('initialization_client_id', 'initialization_client_secret')
105
+ expected = "https://api.rd.services/auth/dialog?client_id=initialization_client_id&redirect_url=#{redirect_url}"
106
+ expect(auth.auth_url(redirect_url)).to eq expected
107
+ end
108
+ end
109
+
110
+ context 'when client_id and client_secret are specified only in configuration' do
111
+ it 'uses those specified in configuration' do
112
+ auth = described_class.new
113
+ expected = "https://api.rd.services/auth/dialog?client_id=#{configuration_client_id}&redirect_url=#{redirect_url}"
114
+ expect(auth.auth_url(redirect_url)).to eq expected
115
+ end
116
+ end
117
+ end
118
+
91
119
  describe '#authenticate' do
92
120
  context 'when the code is valid' do
93
121
  before do
@@ -138,6 +166,37 @@ RSpec.describe RDStation::Authentication do
138
166
  end.to raise_error(RDStation::Error::ExpiredCodeGrant)
139
167
  end
140
168
  end
169
+
170
+ context 'when client_id and client_secret are specified only in configuration' do
171
+ let(:authentication) { described_class.new }
172
+ let(:configuration_client_id) { 'configuration_client_id' }
173
+ let(:configuration_client_secret) { 'configuration_client_secret' }
174
+ let(:token_request_with_valid_code_secrets_from_config) do
175
+ {
176
+ client_id: configuration_client_id,
177
+ client_secret: configuration_client_secret,
178
+ code: 'valid_code'
179
+ }
180
+ end
181
+ before do
182
+ RDStation.configure do |config|
183
+ config.client_id = configuration_client_id
184
+ config.client_secret = configuration_client_secret
185
+ end
186
+
187
+ stub_request(:post, token_endpoint)
188
+ .with(
189
+ headers: request_headers,
190
+ body: token_request_with_valid_code_secrets_from_config.to_json
191
+ )
192
+ .to_return(credentials_response)
193
+ end
194
+
195
+ it 'returns the credentials' do
196
+ credentials_request = authentication.authenticate('valid_code')
197
+ expect(credentials_request).to eq(credentials)
198
+ end
199
+ end
141
200
  end
142
201
 
143
202
  describe '#update_access_token' do
@@ -173,5 +232,110 @@ RSpec.describe RDStation::Authentication do
173
232
  end.to raise_error(RDStation::Error::InvalidCredentials)
174
233
  end
175
234
  end
235
+
236
+ context 'when client_id and client_secret are specified only in configuration' do
237
+ let(:authentication) { described_class.new }
238
+ let(:configuration_client_id) { 'configuration_client_id' }
239
+ let(:configuration_client_secret) { 'configuration_client_secret' }
240
+ let(:token_request_with_valid_refresh_code_secrets_from_config) do
241
+ {
242
+ client_id: configuration_client_id,
243
+ client_secret: configuration_client_secret,
244
+ refresh_token: 'valid_refresh_token'
245
+ }
246
+ end
247
+ before do
248
+ RDStation.configure do |config|
249
+ config.client_id = configuration_client_id
250
+ config.client_secret = configuration_client_secret
251
+ end
252
+
253
+ stub_request(:post, token_endpoint)
254
+ .with(
255
+ headers: request_headers,
256
+ body: token_request_with_valid_refresh_code_secrets_from_config.to_json
257
+ )
258
+ .to_return(credentials_response)
259
+ end
260
+
261
+ it 'returns the credentials' do
262
+ credentials_request = authentication.update_access_token('valid_refresh_token')
263
+ expect(credentials_request).to eq(credentials)
264
+ end
265
+ end
266
+ end
267
+
268
+ describe ".revoke" do
269
+ let(:revoke_endpoint) { 'https://api.rd.services/auth/revoke' }
270
+ let(:request_headers) do
271
+ {
272
+ "Authorization" => "Bearer #{access_token}",
273
+ "Content-Type" => "application/x-www-form-urlencoded"
274
+ }
275
+ end
276
+
277
+ context "valid access_token" do
278
+ let(:access_token) { "valid_access_token" }
279
+
280
+ let(:ok_response) do
281
+ {
282
+ status: 200,
283
+ headers: { 'Content-Type' => 'application/json' },
284
+ body: {}.to_json
285
+ }
286
+ end
287
+
288
+ before do
289
+ stub_request(:post, revoke_endpoint)
290
+ .with(
291
+ headers: request_headers,
292
+ body: URI.encode_www_form({
293
+ token: access_token,
294
+ token_type_hint: 'access_token'
295
+ })
296
+ )
297
+ .to_return(ok_response)
298
+ end
299
+
300
+ it "returns 200 code with an empty hash in the body" do
301
+ request_response = RDStation::Authentication.revoke(access_token: access_token)
302
+ expect(request_response).to eq({})
303
+ end
304
+ end
305
+
306
+ context "invalid access token" do
307
+ let(:access_token) { "invalid_access_token" }
308
+
309
+ let(:unauthorized_response) do
310
+ {
311
+ status: 401,
312
+ headers: { 'Content-Type' => 'application/json' },
313
+ body: {
314
+ errors: {
315
+ error_type: 'UNAUTHORIZED',
316
+ error_message: 'Invalid token.'
317
+ }
318
+ }.to_json
319
+ }
320
+ end
321
+
322
+ before do
323
+ stub_request(:post, revoke_endpoint)
324
+ .with(
325
+ headers: request_headers,
326
+ body: URI.encode_www_form({
327
+ token: access_token,
328
+ token_type_hint: 'access_token'
329
+ })
330
+ )
331
+ .to_return(unauthorized_response)
332
+ end
333
+
334
+ it "raises unauthorized" do
335
+ expect do
336
+ RDStation::Authentication.revoke(access_token: access_token)
337
+ end.to raise_error(RDStation::Error::Unauthorized)
338
+ end
339
+ end
176
340
  end
177
341
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RDStation::Authorization do
4
+
5
+ describe ".initialize" do
6
+ context "when access_token is nil" do
7
+ it "raises an error" do
8
+ expect do
9
+ described_class.new(access_token: nil)
10
+ end.to raise_error(ArgumentError)
11
+ end
12
+ end
13
+ end
14
+
15
+ describe "#headers" do
16
+ let(:access_token) { 'access_token' }
17
+
18
+ it "generates the correct header" do
19
+ header = described_class.new(access_token: access_token).headers
20
+ expect(header['Authorization']).to eq "Bearer #{access_token}"
21
+ expect(header['Content-Type']).to eq "application/json"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe RDStation::Builder::Field do
6
+ def valid_builder
7
+ described_class.new('cf_identifier')
8
+ end
9
+
10
+ describe 'when create a builder' do
11
+ context 'valid' do
12
+ let(:initial_parameters) do
13
+ 'cf_api_identifier'
14
+ end
15
+
16
+ let(:builder) { described_class.new(initial_parameters) }
17
+
18
+ let(:expected_result) do
19
+ {
20
+ 'api_identifier' => 'cf_api_identifier',
21
+ 'data_type' => 'STRING',
22
+ 'presentation_type' => 'TEXT_INPUT',
23
+ 'label' => { 'pt-BR' => 'My label' },
24
+ 'name' => { 'pt-BR' => 'My name' }
25
+ }
26
+ end
27
+
28
+ it 'returns an hash of required values' do
29
+ builder.label 'pt-BR', 'My label'
30
+ builder.name 'pt-BR', 'My name'
31
+ builder.data_type 'STRING'
32
+ builder.presentation_type 'TEXT_INPUT'
33
+
34
+ result = builder.build
35
+ expect(result).to eq(expected_result)
36
+ end
37
+ end
38
+
39
+ context 'invalid' do
40
+ it 'using invalid api_identifier ' do
41
+ expect { described_class.new('invald_identifier') }.to raise_error(
42
+ 'api_identifier is not in a valid format, need start with "cf_"'
43
+ )
44
+ end
45
+
46
+ it 'using invalid data_type ' do
47
+ expect { valid_builder.data_type('invalid_data_type') }.to raise_error(
48
+ 'Not valid data_type - ["STRING", "INTEGER", "BOOLEAN", "STRING[]"]'
49
+ )
50
+ end
51
+
52
+ it 'using invalid presentation_type ' do
53
+ expect { valid_builder.presentation_type('invalid presentation_type') }.to raise_error(
54
+ 'Not valid presentation_type - ["TEXT_INPUT", "TEXT_AREA", "URL_INPUT", "PHONE_INPUT", "EMAIL_INPUT", "CHECK_BOX", "NUMBER_INPUT", "COMBO_BOX", "RADIO_BUTTON", "MULTIPLE_CHOICE"]'
55
+ )
56
+ end
57
+
58
+ it 'without api_identifier' do
59
+ expect { described_class.new(nil) }.to raise_error('api_identifier required')
60
+ end
61
+
62
+ it 'without required fields' do
63
+ expect { valid_builder.build }.to raise_error(
64
+ 'Required fields are missing - ["data_type", "presentation_type", "label", "name"]'
65
+ )
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RDStation::Client do
4
+ context "when access_token is given" do
5
+ let(:access_token) { 'access_token' }
6
+ let(:client) { described_class.new(access_token: access_token) }
7
+ let(:mock_authorization) { double(RDStation::Authorization) }
8
+
9
+ before { allow(RDStation::Authorization).to receive(:new).and_return mock_authorization }
10
+
11
+ it 'returns Contacts endpoint' do
12
+ expect(RDStation::Contacts).to receive(:new).with({ authorization: mock_authorization }).and_call_original
13
+ expect(client.contacts).to be_instance_of RDStation::Contacts
14
+ end
15
+
16
+ it 'returns Events endpoint' do
17
+ expect(RDStation::Events).to receive(:new).with({ authorization: mock_authorization }).and_call_original
18
+ expect(client.events).to be_instance_of RDStation::Events
19
+ end
20
+
21
+ it 'returns Fields endpoint' do
22
+ expect(RDStation::Fields).to receive(:new).with({ authorization: mock_authorization }).and_call_original
23
+ expect(client.fields).to be_instance_of RDStation::Fields
24
+ end
25
+
26
+ it 'returns Webhooks endpoint' do
27
+ expect(RDStation::Webhooks).to receive(:new).with({ authorization: mock_authorization }).and_call_original
28
+ expect(client.webhooks).to be_instance_of RDStation::Webhooks
29
+ end
30
+ end
31
+
32
+ context "when access_token isn't given" do
33
+ it "raises an ArgumentError exception" do
34
+ expect{ described_class.new(access_token: nil) }.to raise_error(ArgumentError)
35
+ end
36
+ end
37
+ end
@@ -11,31 +11,38 @@ RSpec.describe RDStation::Contacts do
11
11
  let(:endpoint_with_valid_email) { "https://api.rd.services/platform/contacts/email:#{valid_email}" }
12
12
  let(:endpoint_with_invalid_email) { "https://api.rd.services/platform/contacts/email:#{invalid_email}" }
13
13
 
14
- let(:valid_auth_token) { 'valid_auth_token' }
15
- let(:invalid_auth_token) { 'invalid_auth_token' }
16
- let(:expired_auth_token) { 'expired_auth_token' }
14
+ let(:valid_access_token) { 'valid_access_token' }
15
+ let(:invalid_access_token) { 'invalid_access_token' }
16
+ let(:expired_access_token) { 'expired_access_token' }
17
+
18
+ let(:contact_with_valid_token) do
19
+ described_class.new(authorization: RDStation::Authorization.new(access_token: valid_access_token))
20
+ end
21
+ let(:contact_with_expired_token) do
22
+ described_class.new(authorization: RDStation::Authorization.new(access_token: expired_access_token))
23
+ end
24
+ let(:contact_with_invalid_token) do
25
+ described_class.new(authorization: RDStation::Authorization.new(access_token: invalid_access_token))
26
+ end
17
27
 
18
- let(:contact_with_valid_token) { described_class.new(valid_auth_token) }
19
- let(:contact_with_expired_token) { described_class.new(expired_auth_token) }
20
- let(:contact_with_invalid_token) { described_class.new(invalid_auth_token) }
21
28
 
22
29
  let(:valid_headers) do
23
30
  {
24
- 'Authorization' => "Bearer #{valid_auth_token}",
31
+ 'Authorization' => "Bearer #{valid_access_token}",
25
32
  'Content-Type' => 'application/json'
26
33
  }
27
34
  end
28
35
 
29
36
  let(:invalid_token_headers) do
30
37
  {
31
- 'Authorization' => "Bearer #{invalid_auth_token}",
38
+ 'Authorization' => "Bearer #{invalid_access_token}",
32
39
  'Content-Type' => 'application/json'
33
40
  }
34
41
  end
35
42
 
36
43
  let(:expired_token_headers) do
37
44
  {
38
- 'Authorization' => "Bearer #{expired_auth_token}",
45
+ 'Authorization' => "Bearer #{expired_access_token}",
39
46
  'Content-Type' => 'application/json'
40
47
  }
41
48
  end
@@ -102,6 +109,11 @@ RSpec.describe RDStation::Contacts do
102
109
  end
103
110
 
104
111
  describe '#by_uuid' do
112
+ it 'calls retryable_request' do
113
+ expect(contact_with_valid_token).to receive(:retryable_request)
114
+ contact_with_valid_token.by_uuid('valid_uuid')
115
+ end
116
+
105
117
  context 'with a valid auth token' do
106
118
  context 'when the contact exists' do
107
119
  let(:contact) do
@@ -130,7 +142,7 @@ RSpec.describe RDStation::Contacts do
130
142
  it 'raises a not found error' do
131
143
  expect do
132
144
  contact_with_valid_token.by_uuid(invalid_uuid)
133
- end.to raise_error(RDStation::Error::ResourceNotFound)
145
+ end.to raise_error(RDStation::Error::NotFound)
134
146
  end
135
147
  end
136
148
  end
@@ -165,6 +177,11 @@ RSpec.describe RDStation::Contacts do
165
177
  end
166
178
 
167
179
  describe '#by_email' do
180
+ it 'calls retryable_request' do
181
+ expect(contact_with_valid_token).to receive(:retryable_request)
182
+ contact_with_valid_token.by_email('x@xpto.com')
183
+ end
184
+
168
185
  context 'with a valid auth token' do
169
186
  context 'when the contact exists' do
170
187
  let(:contact) do
@@ -193,7 +210,7 @@ RSpec.describe RDStation::Contacts do
193
210
  it 'raises a not found error' do
194
211
  expect do
195
212
  contact_with_valid_token.by_email(invalid_email)
196
- end.to raise_error(RDStation::Error::ResourceNotFound)
213
+ end.to raise_error(RDStation::Error::NotFound)
197
214
  end
198
215
  end
199
216
  end
@@ -228,11 +245,16 @@ RSpec.describe RDStation::Contacts do
228
245
  end
229
246
 
230
247
  describe '#update' do
231
- context 'with a valid auth_token' do
232
- let(:valid_auth_token) { 'valid_auth_token' }
248
+ it 'calls retryable_request' do
249
+ expect(contact_with_valid_token).to receive(:retryable_request)
250
+ contact_with_valid_token.update('valid_uuid', {})
251
+ end
252
+
253
+ context 'with a valid access_token' do
254
+ let(:valid_access_token) { 'valid_access_token' }
233
255
  let(:headers) do
234
256
  {
235
- 'Authorization' => "Bearer #{valid_auth_token}",
257
+ 'Authorization' => "Bearer #{valid_access_token}",
236
258
  'Content-Type' => 'application/json'
237
259
  }
238
260
  end
@@ -264,16 +286,16 @@ RSpec.describe RDStation::Contacts do
264
286
  it 'raises a not found error' do
265
287
  expect do
266
288
  contact_with_valid_token.update(invalid_uuid, {})
267
- end.to raise_error(RDStation::Error::ResourceNotFound)
289
+ end.to raise_error(RDStation::Error::NotFound)
268
290
  end
269
291
  end
270
292
  end
271
293
 
272
294
  context 'with an invalid auth token' do
273
- let(:invalid_auth_token) { 'invalid_auth_token' }
295
+ let(:invalid_access_token) { 'invalid_access_token' }
274
296
  let(:headers) do
275
297
  {
276
- 'Authorization' => "Bearer #{invalid_auth_token}",
298
+ 'Authorization' => "Bearer #{invalid_access_token}",
277
299
  'Content-Type' => 'application/json'
278
300
  }
279
301
  end
@@ -292,10 +314,10 @@ RSpec.describe RDStation::Contacts do
292
314
  end
293
315
 
294
316
  context 'with an expired auth token' do
295
- let(:expired_auth_token) { 'expired_auth_token' }
317
+ let(:expired_access_token) { 'expired_access_token' }
296
318
  let(:headers) do
297
319
  {
298
- 'Authorization' => "Bearer #{expired_auth_token}",
320
+ 'Authorization' => "Bearer #{expired_access_token}",
299
321
  'Content-Type' => 'application/json'
300
322
  }
301
323
  end
@@ -315,12 +337,17 @@ RSpec.describe RDStation::Contacts do
315
337
  end
316
338
 
317
339
  describe '#upsert' do
318
- context 'with a valid auth_token' do
319
- let(:valid_auth_token) { 'valid_auth_token' }
340
+ it 'calls retryable_request' do
341
+ expect(contact_with_valid_token).to receive(:retryable_request)
342
+ contact_with_valid_token.upsert('email', 'valid@email.com', {})
343
+ end
344
+
345
+ context 'with a valid access_token' do
346
+ let(:valid_access_token) { 'valid_access_token' }
320
347
 
321
348
  let(:headers) do
322
349
  {
323
- 'Authorization' => "Bearer #{valid_auth_token}",
350
+ 'Authorization' => "Bearer #{valid_access_token}",
324
351
  'Content-Type' => 'application/json'
325
352
  }
326
353
  end
@@ -352,7 +379,7 @@ RSpec.describe RDStation::Contacts do
352
379
  it 'raises a not found error' do
353
380
  expect do
354
381
  contact_with_valid_token.upsert('email', invalid_email, {})
355
- end.to raise_error(RDStation::Error::ResourceNotFound)
382
+ end.to raise_error(RDStation::Error::NotFound)
356
383
  end
357
384
  end
358
385
 
@@ -371,27 +398,13 @@ RSpec.describe RDStation::Contacts do
371
398
  end.to raise_error(RDStation::Error::ConflictingField)
372
399
  end
373
400
  end
374
-
375
- context 'when an unrecognized error occurs' do
376
- before do
377
- stub_request(:patch, endpoint_with_valid_email)
378
- .with(headers: headers)
379
- .to_return(unrecognized_error)
380
- end
381
-
382
- it 'raises an default error' do
383
- expect do
384
- contact_with_valid_token.upsert('email', valid_email, {})
385
- end.to raise_error(RDStation::Error::Default)
386
- end
387
- end
388
401
  end
389
402
 
390
403
  context 'with an invalid auth token' do
391
- let(:invalid_auth_token) { 'invalid_auth_token' }
404
+ let(:invalid_access_token) { 'invalid_access_token' }
392
405
  let(:headers) do
393
406
  {
394
- 'Authorization' => "Bearer #{invalid_auth_token}",
407
+ 'Authorization' => "Bearer #{invalid_access_token}",
395
408
  'Content-Type' => 'application/json'
396
409
  }
397
410
  end
@@ -410,10 +423,10 @@ RSpec.describe RDStation::Contacts do
410
423
  end
411
424
 
412
425
  context 'with an expired auth token' do
413
- let(:expired_auth_token) { 'expired_auth_token' }
426
+ let(:expired_access_token) { 'expired_access_token' }
414
427
  let(:headers) do
415
428
  {
416
- 'Authorization' => "Bearer #{expired_auth_token}",
429
+ 'Authorization' => "Bearer #{expired_access_token}",
417
430
  'Content-Type' => 'application/json'
418
431
  }
419
432
  end