forked from validatorjs/validator.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisISO31661Alpha2.test.js
More file actions
70 lines (65 loc) · 1.58 KB
/
isISO31661Alpha2.test.js
File metadata and controls
70 lines (65 loc) · 1.58 KB
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
import test from '../testFunctions';
describe('isISO31661Alpha2', () => {
it('should validate ISO 3166-1 alpha 2 country codes', () => {
// from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
test({
validator: 'isISO31661Alpha2',
valid: [
'FR',
'fR',
'GB',
'PT',
'CM',
'JP',
'PM',
'ZW',
'MM',
'cc',
'GG',
],
invalid: [
'',
'FRA',
'AA',
'PI',
'RP',
'WV',
'WL',
'UK',
'ZZ',
],
});
});
it('should validate user assigned alpha 2 code if provided', () => {
test({
validator: 'isISO31661Alpha2',
args: [{ userAssignedCodes: ['XK', 'xl', '', 'x'] }],
valid: ['BE', 'FR', 'GB', 'US', 'XK', 'XL'],
invalid: ['XA', 'XB'],
});
});
it('should not validate user assigned alpha 2 not valid code if provided', () => {
test({
validator: 'isISO31661Alpha2',
args: [{ userAssignedCodes: ['', 'x', 'XXX'] }],
valid: ['FR'],
invalid: ['XXX', 'X'],
});
});
it('should still validate ISO 3166-1 alpha 2 country codes if the options object is empty', () => {
test({
validator: 'isISO31661Alpha2',
args: [{}],
valid: ['FR', 'US'],
invalid: ['XK'],
});
});
it('should still validate ISO 3166-1 alpha 2 country codes if the userAssignedCodes option is empty', () => {
test({
validator: 'isISO31661Alpha2',
args: [{ userAssignedCodes: [] }],
valid: ['FR', 'US'],
invalid: ['XK'],
});
});
});