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