You need to sign in to do that
Don't have an account?

test class sending sms
Hi,
I can't test this class...
Any ideas?
Thankyou
I can't test this class...
public class smscontroller { //Send SMS (Routee) @AuraEnabled public static void sendsms(String WhoId, String WhatId, String testo, String destinatario){ //Get Current User MobilePhone String mittente = [Select MobilePhone From User Where Id = :UserInfo.getUserId()][0].MobilePhone; mittente = mittente.deleteWhitespace(); //Routee Authentication and Get Token Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint('https://auth.routee.net/oauth/token'); request.setMethod('POST'); request.setHeader('authorization', 'Basic xxxxxxxxxxxxxxxxx'); request.setHeader('content-type', 'application/x-www-form-urlencoded'); request.setBody('grant_type=client_credentials'); HttpResponse response = http.send(request); // Parse the JSON response if (response.getStatusCode() != 200) { System.debug('The status code returned was not expected: ' + response.getStatusCode() + ' ' + response.getStatus()); } else { System.debug(response.getBody()); String json = response.getBody(); JSONParser parser = System.JSON.createParser(json); while (parser.nextToken() != null) { if(parser.getCurrentName() == 'access_token') { parser.nextValue(); System.debug(parser.getText()); String access_token = parser.getText(); // Send SMS Http http1 = new Http(); HttpRequest request1 = new HttpRequest(); JSONGenerator body = System.JSON.createGenerator(true); body.writeStartObject(); body.writeStringField('from', mittente); body.writeStringField('to', destinatario); body.writeStringField('body',testo); body.writeEndObject(); String bodyS = body.getAsString(); request1.setEndpoint('https://connect.routee.net/sms'); request1.setMethod('POST'); request1.setHeader('authorization', 'Bearer '+ access_token); request1.setHeader('content-type', 'application/json'); request1.setBody(bodyS); HttpResponse response1 = http.send(request1); String json1 = response1.getBody(); //Insert Log Task Task Task = new Task(); task.WhoId = Whoid; task.WhatId = WhatId; task.ActivityDate = system.today(); task.Subject = json1 ; task.Description = json1; insert task; } } } } }
Any ideas?
Thankyou
1. Wrtie mock https class to test the above secnario
2. Call the above class method in regular test class
Synatax snippet
Hope this helps!