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

Hotfix/check email value with dot #13

Merged
merged 4 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions src/__tests__/utils/helpers.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Transaction from '../../models/Transaction';
import {
canProcessSloCode,
checkDomainValue,
checkEmailValue,
extractParamsFromUri,
logOutBody,
prepareConfig,
Expand Down Expand Up @@ -316,3 +318,80 @@ describe('helpers#canProcessSloCode/2', () => {
).toBeTruthy();
});
});

describe('helper#checkEmaiValue/1', () => {
it('returns false if empty string value', () => {
expect(() => checkEmailValue('')).toThrowError(
'Please provide non blank string for email'
);
});
it('returns false if wrong string value', () => {
expect(() => checkEmailValue('azerty')).toThrowError(
'Please provide valid email'
);
});

it('returns false if @ string value', () => {
expect(() => checkEmailValue('@')).toThrowError(
'Please provide valid email'
);
});

it('returns true if simple string value', () => {
expect(checkEmailValue('john@example.com')).toEqual('john@example.com');
});

it('returns true if dotted email string value', () => {
expect(checkEmailValue('john.doe@example.com')).toEqual(
'john.doe@example.com'
);
});

it('returns false if ending first part with dots email string value', () => {
expect(() => checkEmailValue('wrong..@example.com')).toThrowError(
'Please provide valid email'
);
});

it('returns false if alias email string value', () => {
expect(() => checkEmailValue('john+alias@example.com')).toThrowError(
'Please provide valid email'
);
});

it('returns truthy if tiret email string value', () => {
expect(checkEmailValue('john-doe@example.com')).toEqual(
'john-doe@example.com'
);
});

it('returns truthy if underscored email string value', () => {
expect(checkEmailValue('john-doe@example.com')).toEqual(
'john-doe@example.com'
);
});
});

describe('helpers#checkDomainValue/1', () => {
it('should throw error if empy input', () => {
expect(() => checkDomainValue(' ')).toThrowError(
'Please provide non blank string for domain'
);
});

it('should throw error if underscored input', () => {
expect(() => checkDomainValue('_')).toThrowError(
'Please provide valid domain (alphanumeric dashed separated)'
);
});

it('should throw error if standard account complex name input', () => {
expect(() => checkDomainValue("My awesome Company's name")).toThrowError(
'Please provide valid domain (alphanumeric dashed separated)'
);
});

it('should return value if proper domain input', () => {
expect(checkDomainValue('communitiz-app')).toEqual('communitiz-app');
});
});
21 changes: 1 addition & 20 deletions src/components/CryptrGatewayButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,7 @@ import { Locale, useCryptr } from '..';
import { Pressable, Text, View } from 'react-native';
import type { StyleProp, TextStyle, ViewStyle } from 'react-native';
import { defaultStyles } from '../utils/defaultStypes';

const checkEmailValue = (emailValue: string) => {
if (emailValue.trim() === '') {
throw new Error('Please provide non blank string for email');
}
if (!/^[a-zA-Z0-9+]+@(?:[a-zA-Z0-9-]+\.)+[A-Za-z]+$/.test(emailValue)) {
throw new Error('Please provide valid email');
}
return emailValue;
};

const checkDomainValue = (domainValue?: string) => {
if (domainValue !== undefined && domainValue?.trim() !== '') {
if (!/^[a-z0-9-]*$/.test(domainValue)) {
throw new Error(
'Please provide valid domain (alphanumeric dashed separated)'
);
}
}
};
import { checkDomainValue, checkEmailValue } from '../utils/helpers';

type GatewayProps = {
domain?: string;
Expand Down
24 changes: 24 additions & 0 deletions src/utils/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,27 @@ export const canProcessSloCode = (
// ips !== 'google'
);
};

export const checkEmailValue = (emailValue: string) => {
if (emailValue.trim() === '') {
throw new Error('Please provide non blank string for email');
}
if (
!/^[a-z0-9]+[-_.]?[a-z0-9]+@(?:[a-zA-Z0-9-]+\.)+[A-Za-z]+$/.test(emailValue)
) {
throw new Error('Please provide valid email');
}
return emailValue;
};

export const checkDomainValue = (domainValue?: string) => {
if (domainValue === undefined || domainValue.trim() === '') {
throw new Error('Please provide non blank string for domain');
}
if (!/^[a-z0-9-]*$/.test(domainValue)) {
throw new Error(
'Please provide valid domain (alphanumeric dashed separated)'
);
}
return domainValue;
};