I'm trying to write the test class for a method like this.
@AuraEnabled
public static DynamicTableMapping getFilteredAccounts(String filterId){
List<string> headervalue = new List<string>();
String nombreLista = [SELECT Id, Name FROM ListView WHERE Id = :filterId].Name;
HttpRequest req = new HttpRequest();
String baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
String endPoinURL = baseUrl+'/services/data/v45.0/sobjects/Account/listviews/'+filterId+'/describe';
req.setEndpoint(endPoinURL);
req.setMethod('GET');
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
Http http = new Http();
HTTPResponse response = http.send(req);
Map<String, Object> tokenResponse = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
String query = (String) tokenResponse.get('query');
System.debug('query --> ' + query);
for(string s:query.split(',')){
s = s.trim();
if(s.startsWith('SELECT')){
headervalue.add((s.removeStart('SELECT')).trim());
}else if(!s.startsWith('SYSTEMMODSTAMP') && !s.equalsIgnoreCase('SYSTEMMODSTAMP FROM ACCOUNT ORDER BY NAME ASC NULLS FIRST') && !s.contains('ASC')){
headervalue.add(s.trim());
}
}
return new DynamicTableMapping(headervalue);
}
The problem is that I'm getting this error: Method defined as testmethod does not support web service callouts. I've read this answer but I dont understand how to implement the solution: Method defined as testMethod do not support web service callouts, test skipped
What can I do to pass the cover for my method? My method DOESN'T RETURN a http response so I don't know how to make the mock properly. All examples I've found returns a http response...
Thanks in advance
http.send()
.