1 | define(["doh", "../creditCard"], function(doh, validate){ |
---|
2 | |
---|
3 | doh.register("dojox.validate.tests.creditcard", |
---|
4 | [{ |
---|
5 | name:"isValidLuhn", |
---|
6 | runTest: function(tests) { |
---|
7 | tests.t(validate.isValidLuhn('5105105105105100')); //test string input |
---|
8 | tests.t(validate.isValidLuhn('5105-1051 0510-5100')); //test string input with dashes and spaces (commonly used when entering card #'s) |
---|
9 | tests.t(validate.isValidLuhn(38520000023237)); //test numerical input as well |
---|
10 | tests.f(validate.isValidLuhn(3852000002323)); //testing failures |
---|
11 | tests.t(validate.isValidLuhn(18)); //length doesnt matter |
---|
12 | tests.f(validate.isValidLuhn(818181)); //short length failure |
---|
13 | } |
---|
14 | }, |
---|
15 | { |
---|
16 | name:"isValidCvv", |
---|
17 | runTest: function(tests) { |
---|
18 | tests.t(validate.isValidCvv('123','mc')); //string is ok |
---|
19 | tests.f(validate.isValidCvv('5AA','ec')); //invalid characters are not ok |
---|
20 | tests.t(validate.isValidCvv(723,'mc')); //numbers are ok too |
---|
21 | tests.f(validate.isValidCvv(7234,'mc')); //too long |
---|
22 | tests.t(validate.isValidCvv(612,'ec')); |
---|
23 | tests.t(validate.isValidCvv(421,'vi')); |
---|
24 | tests.t(validate.isValidCvv(543,'di')); |
---|
25 | tests.t(validate.isValidCvv('1234','ax')); |
---|
26 | tests.t(validate.isValidCvv(4321,'ax')); |
---|
27 | tests.f(validate.isValidCvv(43215,'ax')); //too long |
---|
28 | tests.f(validate.isValidCvv(215,'ax')); //too short |
---|
29 | } |
---|
30 | }, |
---|
31 | { |
---|
32 | name:"isValidCreditCard", |
---|
33 | runTest: function(tests) { |
---|
34 | //misc checks |
---|
35 | tests.t(validate.isValidCreditCard('5105105105105100','mc')); //test string input |
---|
36 | tests.t(validate.isValidCreditCard('5105-1051 0510-5100','mc')); //test string input with dashes and spaces (commonly used when entering card #'s) |
---|
37 | tests.t(validate.isValidCreditCard(5105105105105100,'mc')); //test numerical input as well |
---|
38 | tests.f(validate.isValidCreditCard('5105105105105100','vi')); //fails, wrong card type |
---|
39 | //Mastercard/Eurocard checks |
---|
40 | tests.t(validate.isValidCreditCard('5105105105105100','mc')); |
---|
41 | tests.t(validate.isValidCreditCard('5204105105105100','ec')); |
---|
42 | tests.t(validate.isValidCreditCard('5303105105105100','mc')); |
---|
43 | tests.t(validate.isValidCreditCard('5402105105105100','ec')); |
---|
44 | tests.t(validate.isValidCreditCard('5501105105105100','mc')); |
---|
45 | //Visa card checks |
---|
46 | tests.t(validate.isValidCreditCard('4111111111111111','vi')); |
---|
47 | tests.t(validate.isValidCreditCard('4111111111010','vi')); |
---|
48 | //American Express card checks |
---|
49 | tests.t(validate.isValidCreditCard('378 2822 4631 0005','ax')); |
---|
50 | tests.t(validate.isValidCreditCard('341-1111-1111-1111','ax')); |
---|
51 | //Diners Club/Carte Blanch card checks |
---|
52 | tests.t(validate.isValidCreditCard('36400000000000','dc')); |
---|
53 | tests.t(validate.isValidCreditCard('38520000023237','bl')); |
---|
54 | tests.t(validate.isValidCreditCard('30009009025904','dc')); |
---|
55 | tests.t(validate.isValidCreditCard('30108009025904','bl')); |
---|
56 | tests.t(validate.isValidCreditCard('30207009025904','dc')); |
---|
57 | tests.t(validate.isValidCreditCard('30306009025904','bl')); |
---|
58 | tests.t(validate.isValidCreditCard('30405009025904','dc')); |
---|
59 | tests.t(validate.isValidCreditCard('30504009025904','bl')); |
---|
60 | //Discover card checks |
---|
61 | tests.t(validate.isValidCreditCard('6011111111111117','di')); |
---|
62 | //JCB card checks |
---|
63 | tests.t(validate.isValidCreditCard('3530111333300000','jcb')); |
---|
64 | tests.t(validate.isValidCreditCard('213100000000001','jcb')); |
---|
65 | tests.t(validate.isValidCreditCard('180000000000002','jcb')); |
---|
66 | tests.f(validate.isValidCreditCard('1800000000000002','jcb')); //should fail, good checksum, good prefix, but wrong length' |
---|
67 | //Enroute card checks |
---|
68 | tests.t(validate.isValidCreditCard('201400000000000','er')); |
---|
69 | tests.t(validate.isValidCreditCard('214900000000000','er')); |
---|
70 | } |
---|
71 | }, |
---|
72 | { |
---|
73 | name:"isValidCreditCardNumber", |
---|
74 | runTest: function(tests) { |
---|
75 | //misc checks |
---|
76 | tests.t(validate.isValidCreditCardNumber('5105105105105100','mc')); //test string input |
---|
77 | tests.t(validate.isValidCreditCardNumber('5105-1051 0510-5100','mc')); //test string input with dashes and spaces (commonly used when entering card #'s) |
---|
78 | tests.t(validate.isValidCreditCardNumber(5105105105105100,'mc')); //test numerical input as well |
---|
79 | tests.f(validate.isValidCreditCardNumber('5105105105105100','vi')); //fails, wrong card type |
---|
80 | //Mastercard/Eurocard checks |
---|
81 | tests.is("mc|ec", validate.isValidCreditCardNumber('5100000000000000')); //should match 'mc|ec' |
---|
82 | tests.is("mc|ec", validate.isValidCreditCardNumber('5200000000000000')); //should match 'mc|ec' |
---|
83 | tests.is("mc|ec", validate.isValidCreditCardNumber('5300000000000000')); //should match 'mc|ec' |
---|
84 | tests.is("mc|ec", validate.isValidCreditCardNumber('5400000000000000')); //should match 'mc|ec' |
---|
85 | tests.is("mc|ec", validate.isValidCreditCardNumber('5500000000000000')); //should match 'mc|ec' |
---|
86 | tests.f(validate.isValidCreditCardNumber('55000000000000000')); //should fail, too long |
---|
87 | //Visa card checks |
---|
88 | tests.is("vi", validate.isValidCreditCardNumber('4111111111111111')); //should match 'vi' |
---|
89 | tests.is("vi", validate.isValidCreditCardNumber('4111111111010')); //should match 'vi' |
---|
90 | //American Express card checks |
---|
91 | tests.is("ax", validate.isValidCreditCardNumber('378 2822 4631 0005')); //should match 'ax' |
---|
92 | tests.is("ax", validate.isValidCreditCardNumber('341-1111-1111-1111')); //should match 'ax' |
---|
93 | //Diners Club/Carte Blanch card checks |
---|
94 | tests.is("dc|bl", validate.isValidCreditCardNumber('36400000000000')); //should match 'dc|bl' |
---|
95 | tests.is("dc|bl", validate.isValidCreditCardNumber('38520000023237')); //should match 'dc|bl' |
---|
96 | tests.is("dc|bl", validate.isValidCreditCardNumber('30009009025904')); //should match 'di|bl' |
---|
97 | tests.is("dc|bl", validate.isValidCreditCardNumber('30108009025904')); //should match 'di|bl' |
---|
98 | tests.is("dc|bl", validate.isValidCreditCardNumber('30207009025904')); //should match 'di|bl' |
---|
99 | tests.is("dc|bl", validate.isValidCreditCardNumber('30306009025904')); //should match 'di|bl' |
---|
100 | tests.is("dc|bl", validate.isValidCreditCardNumber('30405009025904')); //should match 'di|bl' |
---|
101 | tests.is("dc|bl", validate.isValidCreditCardNumber('30504009025904')); //should match 'di|bl' |
---|
102 | //Discover card checks |
---|
103 | tests.is("di", validate.isValidCreditCardNumber('6011111111111117')); //should match 'di' |
---|
104 | //JCB card checks |
---|
105 | tests.is("jcb", validate.isValidCreditCardNumber('3530111333300000')); //should match 'jcb' |
---|
106 | tests.is("jcb", validate.isValidCreditCardNumber('213100000000001')); //should match 'jcb' |
---|
107 | tests.is("jcb", validate.isValidCreditCardNumber('180000000000002')); //should match 'jcb' |
---|
108 | tests.f(validate.isValidCreditCardNumber('1800000000000002')); //should fail, good checksum, good prefix, but wrong length' |
---|
109 | //Enroute card checks |
---|
110 | tests.is("er", validate.isValidCreditCardNumber('201400000000000')); //should match 'er' |
---|
111 | tests.is("er", validate.isValidCreditCardNumber('214900000000000')); //should match 'er' |
---|
112 | } |
---|
113 | } |
---|
114 | ]); |
---|
115 | |
---|
116 | }); |
---|