Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / lib / validation / credit-card.spec.ts
blob8b10d863e435e1fca93e47ead59c9eaae7d4fcee
1 import {
2     formatExpirationDateMMYY,
3     formatExpirationDateMMYYYY,
4     formatExpirationDateYYYYMM,
5 } from '@proton/pass/lib/validation/credit-card';
7 describe('expiration date', () => {
8     describe('formatExpirationDateMMYY', () => {
9         test('should parse and validate MMYY format', () => {
10             expect(formatExpirationDateMMYY('012026')).toEqual('0126');
11             expect(formatExpirationDateMMYY('0126')).toEqual('0126');
12             expect(formatExpirationDateMMYY('122000')).toEqual('1200');
13             expect(formatExpirationDateMMYY('1200')).toEqual('1200');
14         });
16         test('should parse and validate MMYY with separators', () => {
17             expect(formatExpirationDateMMYY('12.34')).toEqual('1234');
18             expect(formatExpirationDateMMYY('12/34')).toEqual('1234');
19             expect(formatExpirationDateMMYY('12-34')).toEqual('1234');
20             expect(formatExpirationDateMMYY('12 34')).toEqual('1234');
21             expect(formatExpirationDateMMYY('12,34')).toEqual('1234');
22         });
24         test('should parse and validate MMYYYY with separators', () => {
25             expect(formatExpirationDateMMYY('12.2034')).toEqual('1234');
26             expect(formatExpirationDateMMYY('12/2034')).toEqual('1234');
27             expect(formatExpirationDateMMYY('12-2034')).toEqual('1234');
28             expect(formatExpirationDateMMYY('12 2034')).toEqual('1234');
29             expect(formatExpirationDateMMYY('12,2034')).toEqual('1234');
30             expect(formatExpirationDateMMYY('12,,2034')).toEqual('1234');
31         });
33         test('should parse and validate YYYY-MM', () => {
34             expect(formatExpirationDateMMYY('2034-12')).toEqual('1234');
35         });
37         test('should return empty string if could not validate date parts', () => {
38             expect(formatExpirationDateMMYY('1')).toEqual('');
39             expect(formatExpirationDateMMYY('12')).toEqual('');
40             expect(formatExpirationDateMMYY('123')).toEqual('');
41             expect(formatExpirationDateMMYY('12345')).toEqual('');
42             expect(formatExpirationDateMMYY('1234567')).toEqual('');
43             expect(formatExpirationDateMMYY('ab26')).toEqual('');
44             expect(formatExpirationDateMMYY('notnumber')).toEqual('');
45             expect(formatExpirationDateMMYY('12-034')).toEqual('');
46         });
47     });
49     describe('formatExpirationDateMMYYYY', () => {
50         test('should parse and validate MMYY format', () => {
51             expect(formatExpirationDateMMYYYY('012026')).toEqual('012026');
52             expect(formatExpirationDateMMYYYY('0126')).toEqual('012026');
53             expect(formatExpirationDateMMYYYY('122000')).toEqual('122000');
54             expect(formatExpirationDateMMYYYY('1200')).toEqual('122000');
55         });
57         test('should parse and validate MMYY with separators', () => {
58             expect(formatExpirationDateMMYYYY('12.34')).toEqual('122034');
59             expect(formatExpirationDateMMYYYY('12/34')).toEqual('122034');
60             expect(formatExpirationDateMMYYYY('12-34')).toEqual('122034');
61             expect(formatExpirationDateMMYYYY('12 34')).toEqual('122034');
62             expect(formatExpirationDateMMYYYY('12,34')).toEqual('122034');
63         });
65         test('should parse and validate MMYYYY with separators', () => {
66             expect(formatExpirationDateMMYYYY('12.2034')).toEqual('122034');
67             expect(formatExpirationDateMMYYYY('12/2034')).toEqual('122034');
68             expect(formatExpirationDateMMYYYY('12-2034')).toEqual('122034');
69             expect(formatExpirationDateMMYYYY('12 2034')).toEqual('122034');
70             expect(formatExpirationDateMMYYYY('12,2034')).toEqual('122034');
71             expect(formatExpirationDateMMYYYY('12,,2034')).toEqual('122034');
72         });
74         test('should parse and validate YYYY-MM', () => {
75             expect(formatExpirationDateMMYYYY('2034-12')).toEqual('122034');
76         });
78         test('should return empty string if could not validate date parts', () => {
79             expect(formatExpirationDateMMYYYY('1')).toEqual('');
80             expect(formatExpirationDateMMYYYY('12')).toEqual('');
81             expect(formatExpirationDateMMYYYY('123')).toEqual('');
82             expect(formatExpirationDateMMYYYY('12345')).toEqual('');
83             expect(formatExpirationDateMMYYYY('1234567')).toEqual('');
84             expect(formatExpirationDateMMYYYY('ab26')).toEqual('');
85             expect(formatExpirationDateMMYYYY('notnumber')).toEqual('');
86             expect(formatExpirationDateMMYYYY('12-034')).toEqual('');
87         });
88     });
90     describe('formatExpirationDateYYYYMM', () => {
91         test('should parse and validate MMYY format', () => {
92             expect(formatExpirationDateYYYYMM('012026')).toEqual('2026-01');
93             expect(formatExpirationDateYYYYMM('0126')).toEqual('2026-01');
94             expect(formatExpirationDateYYYYMM('122000')).toEqual('2000-12');
95             expect(formatExpirationDateYYYYMM('1200')).toEqual('2000-12');
96         });
98         test('should parse and validate MMYY with separators', () => {
99             expect(formatExpirationDateYYYYMM('12.34')).toEqual('2034-12');
100             expect(formatExpirationDateYYYYMM('12/34')).toEqual('2034-12');
101             expect(formatExpirationDateYYYYMM('12-34')).toEqual('2034-12');
102             expect(formatExpirationDateYYYYMM('12 34')).toEqual('2034-12');
103             expect(formatExpirationDateYYYYMM('12,34')).toEqual('2034-12');
104         });
106         test('should parse and validate MMYYYY with separators', () => {
107             expect(formatExpirationDateYYYYMM('12.2034')).toEqual('2034-12');
108             expect(formatExpirationDateYYYYMM('12/2034')).toEqual('2034-12');
109             expect(formatExpirationDateYYYYMM('12-2034')).toEqual('2034-12');
110             expect(formatExpirationDateYYYYMM('12 2034')).toEqual('2034-12');
111             expect(formatExpirationDateYYYYMM('12,2034')).toEqual('2034-12');
112             expect(formatExpirationDateYYYYMM('12,,2034')).toEqual('2034-12');
113         });
115         test('should parse and validate YYYY-MM', () => {
116             expect(formatExpirationDateYYYYMM('2034-12')).toEqual('2034-12');
117         });
119         test('should return empty string if could not validate date parts', () => {
120             expect(formatExpirationDateYYYYMM('1')).toEqual('');
121             expect(formatExpirationDateYYYYMM('12')).toEqual('');
122             expect(formatExpirationDateYYYYMM('123')).toEqual('');
123             expect(formatExpirationDateYYYYMM('12345')).toEqual('');
124             expect(formatExpirationDateYYYYMM('1234567')).toEqual('');
125             expect(formatExpirationDateYYYYMM('ab26')).toEqual('');
126             expect(formatExpirationDateYYYYMM('notnumber')).toEqual('');
127             expect(formatExpirationDateYYYYMM('12-034')).toEqual('');
128         });
129     });