@osimatic/helpers-js 1.4.22 → 1.4.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +12 -0
- package/CHANGELOG +2 -1
- package/array.js +2 -2
- package/bank.js +3 -3
- package/contact_details.js +2 -2
- package/http_client.js +19 -4
- package/location.js +6 -2
- package/package.json +27 -2
- package/tests/array.test.js +458 -0
- package/tests/bank.test.js +158 -0
- package/tests/contact_details.test.js +391 -0
- package/tests/location.test.js +509 -0
- package/tmpclaude-0fa4-cwd +1 -0
- package/tmpclaude-104f-cwd +1 -0
- package/tmpclaude-1468-cwd +1 -0
- package/tmpclaude-324b-cwd +1 -0
- package/tmpclaude-35d3-cwd +1 -0
- package/tmpclaude-4aa8-cwd +1 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
const { IBAN, BankCard } = require('../bank');
|
|
2
|
+
|
|
3
|
+
describe('IBAN', () => {
|
|
4
|
+
describe('format', () => {
|
|
5
|
+
test('should format IBAN with spaces every 4 characters', () => {
|
|
6
|
+
const iban = 'FR7630006000011234567890189';
|
|
7
|
+
expect(IBAN.format(iban)).toBe('FR76 3000 6000 0112 3456 7890 189');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test('should remove non-alphanumeric characters', () => {
|
|
11
|
+
const iban = 'FR76-3000-6000-0112-3456-7890-189';
|
|
12
|
+
expect(IBAN.format(iban)).toBe('FR76 3000 6000 0112 3456 7890 189');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('should handle IBAN with spaces', () => {
|
|
16
|
+
const iban = 'FR76 3000 6000 0112 3456 7890 189';
|
|
17
|
+
expect(IBAN.format(iban)).toBe('FR76 3000 6000 0112 3456 7890 189');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('should handle lowercase letters', () => {
|
|
21
|
+
const iban = 'fr7630006000011234567890189';
|
|
22
|
+
expect(IBAN.format(iban)).toBe('FR76 3000 6000 0112 3456 7890 189');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('should remove special characters and spaces', () => {
|
|
26
|
+
const iban = 'FR76 3000.6000/0112-3456_7890*189';
|
|
27
|
+
expect(IBAN.format(iban)).toBe('FR76 3000 6000 0112 3456 7890 189');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('should handle German IBAN', () => {
|
|
31
|
+
const iban = 'DE89370400440532013000';
|
|
32
|
+
expect(IBAN.format(iban)).toBe('DE89 3704 0044 0532 0130 00');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('should handle Belgian IBAN', () => {
|
|
36
|
+
const iban = 'BE68539007547034';
|
|
37
|
+
expect(IBAN.format(iban)).toBe('BE68 5390 0754 7034');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('should handle empty string', () => {
|
|
41
|
+
expect(IBAN.format('')).toBe('');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('should handle IBAN with mixed case and special chars', () => {
|
|
45
|
+
const iban = 'fR76@3000#6000$0112%3456^7890&189';
|
|
46
|
+
expect(IBAN.format(iban)).toBe('FR76 3000 6000 0112 3456 7890 189');
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('BankCard', () => {
|
|
52
|
+
describe('formatCardNumber', () => {
|
|
53
|
+
test('should format 16-digit card number with dashes', () => {
|
|
54
|
+
const cardNumber = '1234567890123456';
|
|
55
|
+
expect(BankCard.formatCardNumber(cardNumber)).toBe('1234-5678-9012-3456');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('should replace asterisks with X', () => {
|
|
59
|
+
const cardNumber = '1234********3456';
|
|
60
|
+
expect(BankCard.formatCardNumber(cardNumber)).toBe('1234-****-****-3456');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('should replace asterisks with custom hiddenChar', () => {
|
|
64
|
+
const cardNumber = '1234********3456';
|
|
65
|
+
expect(BankCard.formatCardNumber(cardNumber, 'X')).toBe('1234-XXXX-XXXX-3456');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('should replace X with custom hiddenChar', () => {
|
|
69
|
+
const cardNumber = '1234XXXXXXXX3456';
|
|
70
|
+
expect(BankCard.formatCardNumber(cardNumber, '#')).toBe('1234-####-####-3456');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('should replace both * and X with hiddenChar', () => {
|
|
74
|
+
const cardNumber = '1234**XX**XX3456';
|
|
75
|
+
// After formatting: 1234-**XX-**XX-3456
|
|
76
|
+
// After replacing * and X with -: 1234-----------3456 (11 dashes: 3 from formatting + 8 from replacement)
|
|
77
|
+
expect(BankCard.formatCardNumber(cardNumber, '-')).toBe('1234-----------3456');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('should handle lowercase x', () => {
|
|
81
|
+
const cardNumber = '1234xxxxxxxx3456';
|
|
82
|
+
expect(BankCard.formatCardNumber(cardNumber, '•')).toBe('1234-••••-••••-3456');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('should not format if not 16 digits', () => {
|
|
86
|
+
const cardNumber = '12345678901234';
|
|
87
|
+
expect(BankCard.formatCardNumber(cardNumber)).toBe('12345678901234');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('should not format if more than 16 digits', () => {
|
|
91
|
+
const cardNumber = '12345678901234567';
|
|
92
|
+
expect(BankCard.formatCardNumber(cardNumber)).toBe('12345678901234567');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('should handle card number with all zeros', () => {
|
|
96
|
+
const cardNumber = '0000000000000000';
|
|
97
|
+
expect(BankCard.formatCardNumber(cardNumber)).toBe('0000-0000-0000-0000');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('should handle card number with letters (treated as 16 chars)', () => {
|
|
101
|
+
const cardNumber = '123456789012ABCD';
|
|
102
|
+
expect(BankCard.formatCardNumber(cardNumber)).toBe('1234-5678-9012-ABCD');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('should handle empty string', () => {
|
|
106
|
+
expect(BankCard.formatCardNumber('')).toBe('');
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe('formatExpirationDate', () => {
|
|
111
|
+
// Mock SqlDateTime since it's imported from another module
|
|
112
|
+
beforeAll(() => {
|
|
113
|
+
global.SqlDateTime = {
|
|
114
|
+
getMonthName: jest.fn((date, locale) => {
|
|
115
|
+
// Mock implementation
|
|
116
|
+
const d = new Date(date);
|
|
117
|
+
const month = d.toLocaleString(locale, { month: 'long' });
|
|
118
|
+
return month.charAt(0).toUpperCase() + month.slice(1);
|
|
119
|
+
}),
|
|
120
|
+
getYear: jest.fn((date) => {
|
|
121
|
+
const d = new Date(date);
|
|
122
|
+
return d.getFullYear();
|
|
123
|
+
})
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
afterAll(() => {
|
|
128
|
+
delete global.SqlDateTime;
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('should format expiration date in French', () => {
|
|
132
|
+
const date = '2025-12-31';
|
|
133
|
+
const result = BankCard.formatExpirationDate(date, 'fr-FR');
|
|
134
|
+
expect(result).toContain('2025');
|
|
135
|
+
expect(SqlDateTime.getMonthName).toHaveBeenCalledWith(date, 'fr-FR');
|
|
136
|
+
expect(SqlDateTime.getYear).toHaveBeenCalledWith(date);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('should use default locale fr-FR', () => {
|
|
140
|
+
const date = '2025-06-15';
|
|
141
|
+
BankCard.formatExpirationDate(date);
|
|
142
|
+
expect(SqlDateTime.getMonthName).toHaveBeenCalledWith(date, 'fr-FR');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('should format expiration date in English', () => {
|
|
146
|
+
const date = '2025-03-20';
|
|
147
|
+
const result = BankCard.formatExpirationDate(date, 'en-US');
|
|
148
|
+
expect(result).toContain('2025');
|
|
149
|
+
expect(SqlDateTime.getMonthName).toHaveBeenCalledWith(date, 'en-US');
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('should handle different date formats', () => {
|
|
153
|
+
const date = '2026-01-01';
|
|
154
|
+
const result = BankCard.formatExpirationDate(date);
|
|
155
|
+
expect(result).toContain('2026');
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
});
|
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
const { PersonName, Email, TelephoneNumber } = require('../contact_details');
|
|
2
|
+
|
|
3
|
+
describe('PersonName', () => {
|
|
4
|
+
describe('format', () => {
|
|
5
|
+
test('should format full name with firstName and lastName', () => {
|
|
6
|
+
expect(PersonName.format('John', 'Doe')).toBe('John Doe');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
test('should format with only firstName', () => {
|
|
10
|
+
expect(PersonName.format('John', null)).toBe('John');
|
|
11
|
+
expect(PersonName.format('John', '')).toBe('John');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('should format with only lastName', () => {
|
|
15
|
+
expect(PersonName.format(null, 'Doe')).toBe('Doe');
|
|
16
|
+
expect(PersonName.format('', 'Doe')).toBe('Doe');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('should return empty string when both are null', () => {
|
|
20
|
+
expect(PersonName.format(null, null)).toBe('');
|
|
21
|
+
expect(PersonName.format('', '')).toBe('');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('should trim extra spaces', () => {
|
|
25
|
+
expect(PersonName.format(' John ', ' Doe ')).toBe('John Doe');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('should handle names with special characters', () => {
|
|
29
|
+
expect(PersonName.format('Jean-Paul', 'O\'Brien')).toBe('Jean-Paul O\'Brien');
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('checkFirstName', () => {
|
|
34
|
+
test('should accept valid first names', () => {
|
|
35
|
+
expect(PersonName.checkFirstName('John')).toBe(true);
|
|
36
|
+
expect(PersonName.checkFirstName('Jean-Paul')).toBe(true);
|
|
37
|
+
expect(PersonName.checkFirstName('O\'Brien')).toBe(true);
|
|
38
|
+
expect(PersonName.checkFirstName('José')).toBe(true);
|
|
39
|
+
expect(PersonName.checkFirstName('François')).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('should reject first names shorter than 2 characters', () => {
|
|
43
|
+
expect(PersonName.checkFirstName('J')).toBe(false);
|
|
44
|
+
expect(PersonName.checkFirstName('')).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('should reject first names longer than 64 characters', () => {
|
|
48
|
+
const longName = 'A'.repeat(65);
|
|
49
|
+
expect(PersonName.checkFirstName(longName)).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('should reject first names with numbers', () => {
|
|
53
|
+
expect(PersonName.checkFirstName('John123')).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('should reject first names with special characters', () => {
|
|
57
|
+
expect(PersonName.checkFirstName('John@')).toBe(false);
|
|
58
|
+
expect(PersonName.checkFirstName('John!')).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('should accept first names with spaces', () => {
|
|
62
|
+
expect(PersonName.checkFirstName('Jean Paul')).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('should accept first names with accented characters', () => {
|
|
66
|
+
expect(PersonName.checkFirstName('Zoé')).toBe(true);
|
|
67
|
+
expect(PersonName.checkFirstName('Chloë')).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('checkLastName', () => {
|
|
72
|
+
test('should accept valid last names', () => {
|
|
73
|
+
expect(PersonName.checkLastName('Doe')).toBe(true);
|
|
74
|
+
expect(PersonName.checkLastName('Smith-Jones')).toBe(true);
|
|
75
|
+
expect(PersonName.checkLastName('O\'Brien')).toBe(true);
|
|
76
|
+
expect(PersonName.checkLastName('Müller')).toBe(true);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('should reject last names shorter than 2 characters', () => {
|
|
80
|
+
expect(PersonName.checkLastName('D')).toBe(false);
|
|
81
|
+
expect(PersonName.checkLastName('')).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('should reject last names longer than 64 characters', () => {
|
|
85
|
+
const longName = 'A'.repeat(65);
|
|
86
|
+
expect(PersonName.checkLastName(longName)).toBe(false);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('should reject last names with numbers', () => {
|
|
90
|
+
expect(PersonName.checkLastName('Doe123')).toBe(false);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('should reject last names with special characters', () => {
|
|
94
|
+
expect(PersonName.checkLastName('Doe@')).toBe(false);
|
|
95
|
+
expect(PersonName.checkLastName('Doe!')).toBe(false);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('should accept last names with spaces', () => {
|
|
99
|
+
expect(PersonName.checkLastName('Van Der Berg')).toBe(true);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe('Email', () => {
|
|
105
|
+
describe('validateEmail', () => {
|
|
106
|
+
test('should validate correct email addresses', () => {
|
|
107
|
+
expect(Email.validateEmail('test@example.com')).toBe(true);
|
|
108
|
+
expect(Email.validateEmail('user.name@example.com')).toBe(true);
|
|
109
|
+
expect(Email.validateEmail('user+tag@example.co.uk')).toBe(true);
|
|
110
|
+
expect(Email.validateEmail('user_name@example.com')).toBe(true);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('should reject invalid email addresses', () => {
|
|
114
|
+
expect(Email.validateEmail('invalid')).toBe(false);
|
|
115
|
+
expect(Email.validateEmail('invalid@')).toBe(false);
|
|
116
|
+
expect(Email.validateEmail('@example.com')).toBe(false);
|
|
117
|
+
expect(Email.validateEmail('invalid@.com')).toBe(false);
|
|
118
|
+
expect(Email.validateEmail('invalid @example.com')).toBe(false);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('should reject emails with multiple @ symbols', () => {
|
|
122
|
+
expect(Email.validateEmail('user@@example.com')).toBe(false);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('should accept emails with dots in local part', () => {
|
|
126
|
+
expect(Email.validateEmail('first.last@example.com')).toBe(true);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('should accept emails with subdomains', () => {
|
|
130
|
+
expect(Email.validateEmail('user@mail.example.com')).toBe(true);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe('checkEmail', () => {
|
|
135
|
+
test('should validate correct email addresses', () => {
|
|
136
|
+
expect(Email.checkEmail('test@example.com')).toBe(true);
|
|
137
|
+
expect(Email.checkEmail('user.name@example.co')).toBe(true);
|
|
138
|
+
expect(Email.checkEmail('user_name@example.org')).toBe(true);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('should reject invalid email addresses', () => {
|
|
142
|
+
expect(Email.checkEmail('invalid')).toBe(false);
|
|
143
|
+
expect(Email.checkEmail('invalid@')).toBe(false);
|
|
144
|
+
expect(Email.checkEmail('@example.com')).toBe(false);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('should reject emails with TLD longer than 5 characters', () => {
|
|
148
|
+
expect(Email.checkEmail('test@example.museum')).toBe(false);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('should accept emails with TLD up to 5 characters', () => {
|
|
152
|
+
expect(Email.checkEmail('test@example.co')).toBe(true);
|
|
153
|
+
expect(Email.checkEmail('test@example.com')).toBe(true);
|
|
154
|
+
expect(Email.checkEmail('test@example.info')).toBe(true);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe('getMailToLink', () => {
|
|
159
|
+
test('should generate mailto link', () => {
|
|
160
|
+
const email = 'test@example.com';
|
|
161
|
+
const expected = '<a href="mailto:test@example.com">test@example.com</a>';
|
|
162
|
+
expect(Email.getMailToLink(email)).toBe(expected);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test('should handle email with special characters', () => {
|
|
166
|
+
const email = 'user+tag@example.com';
|
|
167
|
+
const expected = '<a href="mailto:user+tag@example.com">user+tag@example.com</a>';
|
|
168
|
+
expect(Email.getMailToLink(email)).toBe(expected);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
describe('TelephoneNumber', () => {
|
|
174
|
+
// Mock libphonenumber
|
|
175
|
+
beforeAll(() => {
|
|
176
|
+
global.libphonenumber = {
|
|
177
|
+
parsePhoneNumber: jest.fn((phoneNumber, countryCode) => {
|
|
178
|
+
// Simple mock implementation
|
|
179
|
+
if (phoneNumber === '+33612345678') {
|
|
180
|
+
return {
|
|
181
|
+
country: 'FR',
|
|
182
|
+
formatNational: () => '06 12 34 56 78',
|
|
183
|
+
formatInternational: () => '+33 6 12 34 56 78',
|
|
184
|
+
isValid: () => true,
|
|
185
|
+
getType: () => 'MOBILE'
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
if (phoneNumber === '+14155552671') {
|
|
189
|
+
return {
|
|
190
|
+
country: 'US',
|
|
191
|
+
formatNational: () => '(415) 555-2671',
|
|
192
|
+
formatInternational: () => '+1 415-555-2671',
|
|
193
|
+
isValid: () => true,
|
|
194
|
+
getType: () => 'FIXED_LINE_OR_MOBILE'
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
if (phoneNumber === 'invalid') {
|
|
198
|
+
throw new Error('Invalid phone number');
|
|
199
|
+
}
|
|
200
|
+
return null;
|
|
201
|
+
})
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
global.Country = {
|
|
205
|
+
getCountryName: jest.fn((code) => {
|
|
206
|
+
const countries = { FR: 'France', US: 'United States' };
|
|
207
|
+
return countries[code] || code;
|
|
208
|
+
}),
|
|
209
|
+
getFlagImg: jest.fn((code) => {
|
|
210
|
+
return `<img src="/flags/${code.toLowerCase()}.png" />`;
|
|
211
|
+
})
|
|
212
|
+
};
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
afterAll(() => {
|
|
216
|
+
delete global.libphonenumber;
|
|
217
|
+
delete global.Country;
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
describe('setLocalCountryCode', () => {
|
|
221
|
+
test('should set local country code', () => {
|
|
222
|
+
TelephoneNumber.setLocalCountryCode('FR');
|
|
223
|
+
expect(TelephoneNumber.localCountryCode).toBe('FR');
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
describe('setIntlTelInputUtilsPath', () => {
|
|
228
|
+
test('should set intl tel input utils path', () => {
|
|
229
|
+
const path = '/path/to/utils.js';
|
|
230
|
+
TelephoneNumber.setIntlTelInputUtilsPath(path);
|
|
231
|
+
expect(TelephoneNumber.intlTelInputUtilsPath).toBe(path);
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
describe('getCountryIsoCode', () => {
|
|
236
|
+
test('should return country code for valid phone number', () => {
|
|
237
|
+
const result = TelephoneNumber.getCountryIsoCode('+33612345678', 'FR');
|
|
238
|
+
expect(result).toBe('FR');
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test('should return null for invalid phone number', () => {
|
|
242
|
+
const result = TelephoneNumber.getCountryIsoCode('invalid', 'FR');
|
|
243
|
+
expect(result).toBeNull();
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
describe('formatNational', () => {
|
|
248
|
+
test('should format phone number in national format', () => {
|
|
249
|
+
const result = TelephoneNumber.formatNational('+33612345678', 'FR');
|
|
250
|
+
expect(result).toBe('06 12 34 56 78');
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
test('should return empty string for invalid phone number', () => {
|
|
254
|
+
const result = TelephoneNumber.formatNational('invalid', 'FR');
|
|
255
|
+
expect(result).toBe('');
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
describe('formatInternational', () => {
|
|
260
|
+
test('should format phone number in international format', () => {
|
|
261
|
+
const result = TelephoneNumber.formatInternational('+33612345678', 'FR');
|
|
262
|
+
expect(result).toBe('+33 6 12 34 56 78');
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test('should return empty string for invalid phone number', () => {
|
|
266
|
+
const result = TelephoneNumber.formatInternational('invalid', 'FR');
|
|
267
|
+
expect(result).toBe('');
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
describe('formatInternationalWithTelLink', () => {
|
|
272
|
+
test('should format phone number with tel link', () => {
|
|
273
|
+
const result = TelephoneNumber.formatInternationalWithTelLink('+33612345678', 'FR');
|
|
274
|
+
expect(result).toBe('<a href="tel:+33612345678">+33 6 12 34 56 78</a>');
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
describe('parse', () => {
|
|
279
|
+
test('should parse valid phone number', () => {
|
|
280
|
+
const result = TelephoneNumber.parse('+33612345678', 'FR');
|
|
281
|
+
expect(result).toBe('+33 6 12 34 56 78');
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
test('should return null for invalid phone number', () => {
|
|
285
|
+
const result = TelephoneNumber.parse('invalid', 'FR');
|
|
286
|
+
expect(result).toBeNull();
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
describe('check', () => {
|
|
291
|
+
test('should validate correct phone number', () => {
|
|
292
|
+
const result = TelephoneNumber.check('+33612345678', 'FR');
|
|
293
|
+
expect(result).toBe(true);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test('should reject invalid phone number', () => {
|
|
297
|
+
const result = TelephoneNumber.check('invalid', 'FR');
|
|
298
|
+
expect(result).toBe(false);
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
describe('checkSyntaxe', () => {
|
|
303
|
+
test('should validate French phone numbers', () => {
|
|
304
|
+
expect(TelephoneNumber.checkSyntaxe('0612345678')).toBe(true);
|
|
305
|
+
expect(TelephoneNumber.checkSyntaxe('06 12 34 56 78')).toBe(true);
|
|
306
|
+
expect(TelephoneNumber.checkSyntaxe('06.12.34.56.78')).toBe(true);
|
|
307
|
+
expect(TelephoneNumber.checkSyntaxe('06-12-34-56-78')).toBe(true);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test('should validate international phone numbers', () => {
|
|
311
|
+
expect(TelephoneNumber.checkSyntaxe('+33612345678')).toBe(true);
|
|
312
|
+
expect(TelephoneNumber.checkSyntaxe('+33 6 12 34 56 78')).toBe(true);
|
|
313
|
+
expect(TelephoneNumber.checkSyntaxe('0033612345678')).toBe(true);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
test('should reject invalid phone numbers', () => {
|
|
317
|
+
expect(TelephoneNumber.checkSyntaxe('123')).toBe(false);
|
|
318
|
+
expect(TelephoneNumber.checkSyntaxe('abcdefghij')).toBe(false);
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
describe('getType', () => {
|
|
323
|
+
test('should return phone type', () => {
|
|
324
|
+
const result = TelephoneNumber.getType('+33612345678', 'FR');
|
|
325
|
+
expect(result).toBe('MOBILE');
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
test('should return MASKED for null or empty phone number', () => {
|
|
329
|
+
expect(TelephoneNumber.getType(null, 'FR')).toBe('MASKED');
|
|
330
|
+
expect(TelephoneNumber.getType('', 'FR')).toBe('MASKED');
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
test('should return null for invalid phone number', () => {
|
|
334
|
+
const result = TelephoneNumber.getType('invalid', 'FR');
|
|
335
|
+
expect(result).toBeNull();
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
describe('getTypeLabelList', () => {
|
|
340
|
+
test('should return type labels object', () => {
|
|
341
|
+
const labels = TelephoneNumber.getTypeLabelList();
|
|
342
|
+
expect(labels).toHaveProperty('MOBILE', 'Mobile');
|
|
343
|
+
expect(labels).toHaveProperty('FIXED_LINE', 'Fixe');
|
|
344
|
+
expect(labels).toHaveProperty('MASKED', 'Masqué');
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
describe('getTypeLabel', () => {
|
|
349
|
+
test('should return label for known type', () => {
|
|
350
|
+
expect(TelephoneNumber.getTypeLabel('MOBILE')).toBe('Mobile');
|
|
351
|
+
expect(TelephoneNumber.getTypeLabel('FIXED_LINE')).toBe('Fixe');
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
test('should return Inconnu for unknown type', () => {
|
|
355
|
+
expect(TelephoneNumber.getTypeLabel('UNKNOWN_TYPE')).toBe('Inconnu');
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
describe('getCountryName', () => {
|
|
360
|
+
test('should return country name for phone number', () => {
|
|
361
|
+
const result = TelephoneNumber.getCountryName('+33612345678', 'FR');
|
|
362
|
+
expect(result).toBe('France');
|
|
363
|
+
expect(Country.getCountryName).toHaveBeenCalledWith('FR');
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
describe('getFlagImg', () => {
|
|
368
|
+
test('should return flag image for phone number', () => {
|
|
369
|
+
const result = TelephoneNumber.getFlagImg('+33612345678', 'FR');
|
|
370
|
+
expect(result).toContain('<img src="/flags/fr.png"');
|
|
371
|
+
expect(Country.getFlagImg).toHaveBeenCalledWith('FR');
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
describe('formatNationalWithFlagImg', () => {
|
|
376
|
+
test('should format phone number with flag image', () => {
|
|
377
|
+
const result = TelephoneNumber.formatNationalWithFlagImg('+33612345678', 'FR');
|
|
378
|
+
expect(result).toContain('<img src="/flags/fr.png"');
|
|
379
|
+
expect(result).toContain('06 12 34 56 78');
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
describe('formatNationalWithFlagImgAndTelLink', () => {
|
|
384
|
+
test('should format phone number with flag and tel link', () => {
|
|
385
|
+
const result = TelephoneNumber.formatNationalWithFlagImgAndTelLink('+33612345678', 'FR');
|
|
386
|
+
expect(result).toContain('<img src="/flags/fr.png"');
|
|
387
|
+
expect(result).toContain('<a href="tel:+33612345678">');
|
|
388
|
+
expect(result).toContain('06 12 34 56 78');
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
});
|