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
data/spec/valvat/syntax_spec.rb
CHANGED
@@ -1,289 +1,68 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe Valvat::Syntax do
|
4
|
-
describe "#validate" do
|
5
|
-
it "validates a DE VAT number" do
|
6
|
-
expect(subject.validate("DE345889003")).to eql(true)
|
7
|
-
|
8
|
-
expect(subject.validate("DE34588900")).to eql(false)
|
9
|
-
expect(subject.validate("DE3458890090")).to eql(false)
|
10
|
-
expect(subject.validate("DE34588900C")).to eql(false)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "validates a AT VAT number" do
|
14
|
-
expect(subject.validate("ATU03458890")).to eql(true)
|
15
|
-
|
16
|
-
expect(subject.validate("ATU034588908")).to eql(false)
|
17
|
-
expect(subject.validate("ATU0345908")).to eql(false)
|
18
|
-
expect(subject.validate("ATU0345889Y")).to eql(false)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should validate BE VAT number" do
|
22
|
-
expect(subject.validate("BE0817331995")).to eql(true)
|
23
|
-
|
24
|
-
expect(subject.validate("BE081733199")).to eql(false)
|
25
|
-
expect(subject.validate("BE08173319944")).to eql(false)
|
26
|
-
expect(subject.validate("BE081733199H")).to eql(false)
|
27
|
-
expect(subject.validate("BE1817331999")).to eql(false)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "validates a BG VAT number" do
|
31
|
-
expect(subject.validate("BG468134789")).to eql(true)
|
32
|
-
expect(subject.validate("BG4681347897")).to eql(true)
|
33
|
-
|
34
|
-
expect(subject.validate("BG46813478979")).to eql(false)
|
35
|
-
expect(subject.validate("BG4681347897C")).to eql(false)
|
36
|
-
expect(subject.validate("BG46813478G")).to eql(false)
|
37
|
-
expect(subject.validate("BG46813478")).to eql(false)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "validates a CY VAT number" do
|
41
|
-
expect(subject.validate("CY36579347A")).to eql(true)
|
42
|
-
expect(subject.validate("CY36579347C")).to eql(true)
|
43
|
-
|
44
|
-
expect(subject.validate("CY36579347")).to eql(false)
|
45
|
-
expect(subject.validate("CY365793478")).to eql(false)
|
46
|
-
expect(subject.validate("CY365793478A")).to eql(false)
|
47
|
-
expect(subject.validate("CY365793G")).to eql(false)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "validates a DK VAT number" do
|
51
|
-
expect(subject.validate("DK67893463")).to eql(true)
|
52
|
-
|
53
|
-
expect(subject.validate("DK678934637")).to eql(false)
|
54
|
-
expect(subject.validate("DK6789346")).to eql(false)
|
55
|
-
expect(subject.validate("DK6789346H")).to eql(false)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "validates a ES VAT number" do
|
59
|
-
expect(subject.validate("ESX67345987")).to eql(true)
|
60
|
-
expect(subject.validate("ESA6734598B")).to eql(true)
|
61
|
-
expect(subject.validate("ES56734598C")).to eql(true)
|
62
|
-
|
63
|
-
expect(subject.validate("ES167345987")).to eql(false)
|
64
|
-
expect(subject.validate("ESX6734598")).to eql(false)
|
65
|
-
expect(subject.validate("ESX673459890")).to eql(false)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "validates a EE VAT number" do
|
69
|
-
expect(subject.validate("EE100207415")).to eql(true)
|
70
|
-
expect(subject.validate("EE1002074150")).to eql(false)
|
71
|
-
expect(subject.validate("EE10020741")).to eql(false)
|
72
|
-
expect(subject.validate("EE100207415K")).to eql(false)
|
73
|
-
end
|
74
|
-
|
75
|
-
it "validates a FI VAT number" do
|
76
|
-
expect(subject.validate("FI67845638")).to eql(true)
|
77
|
-
|
78
|
-
expect(subject.validate("FI678456389")).to eql(false)
|
79
|
-
expect(subject.validate("FI6784563")).to eql(false)
|
80
|
-
expect(subject.validate("FI6784563K")).to eql(false)
|
81
|
-
end
|
82
|
-
|
83
|
-
it "validates a FR VAT number" do
|
84
|
-
expect(subject.validate("FR99123543267")).to eql(true)
|
85
|
-
expect(subject.validate("FRBB123543267")).to eql(true)
|
86
|
-
expect(subject.validate("FR9B123543267")).to eql(true)
|
87
|
-
expect(subject.validate("FRB9123543267")).to eql(true)
|
88
|
-
|
89
|
-
expect(subject.validate("FR99123543267B")).to eql(false)
|
90
|
-
expect(subject.validate("FRBB12354326")).to eql(false)
|
91
|
-
expect(subject.validate("FR9B123543F67")).to eql(false)
|
92
|
-
expect(subject.validate("FRB9123543")).to eql(false)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "validates a EL VAT number" do
|
96
|
-
expect(subject.validate("EL678456345")).to eql(true)
|
97
|
-
|
98
|
-
expect(subject.validate("EL67845634")).to eql(false)
|
99
|
-
expect(subject.validate("EL6784563459")).to eql(false)
|
100
|
-
expect(subject.validate("EL67845634P")).to eql(false)
|
101
|
-
end
|
102
|
-
|
103
|
-
it "validates a HU VAT number" do
|
104
|
-
expect(subject.validate("HU67894595")).to eql(true)
|
105
|
-
|
106
|
-
expect(subject.validate("HU6789459")).to eql(false)
|
107
|
-
expect(subject.validate("HU67894595L")).to eql(false)
|
108
|
-
expect(subject.validate("HU6789459J")).to eql(false)
|
109
|
-
end
|
110
|
-
|
111
|
-
it "validates a HR VAT number" do
|
112
|
-
expect(subject.validate("HR12345678912")).to eql(true)
|
113
|
-
|
114
|
-
expect(subject.validate("HR6789459")).to eql(false)
|
115
|
-
expect(subject.validate("HR67894595L")).to eql(false)
|
116
|
-
expect(subject.validate("HR6789459J")).to eql(false)
|
117
|
-
end
|
118
|
-
|
119
|
-
it "validates a IE VAT number" do
|
120
|
-
expect(subject.validate("IE1B12345J")).to eql(true)
|
121
|
-
expect(subject.validate("IE1234567B")).to eql(true)
|
122
|
-
expect(subject.validate("IE1234567XX")).to eql(true)
|
123
|
-
|
124
|
-
expect(subject.validate("IE1B123459")).to eql(false)
|
125
|
-
expect(subject.validate("IE19123450")).to eql(false)
|
126
|
-
expect(subject.validate("IEA9123450")).to eql(false)
|
127
|
-
expect(subject.validate("IE1B12345XX")).to eql(false)
|
128
|
-
expect(subject.validate("IE1X34567XX")).to eql(false)
|
129
|
-
end
|
130
|
-
|
131
|
-
it "validates a IT VAT number" do
|
132
|
-
expect(subject.validate("IT45875359285")).to eql(true)
|
1
|
+
# frozen_string_literal: true
|
133
2
|
|
134
|
-
|
135
|
-
expect(subject.validate("IT4587535928G")).to eql(false)
|
136
|
-
expect(subject.validate("IT4587535928")).to eql(false)
|
137
|
-
end
|
138
|
-
|
139
|
-
it "validates a LV VAT number" do
|
140
|
-
expect(subject.validate("LV85678368906")).to eql(true)
|
141
|
-
|
142
|
-
expect(subject.validate("LV8567836890")).to eql(false)
|
143
|
-
expect(subject.validate("LV856783689066")).to eql(false)
|
144
|
-
expect(subject.validate("LV8567836890S")).to eql(false)
|
145
|
-
end
|
146
|
-
|
147
|
-
it "validates a LT VAT number" do
|
148
|
-
expect(subject.validate("LT213179412")).to eql(true)
|
149
|
-
expect(subject.validate("LT290061371314")).to eql(true)
|
150
|
-
|
151
|
-
expect(subject.validate("LT21317942")).to eql(false)
|
152
|
-
expect(subject.validate("LT213179422")).to eql(false)
|
153
|
-
expect(subject.validate("LT2131794120")).to eql(false)
|
154
|
-
expect(subject.validate("LT213179412K")).to eql(false)
|
155
|
-
expect(subject.validate("LT29006137132")).to eql(false)
|
156
|
-
expect(subject.validate("LT290061371324")).to eql(false)
|
157
|
-
expect(subject.validate("LT29006137131C")).to eql(false)
|
158
|
-
expect(subject.validate("LT290061371314H")).to eql(false)
|
159
|
-
end
|
160
|
-
|
161
|
-
it "validates a LU VAT number" do
|
162
|
-
expect(subject.validate("LU45679456")).to eql(true)
|
163
|
-
|
164
|
-
expect(subject.validate("LU4567945")).to eql(false)
|
165
|
-
expect(subject.validate("LU456794560")).to eql(false)
|
166
|
-
expect(subject.validate("LU4567945J")).to eql(false)
|
167
|
-
end
|
168
|
-
|
169
|
-
it "validates a MT VAT number" do
|
170
|
-
expect(subject.validate("MT64569367")).to eql(true)
|
171
|
-
|
172
|
-
expect(subject.validate("MT6456936")).to eql(false)
|
173
|
-
expect(subject.validate("MT645693679")).to eql(false)
|
174
|
-
expect(subject.validate("MT6456936L")).to eql(false)
|
175
|
-
end
|
176
|
-
|
177
|
-
it "validates a NL VAT number" do
|
178
|
-
expect(subject.validate("NL673739491B77")).to eql(true)
|
179
|
-
|
180
|
-
expect(subject.validate("NL673739491977")).to eql(false)
|
181
|
-
expect(subject.validate("NL673739491A77")).to eql(false)
|
182
|
-
expect(subject.validate("NL673739491B771")).to eql(false)
|
183
|
-
expect(subject.validate("NL673739491B7")).to eql(false)
|
184
|
-
expect(subject.validate("NL6737394917B7")).to eql(false)
|
185
|
-
end
|
186
|
-
|
187
|
-
it "validates a PL VAT number" do
|
188
|
-
expect(subject.validate("PL6784567284")).to eql(true)
|
189
|
-
|
190
|
-
expect(subject.validate("PL678456728")).to eql(false)
|
191
|
-
expect(subject.validate("PL67845672849")).to eql(false)
|
192
|
-
expect(subject.validate("PL678456728K")).to eql(false)
|
193
|
-
end
|
194
|
-
|
195
|
-
it "validates a PT VAT number" do
|
196
|
-
expect(subject.validate("PT346296476")).to eql(true)
|
197
|
-
|
198
|
-
expect(subject.validate("PT34629647")).to eql(false)
|
199
|
-
expect(subject.validate("PT3462964769")).to eql(false)
|
200
|
-
end
|
201
|
-
|
202
|
-
it "validates a GB VAT number" do
|
203
|
-
expect(subject.validate("GB123456789")).to eql(true)
|
204
|
-
expect(subject.validate("GB123456789012")).to eql(true)
|
205
|
-
expect(subject.validate("GBGD123")).to eql(true)
|
206
|
-
expect(subject.validate("GBHA123")).to eql(true)
|
207
|
-
|
208
|
-
expect(subject.validate("GB12345678")).to eql(false)
|
209
|
-
expect(subject.validate("GB1234567890")).to eql(false)
|
210
|
-
expect(subject.validate("GB12345678901")).to eql(false)
|
211
|
-
expect(subject.validate("GB1234567890123")).to eql(false)
|
212
|
-
expect(subject.validate("GBAB123")).to eql(false)
|
213
|
-
expect(subject.validate("GBAA123")).to eql(false)
|
214
|
-
expect(subject.validate("GBHH123")).to eql(false)
|
215
|
-
expect(subject.validate("GBGD1234")).to eql(false)
|
216
|
-
expect(subject.validate("GBGD12")).to eql(false)
|
217
|
-
end
|
218
|
-
|
219
|
-
it "validates a RO VAT number" do
|
220
|
-
expect(subject.validate("RO1234567890")).to eql(true)
|
221
|
-
expect(subject.validate("RO123456789")).to eql(true)
|
222
|
-
expect(subject.validate("RO12345678")).to eql(true)
|
223
|
-
expect(subject.validate("RO1234567")).to eql(true)
|
224
|
-
expect(subject.validate("RO123456")).to eql(true)
|
225
|
-
expect(subject.validate("RO12345")).to eql(true)
|
226
|
-
expect(subject.validate("RO1234")).to eql(true)
|
227
|
-
expect(subject.validate("RO123")).to eql(true)
|
228
|
-
expect(subject.validate("RO12")).to eql(true)
|
229
|
-
|
230
|
-
expect(subject.validate("RO1")).to eql(false)
|
231
|
-
expect(subject.validate("RO0234567890")).to eql(false)
|
232
|
-
expect(subject.validate("RO023456789")).to eql(false)
|
233
|
-
expect(subject.validate("RO02345678")).to eql(false)
|
234
|
-
expect(subject.validate("RO0234567")).to eql(false)
|
235
|
-
expect(subject.validate("RO023456")).to eql(false)
|
236
|
-
expect(subject.validate("RO02345")).to eql(false)
|
237
|
-
expect(subject.validate("RO0234")).to eql(false)
|
238
|
-
expect(subject.validate("RO023")).to eql(false)
|
239
|
-
expect(subject.validate("RO02")).to eql(false)
|
240
|
-
expect(subject.validate("RO12345678901")).to eql(false)
|
241
|
-
end
|
242
|
-
|
243
|
-
it "validates a SK VAT number" do
|
244
|
-
expect(subject.validate("SK5683075682")).to eql(true)
|
245
|
-
|
246
|
-
expect(subject.validate("SK56830756821")).to eql(false)
|
247
|
-
expect(subject.validate("SK568307568")).to eql(false)
|
248
|
-
end
|
249
|
-
|
250
|
-
it "validates a SI VAT number" do
|
251
|
-
expect(subject.validate("SI74357893")).to eql(true)
|
252
|
-
|
253
|
-
expect(subject.validate("SI743578931")).to eql(false)
|
254
|
-
expect(subject.validate("SI7435789")).to eql(false)
|
255
|
-
end
|
256
|
-
|
257
|
-
it "validates a SE VAT number" do
|
258
|
-
expect(subject.validate("SE567396352701")).to eql(true)
|
259
|
-
|
260
|
-
expect(subject.validate("SE56739635201")).to eql(false)
|
261
|
-
expect(subject.validate("SE5673963527701")).to eql(false)
|
262
|
-
expect(subject.validate("SE567396352702")).to eql(false)
|
263
|
-
expect(subject.validate("SE567396352711")).to eql(false)
|
264
|
-
end
|
265
|
-
|
266
|
-
it "validates a CZ VAT number" do
|
267
|
-
expect(subject.validate("CZ56389267")).to eql(true)
|
268
|
-
expect(subject.validate("CZ563892670")).to eql(true)
|
269
|
-
expect(subject.validate("CZ5638926790")).to eql(true)
|
3
|
+
require 'spec_helper'
|
270
4
|
|
271
|
-
|
272
|
-
|
5
|
+
def it_validates(valid_vats, invalid_vats)
|
6
|
+
valid_vats.each do |valid|
|
7
|
+
it "returns true for #{valid.inspect}" do
|
8
|
+
expect(described_class.validate(valid)).to be(true)
|
273
9
|
end
|
10
|
+
end
|
274
11
|
|
275
|
-
|
276
|
-
|
277
|
-
expect(
|
278
|
-
expect(subject.validate("DE")).to eql(false)
|
279
|
-
expect(subject.validate("atu123xyz")).to eql(false)
|
280
|
-
expect(subject.validate("xxxxxxxxxx")).to eql(false)
|
281
|
-
expect(subject.validate("BEFR")).to eql(false)
|
12
|
+
invalid_vats.each do |invalid|
|
13
|
+
it "returns false for #{invalid.inspect}" do
|
14
|
+
expect(described_class.validate(invalid)).to be(false)
|
282
15
|
end
|
16
|
+
end
|
17
|
+
end
|
283
18
|
|
284
|
-
|
285
|
-
|
286
|
-
|
19
|
+
describe Valvat::Syntax do
|
20
|
+
describe '#validate' do
|
21
|
+
it_validates(%w[ATU03458890], %w[ATU034588908 ATU0345908 ATU0345889Y])
|
22
|
+
it_validates(%w[BE0817331995], %w[BE081733199 BE08173319944 BE081733199H BE1817331999])
|
23
|
+
it_validates(%w[BG468134789 BG4681347897], %w[BG46813478979 BG4681347897C BG46813478G BG46813478])
|
24
|
+
it_validates(%w[CY36579347A CY36579347C], %w[CY36579347 CY365793478 CY365793478A CY365793G])
|
25
|
+
it_validates(%w[CZ56389267 CZ563892670 CZ5638926790], %w[CZ5638926 CZ56389268901])
|
26
|
+
it_validates(%w[DE345889003], %w[DE34588900 DE3458890090 DE34588900C])
|
27
|
+
it_validates(%w[DK67893463], %w[DK678934637 DK6789346 DK6789346H])
|
28
|
+
it_validates(%w[EE100207415], %w[EE1002074150 EE10020741 EE10020741 EE100207415K])
|
29
|
+
it_validates(%w[EL678456345], %w[EL67845634 EL6784563459 EL67845634P])
|
30
|
+
it_validates(%w[ESX67345987 ESA6734598B ES56734598C], %w[ES167345987 ESX6734598 ESX673459890])
|
31
|
+
it_validates(%w[FI67845638], %w[FI678456389 FI6784563 FI6784563K])
|
32
|
+
it_validates(%w[FR99123543267 FRBB123543267 FR9B123543267 FRB9123543267],
|
33
|
+
%w[FR99123543267B FRBB12354326 FR9B123543F67 FRB9123543])
|
34
|
+
it_validates(%w[GB123456789 GB123456789012 GBGD123 GBHA123],
|
35
|
+
%w[GB12345678 GB1234567890 GB12345678901 GB1234567890123 GBAB123 GBAA123 GBHH123 GBGD1234 GBGD12])
|
36
|
+
it_validates(%w[HR12345678912], %w[HR6789459 HR67894595L HR6789459J])
|
37
|
+
it_validates(%w[HU67894595], %w[HU6789459 HU67894595L HU6789459J])
|
38
|
+
it_validates(%w[IE1B12345J IE1234567B IE1234567XX], %w[IE1B123459 IE19123450 IEA9123450 IE1B12345XX IE1X34567XX])
|
39
|
+
it_validates(%w[IT45875359285 IT00146089990], %w[IT458753592859 IT4587535928G IT4587535928])
|
40
|
+
it_validates(%w[LT213179412 LT290061371314],
|
41
|
+
%w[LT21317942 LT213179422 LT2131794120 LT213179412K LT29006137132 LT290061371324 LT29006137131C
|
42
|
+
LT290061371314H])
|
43
|
+
it_validates(%w[LU45679456], %w[LU4567945 LU456794560 LU4567945J])
|
44
|
+
it_validates(%w[LV85678368906], %w[LV8567836890 LV856783689066 LV8567836890S])
|
45
|
+
it_validates(%w[MT64569367], %w[MT6456936 MT645693679 MT6456936L])
|
46
|
+
it_validates(%w[NL673739491B77], %w[NL673739491977 NL673739491A77 NL673739491B771 NL673739491B7 NL6737394917B7])
|
47
|
+
it_validates(%w[PL6784567284], %w[PL678456728 PL67845672849 PL678456728K])
|
48
|
+
it_validates(%w[PT346296476], %w[PT34629647 PT3462964769])
|
49
|
+
it_validates(%w[RO1234567890 RO123456789 RO12345678 RO1234567 RO123456 RO12345 RO1234 RO123 RO12],
|
50
|
+
%w[RO1 RO0234567890 RO023456789 RO02345678 RO0234567 RO023456 RO02345 RO0234 RO02 RO12345678901])
|
51
|
+
it_validates(%w[SE567396352701], %w[SE56739635201 SE5673963527701 SE567396352702 SE567396352711])
|
52
|
+
it_validates(%w[SI74357893], %w[SI743578931 SI7435789])
|
53
|
+
it_validates(%w[SK5683075682], %w[SK56830756821 SK568307568])
|
54
|
+
it_validates(%w[XI123456789 XI123456789012 XIGD123 XIHA123],
|
55
|
+
%w[XI12345678 XI12345678901234 XIGD1234 XIHA1234 XIGD12 XIHA12 XIHD123])
|
56
|
+
|
57
|
+
it 'returns false on blank/non-sense VAT number' do
|
58
|
+
['', ' ', 'DE', 'atu123xyz', 'xxxxxxxxxx', 'BEFR'].each do |input|
|
59
|
+
expect(described_class.validate(input)).to be(false)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'allows Valvat instance as input' do
|
64
|
+
expect(described_class.validate(Valvat.new('DE345889003'))).to be(true)
|
65
|
+
expect(described_class.validate(Valvat.new('DE34588900X'))).to be(false)
|
287
66
|
end
|
288
67
|
end
|
289
68
|
end
|
data/spec/valvat/utils_spec.rb
CHANGED
@@ -1,97 +1,114 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
describe Valvat::Utils do
|
5
|
-
describe
|
6
|
-
it
|
7
|
-
expect(
|
8
|
-
expect(
|
6
|
+
describe '#split' do
|
7
|
+
it 'returns country and rest on VAT number as array' do
|
8
|
+
expect(described_class.split('DE345889003')).to eql(%w[DE 345889003])
|
9
|
+
expect(described_class.split('ESX4588900X')).to eql(%w[ES X4588900X])
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns two nils on non-european iso codes as array' do
|
13
|
+
expect(described_class.split('US345889003')).to eql([nil, nil])
|
14
|
+
expect(described_class.split('RUX4588900X')).to eql([nil, nil])
|
9
15
|
end
|
10
16
|
|
11
|
-
it
|
12
|
-
expect(
|
13
|
-
expect(
|
17
|
+
it 'returns two nils on non-sense input as array' do
|
18
|
+
expect(described_class.split('DE')).to eql([nil, nil])
|
19
|
+
expect(described_class.split('X345889003')).to eql([nil, nil])
|
20
|
+
expect(described_class.split('')).to eql([nil, nil])
|
21
|
+
expect(described_class.split('1234')).to eql([nil, nil])
|
22
|
+
expect(described_class.split(' ')).to eql([nil, nil]) # rubocop:disable Style/RedundantArgument
|
14
23
|
end
|
15
24
|
|
16
|
-
it
|
17
|
-
expect(
|
18
|
-
expect(Valvat::Utils.split("X345889003")).to eql([nil, nil])
|
19
|
-
expect(Valvat::Utils.split("")).to eql([nil, nil])
|
20
|
-
expect(Valvat::Utils.split("1234")).to eql([nil, nil])
|
21
|
-
expect(Valvat::Utils.split(" ")).to eql([nil, nil])
|
25
|
+
it 'returns EL (language iso code) on greek vat' do
|
26
|
+
expect(described_class.split('EL999999999')).to eql(%w[EL 999999999])
|
22
27
|
end
|
23
28
|
|
24
|
-
it
|
25
|
-
expect(
|
29
|
+
it 'returns XI (vat number code) on northern ireland vat' do
|
30
|
+
expect(described_class.split('XI999999999')).to eql(%w[XI 999999999])
|
26
31
|
end
|
27
32
|
end
|
28
33
|
|
29
|
-
describe
|
30
|
-
it
|
31
|
-
expect(
|
32
|
-
expect(
|
34
|
+
describe '#normalize' do
|
35
|
+
it 'returns VAT number with upcase chars' do
|
36
|
+
expect(described_class.normalize('de345889003')).to eql('DE345889003')
|
37
|
+
expect(described_class.normalize('EsX4588900y')).to eql('ESX4588900Y')
|
33
38
|
end
|
34
39
|
|
35
|
-
it
|
36
|
-
expect(
|
37
|
-
expect(
|
38
|
-
expect(
|
40
|
+
it 'returns trimmed VAT number' do
|
41
|
+
expect(described_class.normalize(' DE345889003')).to eql('DE345889003')
|
42
|
+
expect(described_class.normalize(' DE345889003 ')).to eql('DE345889003')
|
43
|
+
expect(described_class.normalize('DE345889003 ')).to eql('DE345889003')
|
39
44
|
end
|
40
45
|
|
41
|
-
it
|
42
|
-
expect(
|
43
|
-
expect(
|
46
|
+
it 'does not change already normalized VAT numbers' do
|
47
|
+
expect(described_class.normalize('DE345889003')).to eql('DE345889003')
|
48
|
+
expect(described_class.normalize('ESX4588900X')).to eql('ESX4588900X')
|
44
49
|
end
|
45
50
|
|
46
|
-
it
|
47
|
-
expect(
|
48
|
-
expect(
|
51
|
+
it 'removes spaces' do
|
52
|
+
expect(described_class.normalize('DE 345889003')).to eql('DE345889003')
|
53
|
+
expect(described_class.normalize('ESX 458 8900 X')).to eql('ESX4588900X')
|
49
54
|
end
|
50
55
|
|
51
|
-
it
|
52
|
-
expect(
|
53
|
-
expect(
|
56
|
+
it 'removes special chars' do
|
57
|
+
expect(described_class.normalize('DE.345-889_00:3,;')).to eql('DE345889003')
|
58
|
+
expect(described_class.normalize("→ DE·Ö34588 9003\0 ☺")).to eql(
|
59
|
+
RUBY_ENGINE == 'truffleruby' ? 'DEÖ345889003' : '→DEÖ345889003☺'
|
60
|
+
)
|
54
61
|
end
|
55
62
|
end
|
56
63
|
|
57
|
-
describe
|
64
|
+
describe '#vat_country_to_iso_country' do
|
58
65
|
it "returns iso country code on greek iso language 'EL'" do
|
59
|
-
expect(
|
66
|
+
expect(described_class.vat_country_to_iso_country('EL')).to eql('GR')
|
67
|
+
end
|
68
|
+
|
69
|
+
it "returns iso country code on northern ireland vat prefix 'XI'" do
|
70
|
+
expect(described_class.vat_country_to_iso_country('XI')).to eql('GB')
|
60
71
|
end
|
61
72
|
|
62
73
|
Valvat::Utils::EU_MEMBER_STATES.each do |iso|
|
63
74
|
it "returns unchanged iso country code '#{iso}'" do
|
64
|
-
expect(
|
75
|
+
expect(described_class.vat_country_to_iso_country(iso)).to eql(iso)
|
65
76
|
end
|
66
77
|
end
|
67
78
|
end
|
68
79
|
|
69
|
-
describe
|
70
|
-
it "returns VAT country on greek iso country code 'GR'" do
|
71
|
-
expect(
|
80
|
+
describe '#iso_country_to_vat_country' do
|
81
|
+
it "returns VAT country EL on greek iso country code 'GR'" do
|
82
|
+
expect(described_class.iso_country_to_vat_country('GR')).to eql('EL')
|
83
|
+
end
|
84
|
+
|
85
|
+
it "returns VAT country XI on british iso country code 'GB'" do
|
86
|
+
expect(described_class.iso_country_to_vat_country('GB')).to eql('XI')
|
72
87
|
end
|
73
88
|
|
74
89
|
Valvat::Utils::EU_MEMBER_STATES.each do |c|
|
90
|
+
next if c == 'GR'
|
91
|
+
|
75
92
|
it "returns unchanged VAT country code '#{c}'" do
|
76
|
-
expect(
|
77
|
-
end
|
93
|
+
expect(described_class.iso_country_to_vat_country(c)).to eql(c)
|
94
|
+
end
|
78
95
|
end
|
79
96
|
end
|
80
97
|
|
81
|
-
describe
|
98
|
+
describe '#country_is_supported?' do
|
82
99
|
Valvat::Utils::EU_MEMBER_STATES.each do |code|
|
83
100
|
it "returns true on #{code}" do
|
84
|
-
expect(
|
101
|
+
expect(described_class.country_is_supported?(code)).to be(true)
|
85
102
|
end
|
86
103
|
end
|
87
104
|
|
88
|
-
it
|
89
|
-
expect(
|
105
|
+
it 'returns true on GB' do
|
106
|
+
expect(described_class.country_is_supported?('GB')).to be(true)
|
90
107
|
end
|
91
108
|
|
92
|
-
[
|
109
|
+
%w[US AE CA CN BR AU NO ML].each do |code|
|
93
110
|
it "returns false on #{code}" do
|
94
|
-
expect(
|
111
|
+
expect(described_class.country_is_supported?(code)).to be(false)
|
95
112
|
end
|
96
113
|
end
|
97
114
|
end
|