vat.js 26 KB

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