-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.test.js
105 lines (96 loc) · 2.4 KB
/
index.test.js
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
const validateDvaNumber = require('./index');
test('throws if the DVA card number is not provided', () => {
expect(() => validateDvaNumber()).toThrowError();
});
test('throws if the DVA card number is not a string', () => {
expect(() => validateDvaNumber(123)).toThrowError();
});
[
"B123456",
"B12345",
"B1234",
"B123",
"B12",
"B1",
" 123456",
" 12345",
" 1234",
" 123",
" 12",
" 1",
"BC12345",
"BC1234",
"BC123",
"BC12",
"BC1",
"BCD1234",
"BCD123",
"BCD12",
"BCD1",
].forEach((cardNumber) => {
["N","V","Q","S","W","T"].forEach(stateId => {
test(`returns true for valid DVA card number ${stateId}${cardNumber}`, () => {
expect(validateDvaNumber(`${stateId}${cardNumber}`)).toEqual(true);
});
test(`returns true for valid DVA card number ${stateId}${cardNumber}Z`, () => {
expect(validateDvaNumber(`${stateId}${cardNumber}Z`)).toEqual(true);
});
// should not accept lower case
test(`returns false for invalid DVA card number ${stateId.toLowerCase()}${cardNumber.toLowerCase()}z`, () => {
expect(validateDvaNumber(`${stateId}${cardNumber}Z`.toLowerCase())).toEqual(false);
});
});
// state ID is not one of "N","V","Q","S","W","T"
"ABCDEFGHIJKLMOPRUXYZ0123456789".split("").forEach(stateId => {
test(`returns false for valid DVA card number ${stateId}${cardNumber}`, () => {
expect(validateDvaNumber(`${stateId}${cardNumber}`)).toEqual(false);
});
test(`returns false for valid DVA card number ${stateId}${cardNumber}Z`, () => {
expect(validateDvaNumber(`${stateId}${cardNumber}Z`)).toEqual(false);
});
});
});
[
// dependency indicator is a digit
"NB1234560",
// too many chars
"NB123456ZZ",
// not enough chars
"N",
"1",
"NB",
"N1",
"1A",
// wrong number of digits in numeric field
"NB1234567",
"NB",
"N 1234567",
"N ",
"NBC123456",
"NBC",
"NBCD12345",
"NBCD",
// war code has digit
"N1123456",
"N11",
"N1C12345",
"N1C1234",
"N1C123",
"N1C12",
"N1C1",
"N1CD1234",
"N1CD123",
"N1CD12",
"N1CD1",
"NB1D1234",
"NB1D123",
"NB1D12",
"NB1D1"
].forEach((cardNumber) => {
test(`returns false for invalid DVA card number ${cardNumber}`, () => {
expect(validateDvaNumber(cardNumber)).toEqual(false);
});
test(`returns false for invalid DVA card number ${cardNumber}Z`, () => {
expect(validateDvaNumber(cardNumber + "Z")).toEqual(false);
});
});