vat.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. describe('vat', function() {
  2. beforeEach(function() {
  3. $([
  4. '<form class="form-horizontal" id="vatForm">',
  5. '<div class="form-group">',
  6. '<select class="form-control" name="country">',
  7. '<option value="AT">Austria</option>',
  8. '<option value="BE">Belgium</option>',
  9. '<option value="BG">Bulgaria</option>',
  10. '<option value="HR">Croatia</option>',
  11. '<option value="CY">Cyprus</option>',
  12. '<option value="CZ">Czech Republic</option>',
  13. '<option value="DK">Denmark</option>',
  14. '<option value="EE">Estonia</option>',
  15. '<option value="FI">Finland</option>',
  16. '<option value="FR">France</option>',
  17. '<option value="DE">Germany</option>',
  18. '<option value="GR">Greece</option>',
  19. '<option value="HU">Hungary</option>',
  20. '<option value="IE">Ireland</option>',
  21. '<option value="IS">Iceland</option>',
  22. '<option value="IT">Italy</option>',
  23. '<option value="LV">Latvia</option>',
  24. '<option value="LT">Lithuania</option>',
  25. '<option value="LU">Luxembourg</option>',
  26. '<option value="MT">Malta</option>',
  27. '<option value="NL">Netherlands</option>',
  28. '<option value="NO">Norway</option>',
  29. '<option value="PL">Poland</option>',
  30. '<option value="PT">Portugal</option>',
  31. '<option value="RO">Romania</option>',
  32. '<option value="RU">Russia</option>',
  33. '<option value="RS">Serbia</option>',
  34. '<option value="SK">Slovakia</option>',
  35. '<option value="SI">Slovenia</option>',
  36. '<option value="ES">Spain</option>',
  37. '<option value="SE">Sweden</option>',
  38. '<option value="CH">Switzerland</option>',
  39. '<option value="GB">United Kingdom</option>',
  40. '<option value="ZA">South Africa</option>',
  41. '</select>',
  42. '</div>',
  43. '<div class="form-group">',
  44. '<input type="text" name="vat" data-bv-vat />',
  45. '</div>',
  46. '</form>',
  47. ].join('\n')).appendTo('body');
  48. $('#vatForm').bootstrapValidator();
  49. /**
  50. * @type {BootstrapValidator}
  51. */
  52. this.bv = $('#vatForm').data('bootstrapValidator');
  53. this.$country = this.bv.getFieldElements('country');
  54. this.$vat = this.bv.getFieldElements('vat');
  55. });
  56. afterEach(function() {
  57. $('#vatForm').bootstrapValidator('destroy').remove();
  58. });
  59. it('dynamic country', function() {
  60. this.$vat.attr('data-bv-vat-country', 'country');
  61. this.bv.destroy();
  62. this.bv = $('#vatForm').bootstrapValidator().data('bootstrapValidator');
  63. this.$country.val('AT');
  64. this.$vat.val('ATU13585627');
  65. this.bv.validate();
  66. expect(this.bv.isValid()).toBeTruthy();
  67. this.bv.resetForm();
  68. this.$country.val('BG');
  69. this.$vat.val('BE0428759497');
  70. this.bv.validate();
  71. expect(this.bv.isValid()).toEqual(false);
  72. this.bv.resetForm();
  73. this.$country.val('BE');
  74. this.$vat.val('BE431150351');
  75. this.bv.validate();
  76. expect(this.bv.isValid()).toEqual(false);
  77. });
  78. it('Austrian VAT number', function() {
  79. this.bv.updateOption('vat', 'vat', 'country', 'AT');
  80. // Valid samples
  81. var validSamples = ['ATU13585627', 'U13585627'];
  82. for (var i in validSamples) {
  83. this.bv.resetForm();
  84. this.$vat.val(validSamples[i]);
  85. this.bv.validate();
  86. expect(this.bv.isValid()).toBeTruthy();
  87. }
  88. // Invalid samples
  89. var invalidSamples = ['ATU13585626', 'U13585626'];
  90. for (i in invalidSamples) {
  91. this.bv.resetForm();
  92. this.$vat.val(invalidSamples[i]);
  93. this.bv.validate();
  94. expect(this.bv.isValid()).toEqual(false);
  95. }
  96. });
  97. it('Belgian VAT number', function() {
  98. this.bv.updateOption('vat', 'vat', 'country', 'BE');
  99. // Valid samples
  100. var validSamples = ['BE0428759497', '0428759497'];
  101. for (var i in validSamples) {
  102. this.bv.resetForm();
  103. this.$vat.val(validSamples[i]);
  104. this.bv.validate();
  105. expect(this.bv.isValid()).toBeTruthy();
  106. }
  107. // Invalid samples
  108. var invalidSamples = ['BE431150351', '431150351'];
  109. for (i in invalidSamples) {
  110. this.bv.resetForm();
  111. this.$vat.val(invalidSamples[i]);
  112. this.bv.validate();
  113. expect(this.bv.isValid()).toEqual(false);
  114. }
  115. });
  116. it('Bulgarian VAT number', function() {
  117. this.bv.updateOption('vat', 'vat', 'country', 'BG');
  118. // Valid samples
  119. var validSamples = ['BG175074752', 'BG7523169263', 'BG8032056031', 'BG7542011030', 'BG7111042925', '175074752', '7523169263', '8032056031'];
  120. for (var i in validSamples) {
  121. this.bv.resetForm();
  122. this.$vat.val(validSamples[i]);
  123. this.bv.validate();
  124. expect(this.bv.isValid()).toBeTruthy();
  125. }
  126. // Invalid samples
  127. var invalidSamples = ['BG175074753', 'BG7552A10004', 'BG7111042922', '175074753', '7552A10004'];
  128. for (i in invalidSamples) {
  129. this.bv.resetForm();
  130. this.$vat.val(invalidSamples[i]);
  131. this.bv.validate();
  132. expect(this.bv.isValid()).toEqual(false);
  133. }
  134. });
  135. it('Cypriot VAT number', function() {
  136. this.bv.updateOption('vat', 'vat', 'country', 'CY');
  137. // Valid samples
  138. var validSamples = ['CY10259033P', '10259033P'];
  139. for (var i in validSamples) {
  140. this.bv.resetForm();
  141. this.$vat.val(validSamples[i]);
  142. this.bv.validate();
  143. expect(this.bv.isValid()).toBeTruthy();
  144. }
  145. // Invalid samples
  146. var invalidSamples = ['CY10259033Z', '10259033Z'];
  147. for (i in invalidSamples) {
  148. this.bv.resetForm();
  149. this.$vat.val(invalidSamples[i]);
  150. this.bv.validate();
  151. expect(this.bv.isValid()).toEqual(false);
  152. }
  153. });
  154. it('Czech Republic VAT number', function() {
  155. this.bv.updateOption('vat', 'vat', 'country', 'CZ');
  156. // Valid samples
  157. var validSamples = ['CZ25123891', 'CZ7103192745', 'CZ991231123', 'CZ640903926', '25123891', '7103192745'];
  158. for (var i in validSamples) {
  159. this.bv.resetForm();
  160. this.$vat.val(validSamples[i]);
  161. this.bv.validate();
  162. expect(this.bv.isValid()).toBeTruthy();
  163. }
  164. // Invalid samples
  165. var invalidSamples = ['CZ25123890', 'CZ1103492745', 'CZ590312123', '25123890', '1103492745'];
  166. for (i in invalidSamples) {
  167. this.bv.resetForm();
  168. this.$vat.val(invalidSamples[i]);
  169. this.bv.validate();
  170. expect(this.bv.isValid()).toEqual(false);
  171. }
  172. });
  173. it('German VAT number', function() {
  174. this.bv.updateOption('vat', 'vat', 'country', 'DE');
  175. // Valid samples
  176. var validSamples = ['DE136695976', '136695976'];
  177. for (var i in validSamples) {
  178. this.bv.resetForm();
  179. this.$vat.val(validSamples[i]);
  180. this.bv.validate();
  181. expect(this.bv.isValid()).toBeTruthy();
  182. }
  183. // Invalid samples
  184. var invalidSamples = ['DE136695978', '136695978'];
  185. for (i in invalidSamples) {
  186. this.bv.resetForm();
  187. this.$vat.val(invalidSamples[i]);
  188. this.bv.validate();
  189. expect(this.bv.isValid()).toEqual(false);
  190. }
  191. });
  192. it('Danish VAT number', function() {
  193. this.bv.updateOption('vat', 'vat', 'country', 'DK');
  194. // Valid samples
  195. var validSamples = ['DK13585628', '13585628'];
  196. for (var i in validSamples) {
  197. this.bv.resetForm();
  198. this.$vat.val(validSamples[i]);
  199. this.bv.validate();
  200. expect(this.bv.isValid()).toBeTruthy();
  201. }
  202. // Invalid samples
  203. var invalidSamples = ['DK13585627', '13585627'];
  204. for (i in invalidSamples) {
  205. this.bv.resetForm();
  206. this.$vat.val(invalidSamples[i]);
  207. this.bv.validate();
  208. expect(this.bv.isValid()).toEqual(false);
  209. }
  210. });
  211. it('Estonian VAT number', function() {
  212. this.bv.updateOption('vat', 'vat', 'country', 'EE');
  213. // Valid samples
  214. var validSamples = ['EE100931558', 'EE100594102', '100931558', '100594102'];
  215. for (var i in validSamples) {
  216. this.bv.resetForm();
  217. this.$vat.val(validSamples[i]);
  218. this.bv.validate();
  219. expect(this.bv.isValid()).toBeTruthy();
  220. }
  221. // Invalid samples
  222. var invalidSamples = ['EE100594103', '100594103'];
  223. for (i in invalidSamples) {
  224. this.bv.resetForm();
  225. this.$vat.val(invalidSamples[i]);
  226. this.bv.validate();
  227. expect(this.bv.isValid()).toEqual(false);
  228. }
  229. });
  230. it('Spanish VAT number (NIF)', function() {
  231. this.bv.updateOption('vat', 'vat', 'country', 'ES');
  232. // Valid samples
  233. var validSamples = ['ES54362315K', 'ESX2482300W', 'ESX5253868R', 'ESM1234567L', 'ESJ99216582', 'ESB58378431', 'ESB64717838', '54362315K', 'X2482300W', 'X5253868R', 'M1234567L', 'J99216582'];
  234. for (var i in validSamples) {
  235. this.bv.resetForm();
  236. this.$vat.val(validSamples[i]);
  237. this.bv.validate();
  238. expect(this.bv.isValid()).toBeTruthy();
  239. }
  240. // Invalid samples
  241. var invalidSamples = ['ES54362315Z', 'ESX2482300A', 'ESJ99216583', '54362315Z', 'X2482300A'];
  242. for (i in invalidSamples) {
  243. this.bv.resetForm();
  244. this.$vat.val(invalidSamples[i]);
  245. this.bv.validate();
  246. expect(this.bv.isValid()).toEqual(false);
  247. }
  248. });
  249. it('Finnish VAT number', function() {
  250. this.bv.updateOption('vat', 'vat', 'country', 'FI');
  251. // Valid samples
  252. var validSamples = ['FI20774740', '20774740'];
  253. for (var i in validSamples) {
  254. this.bv.resetForm();
  255. this.$vat.val(validSamples[i]);
  256. this.bv.validate();
  257. expect(this.bv.isValid()).toBeTruthy();
  258. }
  259. // Invalid samples
  260. var invalidSamples = ['FI20774741', '20774741'];
  261. for (i in invalidSamples) {
  262. this.bv.resetForm();
  263. this.$vat.val(invalidSamples[i]);
  264. this.bv.validate();
  265. expect(this.bv.isValid()).toEqual(false);
  266. }
  267. });
  268. it('French VAT number (TVA)', function() {
  269. this.bv.updateOption('vat', 'vat', 'country', 'FR');
  270. // Valid samples
  271. var validSamples = ['FR40303265045', 'FR23334175221', 'FRK7399859412', 'FR4Z123456782', '40303265045', '23334175221', 'K7399859412'];
  272. for (var i in validSamples) {
  273. this.bv.resetForm();
  274. this.$vat.val(validSamples[i]);
  275. this.bv.validate();
  276. expect(this.bv.isValid()).toBeTruthy();
  277. }
  278. // Invalid samples
  279. var invalidSamples = ['FR84323140391', '84323140391'];
  280. for (i in invalidSamples) {
  281. this.bv.resetForm();
  282. this.$vat.val(invalidSamples[i]);
  283. this.bv.validate();
  284. expect(this.bv.isValid()).toEqual(false);
  285. }
  286. });
  287. it('United Kingdom VAT number', function() {
  288. this.bv.updateOption('vat', 'vat', 'country', 'GB');
  289. // Valid samples
  290. var validSamples = ['GB980780684', '980780684'];
  291. for (var i in validSamples) {
  292. this.bv.resetForm();
  293. this.$vat.val(validSamples[i]);
  294. this.bv.validate();
  295. expect(this.bv.isValid()).toBeTruthy();
  296. }
  297. // Invalid samples
  298. var invalidSamples = ['GB802311781', '802311781'];
  299. for (i in invalidSamples) {
  300. this.bv.resetForm();
  301. this.$vat.val(invalidSamples[i]);
  302. this.bv.validate();
  303. expect(this.bv.isValid()).toEqual(false);
  304. }
  305. });
  306. it('Greek VAT number', function() {
  307. this.bv.updateOption('vat', 'vat', 'country', 'GR');
  308. // Valid samples
  309. var validSamples = ['GR023456780', 'EL094259216', '023456780', '094259216'];
  310. for (var i in validSamples) {
  311. this.bv.resetForm();
  312. this.$vat.val(validSamples[i]);
  313. this.bv.validate();
  314. expect(this.bv.isValid()).toBeTruthy();
  315. }
  316. // Invalid samples
  317. var invalidSamples = ['GR123456781', '123456781'];
  318. for (i in invalidSamples) {
  319. this.bv.resetForm();
  320. this.$vat.val(invalidSamples[i]);
  321. this.bv.validate();
  322. expect(this.bv.isValid()).toEqual(false);
  323. }
  324. });
  325. it('Hungarian VAT number', function() {
  326. this.bv.updateOption('vat', 'vat', 'country', 'HU');
  327. // Valid samples
  328. var validSamples = ['HU12892312', '12892312'];
  329. for (var i in validSamples) {
  330. this.bv.resetForm();
  331. this.$vat.val(validSamples[i]);
  332. this.bv.validate();
  333. expect(this.bv.isValid()).toBeTruthy();
  334. }
  335. // Invalid samples
  336. var invalidSamples = ['HU12892313', '12892313'];
  337. for (i in invalidSamples) {
  338. this.bv.resetForm();
  339. this.$vat.val(invalidSamples[i]);
  340. this.bv.validate();
  341. expect(this.bv.isValid()).toEqual(false);
  342. }
  343. });
  344. it('Croatian VAT number', function() {
  345. this.bv.updateOption('vat', 'vat', 'country', 'HR');
  346. // Valid samples
  347. var validSamples = ['HR33392005961', '33392005961'];
  348. for (var i in validSamples) {
  349. this.bv.resetForm();
  350. this.$vat.val(validSamples[i]);
  351. this.bv.validate();
  352. expect(this.bv.isValid()).toBeTruthy();
  353. }
  354. // Invalid samples
  355. var invalidSamples = ['HR33392005962', '33392005962'];
  356. for (i in invalidSamples) {
  357. this.bv.resetForm();
  358. this.$vat.val(invalidSamples[i]);
  359. this.bv.validate();
  360. expect(this.bv.isValid()).toEqual(false);
  361. }
  362. });
  363. it('Irish VAT number', function() {
  364. this.bv.updateOption('vat', 'vat', 'country', 'IE');
  365. // Valid samples
  366. var validSamples = ['IE6433435F', 'IE6433435OA', 'IE8D79739I', '6433435F', '6433435OA', '8D79739I'];
  367. for (var i in validSamples) {
  368. this.bv.resetForm();
  369. this.$vat.val(validSamples[i]);
  370. this.bv.validate();
  371. expect(this.bv.isValid()).toBeTruthy();
  372. }
  373. // Invalid samples
  374. var invalidSamples = ['IE8D79738J', '8D79738J'];
  375. for (i in invalidSamples) {
  376. this.bv.resetForm();
  377. this.$vat.val(invalidSamples[i]);
  378. this.bv.validate();
  379. expect(this.bv.isValid()).toEqual(false);
  380. }
  381. });
  382. it('Iceland VAT (VSK) number', function() {
  383. this.bv.updateOption('vat', 'vat', 'country', 'IS');
  384. // Valid samples
  385. var validSamples = ['IS11111', 'IS111111', '11111', '111111'];
  386. for (var i in validSamples) {
  387. this.bv.resetForm();
  388. this.$vat.val(validSamples[i]);
  389. this.bv.validate();
  390. expect(this.bv.isValid()).toBeTruthy();
  391. }
  392. // Invalid samples
  393. var invalidSamples = ['IS1234567', 'IS123456ABC', '1234567', '123456ABC'];
  394. for (i in invalidSamples) {
  395. this.bv.resetForm();
  396. this.$vat.val(invalidSamples[i]);
  397. this.bv.validate();
  398. expect(this.bv.isValid()).toEqual(false);
  399. }
  400. });
  401. it('Italian VAT number', function() {
  402. this.bv.updateOption('vat', 'vat', 'country', 'IT');
  403. // Valid samples
  404. var validSamples = ['IT00743110157', '00743110157'];
  405. for (var i in validSamples) {
  406. this.bv.resetForm();
  407. this.$vat.val(validSamples[i]);
  408. this.bv.validate();
  409. expect(this.bv.isValid()).toBeTruthy();
  410. }
  411. // Invalid samples
  412. var invalidSamples = ['IT00743110158', '00743110158'];
  413. for (i in invalidSamples) {
  414. this.bv.resetForm();
  415. this.$vat.val(invalidSamples[i]);
  416. this.bv.validate();
  417. expect(this.bv.isValid()).toEqual(false);
  418. }
  419. });
  420. it('Lithuanian VAT number', function() {
  421. this.bv.updateOption('vat', 'vat', 'country', 'LT');
  422. // Valid samples
  423. var validSamples = ['LT119511515', 'LT100001919017', 'LT100004801610', '119511515', '100001919017', '100004801610'];
  424. for (var i in validSamples) {
  425. this.bv.resetForm();
  426. this.$vat.val(validSamples[i]);
  427. this.bv.validate();
  428. expect(this.bv.isValid()).toBeTruthy();
  429. }
  430. // Invalid samples
  431. var invalidSamples = ['LT100001919018', '100001919018'];
  432. for (i in invalidSamples) {
  433. this.bv.resetForm();
  434. this.$vat.val(invalidSamples[i]);
  435. this.bv.validate();
  436. expect(this.bv.isValid()).toEqual(false);
  437. }
  438. });
  439. it('Luxembourg VAT number', function() {
  440. this.bv.updateOption('vat', 'vat', 'country', 'LU');
  441. // Valid samples
  442. var validSamples = ['LU15027442', '15027442'];
  443. for (var i in validSamples) {
  444. this.bv.resetForm();
  445. this.$vat.val(validSamples[i]);
  446. this.bv.validate();
  447. expect(this.bv.isValid()).toBeTruthy();
  448. }
  449. // Invalid samples
  450. var invalidSamples = ['LU15027443', '15027443'];
  451. for (i in invalidSamples) {
  452. this.bv.resetForm();
  453. this.$vat.val(invalidSamples[i]);
  454. this.bv.validate();
  455. expect(this.bv.isValid()).toEqual(false);
  456. }
  457. });
  458. it('Latvian VAT number', function() {
  459. this.bv.updateOption('vat', 'vat', 'country', 'LV');
  460. // Valid samples
  461. var validSamples = ['LV40003521600', 'LV16117519997', '40003521600', '16117519997'];
  462. for (var i in validSamples) {
  463. this.bv.resetForm();
  464. this.$vat.val(validSamples[i]);
  465. this.bv.validate();
  466. expect(this.bv.isValid()).toBeTruthy();
  467. }
  468. // Invalid samples
  469. var invalidSamples = ['LV40003521601', 'LV16137519997', '40003521601', '16137519997'];
  470. for (i in invalidSamples) {
  471. this.bv.resetForm();
  472. this.$vat.val(invalidSamples[i]);
  473. this.bv.validate();
  474. expect(this.bv.isValid()).toEqual(false);
  475. }
  476. });
  477. it('Maltese VAT number', function() {
  478. this.bv.updateOption('vat', 'vat', 'country', 'MT');
  479. // Valid samples
  480. var validSamples = ['MT11679112', '11679112'];
  481. for (var i in validSamples) {
  482. this.bv.resetForm();
  483. this.$vat.val(validSamples[i]);
  484. this.bv.validate();
  485. expect(this.bv.isValid()).toBeTruthy();
  486. }
  487. // Invalid samples
  488. var invalidSamples = ['MT11679113', '11679113'];
  489. for (i in invalidSamples) {
  490. this.bv.resetForm();
  491. this.$vat.val(invalidSamples[i]);
  492. this.bv.validate();
  493. expect(this.bv.isValid()).toEqual(false);
  494. }
  495. });
  496. it('Dutch VAT number', function() {
  497. this.bv.updateOption('vat', 'vat', 'country', 'NL');
  498. // Valid samples
  499. var validSamples = ['NL004495445B01', '004495445B01'];
  500. for (var i in validSamples) {
  501. this.bv.resetForm();
  502. this.$vat.val(validSamples[i]);
  503. this.bv.validate();
  504. expect(this.bv.isValid()).toBeTruthy();
  505. }
  506. // Invalid samples
  507. var invalidSamples = ['NL123456789B90', '123456789B90'];
  508. for (i in invalidSamples) {
  509. this.bv.resetForm();
  510. this.$vat.val(invalidSamples[i]);
  511. this.bv.validate();
  512. expect(this.bv.isValid()).toEqual(false);
  513. }
  514. });
  515. it('Polish VAT number', function() {
  516. this.bv.updateOption('vat', 'vat', 'country', 'PL');
  517. // Valid samples
  518. var validSamples = ['PL8567346215', '8567346215'];
  519. for (var i in validSamples) {
  520. this.bv.resetForm();
  521. this.$vat.val(validSamples[i]);
  522. this.bv.validate();
  523. expect(this.bv.isValid()).toBeTruthy();
  524. }
  525. // Invalid samples
  526. var invalidSamples = ['PL8567346216', '8567346216'];
  527. for (i in invalidSamples) {
  528. this.bv.resetForm();
  529. this.$vat.val(invalidSamples[i]);
  530. this.bv.validate();
  531. expect(this.bv.isValid()).toEqual(false);
  532. }
  533. });
  534. it('Portuguese VAT number', function() {
  535. this.bv.updateOption('vat', 'vat', 'country', 'PT');
  536. // Valid samples
  537. var validSamples = ['PT501964843', '501964843'];
  538. for (var i in validSamples) {
  539. this.bv.resetForm();
  540. this.$vat.val(validSamples[i]);
  541. this.bv.validate();
  542. expect(this.bv.isValid()).toBeTruthy();
  543. }
  544. // Invalid samples
  545. var invalidSamples = ['PT501964842', '501964842'];
  546. for (i in invalidSamples) {
  547. this.bv.resetForm();
  548. this.$vat.val(invalidSamples[i]);
  549. this.bv.validate();
  550. expect(this.bv.isValid()).toEqual(false);
  551. }
  552. });
  553. it('Romanian VAT number', function() {
  554. this.bv.updateOption('vat', 'vat', 'country', 'RO');
  555. // Valid samples
  556. var validSamples = ['RO18547290', '18547290'];
  557. for (var i in validSamples) {
  558. this.bv.resetForm();
  559. this.$vat.val(validSamples[i]);
  560. this.bv.validate();
  561. expect(this.bv.isValid()).toBeTruthy();
  562. }
  563. // Invalid samples
  564. var invalidSamples = ['RO18547291', '18547291'];
  565. for (i in invalidSamples) {
  566. this.bv.resetForm();
  567. this.$vat.val(invalidSamples[i]);
  568. this.bv.validate();
  569. expect(this.bv.isValid()).toEqual(false);
  570. }
  571. });
  572. it('Swedish VAT number', function() {
  573. this.bv.updateOption('vat', 'vat', 'country', 'SE');
  574. // Valid samples
  575. var validSamples = ['SE123456789701', '123456789701'];
  576. for (var i in validSamples) {
  577. this.bv.resetForm();
  578. this.$vat.val(validSamples[i]);
  579. this.bv.validate();
  580. expect(this.bv.isValid()).toBeTruthy();
  581. }
  582. // Invalid samples
  583. var invalidSamples = ['SE123456789101', '123456789101'];
  584. for (i in invalidSamples) {
  585. this.bv.resetForm();
  586. this.$vat.val(invalidSamples[i]);
  587. this.bv.validate();
  588. expect(this.bv.isValid()).toEqual(false);
  589. }
  590. });
  591. it('Slovenian VAT number', function() {
  592. this.bv.updateOption('vat', 'vat', 'country', 'SI');
  593. // Valid samples
  594. var validSamples = ['SI50223054', '50223054'];
  595. for (var i in validSamples) {
  596. this.bv.resetForm();
  597. this.$vat.val(validSamples[i]);
  598. this.bv.validate();
  599. expect(this.bv.isValid()).toBeTruthy();
  600. }
  601. // Invalid samples
  602. var invalidSamples = ['SI50223055', '50223055'];
  603. for (i in invalidSamples) {
  604. this.bv.resetForm();
  605. this.$vat.val(invalidSamples[i]);
  606. this.bv.validate();
  607. expect(this.bv.isValid()).toEqual(false);
  608. }
  609. });
  610. it('Slovak VAT number', function() {
  611. this.bv.updateOption('vat', 'vat', 'country', 'SK');
  612. // Valid samples
  613. var validSamples = ['SK2022749619', '2022749619'];
  614. for (var i in validSamples) {
  615. this.bv.resetForm();
  616. this.$vat.val(validSamples[i]);
  617. this.bv.validate();
  618. expect(this.bv.isValid()).toBeTruthy();
  619. }
  620. // Invalid samples
  621. var invalidSamples = ['SK2022749618', '2022749618'];
  622. for (i in invalidSamples) {
  623. this.bv.resetForm();
  624. this.$vat.val(invalidSamples[i]);
  625. this.bv.validate();
  626. expect(this.bv.isValid()).toEqual(false);
  627. }
  628. });
  629. it('South African VAT number', function() {
  630. this.bv.updateOption('vat', 'vat', 'country', 'ZA');
  631. // Valid samples
  632. var validSamples = ['ZA4012345678', '4012345678'];
  633. for (var i in validSamples) {
  634. this.bv.resetForm();
  635. this.$vat.val(validSamples[i]);
  636. this.bv.validate();
  637. expect(this.bv.isValid()).toBeTruthy();
  638. }
  639. // Invalid samples
  640. var invalidSamples = ['ZA40123456789', 'ZA0123456789', '40123456789', '0123456789'];
  641. for (i in invalidSamples) {
  642. this.bv.resetForm();
  643. this.$vat.val(invalidSamples[i]);
  644. this.bv.validate();
  645. expect(this.bv.isValid()).toEqual(false);
  646. }
  647. });
  648. });