You need to sign in to do that
Don't have an account?
Mayur Tripathi
Can someone help me with this test class, bit urgent
public class MemberVerificationLightningController { private static Account GetAccount(string accID) { List<Account> listAccount; listAccount = [select Id,OTP_Code__c,OTP_Sent_On__c, Member_Verification_OTP_Invalid_Attempt__c, FirstName, LastName, home_phone__pc, Mobile_Phone__pc, Work_Phone__pc, PersonEmail, Alternate_Email__pc from Account where ID =:accID]; if (listAccount.size() > 0) { Account acc = listAccount[0]; return acc; } return null; } private static List<KeyValuePairModel> GetPhoneList_Options(List<wrapperAccount> listWrapperAccount) { List<KeyValuePairModel> options = new List<KeyValuePairModel>(); if (listWrapperAccount != null && listWrapperAccount.size() > 0) { for (wrapperAccount a : listWrapperAccount) { if (a.fieldType == 'P') { KeyValuePairModel pair = new KeyValuePairModel(); pair.Text = a.fieldName; pair.Value = a.encryptedvalue; options.add(pair); } } system.debug('Phoneoptions-----' + options); } return options; } private static List<KeyValuePairModel> GetEmailsList_Options(List<wrapperAccount> listWrapperAccount) { List<KeyValuePairModel> options = new List<KeyValuePairModel>(); if (listWrapperAccount != null && listWrapperAccount.size() > 0) { for (wrapperAccount a : listWrapperAccount) { if (a.fieldType == 'E') { KeyValuePairModel pair = new KeyValuePairModel(); pair.Text = a.fieldName; pair.Value = a.encryptedvalue; options.add(pair); } } system.debug('Emailoptions-----' + options); } return options; } @auraenabled public static OTPVerificationModel ListOfEmailsAndPhoneNumbers(string accid) { system.debug('accid---' + accid); string Brand; Account acc = GetAccount(accID); List<string> allRelatedAccounts = GetRelatedAccountsPopulated(accid, acc); List<wrapperAccount> listWrapperAccount = new List<wrapperAccount>(); system.debug('allRelatedAccounts 4---' + allRelatedAccounts); string IsIneligibleLocal = 'false'; string NoContactInfo = 'false'; List<Account> listAccount; if (allRelatedAccounts != null && allRelatedAccounts.size() > 0) { listAccount = [select Id, Member_Verification_OTP_Invalid_Attempt__c, Home_Phone__pc, FirstName, LastName, Mobile_Phone__pc, Work_Phone__pc, PersonEmail, Alternate_Email__pc from Account where ID in :allRelatedAccounts]; listWrapperAccount = new List<wrapperAccount>(); set<string> listContacts = new set<string>(); for (Account accountLocal : listAccount) { if (accountLocal.Mobile_Phone__pc != null && accountLocal.Mobile_Phone__pc != '') { if (!listContacts.contains(accountLocal.Mobile_Phone__pc) && accountLocal.id == acc.id) { wrapperAccount accLocal = new wrapperAccount(); accLocal.fieldType = 'P'; accLocal.value = accountLocal.Mobile_Phone__pc; accLocal.encryptedvalue = encryptPhone(accountLocal.Mobile_Phone__pc); accLocal.fieldName = 'Mobile_Phone__pc - ' + accountLocal.Id; listWrapperAccount.Add(accLocal); listContacts.add(accountLocal.Mobile_Phone__pc); } } } for (Account accountLocal : listAccount) { if (accountLocal.Home_Phone__pc != null && accountLocal.Home_Phone__pc != '') { if (!listContacts.contains(accountLocal.Home_Phone__pc) && accountLocal.id == acc.id) { wrapperAccount accLocal = new wrapperAccount(); accLocal.fieldType = 'P'; accLocal.value = accountLocal.Home_Phone__pc; accLocal.encryptedvalue = encryptPhone(accountLocal.Home_Phone__pc); accLocal.fieldName = 'Home_Phone__pc - ' + accountLocal.Id; listWrapperAccount.Add(accLocal); listContacts.add(accountLocal.Home_Phone__pc); } } } for (Account accountLocal : listAccount) { if (accountLocal.Work_Phone__pc != null && accountLocal.Work_Phone__pc != '') { if (!listContacts.contains(accountLocal.Work_Phone__pc) && accountLocal.id == acc.id) { wrapperAccount accLocal = new wrapperAccount(); accLocal.fieldType = 'P'; accLocal.value = accountLocal.Work_Phone__pc; accLocal.encryptedvalue = encryptPhone(accountLocal.Work_Phone__pc); accLocal.fieldName = 'Work_Phone__pc - ' + accountLocal.Id; listWrapperAccount.Add(accLocal); listContacts.add(accountLocal.Work_Phone__pc); } } } for (Account accountLocal : listAccount) { if (accountLocal.PersonEmail != null && accountLocal.PersonEmail != '') { if (!listContacts.contains(accountLocal.PersonEmail) && accountLocal.id == acc.id) { wrapperAccount accLocal = new wrapperAccount(); accLocal.fieldType = 'E'; accLocal.value = accountLocal.PersonEmail; accLocal.encryptedvalue = encryptEmail(accountLocal.PersonEmail); accLocal.fieldName = 'PersonEmail - ' + accountLocal.Id; listWrapperAccount.Add(accLocal); listContacts.add(accountLocal.PersonEmail); } } } for (Account accountLocal : listAccount) { if (accountLocal.Alternate_Email__pc != null && accountLocal.Alternate_Email__pc != '') { if (!listContacts.contains(accountLocal.Alternate_Email__pc) && accountLocal.id == acc.id) { wrapperAccount accLocal = new wrapperAccount(); accLocal.fieldType = 'E'; accLocal.value = accountLocal.Alternate_Email__pc; accLocal.encryptedvalue = encryptEmail(accountLocal.Alternate_Email__pc); accLocal.fieldName = 'Alternate_Email__pc - ' + accountLocal.Id; listWrapperAccount.Add(accLocal); listContacts.Add(accountLocal.Alternate_Email__pc); } } } for (Account accountLocal : listAccount) { if (accountLocal.Mobile_Phone__pc != null && accountLocal.Mobile_Phone__pc != '') { if (!listContacts.contains(accountLocal.Mobile_Phone__pc) && accountLocal.id != acc.id) { wrapperAccount accLocal = new wrapperAccount(); accLocal.fieldType = 'P'; accLocal.value = accountLocal.Mobile_Phone__pc; accLocal.encryptedvalue = encryptPhone(accountLocal.Mobile_Phone__pc); accLocal.fieldName = 'Mobile_Phone__pc - ' + accountLocal.Id; listWrapperAccount.Add(accLocal); listContacts.add(accountLocal.Mobile_Phone__pc); } } } for (Account accountLocal : listAccount) { if (accountLocal.Home_Phone__pc != null && accountLocal.Home_Phone__pc != '') { if (!listContacts.contains(accountLocal.Home_Phone__pc) && accountLocal.id != acc.id) { wrapperAccount accLocal = new wrapperAccount(); accLocal.fieldType = 'P'; accLocal.value = accountLocal.Home_Phone__pc; accLocal.encryptedvalue = encryptPhone(accountLocal.Home_Phone__pc); accLocal.fieldName = 'Home_Phone__pc - ' + accountLocal.Id; listWrapperAccount.Add(accLocal); listContacts.add(accountLocal.Home_Phone__pc); } } } for (Account accountLocal : listAccount) { if (accountLocal.Work_Phone__pc != null && accountLocal.Work_Phone__pc != '') { if (!listContacts.contains(accountLocal.Work_Phone__pc) && accountLocal.id != acc.id) { wrapperAccount accLocal = new wrapperAccount(); accLocal.fieldType = 'P'; accLocal.value = accountLocal.Work_Phone__pc; accLocal.encryptedvalue = encryptPhone(accountLocal.Work_Phone__pc); accLocal.fieldName = 'Work_Phone__pc - ' + accountLocal.Id; listWrapperAccount.Add(accLocal); listContacts.add(accountLocal.Work_Phone__pc); } } } for (Account accountLocal : listAccount) { if (accountLocal.PersonEmail != null && accountLocal.PersonEmail != '') { if (!listContacts.contains(accountLocal.PersonEmail) && accountLocal.id != acc.id) { wrapperAccount accLocal = new wrapperAccount(); accLocal.fieldType = 'E'; accLocal.value = accountLocal.PersonEmail; accLocal.encryptedvalue = encryptEmail(accountLocal.PersonEmail); accLocal.fieldName = 'PersonEmail - ' + accountLocal.Id; listWrapperAccount.Add(accLocal); listContacts.add(accountLocal.PersonEmail); } } } for (Account accountLocal : listAccount) { if (accountLocal.Alternate_Email__pc != null && accountLocal.Alternate_Email__pc != '') { if (!listContacts.contains(accountLocal.Alternate_Email__pc) && accountLocal.id != acc.id) { wrapperAccount accLocal = new wrapperAccount(); accLocal.fieldType = 'E'; accLocal.value = accountLocal.Alternate_Email__pc; accLocal.encryptedvalue = encryptEmail(accountLocal.Alternate_Email__pc); accLocal.fieldName = 'Alternate_Email__pc - ' + accountLocal.Id; listWrapperAccount.Add(accLocal); listContacts.Add(accountLocal.Alternate_Email__pc); } } } } if (listWrapperAccount.size() == 0) { SaveNoContactInfoLog(acc); } else { list<string> accids = GetAccIdsPopulated(accID, acc); system.debug('accids---' + accids); list<Account_Details__c> listAccountDetails = [select Id, Comments_Block__c, Brand__c, Comment_Block_01__c, Comment_Block_02__c, Comment_Block_03__c, Comment_Block_04__c, Comment_Block_05__c, Comment_Block_06__c, Comment_Block_07__c, Comment_Block_08__c, Comment_Block_09__c, Comment_Block_10__c, Comment_Block_11__c, Comment_Block_12__c, Comment_Block_13__c, Comment_Block_14__c, Comment_Block_15__c, Comment_Block_16__c, Comment_Block_17__c, Comment_Block_18__c, Comment_Block_19__c, Comment_Block_20__c from Account_Details__c where Id in: accids]; list<string> wcwList = new list<string>(); if (listAccountDetails.Size() > 0) { Brand = listAccountDetails[0].Brand__c; for (Account_Details__c var: listAccountDetails) { if (var.Comment_Block_01__c != NULL || var.Comment_Block_01__c != '') { wcwList.add(var.Comment_Block_01__c); } if (var.Comment_Block_02__c != NULL || var.Comment_Block_02__c != '') { wcwList.add(var.Comment_Block_02__c); } if (var.Comment_Block_03__c != NULL || var.Comment_Block_03__c != '') { wcwList.add(var.Comment_Block_03__c); } if (var.Comment_Block_04__c != NULL || var.Comment_Block_04__c != '') { wcwList.add(var.Comment_Block_04__c); } if (var.Comment_Block_05__c != NULL || var.Comment_Block_05__c != '') { wcwList.add(var.Comment_Block_05__c); } if (var.Comment_Block_06__c != NULL || var.Comment_Block_06__c != '') { wcwList.add(var.Comment_Block_06__c); } if (var.Comment_Block_07__c != NULL || var.Comment_Block_07__c != '') { wcwList.add(var.Comment_Block_07__c); } if (var.Comment_Block_08__c != NULL || var.Comment_Block_08__c != '') { wcwList.add(var.Comment_Block_08__c); } if (var.Comment_Block_09__c != NULL || var.Comment_Block_09__c != '') { wcwList.add(var.Comment_Block_09__c); } if (var.Comment_Block_10__c != NULL || var.Comment_Block_10__c != '') { wcwList.add(var.Comment_Block_10__c); } if (var.Comment_Block_11__c != NULL || var.Comment_Block_11__c != '') { wcwList.add(var.Comment_Block_11__c); } if (var.Comment_Block_12__c != NULL || var.Comment_Block_12__c != '') { wcwList.add(var.Comment_Block_12__c); } if (var.Comment_Block_13__c != NULL || var.Comment_Block_13__c != '') { wcwList.add(var.Comment_Block_13__c); } if (var.Comment_Block_14__c != NULL || var.Comment_Block_14__c != '') { wcwList.add(var.Comment_Block_14__c); } if (var.Comment_Block_15__c != NULL || var.Comment_Block_15__c != '') { wcwList.add(var.Comment_Block_15__c); } if (var.Comment_Block_16__c != NULL || var.Comment_Block_16__c != '') { wcwList.add(var.Comment_Block_16__c); } if (var.Comment_Block_17__c != NULL || var.Comment_Block_17__c != '') { wcwList.add(var.Comment_Block_17__c); } if (var.Comment_Block_18__c != NULL || var.Comment_Block_18__c != '') { wcwList.add(var.Comment_Block_18__c); } if (var.Comment_Block_19__c != NULL || var.Comment_Block_19__c != '') { wcwList.add(var.Comment_Block_19__c); } if (var.Comment_Block_20__c != NULL || var.Comment_Block_20__c != '') { wcwList.add(var.Comment_Block_20__c); } } if (wcwList.size() > 0) { for (string str : wcwList) { if (str != null && str.Contains('TELEPHONE/EMAIL CHANGED WITHIN 60 DAYS')) { Authenticated_Log__c log = new Authenticated_Log__c(); log.SalesforceID__c = acc.Id; log.First_Name__c = acc.FirstName; log.Last_Name__c = acc.LastName; log.Staff_Name__c = UserInfo.getName(); log.Decision__c = 'OTP – Not Eligible'; insert log; acc.Member_Verification_OTP_Invalid_Attempt__c = system.now(); update acc; System.Debug('not eligible---' + acc.id); IsIneligibleLocal = 'true'; } } } } } List<KeyValuePairModel> listPhoneList = GetPhoneList_Options(listWrapperAccount); List<KeyValuePairModel> listEmailList = GetEmailsList_Options(listWrapperAccount); OTPVerificationModel obj = new OTPVerificationModel(); obj.IsIneligible = IsIneligibleLocal; obj.Brand = Brand; obj.PhoneList_Options = GetPhoneList_Options(listWrapperAccount); obj.EmailsList_Options = GetEmailsList_Options(listWrapperAccount); system.debug('obj---' + obj); return obj; } @auraenabled public static void DeclineOTPAtFirstStep(string accid) { Account acc = GetAccount(accid); Authenticated_Log__c log = new Authenticated_Log__c(); log.SalesforceID__c = acc.Id; log.First_Name__c = acc.FirstName; log.Last_Name__c = acc.LastName; log.Staff_Name__c = UserInfo.getName(); log.Decision__c = 'OTP – Contact Unconfirmed'; insert log; acc.Member_Verification_OTP_Invalid_Attempt__c = system.now(); update acc; } private static void SaveNoContactInfoLog(Account acc) { Authenticated_Log__c log = new Authenticated_Log__c(); system.debug('SalesForceID =' + acc.Id); log.SalesforceID__c = acc.Id; log.First_Name__c = acc.FirstName; log.Last_Name__c = acc.LastName; log.Staff_Name__c = UserInfo.getName(); System.debug('log No Contact Info ' + log); upsert log; log.Decision__c = 'OTP - No Contact Info'; update log; } public static string encryptPhone(string value) { value = 'xxx-xxx-' + value.right(4); return value; } public static string encryptEmail(string value) { List<String> listStr = value.split('@'); string finalNumber = listStr[0].substring(0, 1) + '*****' + +listStr[0].substring(listStr[0].length() - 1, listStr[0].length()) + '@' + listStr[1]; //= listStr[0].substring return finalNumber; } public class wrapperAccount { public string fieldName { get; set; } public string fieldType { get; set; } public string value { get; set; } public string encryptedvalue { get; set; } } public class warningCodeWrapper { public string comms { get; set; } public warningCodeWrapper(string var) { comms = var; } } @auraenabled public static KeyValuePairModel GenerateRandomOTP(string fieldName, string BrandName, string resend, string accid) { List<String> listStr = fieldName.split(' - '); string field = listStr[0]; string accountid = listStr[1]; string phone = ''; string email = ''; boolean IsEmail = false; Account accEmailTOSend = [select Id, Member_Verification_OTP_Invalid_Attempt__c, Home_Phone__pc, FirstName, LastName, Mobile_Phone__pc, Work_Phone__pc, PersonEmail, Alternate_Email__pc from Account where ID =: accountid]; if (field == 'Home_Phone__pc') { phone = accEmailTOSend.Home_Phone__pc; } else if (field == 'Mobile_Phone__pc') { phone = accEmailTOSend.Mobile_Phone__pc; } else if (field == 'Work_Phone__pc') { phone = accEmailTOSend.Work_Phone__pc; } else if (field == 'PersonEmail') { email = accEmailTOSend.PersonEmail; IsEmail = true; } else if (field == 'Alternate_Email__pc') { email = accEmailTOSend.Alternate_Email__pc; IsEmail = true; } string RandomNumber = String.valueOf(Math.random()); RandomNumber= RandomNumber.substring(2,8); Account acc = GetAccount(accid); if(IsEmail) { SendOTPEmail(RandomNumber, email, BrandName, acc); } else { SendSMS(phone, string.valueof(RandomNumber), 'SMS - User', BrandName, acc); } system.debug('keyvaluemodel1---'); KeyValuePairModel keyvaluemodel = new KeyValuePairModel(); system.debug('keyvaluemodel2---' + keyvaluemodel ); keyvaluemodel.Text = EncryptString(RandomNumber); keyvaluemodel.Value = EncryptString(string.valueof( system.now())); system.debug('keyvaluemodel3---' + keyvaluemodel ); Authenticated_Log__c log = new Authenticated_Log__c(); log.SalesforceID__c = acc.Id; log.First_Name__c = acc.FirstName; log.Last_Name__c = acc.LastName; log.Staff_Name__c = UserInfo.getName(); if(IsEmail) { log.OTP_Email__c = email; } else { log.OTP_Phone__c = phone; } if(resend == 'true') { log.Decision__c = 'OTP – Code Resent'; } else { log.Decision__c = 'OTP – Code Sent'; } insert log; system.debug('keyvaluemodel4---' + keyvaluemodel ); return keyvaluemodel; } @auraenabled public static string verifyOTP(string accid, string EnteredOTP, string fieldName, string model) { system.debug('--verify OTP start--'); string fieldValue = fieldName; List<String> listStr = fieldValue.split(' - '); string field = listStr[0]; string accountid = listStr[1]; string phone = ''; string email = ''; boolean IsEmail = false; Account accEmailTOSend = [select Id, Member_Verification_OTP_Invalid_Attempt__c, Home_Phone__pc, FirstName, LastName, Mobile_Phone__pc, Work_Phone__pc, PersonEmail, Alternate_Email__pc from Account where ID =: accountid]; system.debug('field - ' + field); if (field == 'Home_Phone__pc') { phone = accEmailTOSend.Home_Phone__pc; } else if (field == 'Mobile_Phone__pc') { phone = accEmailTOSend.Mobile_Phone__pc; } else if (field == 'Work_Phone__pc') { phone = accEmailTOSend.Work_Phone__pc; } else if (field == 'PersonEmail') { email = accEmailTOSend.PersonEmail; IsEmail = true; } else if (field == 'Alternate_Email__pc') { email = accEmailTOSend.Alternate_Email__pc; IsEmail = true; } system.debug('email - ' + email); OTPSettings__c data1 = OTPSettings__c.getValues('Member Verification'); integer OTPExpiresAfterSeconds = integer.valueOf(data1.OTPExpirationSeconds__c); system.debug('OTPExpiresAfterSeconds - ' + OTPExpiresAfterSeconds); string Verified = ''; system.debug('DencryptString--- Start'); KeyValuePairModel newmodel = (KeyValuePairModel)JSON.deserialize(model, KeyValuePairModel.class); system.debug('decrypted date string - ' + DencryptString(newmodel.Value)); Datetime LastOTPSent = Datetime.valueOf(DencryptString(newmodel.Value)); system.debug('DencryptString--- LastOTPSent' + LastOTPSent); string RandomNumber = DencryptString(newmodel.Text); system.debug('DencryptString--- RandomNumber' + RandomNumber); Account acc = GetAccount(accid); Long startTime = LastOTPSent.getTime(); Long endTime = System.Now().getTime(); Long milliseconds = endTime - startTime; Long seconds = milliseconds / 1000; Authenticated_Log__c log = new Authenticated_Log__c(); log.SalesforceID__c = acc.Id; log.First_Name__c = acc.FirstName; log.Last_Name__c = acc.LastName; if(IsEmail) { log.OTP_Email__c = email; } else { log.OTP_Phone__c = phone; } log.Staff_Name__c = UserInfo.getName(); system.debug('seconds ---' + seconds); system.debug('OTPExpiresAfterSeconds ---' + OTPExpiresAfterSeconds); if(seconds >= OTPExpiresAfterSeconds) { Verified = 'Expired'; acc.Member_Verification_OTP_Invalid_Attempt__c = system.now(); update acc; log.Decision__c = 'OTP – Code Expired'; } else if(EnteredOTP == RandomNumber) { //acc.Member_Verification_OTP_Invalid_Attempt__c = null; //update acc; log.Decision__c = 'OTP – Code valid'; Verified = 'Valid'; } else { acc.Member_Verification_OTP_Invalid_Attempt__c = system.now(); update acc; log.Decision__c = 'OTP – Code Failed'; Verified = 'Invalid'; } insert log; return Verified; } }
https://appexchange.salesforce.com/listingDetail?listingId=a0N3A00000EFozgUAD
I hope it will be helpful.
Please mark it as best answer if the information is informative.
Thanks & Regards
Gopal M.
I ahve installed this from appexchange but still the test class coverage is not there, can you please help me if possible.
Skype: mayurtripathi55@hotmail.com