function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
dlattedlatte 

Help creating a test class to test UserManagement.obfuscateUser(uid)

I would like direction on approaches to write Test Classes for UserManagement.obfuscateUser(uid) please.
My design includes a List of Portal User Ids to Obfuscate and System.enqueueJob to delete the related Contact Records.

Would it be accurate to build my test data for Portal User and related Contact in the Test Method and then issue the UserManagement.obfuscateUser(uid) method to obfuscate the Portal User and then Delete the related Contact?
Or
Would it be more accurate to use Mock Test Data instead?

Also my ideas for assertEquals would be to see if the Contact was deleted.   My knowledge of obfuscated Portal User is once they are obfuscated there is no way to access them, so I'm not certain what I would test with assertEquals for UserManagement.obfuscateUser(uid) method. 

I am developing with Test Driven Development process.
Thank you,
Donna
 
Raj VakatiRaj Vakati
Try like below
 
public class UserManagementController{
    public List <User> users {get; set;}
    
    public UserManagementController()
    {
        Profile p = [select id from profile where name = 'Customer Community User'];
        
        users = [select username, id from User where profileId=:p.id AND isactive=true];
    }
    
    static public void obfuscate(User users)
    {
        
        //User u = [select contactId from user where id=:uid];
        
        System.UserManagement.obfuscateUser(users.id);
        
        
    }
}
 
@istest
public class UserManagementController_Test {
    
    public static testMethod void testRunAs() {
        // Setup test data
        // This code runs as the system user
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
        User u = new User(Alias = 'standt', Email='asdkgahsgd@testorg.com', 
                          EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
                          LocaleSidKey='en_US', ProfileId = p.Id, 
                          TimeZoneSidKey='America/Los_Angeles', UserName='asdkgahsgd@testorg.com');
        
        UserManagementController.obfuscate(u);
    }
}