How We can Write Test Class for this Method.
public static String authMethod(){
Pardot_Credential_Setting__c objSetting = customSetting();
if(objSetting != null){
String email = objSetting.Pardot_Email__c;
String password = objSetting.Pardot_Password__c;
String userKey = objSetting.User_Api_Key__c;
HttpRequest req = new HttpRequest();
req.setEndpoint( objSetting.Pardot_BaseUrl__c+'/api/login/version/4' );
req.setMethod( 'POST' );
req.setBody( 'email=' + email + '&password=' + password + '&user_key=' + userKey );
HttpResponse res = new Http().send( req );
System.debug('>>>>>>>>res'+ res );
System.debug('>>>>>>>>>res.getStatus()'+ res.getStatus() );
System.debug('>>>>>>res.getBody()'+ res.getBody() );
String response = res.getBody();
Integer startIdx;
Integer endIdx;
String apiKey;
if(response.contains('<api_key>')){
startIdx = response.indexOf( '<api_key>' ) + 9;
endIdx = response.indexOf( '</api_key>' );
apiKey = response.substring( startIdx, endIdx );
System.debug( '>>>>>>>apiKey'+ apiKey );
return apiKey;
}
}
return null;
}