I need to create a test class for the below mentioned class so far I am getting the error "List has no rows for assignment ".Here customer address is an object whose parent is contact
Public with sharing class WelcomePageController {
Public WelcomePageController (){
}
Public String getCustomerAddressId() {
Id runningUserid=userinfo.getUserid();
User user=[SELECT ID,ContactId FROM User WHERE IsActive=True AND ID=:runningUserid];
system.debug('user@@@@@'+user);
Contact contact=[SELECT ID FROM Contact WHERE ID=:user.ContactId ];
system.debug('contact@@@@@'+contact);
Customer_Address__c customerAddress=[SELECT ID,Customer__c,Customer_Address_ID__c FROM Customer_Address__c WHERE Customer__c =:contact.Id ];
system.debug('customerAddress@@@@@'+customerAddress);
return customerAddress.Customer_Address_ID__c ;
}
Public PageReference finishRegistration() {
PageReference page = new PageReference('/apex/Dashboard');
page.setredirect(true);
return page;
}
}
Test Class
@isTest(seeAlldata=False)
public class WelcomePageController_Test {
@isTest
public static void testWelcomePageController(){
Profile profile = [SELECT Id,Name FROM Profile WHERE Name='Customer Community Login User'];
Account account = new Account(Name='Test Account Name');
insert account;
Contact contact=new Contact();
contact.LastName='Test';
contact.AccountId=account.Id;
insert contact;
User user=new User();
user.Email='[email protected]';
user.Username='[email protected]';
user.LastName='Test';
user.Alias='testf';
user.CommunityNickname='[email protected]';
user.TimeZoneSidKey='America/Los_Angeles';
user.EmailEncodingKey='UTF-8';
user.LocaleSidKey='en_US';
user.ProfileId=profile.Id;
user.LanguageLocaleKey='en_US';
user.ContactId=contact.id;
user.IsActive = true;
//user.UserRole=;
insert user;
WelcomePageController welcomePageController = new WelcomePageController();
//welcomePageController.runningUserid='005P0000001bEjB';
WelcomePageController.finishRegistration();
WelcomePageController.getCustomerAddressId();
}
}