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
Pedro Garcia GPedro Garcia G 

Make a Unit Test to a method which has a callout method inside

I'm running a unit test for a method which include another callout method. The callout method is already tested. How could I make the unit test?

here is the involved code
@AuraEnabled
    public static List<CAS_User_Identity__c> requestUserIdentities(String x_api_key){
        
        //THIS IS A CALLOUT METHOD
        CASConnectorIdentity results = CASConnector.getUserIdentities(x_api_key);

        if(!String.isEmpty(results.error)){
            
            throw new AuraHandledException('The Connection was not possible. Verify the API KEY!');
            
        }   
        
		//PARSE THE JSON
        List<CASConnectorIdentity.user_identities> userIdentities = (List<CASConnectorIdentity.user_identities>) results.user_identities;

        List<CAS_User_Identity__c> casUserIdentityList = new List<CAS_User_Identity__c>();
        
        for(CASConnectorIdentity.user_identities usid : userIdentities){
            
            CAS_User_Identity__c  casUserIdentity = new CAS_User_Identity__c();
            
            casUserIdentity.Id__c 			= String.valueOf(usid.id);
            casUserIdentity.institution__c 	= usid.institution;
            casUserIdentity.type__c 		= usid.type;
            casUserIdentity.organization__c = usid.organization;
            casUserIdentity.association__c	= usid.association;
            casUserIdentity.cycle__c		= usid.cycle;
            
            
            casUserIdentityList.add(casUserIdentity);
            
             
        }        
        
    
        //REMOVE ALL RECORDS AND INSERT AGAIN.
        List<CAS_User_Identity__c> userIdentitiesDB = [Select Id from CAS_User_Identity__c];        
        
        if(userIdentities.size() > 0 ){
            
            delete userIdentitiesDB;
            
            insert casUserIdentityList;
            

        }
        
		Insert
        CASProgram.insertProgram( x_api_key);
        
        return casUserIdentityList;

    }

 
Best Answer chosen by Pedro Garcia G
Pedro Garcia GPedro Garcia G
I found this: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex_testing.htm

Thanks everyone!