valvat 0.9.1 → 1.1.1
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.tar.gz.sig +0 -0
- data/.github/workflows/ruby.yml +35 -0
- data/.gitignore +3 -1
- data/.rubocop.yml +15 -0
- data/CHANGES.md +36 -1
- data/Gemfile +4 -3
- data/Guardfile +6 -4
- data/README.md +99 -47
- data/Rakefile +3 -1
- data/certs/yolk.pem +21 -21
- data/gemfiles/activemodel-5 +4 -5
- data/gemfiles/activemodel-6 +7 -0
- data/gemfiles/standalone +3 -5
- data/lib/active_model/validations/valvat_validator.rb +70 -22
- data/lib/valvat.rb +7 -3
- data/lib/valvat/checksum.rb +24 -28
- 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 +53 -21
- 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/error.rb +31 -0
- data/lib/valvat/local.rb +8 -5
- 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/locales/pt.yml +28 -28
- data/lib/valvat/lookup.rb +14 -45
- data/lib/valvat/lookup/fault.rb +31 -0
- data/lib/valvat/lookup/request.rb +37 -11
- data/lib/valvat/lookup/response.rb +37 -0
- data/lib/valvat/syntax.rb +31 -30
- data/lib/valvat/utils.rb +20 -9
- data/lib/valvat/version.rb +3 -1
- data/spec/active_model/validations/valvat_validator_spec.rb +132 -100
- data/spec/spec_helper.rb +8 -8
- data/spec/valvat/checksum/at_spec.rb +8 -6
- data/spec/valvat/checksum/be_spec.rb +8 -6
- data/spec/valvat/checksum/bg_spec.rb +9 -6
- data/spec/valvat/checksum/cy_spec.rb +5 -3
- data/spec/valvat/checksum/de_spec.rb +8 -6
- data/spec/valvat/checksum/dk_spec.rb +8 -6
- data/spec/valvat/checksum/ee_spec.rb +5 -3
- data/spec/valvat/checksum/es_spec.rb +9 -6
- data/spec/valvat/checksum/fi_spec.rb +8 -6
- data/spec/valvat/checksum/fr_spec.rb +8 -6
- data/spec/valvat/checksum/gb_spec.rb +9 -5
- data/spec/valvat/checksum/gr_spec.rb +8 -6
- data/spec/valvat/checksum/hr_spec.rb +5 -3
- data/spec/valvat/checksum/hu_spec.rb +5 -3
- data/spec/valvat/checksum/ie_spec.rb +13 -5
- data/spec/valvat/checksum/it_spec.rb +12 -10
- data/spec/valvat/checksum/lt_spec.rb +5 -3
- data/spec/valvat/checksum/lu_spec.rb +8 -6
- data/spec/valvat/checksum/mt_spec.rb +5 -3
- data/spec/valvat/checksum/nl_spec.rb +9 -7
- data/spec/valvat/checksum/pl_spec.rb +10 -8
- data/spec/valvat/checksum/pt_spec.rb +12 -13
- data/spec/valvat/checksum/ro_spec.rb +5 -3
- data/spec/valvat/checksum/se_spec.rb +10 -8
- data/spec/valvat/checksum/si_spec.rb +12 -10
- data/spec/valvat/checksum_spec.rb +25 -10
- data/spec/valvat/lookup/fault_spec.rb +34 -0
- data/spec/valvat/lookup/request_spec.rb +19 -0
- data/spec/valvat/lookup/response_spec.rb +29 -0
- data/spec/valvat/lookup_spec.rb +202 -84
- data/spec/valvat/syntax_spec.rb +59 -280
- data/spec/valvat/utils_spec.rb +76 -43
- data/spec/valvat_spec.rb +140 -152
- data/valvat.gemspec +18 -17
- metadata +61 -41
- metadata.gz.sig +0 -0
- data/.travis.yml +0 -33
- data/gemfiles/activemodel-3-2 +0 -8
- data/gemfiles/activemodel-4 +0 -8
- data/gemfiles/before-ruby21/activemodel-3-2 +0 -9
- data/gemfiles/before-ruby21/activemodel-4 +0 -9
- data/gemfiles/before-ruby21/standalone +0 -8
- data/lib/valvat/lookup/request_with_id.rb +0 -31
@@ -1,15 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Valvat::Checksum::LU do
|
4
|
-
%w
|
5
|
-
it "returns true on valid
|
6
|
-
expect(Valvat::Checksum.validate(valid_vat)).to
|
6
|
+
%w[LU13669580 LU25361352 LU23124018 LU17560609].each do |valid_vat|
|
7
|
+
it "returns true on valid VAT #{valid_vat}" do
|
8
|
+
expect(Valvat::Checksum.validate(valid_vat)).to be(true)
|
7
9
|
end
|
8
10
|
|
9
11
|
invalid_vat = "#{valid_vat[0..-4]}#{valid_vat[-2]}#{valid_vat[-3]}#{valid_vat[-1]}"
|
10
12
|
|
11
|
-
it "returns false on invalid
|
12
|
-
expect(Valvat::Checksum.validate(invalid_vat)).to
|
13
|
+
it "returns false on invalid VAT #{invalid_vat}" do
|
14
|
+
expect(Valvat::Checksum.validate(invalid_vat)).to be(false)
|
13
15
|
end
|
14
16
|
end
|
15
|
-
end
|
17
|
+
end
|
@@ -1,14 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Valvat::Checksum::MT do
|
4
|
-
%w
|
5
|
-
it "returns true on valid
|
6
|
+
%w[MT11407334 MT10126313 MT11539237].each do |valid_vat|
|
7
|
+
it "returns true on valid VAT #{valid_vat}" do
|
6
8
|
expect(Valvat::Checksum.validate(valid_vat)).to be true
|
7
9
|
end
|
8
10
|
|
9
11
|
invalid_vat = "#{valid_vat[0..-3]}#{valid_vat[-1]}#{valid_vat[-2]}"
|
10
12
|
|
11
|
-
it "returns false on invalid
|
13
|
+
it "returns false on invalid VAT #{invalid_vat}" do
|
12
14
|
expect(Valvat::Checksum.validate(invalid_vat)).to be false
|
13
15
|
end
|
14
16
|
end
|
@@ -1,15 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Valvat::Checksum::NL do
|
4
|
-
%w
|
5
|
-
it "returns true on valid
|
6
|
-
expect(Valvat::Checksum.validate(
|
6
|
+
%w[NL123456782B12 NL802549391B01 NL808661863B01 NL820893559B01 NL000099998B57 NL123456789B13].each do |valid|
|
7
|
+
it "returns true on valid VAT #{valid}" do
|
8
|
+
expect(Valvat::Checksum.validate(valid)).to be(true)
|
7
9
|
end
|
8
10
|
|
9
|
-
|
11
|
+
invalid = "#{valid[0..-5]}#{valid[-2]}#{valid[-3]}#{valid[-4]}#{valid[-1]}#{valid[-2]}#{valid[-3]}"
|
10
12
|
|
11
|
-
it "returns false on invalid
|
12
|
-
expect(Valvat::Checksum.validate(
|
13
|
+
it "returns false on invalid VAT #{invalid}" do
|
14
|
+
expect(Valvat::Checksum.validate(invalid)).to be(false)
|
13
15
|
end
|
14
16
|
end
|
15
|
-
end
|
17
|
+
end
|
@@ -1,19 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Valvat::Checksum::PL do
|
4
|
-
%w
|
5
|
-
it "returns true on valid
|
6
|
-
expect(Valvat::Checksum.validate(valid_vat)).to
|
6
|
+
%w[PL8567346215 PL5260211587 PL9720575348 PL5272650022].each do |valid_vat|
|
7
|
+
it "returns true on valid VAT #{valid_vat}" do
|
8
|
+
expect(Valvat::Checksum.validate(valid_vat)).to be(true)
|
7
9
|
end
|
8
10
|
|
9
11
|
invalid_vat = "#{valid_vat[0..-4]}#{valid_vat[-1]}#{valid_vat[-2]}#{valid_vat[-3]}"
|
10
12
|
|
11
|
-
it "returns false on invalid
|
12
|
-
expect(Valvat::Checksum.validate(invalid_vat)).to
|
13
|
+
it "returns false on invalid VAT #{invalid_vat}" do
|
14
|
+
expect(Valvat::Checksum.validate(invalid_vat)).to be(false)
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
16
|
-
it
|
17
|
-
expect(Valvat::Checksum.validate(
|
18
|
+
it 'returns false on special case invalid VAT PL8566445330' do
|
19
|
+
expect(Valvat::Checksum.validate('PL8566445330')).to be(false)
|
18
20
|
end
|
19
|
-
end
|
21
|
+
end
|
@@ -1,31 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Valvat::Checksum::PT do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
%w(PT136695973 PT501413197 PT503037753 PT500243590 PT500100144 PT502921838).each do |valid_vat|
|
8
|
-
it "returns true on valid vat #{valid_vat}" do
|
9
|
-
expect(subject.validate(valid_vat)).to eql(true)
|
6
|
+
%w[PT136695973 PT501413197 PT503037753 PT500243590 PT500100144 PT502921838].each do |valid_vat|
|
7
|
+
it "returns true on valid VAT #{valid_vat}" do
|
8
|
+
expect(Valvat::Checksum.validate(valid_vat)).to be(true)
|
10
9
|
end
|
11
10
|
|
12
11
|
invalid_vat = "#{valid_vat[0..-5]}#{valid_vat[-1]}#{valid_vat[-4]}#{valid_vat[-2]}#{valid_vat[-3]}"
|
13
12
|
|
14
|
-
it "returns false on invalid
|
15
|
-
expect(
|
13
|
+
it "returns false on invalid VAT #{invalid_vat}" do
|
14
|
+
expect(Valvat::Checksum.validate(invalid_vat)).to be(false)
|
16
15
|
end
|
17
16
|
end
|
18
17
|
|
19
18
|
# Portuguese business VAT should start with the following numbers
|
20
19
|
# 1 or 2 (pessoa singular) - singular person
|
21
20
|
# 5 (pessoa colectiva) - collective person
|
22
|
-
# 6 (pessoa colectiva
|
23
|
-
# 8 (
|
24
|
-
# 9 (pessoa colectiva irregular ou
|
21
|
+
# 6 (pessoa colectiva publica) - public collective person
|
22
|
+
# 8 (empresario em nome individual) - individual enterpreneur
|
23
|
+
# 9 (pessoa colectiva irregular ou numero provisorio) - provisional number
|
25
24
|
# http://www.nif.pt/nif-das-empresas/
|
26
|
-
%w
|
25
|
+
%w[PT148166644 PT111623448 PT204874866 PT292261314 PT579104222 PT628910002 PT812627318 PT943935784].each do |number|
|
27
26
|
it "returns true on a valid number - #{number}" do
|
28
|
-
expect(
|
27
|
+
expect(Valvat::Checksum.validate(number)).to be(true)
|
29
28
|
end
|
30
29
|
end
|
31
30
|
end
|
@@ -1,14 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Valvat::Checksum::RO do
|
4
|
-
%w
|
5
|
-
it "returns true on valid
|
6
|
+
%w[RO123456789 RO99908 RO19 RO124 RO13182060].each do |valid_vat|
|
7
|
+
it "returns true on valid VAT #{valid_vat}" do
|
6
8
|
expect(Valvat::Checksum.validate(valid_vat)).to be true
|
7
9
|
end
|
8
10
|
|
9
11
|
invalid_vat = "#{valid_vat[0..-3]}#{valid_vat[-1]}#{valid_vat[-2]}"
|
10
12
|
|
11
|
-
it "returns false on invalid
|
13
|
+
it "returns false on invalid VAT #{invalid_vat}" do
|
12
14
|
expect(Valvat::Checksum.validate(invalid_vat)).to be false
|
13
15
|
end
|
14
16
|
end
|
@@ -1,19 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Valvat::Checksum::SE do
|
4
|
-
%w
|
5
|
-
it "returns true on valid
|
6
|
-
expect(Valvat::Checksum.validate(valid_vat)).to
|
6
|
+
%w[SE136695975501 SE556464687401 SE502052817901 SE556555952201 SE556084097601].each do |valid_vat|
|
7
|
+
it "returns true on valid VAT #{valid_vat}" do
|
8
|
+
expect(Valvat::Checksum.validate(valid_vat)).to be(true)
|
7
9
|
end
|
8
10
|
|
9
11
|
invalid_vat = "#{valid_vat[0..-4]}#{valid_vat[-1]}#{valid_vat[-2]}#{valid_vat[-3]}"
|
10
12
|
|
11
|
-
it "returns false on invalid
|
12
|
-
expect(Valvat::Checksum.validate(invalid_vat)).to
|
13
|
+
it "returns false on invalid VAT #{invalid_vat}" do
|
14
|
+
expect(Valvat::Checksum.validate(invalid_vat)).to be(false)
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
16
|
-
it
|
17
|
-
expect(Valvat::Checksum.validate(
|
18
|
+
it 'returns false on special case invalid VAT SE556464687400' do
|
19
|
+
expect(Valvat::Checksum.validate('SE556464687400')).to be(false)
|
18
20
|
end
|
19
|
-
end
|
21
|
+
end
|
@@ -1,23 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Valvat::Checksum::SI do
|
4
|
-
%w
|
5
|
-
it "returns true on valid
|
6
|
-
expect(Valvat::Checksum.validate(valid_vat)).to
|
6
|
+
%w[SI59082437 SI51049406 SI86154575 SI47431857 SI22511822 SI26833921].each do |valid_vat|
|
7
|
+
it "returns true on valid VAT #{valid_vat}" do
|
8
|
+
expect(Valvat::Checksum.validate(valid_vat)).to be(true)
|
7
9
|
end
|
8
10
|
|
9
|
-
invalid_vat = "#{valid_vat[0..-2]}#{valid_vat[-1].to_i+1}"
|
11
|
+
invalid_vat = "#{valid_vat[0..-2]}#{valid_vat[-1].to_i + 1}"
|
10
12
|
|
11
|
-
it "returns false on invalid
|
12
|
-
expect(Valvat::Checksum.validate(invalid_vat)).to
|
13
|
+
it "returns false on invalid VAT #{invalid_vat}" do
|
14
|
+
expect(Valvat::Checksum.validate(invalid_vat)).to be(false)
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
16
|
-
it
|
17
|
-
expect(Valvat::Checksum.validate(
|
18
|
+
it 'returns false on special case invalid VAT SI11111107' do
|
19
|
+
expect(Valvat::Checksum.validate('SI11111107')).to be(false)
|
18
20
|
end
|
19
21
|
|
20
|
-
it
|
21
|
-
expect(Valvat::Checksum.validate(
|
22
|
+
it 'returns false on special case invalid VAT SI01111108' do
|
23
|
+
expect(Valvat::Checksum.validate('SI01111108')).to be(false)
|
22
24
|
end
|
23
25
|
end
|
@@ -1,25 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
begin
|
4
|
-
require File.dirname(__FILE__)
|
6
|
+
require "#{File.dirname(__FILE__)}/../../tmp/valid_vat_numbers.rb"
|
5
7
|
rescue LoadError
|
6
|
-
VALID_VAT_NUMBERS = []
|
8
|
+
VALID_VAT_NUMBERS = [].freeze
|
7
9
|
end
|
8
10
|
|
11
|
+
# Syntax is correct, but checksum invalid
|
12
|
+
INVALID_VAT_NUMBERS = %w[
|
13
|
+
DE002768611 DE161216774 DE192970834 DE223361232 DE226095231
|
14
|
+
DE227411313 DE230928917 DE232123248 DE267748405 DE275615509
|
15
|
+
DE311927825 DE329214395 DE815842425 DE821530465 DE999999999
|
16
|
+
].freeze
|
17
|
+
|
9
18
|
describe Valvat::Checksum do
|
10
|
-
describe
|
11
|
-
it
|
12
|
-
expect(
|
19
|
+
describe '#validate' do
|
20
|
+
it 'returns true on VAT number with unknown checksum algorithm' do
|
21
|
+
expect(described_class.validate('CZ699001237')).to be(true)
|
13
22
|
end
|
14
23
|
|
15
|
-
it
|
16
|
-
expect(
|
24
|
+
it 'returns false on corrupt number (e.g checks syntax)' do
|
25
|
+
expect(described_class.validate('FI1234567891')).to be(false)
|
17
26
|
end
|
18
27
|
|
19
28
|
VALID_VAT_NUMBERS.each do |valid_vat|
|
20
|
-
it "returns true on valid
|
21
|
-
expect(
|
29
|
+
it "returns true on valid VAT number #{valid_vat}" do
|
30
|
+
expect(described_class.validate(valid_vat)).to be(true)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
INVALID_VAT_NUMBERS.each do |invalid_vat|
|
35
|
+
it "returns false on invalid VAT number #{invalid_vat}" do
|
36
|
+
expect(described_class.validate(invalid_vat)).to be(false)
|
22
37
|
end
|
23
38
|
end
|
24
39
|
end
|
25
|
-
end
|
40
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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
|
@@ -0,0 +1,19 @@
|
|
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
|
+
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,125 +1,243 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Valvat::Lookup do
|
4
|
-
describe
|
5
|
-
context
|
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?
|
12
|
+
end
|
6
13
|
|
7
|
-
it
|
8
|
-
result =
|
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?
|
18
|
+
end
|
19
|
+
end
|
9
20
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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?
|
15
26
|
end
|
27
|
+
end
|
16
28
|
|
17
|
-
|
18
|
-
|
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)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
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
|
19
46
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
51
|
+
expect(result.delete(:request_date)).to be_kind_of(Date)
|
52
|
+
expect(result).to eql(details)
|
24
53
|
end
|
25
54
|
end
|
55
|
+
|
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?
|
60
|
+
end
|
26
61
|
end
|
27
62
|
|
28
|
-
context
|
29
|
-
|
30
|
-
|
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
|
31
75
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
76
|
+
it 'returns hash of details instead of true' do
|
77
|
+
# Skip if VIES is down
|
78
|
+
if response
|
79
|
+
expect(response.delete(:request_identifier).size).to be(16)
|
80
|
+
expect(response.delete(:request_date)).to be_kind_of(Date)
|
81
|
+
expect(response).to eql(details)
|
36
82
|
end
|
37
83
|
end
|
84
|
+
|
85
|
+
it 'supports old :requester_vat option for backwards stability' do
|
86
|
+
expect(
|
87
|
+
described_class.new('IE6388047V', requester_vat: 'LU21416127').instance_variable_get(:@options)[:requester]
|
88
|
+
).to eql('LU21416127')
|
89
|
+
end
|
38
90
|
end
|
91
|
+
end
|
39
92
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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) }
|
101
|
+
|
102
|
+
it 'returns true' do
|
103
|
+
expect(result).to be(true)
|
44
104
|
end
|
45
105
|
end
|
46
106
|
|
47
|
-
context
|
48
|
-
|
49
|
-
result = Valvat::Lookup.validate("IE6388047V", :detail => true)
|
107
|
+
context 'with valid request with an invalid VAT number' do
|
108
|
+
subject(:result) { described_class.validate('DE200', options) }
|
50
109
|
|
51
|
-
|
52
|
-
|
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
|
-
})
|
59
|
-
else
|
60
|
-
puts "Skipping IE vies lookup spec; result = #{result.inspect}"
|
61
|
-
end
|
110
|
+
it 'returns false' do
|
111
|
+
expect(result).to be(false)
|
62
112
|
end
|
113
|
+
end
|
63
114
|
|
64
|
-
|
65
|
-
|
115
|
+
describe 'Error : INVALID_INPUT' do
|
116
|
+
subject(:result) { described_class.validate('DE201', options) }
|
66
117
|
|
67
|
-
|
68
|
-
|
69
|
-
else
|
70
|
-
puts "Skipping LU vies lookup spec"
|
71
|
-
end
|
118
|
+
it 'returns false' do
|
119
|
+
expect(result).to be(false)
|
72
120
|
end
|
73
121
|
end
|
74
122
|
|
75
|
-
|
76
|
-
|
77
|
-
response = Valvat::Lookup.validate("IE6388047V", :requester_vat => "IE6388047V")
|
123
|
+
describe 'Error : INVALID_REQUESTER_INFO' do
|
124
|
+
subject(:result) { described_class.validate('DE202', options) }
|
78
125
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
126
|
+
it 'raises Valvat::InvalidRequester' do
|
127
|
+
expect { result }.to raise_error(Valvat::InvalidRequester)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
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
|
137
|
+
|
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)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe 'Error : MS_UNAVAILABLE' do
|
146
|
+
subject(:result) { described_class.validate('DE301', options) }
|
147
|
+
|
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)
|
94
156
|
end
|
95
157
|
end
|
96
158
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
159
|
+
describe 'Error : TIMEOUT' do
|
160
|
+
subject(:result) { described_class.validate('DE302', options) }
|
161
|
+
|
162
|
+
it 'raises error' do
|
163
|
+
expect { result }.to raise_error(Valvat::Timeout)
|
102
164
|
end
|
103
165
|
|
104
|
-
it
|
105
|
-
expect(
|
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)
|
106
168
|
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe 'Error : VAT_BLOCKED' do
|
172
|
+
subject(:result) { described_class.validate('DE400', options) }
|
107
173
|
|
108
|
-
it
|
109
|
-
expect {
|
174
|
+
it 'raises error' do
|
175
|
+
expect { result }.to raise_error(Valvat::BlockedError, /VAT_BLOCKED/)
|
176
|
+
end
|
177
|
+
|
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)
|
110
180
|
end
|
111
181
|
end
|
112
182
|
|
113
|
-
|
114
|
-
|
115
|
-
# before do
|
116
|
-
# json = "{\"error_message\": \"Member State service unavailable.\", \"error_code\": 1, \"error\": true}"
|
117
|
-
# FakeWeb.register_uri(:get, "http://isvat.appspot.com/DE/259597697/", :body => json)
|
118
|
-
# end
|
183
|
+
describe 'Error : IP_BLOCKED' do
|
184
|
+
subject(:result) { described_class.validate('DE401', options) }
|
119
185
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
186
|
+
it 'raises error' do
|
187
|
+
expect { result }.to raise_error(Valvat::BlockedError, /IP_BLOCKED/)
|
188
|
+
end
|
189
|
+
|
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)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe 'Error : GLOBAL_MAX_CONCURRENT_REQ' do
|
196
|
+
subject(:result) { described_class.validate('DE500', options) }
|
197
|
+
|
198
|
+
it 'raises error' do
|
199
|
+
expect { result }.to raise_error(Valvat::RateLimitError, /GLOBAL_MAX_CONCURRENT_REQ/)
|
200
|
+
end
|
201
|
+
|
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)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe 'Error : GLOBAL_MAX_CONCURRENT_REQ_TIME' do
|
208
|
+
subject(:result) { described_class.validate('DE501', options) }
|
209
|
+
|
210
|
+
it 'raises error' do
|
211
|
+
expect { result }.to raise_error(Valvat::RateLimitError, /GLOBAL_MAX_CONCURRENT_REQ_TIME/)
|
212
|
+
end
|
213
|
+
|
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)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
describe 'Error : MS_MAX_CONCURRENT_REQ' do
|
220
|
+
subject(:result) { described_class.validate('DE600', options) }
|
221
|
+
|
222
|
+
it 'raises error' do
|
223
|
+
expect { result }.to raise_error(Valvat::RateLimitError, /MS_MAX_CONCURRENT_REQ/)
|
224
|
+
end
|
225
|
+
|
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)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
describe 'Error : MS_MAX_CONCURRENT_REQ_TIME' do
|
232
|
+
subject(:result) { described_class.validate('DE601', options) }
|
233
|
+
|
234
|
+
it 'raises error' do
|
235
|
+
expect { result }.to raise_error(Valvat::RateLimitError, /MS_MAX_CONCURRENT_REQ_TIME/)
|
236
|
+
end
|
237
|
+
|
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)
|
240
|
+
end
|
241
|
+
end
|
124
242
|
end
|
125
243
|
end
|