All files / src website.js

100% Statements 15/15
100% Branches 2/2
100% Functions 5/5
100% Lines 13/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33            2x 275x   2x 6x   18x     2x 7x 1x     6x     2x 2x 2x   2x          
import R from 'ramda';
 
import forbiddenAddresses from './forbiddenAddresses';
import { checkSingle, checkMultiple } from './common';
import errorMessages from './errorMessages';
 
const checkOfficialAddress = (value) => {
    return !forbiddenAddresses.some((subString) => value.toLowerCase().includes(subString));
};
const hasForbiddenChars = (value) => {
    const forbiddenCharacters = [ '[at]', '(at)', '@' ];
 
    return !forbiddenCharacters.some((subString) => value.toLowerCase().includes(subString));
};
 
const checkForAbsoluteUrl = (value) => {
    if (!value) {
        return true;
    }
 
    return R.or(value.startsWith('http://'), value.startsWith('https://'));
};
 
export const isOfficialAddress = checkSingle(checkOfficialAddress, errorMessages.unofficialWebsite);
export const isValidAddress = checkSingle(hasForbiddenChars, errorMessages.notValidWebsite);
export const isAbsoluteUrl = checkSingle(checkForAbsoluteUrl, errorMessages.notAbsoluteUrl);
 
export const websiteSchema = checkMultiple([
    isOfficialAddress(),
    isValidAddress(),
    isAbsoluteUrl()
]);