All files / src/automaticRecognition index.js

85.29% Statements 29/34
80% Branches 32/40
100% Functions 1/1
85.29% Lines 29/34
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70          14x   14x 13x 2x     11x             11x 6x 1x   1x 1x       5x 1x     4x 1x     3x 1x     2x   5x 3x 1x     2x 1x     1x   2x 1x       1x       1x   1x   1x      
import { isVoid, isValid } from '../validation';
import config from '../config';
import UserView from '../userView';
 
export default (username, password, regexObject) => {
    const UserViewInstance = new UserView();
 
    if (regexObject) {
        if (isVoid(username)) {
            throw new Error('useris-error-msg');
        }
 
        Iif (config.get('enableGoogleCheckbox')) {
            const element = UserViewInstance.getElement('terms');
            if (element && !element.checked) {
                throw new Error('useris-error-empty-terms');
            }
        }
 
        if (isValid(username, regexObject.msisdn)) { // MSISDN
            if (config.get('operatorList')) {
                const operatorArray = UserViewInstance.getElementsByName('operator') || [];
 
                Eif (!UserViewInstance.getCheckedRadioValue(operatorArray)) {
                    throw new Error('useris-error-op');
                }
            }
 
            if (config.get('disablePinInput')) {
                return 'MSISDN';
            }
 
            if (isVoid(password)) {
                throw new Error('useris-error-pin');
            }
 
            if (!isValid(password, regexObject.pin)) {
                throw new Error('useris-error-pin');
            }
 
            return 'MSISDN';
        }
        if (isValid(username, regexObject.email) && config.get('emailIdentityEnabled')) { // EMAIL
            if (isVoid(password)) {
                throw new Error('useris-error-pin');
            }
 
            if (!isValid(password, regexObject.password)) {
                throw new Error('useris-error-pin');
            }
 
            return 'EMAIL';
        }
        if (isValid(username, regexObject.generic) && config.get('emailIdentityEnabled')) { // GENERIC
            Iif (isVoid(password)) {
                throw new Error('useris-error-pin');
            }
 
            Iif (!isValid(password, regexObject.genericPassword)) {
                throw new Error('useris-error-pin');
            }
 
            return 'GENERIC';
        }
        throw new Error('useris-error-msg');
    } else {
        throw new Error('errorNoRegex');
    }
};