valvat 1.4.0 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +2 -1
  3. data/lib/valvat/lookup/vies.rb +2 -2
  4. data/lib/valvat/version.rb +1 -1
  5. data.tar.gz.sig +0 -0
  6. metadata +35 -103
  7. metadata.gz.sig +0 -0
  8. data/.editorconfig +0 -15
  9. data/.github/workflows/rubocop.yml +0 -17
  10. data/.github/workflows/specs.yml +0 -45
  11. data/.gitignore +0 -9
  12. data/.rubocop.yml +0 -24
  13. data/CHANGES.md +0 -413
  14. data/Gemfile +0 -14
  15. data/Guardfile +0 -7
  16. data/MIT-LICENSE +0 -20
  17. data/README.md +0 -350
  18. data/Rakefile +0 -10
  19. data/certs/mite.pem +0 -26
  20. data/gemfiles/activemodel-5 +0 -8
  21. data/gemfiles/activemodel-6 +0 -8
  22. data/gemfiles/activemodel-7 +0 -8
  23. data/gemfiles/standalone +0 -7
  24. data/lib/valvat/locales/bg.yml +0 -34
  25. data/lib/valvat/locales/ca.yml +0 -34
  26. data/lib/valvat/locales/cs.yml +0 -34
  27. data/lib/valvat/locales/da.yml +0 -34
  28. data/lib/valvat/locales/de.yml +0 -35
  29. data/lib/valvat/locales/en.yml +0 -35
  30. data/lib/valvat/locales/es.yml +0 -35
  31. data/lib/valvat/locales/fi.yml +0 -34
  32. data/lib/valvat/locales/fr.yml +0 -34
  33. data/lib/valvat/locales/hu.yml +0 -35
  34. data/lib/valvat/locales/it.yml +0 -34
  35. data/lib/valvat/locales/lv.yml +0 -34
  36. data/lib/valvat/locales/nb.yml +0 -34
  37. data/lib/valvat/locales/nl.yml +0 -35
  38. data/lib/valvat/locales/pl.yml +0 -35
  39. data/lib/valvat/locales/pt.yml +0 -34
  40. data/lib/valvat/locales/ro.yml +0 -34
  41. data/lib/valvat/locales/sk.yml +0 -34
  42. data/lib/valvat/locales/sv.yml +0 -34
  43. data/lib/valvat/locales/tr.yml +0 -34
  44. data/spec/active_model/validations/valvat_validator_spec.rb +0 -274
  45. data/spec/spec_helper.rb +0 -37
  46. data/spec/valvat/checksum/at_spec.rb +0 -17
  47. data/spec/valvat/checksum/be_spec.rb +0 -17
  48. data/spec/valvat/checksum/bg_spec.rb +0 -18
  49. data/spec/valvat/checksum/cy_spec.rb +0 -17
  50. data/spec/valvat/checksum/de_spec.rb +0 -17
  51. data/spec/valvat/checksum/dk_spec.rb +0 -17
  52. data/spec/valvat/checksum/ee_spec.rb +0 -17
  53. data/spec/valvat/checksum/es_spec.rb +0 -65
  54. data/spec/valvat/checksum/fi_spec.rb +0 -17
  55. data/spec/valvat/checksum/fr_spec.rb +0 -17
  56. data/spec/valvat/checksum/gb_spec.rb +0 -34
  57. data/spec/valvat/checksum/gr_spec.rb +0 -17
  58. data/spec/valvat/checksum/hr_spec.rb +0 -17
  59. data/spec/valvat/checksum/hu_spec.rb +0 -17
  60. data/spec/valvat/checksum/ie_spec.rb +0 -24
  61. data/spec/valvat/checksum/it_spec.rb +0 -25
  62. data/spec/valvat/checksum/lt_spec.rb +0 -17
  63. data/spec/valvat/checksum/lu_spec.rb +0 -17
  64. data/spec/valvat/checksum/mt_spec.rb +0 -17
  65. data/spec/valvat/checksum/nl_spec.rb +0 -17
  66. data/spec/valvat/checksum/pl_spec.rb +0 -21
  67. data/spec/valvat/checksum/pt_spec.rb +0 -30
  68. data/spec/valvat/checksum/ro_spec.rb +0 -17
  69. data/spec/valvat/checksum/se_spec.rb +0 -21
  70. data/spec/valvat/checksum/si_spec.rb +0 -25
  71. data/spec/valvat/checksum_spec.rb +0 -40
  72. data/spec/valvat/lookup/hmrc_spec.rb +0 -58
  73. data/spec/valvat/lookup/vies_spec.rb +0 -25
  74. data/spec/valvat/lookup_spec.rb +0 -493
  75. data/spec/valvat/options_spec.rb +0 -23
  76. data/spec/valvat/syntax_spec.rb +0 -68
  77. data/spec/valvat/utils_spec.rb +0 -125
  78. data/spec/valvat_spec.rb +0 -276
  79. data/valvat.gemspec +0 -24
@@ -1,493 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Valvat::Lookup do
6
- describe '#validate' do
7
- context 'with existing EU VAT number' do
8
- it 'returns true' do
9
- result = described_class.validate('IE6388047V')
10
- skip 'VIES is down' if result.nil?
11
- expect(result).to be(true)
12
- end
13
-
14
- it 'allows Valvat instance as input' do
15
- result = described_class.validate(Valvat.new('IE6388047V'))
16
- skip 'VIES is down' if result.nil?
17
- expect(result).to be(true)
18
- end
19
-
20
- context 'with details' do
21
- it 'returns hash of details instead of true' do
22
- result = described_class.validate('IE6388047V', detail: true)
23
- skip 'VIES is down' if result.nil?
24
-
25
- expect(result).to match({
26
- request_date: kind_of(Date),
27
- country_code: 'IE',
28
- vat_number: '6388047V',
29
- name: 'GOOGLE IRELAND LIMITED',
30
- address: '3RD FLOOR, GORDON HOUSE, BARROW STREET, DUBLIN 4',
31
- valid: true
32
- })
33
- end
34
- end
35
- end
36
-
37
- context 'with existing GB VAT number' do
38
- it 'returns true' do
39
- result = described_class.validate('GB727255821', uk: true)
40
- skip 'HMRC is down' if result.nil?
41
- expect(result).to be(true)
42
- end
43
-
44
- it 'returns details in format similar to VIES' do
45
- result = described_class.validate('GB727255821', detail: true, uk: true)
46
- skip 'HMRC is down' if result.nil?
47
- expect(result).to match({
48
- request_date: kind_of(Time),
49
- country_code: 'GB',
50
- vat_number: '727255821',
51
- name: 'AMAZON EU SARL',
52
- address: "1 PRINCIPAL PLACE\nWORSHIP STREET\nLONDON\nEC2A 2FA\nGB",
53
- valid: true
54
- })
55
- end
56
- end
57
-
58
- context 'with not existing EU VAT number' do
59
- it 'returns false' do
60
- result = described_class.validate('IE6388048V')
61
- skip 'VIES is down' if result.nil?
62
- expect(result).to be(false)
63
- end
64
-
65
- context 'with details' do
66
- it 'still returns false' do
67
- result = described_class.validate('LU21416128', detail: true)
68
- skip 'VIES is down' if result.nil?
69
- expect(result).to be(false)
70
- end
71
- end
72
- end
73
-
74
- context 'with not existing GB VAT number' do
75
- it 'returns false' do
76
- result = described_class.validate('GB727255820', uk: true)
77
- skip 'HMRC is down' if result.nil?
78
- expect(result).to be(false)
79
- end
80
- end
81
-
82
- context 'with invalid country code / input' do
83
- it 'returns false' do
84
- expect(described_class.validate('AE259597697')).to be(false)
85
- expect(described_class.validate('')).to be(false)
86
- end
87
- end
88
-
89
- context 'with request identifier' do
90
- it 'returns hash of details instead of true' do
91
- result = described_class.validate('IE6388047V', requester: 'IE6388047V')
92
-
93
- skip 'VIES is down' if result.nil?
94
-
95
- expect(result).to match({
96
- request_date: kind_of(Date),
97
- request_identifier: /\A[\w\W]{16}\Z/,
98
- country_code: 'IE',
99
- vat_number: '6388047V',
100
- name: 'GOOGLE IRELAND LIMITED',
101
- company_type: nil,
102
- address: '3RD FLOOR, GORDON HOUSE, BARROW STREET, DUBLIN 4',
103
- valid: true
104
- })
105
- end
106
-
107
- it 'supports old :requester_vat option for backwards compatibility' do
108
- result = described_class.validate('IE6388047V', requester_vat: 'LU21416127')
109
-
110
- skip 'VIES is down' if result.nil?
111
-
112
- expect(result).to match({
113
- request_date: kind_of(Date),
114
- request_identifier: /\A[\w\W]{16}\Z/,
115
- country_code: 'IE',
116
- vat_number: '6388047V',
117
- name: 'GOOGLE IRELAND LIMITED',
118
- company_type: nil,
119
- address: '3RD FLOOR, GORDON HOUSE, BARROW STREET, DUBLIN 4',
120
- valid: true
121
- })
122
- end
123
-
124
- context 'with GB VAT number' do
125
- it 'returns hash of details with request number' do
126
- response = described_class.validate('GB727255821', requester: 'GB727255821', uk: true)
127
- skip 'HMRC is down' if response.nil?
128
- expect(response).to match({
129
- request_date: kind_of(Time),
130
- request_identifier: /\A\w\w\w-\w\w\w-\w\w\w\Z/,
131
- country_code: 'GB',
132
- vat_number: '727255821',
133
- name: 'AMAZON EU SARL',
134
- address: "1 PRINCIPAL PLACE\nWORSHIP STREET\nLONDON\nEC2A 2FA\nGB",
135
- valid: true
136
- })
137
- end
138
-
139
- it 'raises exception if requester is not from GB' do
140
- expect do
141
- described_class.validate('GB727255821', requester: 'IE6388047V', uk: true)
142
- end.to raise_error(Valvat::InvalidRequester,
143
- 'The HMRC web service returned the error: ' \
144
- 'INVALID_REQUEST (Invalid requesterVrn - Vrn parameters should be 9 or 12 digits)')
145
- end
146
-
147
- it 'raises exception if requester is not valid' do
148
- expect do
149
- described_class.validate('GB727255821', requester: 'GB6388047', uk: true)
150
- end.to raise_error(Valvat::InvalidRequester,
151
- 'The HMRC web service returned the error: ' \
152
- 'INVALID_REQUEST (Invalid requesterVrn - Vrn parameters should be 9 or 12 digits)')
153
- end
154
- end
155
-
156
- context 'when set in global config' do
157
- before { Valvat.configure(requester: 'IE6388047V') }
158
- after { Valvat.configure(requester: nil) }
159
-
160
- it 'returns hash of details instead of true' do
161
- result = described_class.validate('IE6388047V')
162
-
163
- skip 'VIES is down' if result.nil?
164
-
165
- expect(result).to match({
166
- request_date: kind_of(Date),
167
- request_identifier: /\A[\w\W]{16}\Z/,
168
- country_code: 'IE',
169
- vat_number: '6388047V',
170
- name: 'GOOGLE IRELAND LIMITED',
171
- company_type: nil,
172
- address: '3RD FLOOR, GORDON HOUSE, BARROW STREET, DUBLIN 4',
173
- valid: true
174
- })
175
- end
176
- end
177
- end
178
- end
179
-
180
- describe '#validate with VIES test enviroment' do
181
- let(:options) do
182
- { skip_local_validation: true }
183
- end
184
-
185
- before do
186
- stub_const('Valvat::Lookup::VIES::ENDPOINT_URI', URI('https://ec.europa.eu/taxation_customs/vies/test-services/checkVatTestService'))
187
- end
188
-
189
- context 'with valid request with valid VAT number' do
190
- subject(:result) { described_class.validate('DE100', options) }
191
-
192
- it 'returns true' do
193
- expect(result).to be(true)
194
- end
195
- end
196
-
197
- context 'with valid request with an invalid VAT number' do
198
- subject(:result) { described_class.validate('DE200', options) }
199
-
200
- it 'returns false' do
201
- expect(result).to be(false)
202
- end
203
- end
204
-
205
- describe 'Error : INVALID_INPUT' do
206
- subject(:result) { described_class.validate('DE201', options) }
207
-
208
- it 'returns false' do
209
- expect(result).to be(false)
210
- end
211
- end
212
-
213
- describe 'Error : INVALID_REQUESTER_INFO' do
214
- subject(:result) { described_class.validate('DE202', options) }
215
-
216
- it 'raises Valvat::InvalidRequester' do
217
- expect { result }.to raise_error(Valvat::InvalidRequester)
218
- end
219
- end
220
-
221
- describe 'Error : SERVICE_UNAVAILABLE' do
222
- subject(:result) { described_class.validate('DE300', options) }
223
-
224
- it 'returns nil' do
225
- expect(result).to be_nil
226
- end
227
-
228
- it 'raises error with raise_error: true' do
229
- expect do
230
- described_class.validate('DE300', options.merge(raise_error: true))
231
- end.to raise_error(Valvat::ServiceUnavailable)
232
- end
233
- end
234
-
235
- describe 'Error : MS_UNAVAILABLE' do
236
- subject(:result) { described_class.validate('DE301', options) }
237
-
238
- it 'returns nil' do
239
- expect(result).to be_nil
240
- end
241
-
242
- it 'raises error with raise_error: true' do
243
- expect do
244
- described_class.validate('DE301', options.merge(raise_error: true))
245
- end.to raise_error(Valvat::MemberStateUnavailable)
246
- end
247
- end
248
-
249
- describe 'Error : TIMEOUT' do
250
- subject(:result) { described_class.validate('DE302', options) }
251
-
252
- it 'raises error' do
253
- expect { result }.to raise_error(Valvat::Timeout)
254
- end
255
-
256
- it 'returns nil with raise_error set to false' do
257
- expect(described_class.validate('DE302', options.merge(raise_error: false))).to be_nil
258
- end
259
- end
260
-
261
- describe 'Network timeout' do
262
- subject(:result) { described_class.validate('DE200', options) }
263
-
264
- before { stub_request(:post, /ec.europa.eu/).to_timeout }
265
-
266
- it 'raises error' do
267
- expect { result }.to raise_error(Net::OpenTimeout, 'execution expired')
268
- end
269
-
270
- it 'also raises error with raise_error set to false (not handled)' do
271
- expect do
272
- described_class.validate('DE302', options.merge(raise_error: false))
273
- end.to raise_error(Net::OpenTimeout, 'execution expired')
274
- end
275
- end
276
-
277
- describe 'Error : VAT_BLOCKED' do
278
- subject(:result) { described_class.validate('DE400', options) }
279
-
280
- it 'raises error' do
281
- expect { result }.to raise_error(Valvat::BlockedError, /VAT_BLOCKED/)
282
- end
283
-
284
- it 'returns nil with raise_error set to false' do
285
- expect(described_class.validate('DE400', options.merge(raise_error: false))).to be_nil
286
- end
287
- end
288
-
289
- describe 'Error : IP_BLOCKED' do
290
- subject(:result) { described_class.validate('DE401', options) }
291
-
292
- it 'raises error' do
293
- expect { result }.to raise_error(Valvat::BlockedError, /IP_BLOCKED/)
294
- end
295
-
296
- it 'returns nil with raise_error set to false' do
297
- expect(described_class.validate('DE401', options.merge(raise_error: false))).to be_nil
298
- end
299
- end
300
-
301
- describe 'Error : GLOBAL_MAX_CONCURRENT_REQ' do
302
- subject(:result) { described_class.validate('DE500', options) }
303
-
304
- it 'raises error' do
305
- expect { result }.to raise_error(Valvat::RateLimitError, /GLOBAL_MAX_CONCURRENT_REQ/)
306
- end
307
-
308
- it 'returns nil with raise_error set to false' do
309
- expect(described_class.validate('DE500', options.merge(raise_error: false))).to be_nil
310
- end
311
- end
312
-
313
- describe 'Error : GLOBAL_MAX_CONCURRENT_REQ_TIME' do
314
- subject(:result) { described_class.validate('DE501', options) }
315
-
316
- it 'raises error' do
317
- expect { result }.to raise_error(Valvat::RateLimitError, /GLOBAL_MAX_CONCURRENT_REQ_TIME/)
318
- end
319
-
320
- it 'returns nil with raise_error set to false' do
321
- expect(described_class.validate('DE501', options.merge(raise_error: false))).to be_nil
322
- end
323
- end
324
-
325
- describe 'Error : MS_MAX_CONCURRENT_REQ' do
326
- subject(:result) { described_class.validate('DE600', options) }
327
-
328
- it 'raises error' do
329
- expect { result }.to raise_error(Valvat::RateLimitError, /MS_MAX_CONCURRENT_REQ/)
330
- end
331
-
332
- it 'returns nil with raise_error set to false' do
333
- expect(described_class.validate('DE600', options.merge(raise_error: false))).to be_nil
334
- end
335
- end
336
-
337
- describe 'Error : MS_MAX_CONCURRENT_REQ_TIME' do
338
- subject(:result) { described_class.validate('DE601', options) }
339
-
340
- it 'raises error' do
341
- expect { result }.to raise_error(Valvat::RateLimitError, /MS_MAX_CONCURRENT_REQ_TIME/)
342
- end
343
-
344
- it 'returns nil with raise_error set to false' do
345
- expect(described_class.validate('DE601', options.merge(raise_error: false))).to be_nil
346
- end
347
- end
348
-
349
- describe 'Error : HTTP error' do
350
- subject(:result) { described_class.validate('DE601', options) }
351
-
352
- before do
353
- stub_request(:post, %r{\Ahttps://ec\.europa\.eu}).to_return({ status: 405 })
354
- end
355
-
356
- it 'raises error' do
357
- expect { result }.to raise_error(Valvat::HTTPError, 'The VIES web service returned the error: 405')
358
- end
359
-
360
- it 'returns nil with raise_error set to false' do
361
- expect(described_class.validate('DE601', options.merge(raise_error: false))).to be_nil
362
- end
363
- end
364
- end
365
-
366
- describe '#validate with HMRC test enviroment' do
367
- # https://developer.service.hmrc.gov.uk/api-documentation/docs/testing
368
- # https://github.com/hmrc/vat-registered-companies-api/blob/master/public/api/conf/1.0/test-data/vrn.csv
369
- subject(:result) { described_class.validate('GB123456789', uk: true) }
370
-
371
- before do
372
- stub_const('Valvat::Lookup::HMRC::ENDPOINT_URL', 'https://test-api.service.hmrc.gov.uk/organisations/vat/check-vat-number/lookup')
373
- end
374
-
375
- context 'with valid request with valid VAT number' do
376
- it 'returns true' do
377
- expect(described_class.validate('GB553557881', uk: true)).to be(true)
378
- expect(described_class.validate('GB146295999727', uk: true)).to be(true)
379
- end
380
- end
381
-
382
- context 'with valid request with an invalid VAT number' do
383
- it 'returns false' do
384
- expect(result).to be(false)
385
- end
386
- end
387
-
388
- describe 'Error : MESSAGE_THROTTLED_OUT' do
389
- before do
390
- stub_request(:get, /test-api\.service\.hmrc\.gov\.uk/).to_return(
391
- status: 429,
392
- body: '{"code":"MESSAGE_THROTTLED_OUT"}'
393
- )
394
- end
395
-
396
- it 'raises error' do
397
- expect { result }.to raise_error(Valvat::RateLimitError, /MESSAGE_THROTTLED_OUT/)
398
- end
399
-
400
- it 'returns nil with raise_error set to false' do
401
- expect(described_class.validate('GB123456789', raise_error: false, uk: true)).to be_nil
402
- end
403
- end
404
-
405
- describe 'Error : SCHEDULED_MAINTENANCE' do
406
- before do
407
- stub_request(:get, /test-api\.service\.hmrc\.gov\.uk/).to_return(
408
- status: 503,
409
- body: '{"code":"SCHEDULED_MAINTENANCE"}'
410
- )
411
- end
412
-
413
- it 'returns nil' do
414
- expect(result).to be_nil
415
- end
416
-
417
- it 'raises error with raise_error set to false' do
418
- expect do
419
- described_class.validate('GB123456789', raise_error: true, uk: true)
420
- end.to raise_error(Valvat::ServiceUnavailable, 'The HMRC web service returned the error: SCHEDULED_MAINTENANCE')
421
- end
422
- end
423
-
424
- describe 'Error : SERVER_ERROR' do
425
- before do
426
- stub_request(:get, /test-api\.service\.hmrc\.gov\.uk/).to_return(
427
- status: 503,
428
- body: '{"code":"SERVER_ERROR"}'
429
- )
430
- end
431
-
432
- it 'returns nil' do
433
- expect(result).to be_nil
434
- end
435
-
436
- it 'raises error with raise_error set to false' do
437
- expect do
438
- described_class.validate('GB123456789', raise_error: true, uk: true)
439
- end.to raise_error(Valvat::ServiceUnavailable, 'The HMRC web service returned the error: SERVER_ERROR')
440
- end
441
- end
442
-
443
- describe 'Error : GATEWAY_TIMEOUT' do
444
- before do
445
- stub_request(:get, /test-api\.service\.hmrc\.gov\.uk/).to_return(
446
- status: 504,
447
- body: '{"code":"GATEWAY_TIMEOUT"}'
448
- )
449
- end
450
-
451
- it 'raises error' do
452
- expect { result }.to raise_error(Valvat::Timeout, /GATEWAY_TIMEOUT/)
453
- end
454
-
455
- it 'returns nil with raise_error set to false' do
456
- expect(described_class.validate('GB123456789', raise_error: false, uk: true)).to be_nil
457
- end
458
- end
459
-
460
- describe 'Network timeout' do
461
- before do
462
- stub_request(:get, /test-api\.service\.hmrc\.gov\.uk/).to_timeout
463
- end
464
-
465
- it 'raises error' do
466
- expect { result }.to raise_error(Net::OpenTimeout)
467
- end
468
-
469
- it 'also raises error with raise_error set to false (not handled)' do
470
- expect do
471
- described_class.validate('GB123456789', raise_error: false, uk: true)
472
- end.to raise_error(Net::OpenTimeout)
473
- end
474
- end
475
-
476
- describe 'Error : INTERNAL_SERVER_ERROR' do
477
- before do
478
- stub_request(:get, /test-api\.service\.hmrc\.gov\.uk/).to_return(
479
- status: 500,
480
- body: '{"code":"INTERNAL_SERVER_ERROR"}'
481
- )
482
- end
483
-
484
- it 'raises error' do
485
- expect { result }.to raise_error(Valvat::UnknownLookupError, /INTERNAL_SERVER_ERROR/)
486
- end
487
-
488
- it 'returns nil with raise_error set to false' do
489
- expect(described_class.validate('GB123456789', raise_error: false, uk: true)).to be_nil
490
- end
491
- end
492
- end
493
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Valvat::Options do
6
- describe '#[]' do
7
- it 'returns global config by default' do
8
- expect(described_class.new({})[:uk]).to be(false)
9
- end
10
-
11
- it 'returns option if set' do
12
- expect(described_class.new({ uk: true })[:uk]).to be(true)
13
- end
14
-
15
- context 'when options contains deprecated key' do
16
- let(:options) { described_class.new({ requester_vat: 'DE123' }, silence: true) }
17
-
18
- it 'returns it on new key' do
19
- expect(options[:requester]).to be('DE123')
20
- end
21
- end
22
- end
23
- end
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
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)
9
- end
10
- end
11
-
12
- invalid_vats.each do |invalid|
13
- it "returns false for #{invalid.inspect}" do
14
- expect(described_class.validate(invalid)).to be(false)
15
- end
16
- end
17
- end
18
-
19
- describe Valvat::Syntax do
20
- describe '#validate' do
21
- it_validates(%w[ATU03458890], %w[ATU034588908 ATU0345908 ATU0345889Y])
22
- it_validates(%w[BE0817331995 BE1817331999], %w[BE081733199 BE08173319944 BE081733199H BE2817331999])
23
- it_validates(%w[BG468134789 BG4681347897], %w[BG46813478979 BG4681347897C BG46813478G BG46813478])
24
- it_validates(%w[CY36579347A CY36579347C CY60000347C], %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)
66
- end
67
- end
68
- end