Skip to content

Instantly share code, notes, and snippets.

@britishboyindc
Last active March 14, 2019 22:52
Show Gist options
  • Save britishboyindc/c8f82d7aee18f85a715178017cbeab3a to your computer and use it in GitHub Desktop.
Save britishboyindc/c8f82d7aee18f85a715178017cbeab3a to your computer and use it in GitHub Desktop.
Logged in User Test Class
@isTest
public class CommunityController_TEST {
@isTest
private static void testContactUser() {
//You'll need to use an actual Profile name in your org
Id p = [select id from profile where name='Customer Community User'].id;
Account ac = new Account(name ='Test Community One') ;
insert ac;
Contact con = new Contact(LastName ='testCon',AccountId = ac.Id);
insert con;
User user = new User(alias = 'test123', email='[email protected]',
emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
localesidkey='en_US', profileid = p, country='United States',IsActive =true,
ContactId = con.Id,
timezonesidkey='America/Los_Angeles', username='[email protected]');
insert user;
system.runAs(user) {
User testUser = CommunityController.getLoggedInUser();
system.assertequals(testUser.Id, user.Id);
system.assertequals(testUser.Contact.AccountId, ac.Id);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment