0

I am trying to write a test class for a @future method which makes a REST callout whose response is just 200 {"status" : "ok"}. It does not make any updates to records. I am finding it difficult to assert the test. I do have a mockResponse but not able to access it as the method it void.

@future(Callout=true)
 public static void deleteLogCallout() {
    Http h = new Http();
    HttpRequest req = new HttpRequest();
    req.setEndpoint('https://abc/transcripts');
    req.setMethod('DELETE');
    req.setHeader('x-api-key', 'xyz');
    h.send(req);
   }
@IsTest
    private static void testDeleteLog() {

        Test.startTest();
        Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator());
        ChatLog.deleteLog();
        Test.stopTest();
        System.assertEquals('?','?');
    }

Does anyone have any ideas on how to write the asserts for it?

4

In unit tests, you generally make assertions on the output and the result of running a piece of code.

Given the name of the thing you're testing (Chatlog.deleteLog()), I'd assume there is a chat log you should be deleting. You want to assert that the intended log is actually deleted (done by querying before and after running the target piece of code) if that log is stored in Salesforce.

As for the callout, the only things we should test are the things that we have control over (and within Salesforce). That means the callout process and the logic run by that third party service are out of scope for this test. About the only thing that you do have control over here is whether a callout is made or not.

You can make an assertion against whether a callout was made or not (use Limits.getCallouts() before and after, or have your mock set a static variable that you can check).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.