You need to sign in to do that
Don't have an account?
AntonPavlov
write test class for htttp request
Help to write test class for htttp request I i can't figure it out
public with sharing class currencyRates {
@AuraEnabled
public static List<Object> getRates(){
String requestData='https://www.nbrb.by/api/exrates/rates?periodicity=0';
Http http =new Http();
HttpRequest request = new HttpRequest();
request.setEndPoint(requestData);
request.setMethod('GET');
HttpResponse response = http.send(request);
List<Object> result =null;
if(response.getStatusCode()==200){
result =(List<Object>)JSON.deserializeUntyped(response.getBody());
}else{
ApexPages.Message mes =new ApexPages.Message(ApexPages.Severity.ERROR,'There was an error in reading Data');
}
return result;
}
}
public with sharing class currencyRates {
@AuraEnabled
public static List<Object> getRates(){
String requestData='https://www.nbrb.by/api/exrates/rates?periodicity=0';
Http http =new Http();
HttpRequest request = new HttpRequest();
request.setEndPoint(requestData);
request.setMethod('GET');
HttpResponse response = http.send(request);
List<Object> result =null;
if(response.getStatusCode()==200){
result =(List<Object>)JSON.deserializeUntyped(response.getBody());
}else{
ApexPages.Message mes =new ApexPages.Message(ApexPages.Severity.ERROR,'There was an error in reading Data');
}
return result;
}
}
1. Create a new mock apex class for httprequest:
2. Create the below test class:
Thanks,
Maharajan.C
All Answers
>> https://salesforce.stackexchange.com/questions/273737/rest-callout-test-class-how-to-cover-auraenabled-method
The above link has an example of a test class for an auraenabled class with HTTP callout can you try implementing a test class and see if it works?
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
1. Create a new mock apex class for httprequest:
2. Create the below test class:
Thanks,
Maharajan.C