valvat 1.1.5 → 1.2.0
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 +2 -2
- data/.rubocop.yml +9 -3
- data/CHANGES.md +11 -2
- data/MIT-LICENSE +1 -1
- data/README.md +48 -33
- data/lib/valvat/checksum/es.rb +49 -16
- data/lib/valvat/error.rb +16 -16
- data/lib/valvat/local.rb +2 -49
- data/lib/valvat/lookup/base.rb +73 -0
- data/lib/valvat/lookup/hmrc.rb +86 -0
- data/lib/valvat/lookup/vies.rb +98 -0
- data/lib/valvat/lookup.rb +16 -5
- data/lib/valvat/utils.rb +0 -1
- data/lib/valvat/version.rb +1 -1
- data/lib/valvat.rb +50 -4
- data/spec/spec_helper.rb +2 -1
- data/spec/valvat/checksum/es_spec.rb +41 -1
- data/spec/valvat/checksum/gb_spec.rb +1 -0
- data/spec/valvat/lookup/hmrc_spec.rb +32 -0
- data/spec/valvat/lookup/vies_spec.rb +23 -0
- data/spec/valvat/lookup_spec.rb +259 -71
- data/valvat.gemspec +2 -2
- data.tar.gz.sig +0 -0
- metadata +22 -24
- metadata.gz.sig +0 -0
- data/lib/valvat/lookup/fault.rb +0 -44
- data/lib/valvat/lookup/request.rb +0 -57
- data/lib/valvat/lookup/response.rb +0 -37
- data/spec/valvat/lookup/fault_spec.rb +0 -34
- data/spec/valvat/lookup/request_spec.rb +0 -32
- data/spec/valvat/lookup/response_spec.rb +0 -29
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Valvat::Lookup::Fault do
|
6
|
-
it "returns {valid: false} on fault 'INVALID_INPUT'" do
|
7
|
-
expect(described_class.new({
|
8
|
-
fault: { faultstring: 'INVALID_INPUT' }
|
9
|
-
}).to_hash).to eql({ valid: false })
|
10
|
-
end
|
11
|
-
|
12
|
-
{
|
13
|
-
'SERVICE_UNAVAILABLE' => Valvat::ServiceUnavailable,
|
14
|
-
'MS_UNAVAILABLE' => Valvat::MemberStateUnavailable,
|
15
|
-
'INVALID_REQUESTER_INFO' => Valvat::InvalidRequester,
|
16
|
-
'TIMEOUT' => Valvat::Timeout,
|
17
|
-
'VAT_BLOCKED' => Valvat::BlockedError,
|
18
|
-
'IP_BLOCKED' => Valvat::BlockedError,
|
19
|
-
'GLOBAL_MAX_CONCURRENT_REQ' => Valvat::RateLimitError,
|
20
|
-
'GLOBAL_MAX_CONCURRENT_REQ_TIME' => Valvat::RateLimitError,
|
21
|
-
'MS_MAX_CONCURRENT_REQ' => Valvat::RateLimitError,
|
22
|
-
'MS_MAX_CONCURRENT_REQ_TIME' => Valvat::RateLimitError,
|
23
|
-
'ANYTHING ELSE' => Valvat::UnknownViesError,
|
24
|
-
'REALLY ANYTHING' => Valvat::UnknownViesError
|
25
|
-
}.each do |fault, error|
|
26
|
-
it "returns error on fault '#{fault}'" do
|
27
|
-
expect(described_class.new({
|
28
|
-
fault: { faultstring: fault }
|
29
|
-
}).to_hash).to eql({
|
30
|
-
error: error.new(fault)
|
31
|
-
})
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,32 +0,0 @@
|
|
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 = instance_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
|
@@ -1,29 +0,0 @@
|
|
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
|