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