valvat 1.0.1 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.github/workflows/ruby.yml +41 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +15 -0
- data/CHANGES.md +27 -1
- data/Gemfile +2 -0
- data/Guardfile +6 -4
- data/README.md +6 -4
- data/Rakefile +3 -1
- data/certs/yolk.pem +25 -24
- data/gemfiles/activemodel-5 +1 -1
- data/gemfiles/activemodel-6 +1 -1
- data/gemfiles/{activemodel-3-2 → activemodel-7} +2 -2
- data/lib/active_model/validations/valvat_validator.rb +65 -32
- data/lib/valvat/checksum/at.rb +3 -1
- data/lib/valvat/checksum/be.rb +3 -1
- data/lib/valvat/checksum/bg.rb +17 -17
- data/lib/valvat/checksum/cy.rb +2 -0
- data/lib/valvat/checksum/de.rb +5 -3
- data/lib/valvat/checksum/dk.rb +3 -1
- data/lib/valvat/checksum/ee.rb +2 -0
- data/lib/valvat/checksum/es.rb +14 -16
- data/lib/valvat/checksum/fi.rb +3 -1
- data/lib/valvat/checksum/fr.rb +4 -2
- data/lib/valvat/checksum/gb.rb +46 -31
- data/lib/valvat/checksum/gr.rb +4 -2
- data/lib/valvat/checksum/hr.rb +2 -0
- data/lib/valvat/checksum/hu.rb +2 -0
- data/lib/valvat/checksum/ie.rb +5 -6
- data/lib/valvat/checksum/it.rb +7 -5
- data/lib/valvat/checksum/lt.rb +2 -0
- data/lib/valvat/checksum/lu.rb +3 -1
- data/lib/valvat/checksum/mt.rb +2 -0
- data/lib/valvat/checksum/nl.rb +5 -3
- data/lib/valvat/checksum/pl.rb +3 -1
- data/lib/valvat/checksum/pt.rb +3 -1
- data/lib/valvat/checksum/ro.rb +2 -0
- data/lib/valvat/checksum/se.rb +5 -3
- data/lib/valvat/checksum/si.rb +4 -2
- data/lib/valvat/checksum.rb +24 -28
- data/lib/valvat/error.rb +8 -2
- data/lib/valvat/local.rb +6 -4
- data/lib/valvat/locales/de.yml +2 -1
- data/lib/valvat/locales/en.yml +2 -1
- data/lib/valvat/locales/es.yml +1 -0
- data/lib/valvat/locales/fr.yml +1 -0
- data/lib/valvat/locales/hu.yml +1 -0
- data/lib/valvat/locales/nl.yml +1 -0
- data/lib/valvat/locales/pl.yml +1 -0
- data/lib/valvat/lookup/fault.rb +29 -21
- data/lib/valvat/lookup/request.rb +21 -16
- data/lib/valvat/lookup/response.rb +11 -10
- data/lib/valvat/lookup.rb +5 -4
- data/lib/valvat/syntax.rb +31 -30
- data/lib/valvat/utils.rb +12 -9
- data/lib/valvat/version.rb +3 -1
- data/lib/valvat.rb +4 -2
- data/spec/active_model/validations/valvat_validator_spec.rb +99 -93
- data/spec/spec_helper.rb +8 -8
- data/spec/valvat/checksum/at_spec.rb +6 -4
- data/spec/valvat/checksum/be_spec.rb +6 -4
- data/spec/valvat/checksum/bg_spec.rb +7 -4
- data/spec/valvat/checksum/cy_spec.rb +3 -1
- data/spec/valvat/checksum/de_spec.rb +6 -4
- data/spec/valvat/checksum/dk_spec.rb +6 -4
- data/spec/valvat/checksum/ee_spec.rb +3 -1
- data/spec/valvat/checksum/es_spec.rb +7 -4
- data/spec/valvat/checksum/fi_spec.rb +6 -4
- data/spec/valvat/checksum/fr_spec.rb +6 -4
- data/spec/valvat/checksum/gb_spec.rb +4 -2
- data/spec/valvat/checksum/gr_spec.rb +6 -4
- data/spec/valvat/checksum/hr_spec.rb +3 -1
- data/spec/valvat/checksum/hu_spec.rb +3 -1
- data/spec/valvat/checksum/ie_spec.rb +8 -6
- data/spec/valvat/checksum/it_spec.rb +10 -8
- data/spec/valvat/checksum/lt_spec.rb +3 -1
- data/spec/valvat/checksum/lu_spec.rb +6 -4
- data/spec/valvat/checksum/mt_spec.rb +3 -1
- data/spec/valvat/checksum/nl_spec.rb +9 -7
- data/spec/valvat/checksum/pl_spec.rb +8 -6
- data/spec/valvat/checksum/pt_spec.rb +10 -11
- data/spec/valvat/checksum/ro_spec.rb +3 -1
- data/spec/valvat/checksum/se_spec.rb +8 -6
- data/spec/valvat/checksum/si_spec.rb +10 -8
- data/spec/valvat/checksum_spec.rb +24 -9
- data/spec/valvat/lookup/fault_spec.rb +34 -0
- data/spec/valvat/lookup/request_spec.rb +32 -0
- data/spec/valvat/lookup/response_spec.rb +29 -0
- data/spec/valvat/lookup_spec.rb +171 -152
- data/spec/valvat/syntax_spec.rb +59 -280
- data/spec/valvat/utils_spec.rb +64 -47
- data/spec/valvat_spec.rb +140 -152
- data/valvat.gemspec +17 -17
- data.tar.gz.sig +1 -2
- metadata +48 -50
- metadata.gz.sig +0 -0
- data/.travis.yml +0 -47
- data/gemfiles/activemodel-4 +0 -7
- data/gemfiles/before-ruby21/activemodel-3-2 +0 -8
- data/gemfiles/before-ruby21/activemodel-4 +0 -8
- data/gemfiles/before-ruby21/standalone +0 -7
- data/spec/valvat/lockup/fault_spec.rb +0 -32
- data/spec/valvat/lockup/request_spec.rb +0 -15
- data/spec/valvat/lockup/response_spec.rb +0 -27
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Valvat::Lookup::Request do
|
6
|
+
it 'returns Response on success' do
|
7
|
+
response = described_class.new('IE6388047V', {}).perform
|
8
|
+
expect(response).to be_a(Valvat::Lookup::Response)
|
9
|
+
|
10
|
+
# Skip if VIES is down
|
11
|
+
expect(response.to_hash[:name]).to eql('GOOGLE IRELAND LIMITED') unless response.is_a?(Valvat::Lookup::Fault)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns Fault on failure' do
|
15
|
+
response = described_class.new('XC123123', {}).perform
|
16
|
+
expect(response).to be_a(Valvat::Lookup::Fault)
|
17
|
+
expect(response.to_hash).to eql({ valid: false })
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when Savon::UnknownOperationError is (wrongly) thrown' do
|
21
|
+
before do
|
22
|
+
dbl = double(Savon::Client)
|
23
|
+
allow(Savon::Client).to receive(:new).and_return(dbl)
|
24
|
+
allow(dbl).to receive(:call).and_raise(Savon::UnknownOperationError.new('from stub'))
|
25
|
+
end
|
26
|
+
|
27
|
+
it "does handle it like vies down" do
|
28
|
+
response = described_class.new('IE6388047V', {}).perform
|
29
|
+
expect(response.to_hash[:error]).to be_a(Valvat::OperationUnknown)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Valvat::Lookup::Response do
|
6
|
+
it 'removes @xmlns from :check_vat_response hash' do
|
7
|
+
expect(described_class.new({
|
8
|
+
check_vat_response: { :a => 1, :b => 2, :@xmlns => true }
|
9
|
+
}).to_hash).to eql({ a: 1, b: 2 })
|
10
|
+
end
|
11
|
+
|
12
|
+
it "removes 'trader_'-Prefixes :check_vat_response hash" do
|
13
|
+
expect(described_class.new({
|
14
|
+
check_vat_response: { a: 1, trader_b: 2 }
|
15
|
+
}).to_hash).to eql({ a: 1, b: 2 })
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'accepts hash keyed as :check_vat_approx_response' do
|
19
|
+
expect(described_class.new({
|
20
|
+
check_vat_approx_response: { a: 1, b: 2 }
|
21
|
+
}).to_hash).to eql({ a: 1, b: 2 })
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'allows direct access to hash via []' do
|
25
|
+
expect(described_class.new({
|
26
|
+
check_vat_response: { a: 123, b: 2 }
|
27
|
+
})[:a]).to be(123)
|
28
|
+
end
|
29
|
+
end
|
data/spec/valvat/lookup_spec.rb
CHANGED
@@ -1,257 +1,276 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Valvat::Lookup do
|
4
|
-
describe
|
5
|
-
context
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
unless result.nil?
|
11
|
-
expect(result).to eql(true)
|
12
|
-
else
|
13
|
-
puts "Skipping IE vies lookup spec"
|
14
|
-
end
|
6
|
+
describe '#validate' do
|
7
|
+
context 'with existing VAT number' do
|
8
|
+
it 'returns true' do
|
9
|
+
result = described_class.validate('IE6388047V')
|
10
|
+
# Skip if VIES is down
|
11
|
+
expect(result).to be(true) unless result.nil?
|
15
12
|
end
|
16
13
|
|
17
|
-
it
|
18
|
-
result =
|
19
|
-
|
20
|
-
unless result.nil?
|
21
|
-
expect(result).to eql(true)
|
22
|
-
else
|
23
|
-
puts "Skipping IE vies lookup spec"
|
24
|
-
end
|
14
|
+
it 'allows Valvat instance as input' do
|
15
|
+
result = described_class.validate(Valvat.new('IE6388047V'))
|
16
|
+
# Skip if VIES is down
|
17
|
+
expect(result).to be(true) unless result.nil?
|
25
18
|
end
|
26
19
|
end
|
27
20
|
|
28
|
-
context
|
29
|
-
it
|
30
|
-
result =
|
31
|
-
|
32
|
-
unless result.nil?
|
33
|
-
expect(result).to eql(false)
|
34
|
-
else
|
35
|
-
puts "Skipping IE vies lookup spec"
|
36
|
-
end
|
21
|
+
context 'with not existing VAT number' do
|
22
|
+
it 'returns false' do
|
23
|
+
result = described_class.validate('IE6388048V')
|
24
|
+
# Skip if VIES is down
|
25
|
+
expect(result).to be(false) unless result.nil?
|
37
26
|
end
|
38
27
|
end
|
39
28
|
|
40
|
-
context
|
41
|
-
it
|
42
|
-
expect(
|
43
|
-
expect(
|
29
|
+
context 'with invalid country code / input' do
|
30
|
+
it 'returns false' do
|
31
|
+
expect(described_class.validate('AE259597697')).to be(false)
|
32
|
+
expect(described_class.validate('')).to be(false)
|
44
33
|
end
|
45
34
|
end
|
46
35
|
|
47
|
-
context
|
48
|
-
|
49
|
-
|
36
|
+
context 'with details' do
|
37
|
+
let(:details) do
|
38
|
+
{
|
39
|
+
country_code: 'IE',
|
40
|
+
vat_number: '6388047V',
|
41
|
+
name: 'GOOGLE IRELAND LIMITED',
|
42
|
+
address: '3RD FLOOR, GORDON HOUSE, BARROW STREET, DUBLIN 4',
|
43
|
+
valid: true
|
44
|
+
}
|
45
|
+
end
|
50
46
|
|
51
|
-
|
47
|
+
it 'returns hash of details instead of true' do
|
48
|
+
result = described_class.validate('IE6388047V', detail: true)
|
49
|
+
# Skip if VIES is down
|
50
|
+
if result
|
52
51
|
expect(result.delete(:request_date)).to be_kind_of(Date)
|
53
|
-
expect(result).to eql(
|
54
|
-
country_code: "IE",
|
55
|
-
vat_number: "6388047V",
|
56
|
-
name: "GOOGLE IRELAND LIMITED",
|
57
|
-
address: "3RD FLOOR, GORDON HOUSE, BARROW STREET, DUBLIN 4",
|
58
|
-
valid: true
|
59
|
-
})
|
60
|
-
else
|
61
|
-
puts "Skipping IE vies lookup spec; result = #{result.inspect}"
|
52
|
+
expect(result).to eql(details)
|
62
53
|
end
|
63
54
|
end
|
64
55
|
|
65
|
-
it
|
66
|
-
result =
|
67
|
-
|
68
|
-
unless result.nil?
|
69
|
-
expect(result).to eql(false)
|
70
|
-
else
|
71
|
-
puts "Skipping LU vies lookup spec"
|
72
|
-
end
|
56
|
+
it 'still returns false on not existing VAT number' do
|
57
|
+
result = described_class.validate('LU21416128', detail: true)
|
58
|
+
# Skip if VIES is down
|
59
|
+
expect(result).to be(false) unless result.nil?
|
73
60
|
end
|
74
61
|
end
|
75
62
|
|
76
|
-
context
|
77
|
-
|
78
|
-
|
63
|
+
context 'with request identifier' do
|
64
|
+
let(:response) { described_class.validate('IE6388047V', requester: 'IE6388047V') }
|
65
|
+
let(:details) do
|
66
|
+
{
|
67
|
+
country_code: 'IE',
|
68
|
+
vat_number: '6388047V',
|
69
|
+
name: 'GOOGLE IRELAND LIMITED',
|
70
|
+
company_type: nil,
|
71
|
+
address: '3RD FLOOR, GORDON HOUSE, BARROW STREET, DUBLIN 4',
|
72
|
+
valid: true
|
73
|
+
}
|
74
|
+
end
|
79
75
|
|
76
|
+
it 'returns hash of details instead of true' do
|
77
|
+
# Skip if VIES is down
|
80
78
|
if response
|
81
|
-
expect(response
|
82
|
-
request_identifier = response[:request_identifier]
|
79
|
+
expect(response.delete(:request_identifier).size).to be(16)
|
83
80
|
expect(response.delete(:request_date)).to be_kind_of(Date)
|
84
|
-
expect(response).to eql(
|
85
|
-
country_code: "IE",
|
86
|
-
vat_number: "6388047V",
|
87
|
-
name: "GOOGLE IRELAND LIMITED",
|
88
|
-
company_type:nil,
|
89
|
-
address: "3RD FLOOR, GORDON HOUSE, BARROW STREET, DUBLIN 4",
|
90
|
-
request_identifier: request_identifier,
|
91
|
-
valid: true
|
92
|
-
})
|
93
|
-
else
|
94
|
-
puts "Skipping IE vies lookup spec"
|
81
|
+
expect(response).to eql(details)
|
95
82
|
end
|
96
83
|
end
|
97
84
|
|
98
|
-
it
|
99
|
-
expect(
|
100
|
-
Valvat::Lookup.new("IE6388047V", requester_vat: "LU21416127").instance_variable_get(:@options)[:requester]
|
101
|
-
).to eql("LU21416127")
|
102
|
-
|
85
|
+
it 'supports old :requester_vat option for backwards stability' do
|
103
86
|
expect(
|
104
|
-
|
105
|
-
).to eql(
|
87
|
+
described_class.new('IE6388047V', requester_vat: 'LU21416127').instance_variable_get(:@options)[:requester]
|
88
|
+
).to eql('LU21416127')
|
106
89
|
end
|
107
90
|
end
|
108
91
|
end
|
109
92
|
|
110
|
-
describe
|
93
|
+
describe '#validate with VIES test enviroment' do
|
94
|
+
let(:options) do
|
95
|
+
{ savon: { wsdl: 'https://ec.europa.eu/taxation_customs/vies/checkVatTestService.wsdl' },
|
96
|
+
skip_local_validation: true }
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'with valid request with valid VAT number' do
|
100
|
+
subject(:result) { described_class.validate('DE100', options) }
|
111
101
|
|
112
|
-
|
102
|
+
it 'returns true' do
|
103
|
+
expect(result).to be(true)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'with valid request with an invalid VAT number' do
|
108
|
+
subject(:result) { described_class.validate('DE200', options) }
|
109
|
+
|
110
|
+
it 'returns false' do
|
111
|
+
expect(result).to be(false)
|
112
|
+
end
|
113
|
+
end
|
113
114
|
|
114
|
-
|
115
|
-
subject{
|
115
|
+
describe 'Error : INVALID_INPUT' do
|
116
|
+
subject(:result) { described_class.validate('DE201', options) }
|
116
117
|
|
117
|
-
it
|
118
|
-
expect(
|
118
|
+
it 'returns false' do
|
119
|
+
expect(result).to be(false)
|
119
120
|
end
|
120
121
|
end
|
121
122
|
|
122
|
-
|
123
|
-
subject{
|
123
|
+
describe 'Error : INVALID_REQUESTER_INFO' do
|
124
|
+
subject(:result) { described_class.validate('DE202', options) }
|
124
125
|
|
125
|
-
it
|
126
|
-
expect
|
126
|
+
it 'raises Valvat::InvalidRequester' do
|
127
|
+
expect { result }.to raise_error(Valvat::InvalidRequester)
|
127
128
|
end
|
128
129
|
end
|
129
130
|
|
130
|
-
|
131
|
-
subject{
|
131
|
+
describe 'Error : SERVICE_UNAVAILABLE' do
|
132
|
+
subject(:result) { described_class.validate('DE300', options) }
|
133
|
+
|
134
|
+
it 'returns nil' do
|
135
|
+
expect(result).to be(nil)
|
136
|
+
end
|
132
137
|
|
133
|
-
it
|
134
|
-
expect
|
138
|
+
it 'raises error with raise_error: true' do
|
139
|
+
expect do
|
140
|
+
described_class.validate('DE300', options.merge(raise_error: true))
|
141
|
+
end.to raise_error(Valvat::ServiceUnavailable)
|
135
142
|
end
|
136
143
|
end
|
137
144
|
|
138
|
-
|
139
|
-
subject{
|
145
|
+
describe 'Error : MS_UNAVAILABLE' do
|
146
|
+
subject(:result) { described_class.validate('DE301', options) }
|
140
147
|
|
141
|
-
it
|
142
|
-
expect
|
148
|
+
it 'returns nil' do
|
149
|
+
expect(result).to be(nil)
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'raises error with raise_error: true' do
|
153
|
+
expect do
|
154
|
+
described_class.validate('DE301', options.merge(raise_error: true))
|
155
|
+
end.to raise_error(Valvat::MemberStateUnavailable)
|
143
156
|
end
|
144
157
|
end
|
145
158
|
|
146
|
-
|
147
|
-
subject{
|
159
|
+
describe 'Error : TIMEOUT' do
|
160
|
+
subject(:result) { described_class.validate('DE302', options) }
|
148
161
|
|
149
|
-
it
|
150
|
-
expect
|
162
|
+
it 'raises error' do
|
163
|
+
expect { result }.to raise_error(Valvat::Timeout)
|
151
164
|
end
|
152
165
|
|
153
|
-
it
|
154
|
-
expect
|
155
|
-
Valvat::Lookup.validate("DE300", options.merge(raise_error: true)
|
156
|
-
) }.to raise_error(Valvat::ServiceUnavailable)
|
166
|
+
it 'returns nil with raise_error set to false' do
|
167
|
+
expect(described_class.validate('DE302', options.merge(raise_error: false))).to be(nil)
|
157
168
|
end
|
158
169
|
end
|
159
170
|
|
160
|
-
|
161
|
-
subject{
|
171
|
+
describe 'Error : VAT_BLOCKED' do
|
172
|
+
subject(:result) { described_class.validate('DE400', options) }
|
162
173
|
|
163
|
-
it
|
164
|
-
expect
|
174
|
+
it 'raises error' do
|
175
|
+
expect { result }.to raise_error(Valvat::BlockedError, /VAT_BLOCKED/)
|
165
176
|
end
|
166
177
|
|
167
|
-
it
|
168
|
-
expect
|
169
|
-
Valvat::Lookup.validate("DE301", options.merge(raise_error: true)
|
170
|
-
) }.to raise_error(Valvat::MemberStateUnavailable)
|
178
|
+
it 'returns nil with raise_error set to false' do
|
179
|
+
expect(described_class.validate('DE400', options.merge(raise_error: false))).to be(nil)
|
171
180
|
end
|
172
181
|
end
|
173
182
|
|
174
|
-
|
175
|
-
subject{
|
183
|
+
describe 'Error : IP_BLOCKED' do
|
184
|
+
subject(:result) { described_class.validate('DE401', options) }
|
176
185
|
|
177
|
-
it
|
178
|
-
expect{
|
186
|
+
it 'raises error' do
|
187
|
+
expect { result }.to raise_error(Valvat::BlockedError, /IP_BLOCKED/)
|
179
188
|
end
|
180
189
|
|
181
|
-
it
|
182
|
-
expect(
|
190
|
+
it 'returns nil with raise_error set to false' do
|
191
|
+
expect(described_class.validate('DE401', options.merge(raise_error: false))).to be(nil)
|
183
192
|
end
|
184
193
|
end
|
185
194
|
|
186
|
-
|
187
|
-
subject{
|
195
|
+
describe 'Error : GLOBAL_MAX_CONCURRENT_REQ' do
|
196
|
+
subject(:result) { described_class.validate('DE500', options) }
|
188
197
|
|
189
|
-
it
|
190
|
-
expect{
|
198
|
+
it 'raises error' do
|
199
|
+
expect { result }.to raise_error(Valvat::RateLimitError, /GLOBAL_MAX_CONCURRENT_REQ/)
|
191
200
|
end
|
192
201
|
|
193
|
-
it
|
194
|
-
expect(
|
202
|
+
it 'returns nil with raise_error set to false' do
|
203
|
+
expect(described_class.validate('DE500', options.merge(raise_error: false))).to be(nil)
|
195
204
|
end
|
196
205
|
end
|
197
206
|
|
198
|
-
|
199
|
-
subject{
|
207
|
+
describe 'Error : GLOBAL_MAX_CONCURRENT_REQ_TIME' do
|
208
|
+
subject(:result) { described_class.validate('DE501', options) }
|
200
209
|
|
201
|
-
it
|
202
|
-
expect{
|
210
|
+
it 'raises error' do
|
211
|
+
expect { result }.to raise_error(Valvat::RateLimitError, /GLOBAL_MAX_CONCURRENT_REQ_TIME/)
|
203
212
|
end
|
204
213
|
|
205
|
-
it
|
206
|
-
expect(
|
214
|
+
it 'returns nil with raise_error set to false' do
|
215
|
+
expect(described_class.validate('DE501', options.merge(raise_error: false))).to be(nil)
|
207
216
|
end
|
208
217
|
end
|
209
218
|
|
210
|
-
|
211
|
-
subject{
|
219
|
+
describe 'Error : MS_MAX_CONCURRENT_REQ' do
|
220
|
+
subject(:result) { described_class.validate('DE600', options) }
|
212
221
|
|
213
|
-
it
|
214
|
-
expect{
|
222
|
+
it 'raises error' do
|
223
|
+
expect { result }.to raise_error(Valvat::RateLimitError, /MS_MAX_CONCURRENT_REQ/)
|
215
224
|
end
|
216
225
|
|
217
|
-
it
|
218
|
-
expect(
|
226
|
+
it 'returns nil with raise_error set to false' do
|
227
|
+
expect(described_class.validate('DE600', options.merge(raise_error: false))).to be(nil)
|
219
228
|
end
|
220
229
|
end
|
221
230
|
|
222
|
-
|
223
|
-
subject{
|
231
|
+
describe 'Error : MS_MAX_CONCURRENT_REQ_TIME' do
|
232
|
+
subject(:result) { described_class.validate('DE601', options) }
|
224
233
|
|
225
|
-
it
|
226
|
-
expect{
|
234
|
+
it 'raises error' do
|
235
|
+
expect { result }.to raise_error(Valvat::RateLimitError, /MS_MAX_CONCURRENT_REQ_TIME/)
|
227
236
|
end
|
228
237
|
|
229
|
-
it
|
230
|
-
expect(
|
238
|
+
it 'returns nil with raise_error set to false' do
|
239
|
+
expect(described_class.validate('DE601', options.merge(raise_error: false))).to be(nil)
|
231
240
|
end
|
232
241
|
end
|
233
242
|
|
234
|
-
|
235
|
-
|
243
|
+
describe 'Error : Savon::UnknownOperationError' do
|
244
|
+
before do
|
245
|
+
dbl = double(Savon::Client)
|
246
|
+
allow(Savon::Client).to receive(:new).and_return(dbl)
|
247
|
+
allow(dbl).to receive(:call).and_raise(Savon::UnknownOperationError.new('from stub'))
|
248
|
+
end
|
249
|
+
subject(:result) { described_class.validate('DE601', options) }
|
236
250
|
|
237
|
-
it
|
238
|
-
expect{
|
251
|
+
it 'raises error' do
|
252
|
+
expect { result }.to raise_error(Valvat::OperationUnknown, /#<Savon::UnknownOperationError: from stub>/)
|
239
253
|
end
|
240
254
|
|
241
|
-
it
|
242
|
-
expect(
|
255
|
+
it 'returns nil with raise_error set to false' do
|
256
|
+
expect(described_class.validate('DE601', options.merge(raise_error: false))).to be(nil)
|
243
257
|
end
|
244
258
|
end
|
245
259
|
|
246
|
-
|
247
|
-
|
260
|
+
describe 'Error : Savon::HTTPError' do
|
261
|
+
before do
|
262
|
+
dbl = double(Savon::Client)
|
263
|
+
allow(Savon::Client).to receive(:new).and_return(dbl)
|
264
|
+
allow(dbl).to receive(:call).and_raise(Savon::HTTPError.new(Struct.new(:code, :body).new(403, 'from stub')))
|
265
|
+
end
|
266
|
+
subject(:result) { described_class.validate('DE601', options) }
|
248
267
|
|
249
|
-
it
|
250
|
-
expect{
|
268
|
+
it 'raises error' do
|
269
|
+
expect { result }.to raise_error(Valvat::HTTPError, /#<Savon::HTTPError: HTTP error \(403\): from stub>/)
|
251
270
|
end
|
252
271
|
|
253
|
-
it
|
254
|
-
expect(
|
272
|
+
it 'returns nil with raise_error set to false' do
|
273
|
+
expect(described_class.validate('DE601', options.merge(raise_error: false))).to be(nil)
|
255
274
|
end
|
256
275
|
end
|
257
276
|
end
|