UNPKG

2.8 kBJavaScriptView Raw
1import test from 'ava'
2import Chance from '../chance.js'
3import _ from 'lodash'
4
5const chance = new Chance()
6
7// chance.cf()
8test('cf() returns a valid random cf', t => {
9 _.times(1000, () => {
10 let cf = chance.cf()
11 t.true(_.isString(cf))
12 t.is(cf.length, 16)
13 t.true(/[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]/.test(cf))
14 })
15})
16
17test('cf() returns a consistent cf', t => {
18 let testCases = [{
19 item: {
20 first: 'Aldo',
21 last: 'Fabrizi',
22 gender: 'Male',
23 birthday: new Date(1905,10,1),
24 city: 'h501'
25 },
26 cf: 'FBRLDA05S01H501A'
27 }, {
28 item: {
29 first: 'Sophia',
30 last: 'Loren',
31 gender: 'Female',
32 birthday: new Date(1934,8,20),
33 city: 'h501'
34 },
35 cf: 'LRNSPH34P60H501G'
36 }, {
37 item: {
38 first: 'Claudia',
39 last: 'Cardinale',
40 gender: 'Female',
41 birthday: new Date(1938,3,15),
42 city: 'z352'
43 },
44 cf: 'CRDCLD38D55Z352Q'
45 }, {
46 item: {
47 first: 'Sergio',
48 last: 'Leone',
49 gender: 'Male',
50 birthday: new Date(1929,0,3),
51 city: 'h501'
52 },
53 cf: 'LNESRG29A03H501W'
54 }, {
55 item: {
56 first: 'Claudio',
57 last: 'Marchisio',
58 gender: 'Male',
59 birthday: new Date(1986,0,19),
60 city: 'l219'
61 },
62 cf: 'MRCCLD86A19L219F'
63 }, {
64 item: {
65 first: 'Eu',
66 last: 'Ho',
67 gender: 'Male',
68 birthday: new Date(2012,3,12),
69 city: 'z210'
70 },
71 cf: 'HOXEUX12D12Z210Q'
72 }];
73
74 testCases.map((test) => {
75 t.is(chance.cf(test.item), test.cf)
76 })
77})
78
79// chance.pl_nip()
80test('pl_nip() returns a valid NIP number', t => {
81 _.times(1000, () => {
82 let nip = chance.pl_nip()
83 t.true(_.isString(nip))
84 t.is(nip.length, 10)
85 })
86})
87
88// chance.pl_pesel()
89test('pl_pesel() returns a valid PESEL number', t => {
90 _.times(1000, () => {
91 let pesel = chance.pl_pesel()
92 t.true(_.isString(pesel))
93 t.is(pesel.length, 11)
94 })
95})
96
97// chance.pl_regon()
98test('pl_regon() returns a valid REGON number', t => {
99 _.times(1000, () => {
100 let regon = chance.pl_regon()
101 t.true(_.isString(regon))
102 t.is(regon.length, 9)
103 })
104})
105
106// chance.vat()
107test('vat() returns a valid italian vat number', t => {
108 _.times(1000, () => {
109 let vat = chance.vat({ country: 'it' })
110 t.true(_.isString(vat))
111 t.is(vat.length, 11)
112 let first = vat.charAt(0)
113 t.true(first === '0' || first === '1')
114 t.true(chance.luhn_check(vat))
115 })
116})