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
Miriam LückeMiriam Lücke 

http request test coverage problems

I have a http request method and I can't figure out how to cover my code. Can anybody help?
public static String basicAuthCallout(String PaymillToken, String Endpoint)
	{
		String PrivateKey = 'private';
		String PaymentId = 'wrong';
		HttpRequest req = new HttpRequest();
 		req.setEndpoint(Endpoint);
 		req.setMethod('POST');

 		//Set token for http request
 		req.SetBody('token='+PaymillToken);
 		system.debug(req.getBody());

		 // Specify the required password to access the endpoint (Private key)
		 // As well as the header and header information
			
		 Blob headerValue = Blob.valueOf(PrivateKey);
		 String authorizationHeader = 'BASIC ' +
		 EncodingUtil.base64Encode(headerValue);
		 req.setHeader('Authorization', authorizationHeader);
		
		 // Create a new http object to send the request object
		 // A response object is generated as a result of the request  

		system.debug(req);
		Http http = new Http();
		HTTPResponse res = http.send(req);
		String response = res.getBody();
		System.debug(response);
		integer startPoint = response.IndexOf('pay');
		if(startPoint > 0)
		{
			String temp = response.subString(startPoint);
			integer EndString = startPoint + temp.IndexOf('\",');
			PaymentId = response.subString(startPoint, EndString);
			system.debug(PaymentId);
		}
		
		return PaymentId;
	}

 
pconpcon
You'll want to read up on these two articles.  Afterwards, if you have any specific issues, please include any tests that you have written and we can try to help you figure it out.

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http_testing_static.htm
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http_testing_httpcalloutmock.htm