You need to sign in to do that
Don't have an account?
Sahil Yadav
Apex Test Class Code Coverage Issue
Hello Folks,
I will be facing some test coverage related issue which I tried in multiple ways but still stuck on this Hopefully our community will help me to make understand where I did something wrong
This is the error which i am getting exactly but not able to relate what exactly its means to say
on the second image this piece of line is not been getting covered
any help would be highl appreciated
I will be facing some test coverage related issue which I tried in multiple ways but still stuck on this Hopefully our community will help me to make understand where I did something wrong
Apex Class :- GetTeamsMeetingURL global class GetTeamsMeetingURL { @InvocableMethod(label='Get MS Teams Meeting URL' description='Returns a meeting URL For MS Teams') //global static List<String> makeApiCallout(List<List<String>> inputTeamsParms) global static List<String> makeApiCallout() { // Setup the HTTP Initial Request HttpRequest req = new HttpRequest(); Http http = new Http(); //Setup the Headers, format the body, and call the MS Graph API req.setEndpoint('callout:MS_Azure_OnlineMeeting'); req.setMethod('POST'); req.setHeader('Content-Type','application/json'); req.setHeader('Accept','*/*'); req.setHeader('Accept-Encoding','gzip, deflate, br'); /* Setup the Parameters for Meetings, subject, etc. */ // Note: The initial demo only utilized title, further development can use other inputs. /* system.debug('Array size =' + inputTeamsParms.get(0).size()); String inTitle = '"' + inputTeamsParms.get(0).get(0) + '"'; system.debug('inTitle =' + inTitle); String inAgenda = '"' + inputTeamsParms.get(0).get(0) + '"'; system.debug('inAgenda =' + inAgenda); String inPwd = '"' + inputTeamsParms.get(0).get(1) + '"'; system.debug('inPwd =' + inPwd); String inStart = '"' + inputTeamsParms.get(0).get(2) + '"'; system.debug('inStart =' + inStart); String inEnd = '"' + inputTeamsParms.get(0).get(3) + '"'; system.debug('inEnd =' + inEnd);*/ // Setup the Body String reqHTTPString = ''; //reqHTTPString = '{"subject":' + inTitle +'}'; //reqHTTPString = '{"Subject":' + "DDI Training Registration"}' reqHTTPString = '{"Subject":"DDI Training Registration"}'; req.setBody(reqHTTPString); System.debug('The Request Body' +reqHTTPString); /* Send request to MS Teams Server */ HTTPResponse res = http.send(req); System.debug('The Response' +res); System.debug('The Response Body Is : '+res.getBody()); /* Parse Response from MS Team Server */ JSONParser parser = JSON.createParser(res.getBody()); String webLink; webLink = 'MSTeamsNotSetup'; System.debug(weblink); System.debug('The Parser :'+parser); while (parser.nextToken() != null) { if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'joinWebUrl')) { parser.nextToken(); System.debug('@@ParserNextToken' +parser.nextToken()); System.debug('@@' +parser.getText()); webLink = parser.getText(); System.debug('Weblink' +webLink); System.debug('joinWebUrl= ' + webLink); } } // Apex Actions Return. The method signature for invocable method requires a List of Strings to be returned. // System.debug('Weblink: '+webLink); return new List<String>{webLink}; } }
HttpMockClass :- HttpMockFactory @isTest global class HttpMockFactory implements HttpCalloutMock{ protected Integer Code; protected String Status; protected String Body; public HttpMockFactory(Integer Code, String Status, String Body){ this.Code = Code; this.Status = Status; this.Body = Body; } public HttpResponse respond(HttpRequest req){ HttpResponse response = new HttpResponse(); response.setStatusCode(this.Code); response.setStatus(this.Status); response.setBody(this.Body); return response; } }
Test Class :- TestAzure @istest public class TestAzure { /* Test Method for Unit Testing Connection */ @istest public static String getMeetingUrl() { HttpMockFactory mock = new HttpMockFactory(200 ,'OK','Result Found'); Test.setMock(HttpCalloutMock.class, mock); GetTeamsMeetingURL.makeApiCallout(); // System.assertEquals(result, 'Result Found'); HttpRequest req = new HttpRequest(); Http http = new Http(); //Setup the Endpoint and append the name of the file req.setEndpoint('callout:MS_Azure_OnlineMeeting'); //req.setEndpoint('https://graph.microsoft.com/v1.0/me/onlineMeetings'); req.setMethod('POST'); req.setHeader('Content-Type','application/json'); req.setHeader('Accept','*/*'); req.setHeader('Accept-Encoding','gzip, deflate, br'); //Setup the JSON Body - in the test just set a subject, can add more through Postman or other tests req.setBody('{"subject":"Delegated User Test Meeting"}'); //req.setBody('{}'); System.debug('Body: ' + req.getBody()); System.debug('Endpoint Value: '+ req.getEndpoint()); System.debug('Request: ' + req); HTTPResponse res = http.send(req); System.debug('Response Body: '+res.getBody()); /* Parse Response */ JSONParser parser = JSON.createParser(res.getBody()); String webLink; webLink = 'MSTeamsNotSetup'; while (parser.nextToken() != null) { if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'joinWebUrl')) { parser.nextToken(); webLink = parser.getText(); System.debug('joinWebUrl= ' + webLink); } } return webLink; } }Code Coverage which I will be getting is 80% but the test class is still failing .
This is the error which i am getting exactly but not able to relate what exactly its means to say
on the second image this piece of line is not been getting covered
any help would be highl appreciated