Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit a81129a

Browse files
authored
Hotfix/check email value with dot (#13)
* replace function in helpers * adapt testing * adapt email regex to handle tiret and underscores * hotfix test result
1 parent 80243e0 commit a81129a

File tree

3 files changed

+104
-20
lines changed

3 files changed

+104
-20
lines changed

src/__tests__/utils/helpers.test.tsx

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import Transaction from '../../models/Transaction';
22
import {
33
canProcessSloCode,
4+
checkDomainValue,
5+
checkEmailValue,
46
extractParamsFromUri,
57
logOutBody,
68
prepareConfig,
@@ -316,3 +318,80 @@ describe('helpers#canProcessSloCode/2', () => {
316318
).toBeTruthy();
317319
});
318320
});
321+
322+
describe('helper#checkEmaiValue/1', () => {
323+
it('returns false if empty string value', () => {
324+
expect(() => checkEmailValue('')).toThrowError(
325+
'Please provide non blank string for email'
326+
);
327+
});
328+
it('returns false if wrong string value', () => {
329+
expect(() => checkEmailValue('azerty')).toThrowError(
330+
'Please provide valid email'
331+
);
332+
});
333+
334+
it('returns false if @ string value', () => {
335+
expect(() => checkEmailValue('@')).toThrowError(
336+
'Please provide valid email'
337+
);
338+
});
339+
340+
it('returns true if simple string value', () => {
341+
expect(checkEmailValue('john@example.com')).toEqual('john@example.com');
342+
});
343+
344+
it('returns true if dotted email string value', () => {
345+
expect(checkEmailValue('john.doe@example.com')).toEqual(
346+
'john.doe@example.com'
347+
);
348+
});
349+
350+
it('returns false if ending first part with dots email string value', () => {
351+
expect(() => checkEmailValue('wrong..@example.com')).toThrowError(
352+
'Please provide valid email'
353+
);
354+
});
355+
356+
it('returns false if alias email string value', () => {
357+
expect(() => checkEmailValue('john+alias@example.com')).toThrowError(
358+
'Please provide valid email'
359+
);
360+
});
361+
362+
it('returns truthy if tiret email string value', () => {
363+
expect(checkEmailValue('john-doe@example.com')).toEqual(
364+
'john-doe@example.com'
365+
);
366+
});
367+
368+
it('returns truthy if underscored email string value', () => {
369+
expect(checkEmailValue('john-doe@example.com')).toEqual(
370+
'john-doe@example.com'
371+
);
372+
});
373+
});
374+
375+
describe('helpers#checkDomainValue/1', () => {
376+
it('should throw error if empy input', () => {
377+
expect(() => checkDomainValue(' ')).toThrowError(
378+
'Please provide non blank string for domain'
379+
);
380+
});
381+
382+
it('should throw error if underscored input', () => {
383+
expect(() => checkDomainValue('_')).toThrowError(
384+
'Please provide valid domain (alphanumeric dashed separated)'
385+
);
386+
});
387+
388+
it('should throw error if standard account complex name input', () => {
389+
expect(() => checkDomainValue("My awesome Company's name")).toThrowError(
390+
'Please provide valid domain (alphanumeric dashed separated)'
391+
);
392+
});
393+
394+
it('should return value if proper domain input', () => {
395+
expect(checkDomainValue('communitiz-app')).toEqual('communitiz-app');
396+
});
397+
});

src/components/CryptrGatewayButton.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,7 @@ import { Locale, useCryptr } from '..';
33
import { Pressable, Text, View } from 'react-native';
44
import type { StyleProp, TextStyle, ViewStyle } from 'react-native';
55
import { defaultStyles } from '../utils/defaultStypes';
6-
7-
const checkEmailValue = (emailValue: string) => {
8-
if (emailValue.trim() === '') {
9-
throw new Error('Please provide non blank string for email');
10-
}
11-
if (!/^[a-zA-Z0-9+]+@(?:[a-zA-Z0-9-]+\.)+[A-Za-z]+$/.test(emailValue)) {
12-
throw new Error('Please provide valid email');
13-
}
14-
return emailValue;
15-
};
16-
17-
const checkDomainValue = (domainValue?: string) => {
18-
if (domainValue !== undefined && domainValue?.trim() !== '') {
19-
if (!/^[a-z0-9-]*$/.test(domainValue)) {
20-
throw new Error(
21-
'Please provide valid domain (alphanumeric dashed separated)'
22-
);
23-
}
24-
}
25-
};
6+
import { checkDomainValue, checkEmailValue } from '../utils/helpers';
267

278
type GatewayProps = {
289
domain?: string;

src/utils/helpers.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,27 @@ export const canProcessSloCode = (
157157
// ips !== 'google'
158158
);
159159
};
160+
161+
export const checkEmailValue = (emailValue: string) => {
162+
if (emailValue.trim() === '') {
163+
throw new Error('Please provide non blank string for email');
164+
}
165+
if (
166+
!/^[a-z0-9]+[-_.]?[a-z0-9]+@(?:[a-zA-Z0-9-]+\.)+[A-Za-z]+$/.test(emailValue)
167+
) {
168+
throw new Error('Please provide valid email');
169+
}
170+
return emailValue;
171+
};
172+
173+
export const checkDomainValue = (domainValue?: string) => {
174+
if (domainValue === undefined || domainValue.trim() === '') {
175+
throw new Error('Please provide non blank string for domain');
176+
}
177+
if (!/^[a-z0-9-]*$/.test(domainValue)) {
178+
throw new Error(
179+
'Please provide valid domain (alphanumeric dashed separated)'
180+
);
181+
}
182+
return domainValue;
183+
};

0 commit comments

Comments
 (0)