-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.js
300 lines (271 loc) · 3.99 KB
/
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/**
* Module dependencies
*/
import test from 'ava'
import { cardType, cards } from '.'
/**
* Helpers
*/
function check (values, expected, t) {
values.forEach(value => {
const result = cardType(value)
t.is(result, expected, `${value} ${expected}`)
})
}
/**
* Visa
*/
test('visa', t => {
check([
'4539 9159 2637 3409',
'4024 0071 0766 6264',
'4435 0781 5370 6992',
4485830237950387,
4929344394064762,
4242967748272382,
4916544705132373,
4485378898061854,
455651,
432089,
453298,
4
], 'visa', t)
})
/**
* Mastercard
*/
test('mastercard', t => {
check([
51,
52,
53,
54,
55,
2221,
2300,
2500,
2700,
2720,
548787,
559323,
530870,
5577667174729333,
5489068089509224,
5357180094331095,
5291634686734594,
5166041234457912,
'5143 5709 0399 4704',
'5378 1024 5642 6649',
'5109 3682 1719 1865',
5021
], 'mastercard', t)
})
/**
* Amex
*/
test('amex', t => {
check([
34,
37,
372873,
372833,
'3723 484435 99298',
'3718 831054 67195',
'3420 647423 01560'
], 'amex', t)
})
/**
* Diners
*/
test('diners', t => {
check([
36,
309,
300,
301,
302,
303,
304,
305,
38,
39,
302629,
369361,
301262,
302928,
382645,
367401,
'3043 6421 9929 34',
'3028 3494 8262 13',
'3023 0683 7829 88'
], 'diners', t)
})
/**
* Discover
*/
test('discover', t => {
check([
6011,
622126,
622500,
622925,
644,
645,
646,
647,
648,
649,
'6011 8428 5776 0002',
'6443 1841 3438 7285',
'6476 5765 4268 3546',
'6452 4343 0569 4565',
'6491 6370 0432 3988',
65
], 'discover', t)
})
/**
* JCB
*/
test('jcb', t => {
check([
35,
3598764806994755,
3511493474905992,
3567616923080248
], 'jcb', t)
})
/**
* Maestro
*/
test('maestro', t => {
check([
5018,
502,
503,
506,
56,
57,
58,
639,
6220,
67,
6761623100389274,
5893283673889961,
6759338645083381,
6761298746142435,
5893707694036418,
6762189844181996,
5018200124130738,
6763079183697679,
5038122985997870,
5893039179790321,
5038207835809571,
6762950935257718
], 'maestro', t)
})
/**
* UnionPay
*/
test('unionpay', t => {
check([
62,
6253515620151132,
6206860290094917,
6286130646276326,
6255562422723716,
6272658799445716,
6213979531964687
], 'unionpay', t)
})
/**
* Elo
*/
test('elo', t => {
check([
4514168859308310,
5041756618991399,
6363683158991522,
6363683797780922,
4389359217109506,
6363688156148769,
4389354782591840,
6363687735844443,
4514169657425462,
6362970772545037,
6362974224176045,
6362978630338073,
6362970235469635,
6362973411041483,
6363685522292321,
4514168363042371,
6362970271833165,
5041755993276913,
4514160049830105,
6363680451085044,
5067784660549021,
6500452845766133,
6504053432889548,
4576318895170753,
6504147787294377,
6507172176585620,
6500386040620291,
6500384334710548,
6504212837657195,
6550193275594392,
6500431141094440,
6507146937094106,
6550588091236484,
6500438036893984,
6500351162499700,
4011785175079669,
6500356316423670,
6509019436969045,
6500319095127086,
5067786156765581,
6362975541469369,
4514165947540227
], 'elo', t)
})
/**
* Hipercard
*/
test('hipercard', t => {
check([
384100,
384140,
6062
], 'hipercard', t)
})
/**
* Unknown cards
*/
test('unknown', t => {
const values = [
'',
0,
'11111 11111'
]
values.forEach(value => {
t.deepEqual(cardType(value), '')
})
})
/**
* New card.
*/
test('new card', t => {
cards.push({
name: 'new-card',
pattern: [
777,
[100, 200]
]
})
check([
777,
'777 500 600',
100,
150,
199,
200
], 'new-card', t)
})