creditsafe 0.5.0 → 0.5.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 +4 -4
- data/.rubocop.yml +8 -21
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -3
- data/Gemfile.lock +25 -60
- data/creditsafe.gemspec +23 -23
- data/lib/creditsafe/client.rb +33 -24
- data/lib/creditsafe/errors.rb +1 -0
- data/lib/creditsafe/match_type.rb +6 -6
- data/lib/creditsafe/messages.rb +28 -27
- data/lib/creditsafe/namespace.rb +7 -7
- data/lib/creditsafe/request/company_report.rb +7 -5
- data/lib/creditsafe/request/find_company.rb +24 -16
- data/lib/creditsafe/version.rb +2 -1
- data/lib/creditsafe.rb +3 -2
- data/spec/creditsafe/client_spec.rb +133 -112
- data/spec/creditsafe/messages_spec.rb +16 -9
- data/spec/spec_helper.rb +7 -6
- metadata +34 -36
- data/.rubocop_todo.yml +0 -16
- data/Guardfile +0 -76
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "creditsafe/match_type"
|
4
|
+
require "creditsafe/namespace"
|
5
5
|
|
6
6
|
module Creditsafe
|
7
7
|
module Request
|
@@ -20,23 +20,29 @@ module Creditsafe
|
|
20
20
|
def message
|
21
21
|
search_criteria = {}
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
unless company_name.nil?
|
24
|
+
search_criteria["#{Creditsafe::Namespace::DAT}:Name"] = {
|
25
|
+
"@MatchType" => match_type,
|
26
|
+
:content! => company_name,
|
27
|
+
}
|
28
|
+
end
|
27
29
|
|
28
30
|
unless registration_number.nil?
|
29
31
|
search_criteria["#{Creditsafe::Namespace::DAT}:RegistrationNumber"] =
|
30
32
|
registration_number
|
31
33
|
end
|
32
34
|
|
33
|
-
|
34
|
-
"#{Creditsafe::Namespace::DAT}:
|
35
|
-
|
35
|
+
unless city.nil?
|
36
|
+
search_criteria["#{Creditsafe::Namespace::DAT}:Address"] = {
|
37
|
+
"#{Creditsafe::Namespace::DAT}:City" => city,
|
38
|
+
}
|
39
|
+
end
|
36
40
|
|
37
|
-
|
38
|
-
"#{Creditsafe::Namespace::DAT}:
|
39
|
-
|
41
|
+
unless postal_code.nil?
|
42
|
+
search_criteria["#{Creditsafe::Namespace::DAT}:Address"] = {
|
43
|
+
"#{Creditsafe::Namespace::DAT}:PostalCode" => postal_code,
|
44
|
+
}
|
45
|
+
end
|
40
46
|
|
41
47
|
build_message(search_criteria)
|
42
48
|
end
|
@@ -55,13 +61,14 @@ module Creditsafe
|
|
55
61
|
def build_message(search_criteria)
|
56
62
|
{
|
57
63
|
"#{Creditsafe::Namespace::OPER}:countries" => {
|
58
|
-
"#{Creditsafe::Namespace::CRED}:CountryCode" => country_code
|
64
|
+
"#{Creditsafe::Namespace::CRED}:CountryCode" => country_code,
|
59
65
|
},
|
60
|
-
"#{Creditsafe::Namespace::OPER}:searchCriteria" => search_criteria
|
66
|
+
"#{Creditsafe::Namespace::OPER}:searchCriteria" => search_criteria,
|
61
67
|
}
|
62
68
|
end
|
63
69
|
|
64
70
|
# rubocop:disable Metrics/CyclomaticComplexity
|
71
|
+
# rubocop:disable Metrics/MethodLength
|
65
72
|
def check_search_criteria(search_criteria)
|
66
73
|
if search_criteria[:country_code].nil?
|
67
74
|
raise ArgumentError, "country_code is a required search criteria"
|
@@ -72,14 +79,15 @@ module Creditsafe
|
|
72
79
|
"required search criteria"
|
73
80
|
end
|
74
81
|
|
75
|
-
if search_criteria[:city] && search_criteria[:country_code] !=
|
82
|
+
if search_criteria[:city] && search_criteria[:country_code] != "DE"
|
76
83
|
raise ArgumentError, "city is only supported for German searches"
|
77
84
|
end
|
78
85
|
|
79
|
-
if search_criteria[:postal_code] && search_criteria[:country_code] !=
|
86
|
+
if search_criteria[:postal_code] && search_criteria[:country_code] != "DE"
|
80
87
|
raise ArgumentError, "Postal code is only supported for German searches"
|
81
88
|
end
|
82
89
|
end
|
90
|
+
# rubocop:enable Metrics/MethodLength
|
83
91
|
# rubocop:enable Metrics/CyclomaticComplexity
|
84
92
|
|
85
93
|
def only_registration_number_or_company_name_provided?(search_criteria)
|
data/lib/creditsafe/version.rb
CHANGED
data/lib/creditsafe.rb
CHANGED
@@ -1,50 +1,60 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'spec_helper'
|
3
|
-
require 'creditsafe/client'
|
4
|
-
require 'timecop'
|
5
2
|
|
6
|
-
|
7
|
-
|
3
|
+
require "spec_helper"
|
4
|
+
require "creditsafe/client"
|
5
|
+
require "timecop"
|
6
|
+
|
7
|
+
URL = "https://webservices.creditsafe.com/GlobalData/1.3/"\
|
8
|
+
"MainServiceBasic.svc"
|
8
9
|
|
9
10
|
RSpec.describe(Creditsafe::Client) do
|
10
11
|
notifications = []
|
11
12
|
let(:username) { "AzureDiamond" }
|
12
13
|
let(:password) { "hunter2" }
|
14
|
+
|
15
|
+
# rubocop:disable RSpec/BeforeAfterAll
|
13
16
|
before(:all) do
|
14
17
|
ActiveSupport::Notifications.subscribe do |*args|
|
15
18
|
notifications << ActiveSupport::Notifications::Event.new(*args)
|
16
19
|
end
|
17
20
|
end
|
18
|
-
|
21
|
+
# rubocop:enable RSpec/BeforeAfterAll
|
19
22
|
|
20
|
-
|
23
|
+
before { notifications = [] }
|
24
|
+
|
25
|
+
shared_examples_for "sends notifications" do
|
21
26
|
let(:time) { Time.local(1990) }
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
expect(notifications).to match(
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
|
28
|
+
it "records a SOAP event" do
|
29
|
+
Timecop.freeze(time) { method_call }
|
30
|
+
|
31
|
+
expect(notifications).to match(
|
32
|
+
[
|
33
|
+
have_attributes(
|
34
|
+
name: "creditsafe.#{soap_verb}",
|
35
|
+
transaction_id: match(/\A.{20}\Z/),
|
36
|
+
time: time,
|
37
|
+
end: time,
|
38
|
+
payload: {
|
39
|
+
request: be_truthy,
|
40
|
+
response: be_truthy,
|
41
|
+
},
|
42
|
+
),
|
43
|
+
],
|
44
|
+
)
|
36
45
|
end
|
37
46
|
end
|
38
|
-
|
39
|
-
|
47
|
+
|
48
|
+
shared_examples_for "handles api errors" do
|
49
|
+
context "when an error occurs due to invalid credentials" do
|
40
50
|
before do
|
41
51
|
stub_request(:post, URL).to_return(
|
42
|
-
body: load_fixture(
|
43
|
-
status: 401
|
52
|
+
body: load_fixture("error-invalid-credentials.html"),
|
53
|
+
status: 401,
|
44
54
|
)
|
45
55
|
end
|
46
56
|
|
47
|
-
it
|
57
|
+
it "raises an AccountError" do
|
48
58
|
expect { method_call }.to raise_error(
|
49
59
|
Creditsafe::AccountError, /invalid credentials/
|
50
60
|
) do |error|
|
@@ -54,49 +64,46 @@ RSpec.describe(Creditsafe::Client) do
|
|
54
64
|
name: "creditsafe.#{soap_verb}",
|
55
65
|
payload: {
|
56
66
|
request: be_truthy,
|
57
|
-
error: error
|
58
|
-
}
|
59
|
-
)
|
60
|
-
]
|
67
|
+
error: error,
|
68
|
+
},
|
69
|
+
),
|
70
|
+
],
|
61
71
|
)
|
62
72
|
end
|
63
73
|
end
|
64
74
|
end
|
65
75
|
|
66
|
-
context
|
76
|
+
context "when an error occurs due to a fault" do
|
67
77
|
before do
|
68
78
|
stub_request(:post, URL).
|
69
|
-
to_return(body: load_fixture(
|
79
|
+
to_return(body: load_fixture("error-fault.xml"))
|
70
80
|
end
|
71
81
|
|
72
|
-
it
|
73
|
-
expect { method_call }.to raise_error(
|
74
|
-
Creditsafe::UnknownApiError
|
75
|
-
) do |error|
|
82
|
+
it "raises an UnknownApiError" do
|
83
|
+
expect { method_call }.to raise_error(Creditsafe::UnknownApiError) do |error|
|
76
84
|
expect(notifications).to match(
|
77
85
|
[
|
78
86
|
have_attributes(
|
79
87
|
name: "creditsafe.#{soap_verb}",
|
80
88
|
payload: {
|
81
89
|
request: be_truthy,
|
82
|
-
error: error
|
83
|
-
}
|
84
|
-
)
|
85
|
-
]
|
90
|
+
error: error,
|
91
|
+
},
|
92
|
+
),
|
93
|
+
],
|
86
94
|
)
|
87
95
|
end
|
88
96
|
end
|
89
97
|
end
|
90
98
|
|
91
|
-
context
|
99
|
+
context "when a HTTP error occurs" do
|
92
100
|
before do
|
93
101
|
stub_request(:post, URL).to_timeout
|
94
102
|
end
|
95
103
|
|
96
|
-
it
|
97
|
-
expect { method_call }.
|
98
|
-
raise_error(Creditsafe::HttpError, /Excon::Error(?:s)?::Timeout/)
|
99
|
-
)
|
104
|
+
it "raises an HttpError" do
|
105
|
+
expect { method_call }.
|
106
|
+
to raise_error(Creditsafe::HttpError, /Excon::Error(?:s)?::Timeout/)
|
100
107
|
end
|
101
108
|
end
|
102
109
|
end
|
@@ -110,19 +117,23 @@ RSpec.describe(Creditsafe::Client) do
|
|
110
117
|
|
111
118
|
context "without a username" do
|
112
119
|
let(:username) { nil }
|
120
|
+
|
113
121
|
it { is_expected.to raise_error(ArgumentError) }
|
114
122
|
end
|
115
123
|
end
|
116
124
|
|
117
125
|
describe "#inspect" do
|
118
|
-
let(:client) { described_class.new(username: username, password: password) }
|
119
126
|
subject { client.inspect }
|
120
127
|
|
128
|
+
let(:client) { described_class.new(username: username, password: password) }
|
129
|
+
|
121
130
|
it { is_expected.to_not include(password) }
|
122
131
|
end
|
123
132
|
|
124
|
-
describe
|
125
|
-
|
133
|
+
describe "#find_company" do
|
134
|
+
subject { -> { method_call } }
|
135
|
+
|
136
|
+
let(:soap_verb) { "find_companies" }
|
126
137
|
let(:client) { described_class.new(username: username, password: password) }
|
127
138
|
let(:country_code) { "GB" }
|
128
139
|
let(:registration_number) { "RN123" }
|
@@ -133,49 +144,54 @@ RSpec.describe(Creditsafe::Client) do
|
|
133
144
|
country_code: country_code,
|
134
145
|
registration_number: registration_number,
|
135
146
|
city: city,
|
136
|
-
postal_code: postal_code
|
147
|
+
postal_code: postal_code,
|
137
148
|
}.reject { |_, v| v.nil? }
|
138
149
|
end
|
139
150
|
|
140
|
-
|
141
|
-
|
151
|
+
let(:find_company) { client.find_company(search_criteria) }
|
152
|
+
let(:method_call) { find_company }
|
142
153
|
|
143
154
|
before do
|
144
155
|
stub_request(:post, URL).to_return(
|
145
|
-
body: load_fixture(
|
146
|
-
status: 200
|
156
|
+
body: load_fixture("find-companies-successful.xml"),
|
157
|
+
status: 200,
|
147
158
|
)
|
148
159
|
end
|
149
160
|
|
150
|
-
subject { -> { method_call } }
|
151
161
|
it { is_expected.to_not raise_error }
|
152
162
|
|
153
163
|
context "without a country_code" do
|
154
164
|
let(:country_code) { nil }
|
165
|
+
|
155
166
|
it { is_expected.to raise_error(ArgumentError) }
|
156
167
|
end
|
157
168
|
|
158
169
|
context "without a registration_number" do
|
159
170
|
let(:registration_number) { nil }
|
171
|
+
|
160
172
|
it { is_expected.to raise_error(ArgumentError) }
|
161
173
|
end
|
162
174
|
|
163
175
|
context "with a city" do
|
164
176
|
let(:city) { "Berlin" }
|
177
|
+
|
165
178
|
it { is_expected.to raise_error(ArgumentError) }
|
166
179
|
|
167
180
|
context "in Germany" do
|
168
181
|
let(:country_code) { "DE" }
|
182
|
+
|
169
183
|
it { is_expected.to_not raise_error }
|
170
184
|
end
|
171
185
|
end
|
172
186
|
|
173
187
|
context "with a postal_code" do
|
174
188
|
let(:postal_code) { "41199" }
|
189
|
+
|
175
190
|
it { is_expected.to raise_error(ArgumentError) }
|
176
191
|
|
177
192
|
context "in Germany" do
|
178
193
|
let(:country_code) { "DE" }
|
194
|
+
|
179
195
|
it { is_expected.to_not raise_error }
|
180
196
|
end
|
181
197
|
end
|
@@ -198,44 +214,44 @@ RSpec.describe(Creditsafe::Client) do
|
|
198
214
|
end
|
199
215
|
end
|
200
216
|
|
201
|
-
it
|
217
|
+
it "requests the company deatils" do
|
202
218
|
find_company
|
203
219
|
expect(a_request(:post, URL).with do |req|
|
204
220
|
expect(CompareXML.equivalent?(
|
205
221
|
Nokogiri::XML(req.body),
|
206
|
-
load_xml_fixture(
|
207
|
-
verbose: true
|
222
|
+
load_xml_fixture("find-companies-request.xml"),
|
223
|
+
verbose: true,
|
208
224
|
)).to eq([])
|
209
225
|
end).to have_been_made
|
210
226
|
end
|
211
227
|
|
212
|
-
it
|
228
|
+
it "returns the company details" do
|
213
229
|
expect(find_company).
|
214
|
-
to eq(:name =>
|
215
|
-
:type =>
|
216
|
-
:status =>
|
217
|
-
:registration_number =>
|
230
|
+
to eq(:name => "GOCARDLESS LTD",
|
231
|
+
:type => "Ltd",
|
232
|
+
:status => "Active",
|
233
|
+
:registration_number => "07495895",
|
218
234
|
:address => {
|
219
|
-
simple_value:
|
220
|
-
postal_code:
|
235
|
+
simple_value: "338-346, GOSWELL, LONDON",
|
236
|
+
postal_code: "EC1V7LQ",
|
221
237
|
},
|
222
|
-
:available_report_types => { available_report_type:
|
223
|
-
:available_languages => { available_language:
|
224
|
-
:@date_of_latest_accounts =>
|
225
|
-
:@online_reports =>
|
226
|
-
:@monitoring =>
|
227
|
-
:@country =>
|
228
|
-
:@id =>
|
238
|
+
:available_report_types => { available_report_type: "Full" },
|
239
|
+
:available_languages => { available_language: "EN" },
|
240
|
+
:@date_of_latest_accounts => "2014-01-31T00:00:00Z",
|
241
|
+
:@online_reports => "true",
|
242
|
+
:@monitoring => "false",
|
243
|
+
:@country => "GB",
|
244
|
+
:@id => "GB003/0/07495895")
|
229
245
|
end
|
230
246
|
|
231
|
-
include_examples
|
232
|
-
include_examples
|
247
|
+
include_examples "sends notifications"
|
248
|
+
include_examples "handles api errors"
|
233
249
|
|
234
250
|
context "when no companies are found" do
|
235
251
|
before do
|
236
252
|
stub_request(:post, URL).to_return(
|
237
|
-
body: load_fixture(
|
238
|
-
status: 200
|
253
|
+
body: load_fixture("find-companies-none-found.xml"),
|
254
|
+
status: 200,
|
239
255
|
)
|
240
256
|
end
|
241
257
|
|
@@ -253,14 +269,14 @@ RSpec.describe(Creditsafe::Client) do
|
|
253
269
|
find_companies_result: include(
|
254
270
|
messages: {
|
255
271
|
message: include(
|
256
|
-
"There are no results matching specified criteria."
|
257
|
-
)
|
272
|
+
"There are no results matching specified criteria.",
|
273
|
+
),
|
258
274
|
},
|
259
|
-
companies: be_nil
|
260
|
-
)
|
261
|
-
)
|
262
|
-
}
|
263
|
-
}
|
275
|
+
companies: be_nil,
|
276
|
+
),
|
277
|
+
),
|
278
|
+
},
|
279
|
+
},
|
264
280
|
)])
|
265
281
|
end
|
266
282
|
end
|
@@ -268,80 +284,85 @@ RSpec.describe(Creditsafe::Client) do
|
|
268
284
|
context "when an error occurs with further details" do
|
269
285
|
before do
|
270
286
|
stub_request(:post, URL).to_return(
|
271
|
-
body: load_fixture(
|
272
|
-
status: 200
|
287
|
+
body: load_fixture("find-companies-error.xml"),
|
288
|
+
status: 200,
|
273
289
|
)
|
274
290
|
end
|
275
291
|
|
276
|
-
it
|
292
|
+
it "gives a useful error, with the specific error in the response" do
|
277
293
|
expect { method_call }.to raise_error(
|
278
294
|
Creditsafe::RequestError,
|
279
|
-
|
295
|
+
"Invalid operation parameters (Invalid countries list specified.)",
|
280
296
|
)
|
281
297
|
end
|
282
298
|
|
283
299
|
context "with further details provided in the response" do
|
284
300
|
before do
|
285
301
|
stub_request(:post, URL).to_return(
|
286
|
-
body: load_fixture(
|
287
|
-
status: 200
|
302
|
+
body: load_fixture("find-companies-error-no-text.xml"),
|
303
|
+
status: 200,
|
288
304
|
)
|
289
305
|
end
|
290
306
|
|
291
|
-
it
|
307
|
+
it "gives a useful error, with the specific error in the response" do
|
292
308
|
expect { method_call }.to raise_error(
|
293
309
|
Creditsafe::RequestError,
|
294
|
-
|
310
|
+
"Invalid operation parameters",
|
295
311
|
)
|
296
312
|
end
|
297
313
|
end
|
298
314
|
end
|
299
315
|
end
|
300
316
|
|
301
|
-
describe
|
302
|
-
let(:soap_verb) { 'retrieve_company_online_report' }
|
317
|
+
describe "#company_report" do
|
303
318
|
before do
|
304
319
|
stub_request(:post, URL).to_return(
|
305
|
-
body: load_fixture(
|
306
|
-
status: 200
|
320
|
+
body: load_fixture("company-report-successful.xml"),
|
321
|
+
status: 200,
|
307
322
|
)
|
308
323
|
end
|
324
|
+
|
325
|
+
let(:soap_verb) { "retrieve_company_online_report" }
|
309
326
|
let(:client) { described_class.new(username: username, password: password) }
|
310
327
|
let(:custom_data) { { foo: "bar", bar: "baz" } }
|
311
|
-
|
312
|
-
client.company_report(
|
328
|
+
let(:company_report) do
|
329
|
+
client.company_report("GB003/0/07495895", custom_data: custom_data)
|
313
330
|
end
|
314
|
-
|
331
|
+
let(:method_call) { company_report }
|
315
332
|
|
316
|
-
it
|
333
|
+
it "requests the company details" do
|
317
334
|
company_report
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
335
|
+
request = a_request(:post, URL).with do |req|
|
336
|
+
expect(
|
337
|
+
CompareXML.equivalent?(
|
338
|
+
Nokogiri::XML(req.body),
|
339
|
+
load_xml_fixture("company-report-request.xml"),
|
340
|
+
verbose: true,
|
341
|
+
),
|
342
|
+
).to eq([])
|
343
|
+
end
|
344
|
+
|
345
|
+
expect(request).to have_been_made
|
325
346
|
end
|
326
347
|
|
327
|
-
it
|
348
|
+
it "returns the company details" do
|
328
349
|
expect(company_report).to include(:company_summary)
|
329
350
|
end
|
330
351
|
|
331
|
-
include_examples
|
332
|
-
include_examples
|
352
|
+
include_examples "sends notifications"
|
353
|
+
include_examples "handles api errors"
|
333
354
|
|
334
|
-
context
|
355
|
+
context "when a report is unavailable" do
|
335
356
|
before do
|
336
357
|
stub_request(:post, URL).
|
337
|
-
to_return(body: load_fixture(
|
358
|
+
to_return(body: load_fixture("company-report-not-found.xml"))
|
338
359
|
end
|
339
360
|
|
340
|
-
it
|
361
|
+
it "raises an error" do
|
341
362
|
expect { company_report }.to raise_error(Creditsafe::DataError)
|
342
363
|
end
|
343
364
|
|
344
|
-
it
|
365
|
+
it "gives a useful error message" do
|
345
366
|
expect { company_report }.to raise_error(
|
346
367
|
Creditsafe::DataError, /Report unavailable/
|
347
368
|
)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require "creditsafe/messages"
|
4
5
|
|
5
6
|
RSpec.describe(Creditsafe::Messages) do
|
6
7
|
describe ".for_code" do
|
@@ -8,27 +9,31 @@ RSpec.describe(Creditsafe::Messages) do
|
|
8
9
|
|
9
10
|
context "for a valid code" do
|
10
11
|
let(:code) { "020101" }
|
12
|
+
|
11
13
|
its(:code) { is_expected.to eq(code) }
|
12
|
-
its(:message) { is_expected.to eq(
|
14
|
+
its(:message) { is_expected.to eq("Invalid credentials") }
|
13
15
|
its(:error_class) { is_expected.to eq(Creditsafe::AccountError) }
|
14
16
|
end
|
15
17
|
|
16
18
|
context "for a code without leading zero" do
|
17
19
|
let(:code) { "20101" }
|
20
|
+
|
18
21
|
its(:code) { is_expected.to eq("0#{code}") }
|
19
|
-
its(:message) { is_expected.to eq(
|
22
|
+
its(:message) { is_expected.to eq("Invalid credentials") }
|
20
23
|
its(:error_class) { is_expected.to eq(Creditsafe::AccountError) }
|
21
24
|
end
|
22
25
|
|
23
26
|
context "for an unknown code" do
|
24
27
|
let(:code) { "999999" }
|
28
|
+
|
25
29
|
its(:code) { is_expected.to eq(code) }
|
26
|
-
its(:message) { is_expected.to eq(
|
30
|
+
its(:message) { is_expected.to eq("Unknown error") }
|
27
31
|
its(:error_class) { is_expected.to eq(Creditsafe::UnknownApiError) }
|
28
32
|
end
|
29
33
|
|
30
34
|
context "for an empty code" do
|
31
|
-
let(:code) {
|
35
|
+
let(:code) { "" }
|
36
|
+
|
32
37
|
it "was passed the wrong parameters" do
|
33
38
|
expect { subject(:message) }.to raise_error(ArgumentError)
|
34
39
|
end
|
@@ -36,9 +41,8 @@ RSpec.describe(Creditsafe::Messages) do
|
|
36
41
|
end
|
37
42
|
|
38
43
|
describe(Creditsafe::Messages::Message) do
|
39
|
-
subject(:message)
|
40
|
-
|
41
|
-
end
|
44
|
+
subject(:message) { described_class.new(code: code, message: text, error: error) }
|
45
|
+
|
42
46
|
let(:text) { "Error message" }
|
43
47
|
let(:code) { "020101" }
|
44
48
|
let(:error) { true }
|
@@ -48,6 +52,7 @@ RSpec.describe(Creditsafe::Messages) do
|
|
48
52
|
|
49
53
|
context "when there is no error" do
|
50
54
|
let(:error) { false }
|
55
|
+
|
51
56
|
it { is_expected.to be_nil }
|
52
57
|
end
|
53
58
|
|
@@ -56,11 +61,13 @@ RSpec.describe(Creditsafe::Messages) do
|
|
56
61
|
|
57
62
|
context "for a processing error code" do
|
58
63
|
let(:code) { "040102" }
|
64
|
+
|
59
65
|
it { is_expected.to eq(Creditsafe::ProcessingError) }
|
60
66
|
end
|
61
67
|
|
62
68
|
context "for an unknown error code" do
|
63
69
|
let(:code) { "060102" }
|
70
|
+
|
64
71
|
it { is_expected.to eq(Creditsafe::UnknownApiError) }
|
65
72
|
end
|
66
73
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
2
|
+
|
3
|
+
require "webmock/rspec"
|
4
|
+
require "nokogiri"
|
5
|
+
require "rspec/its"
|
6
|
+
require "compare-xml"
|
6
7
|
|
7
8
|
def load_fixture(name)
|
8
|
-
File.read(File.join(File.dirname(__FILE__),
|
9
|
+
File.read(File.join(File.dirname(__FILE__), "fixtures", name))
|
9
10
|
end
|
10
11
|
|
11
12
|
def load_xml_fixture(name)
|
12
|
-
Nokogiri::XML(File.open(File.join(File.dirname(__FILE__),
|
13
|
+
Nokogiri::XML(File.open(File.join(File.dirname(__FILE__), "fixtures", name)))
|
13
14
|
end
|