Trying to wrap my head around this one.
I have a custom object managed by an apex class that has a Process defined along with it. This process has an immediate action that calls an apex class that effectively does equivalent of webhook.
When I write a testClass for it, doing a basic CRUD test, it fails with this message: Methods defined as TestMethod do not support Web service callouts
How does one write a testcase for this?
adding some code:
public class with sharing WebHook {
public class Ids {
@InvokableVariable(label='Id')
public String idfield;
}
@InvokableMethod
public static void postIt(List<Ids> ids) {
Ids aid = ids[0];
Map<String, String> m = new Map(...);
m.put('idfield', aid.idfield);
System.enqueueJob(new QueueableCall('http://localhost:8000', 'POST', JSON.serialize(m)));
}
public class QueueableCall implements System.Queueable, Database.AllowsCallouts {
private final String url;
private final String method;
private final String body;
public QueueableCall(String url, String method, String body) {
this.url = url;
this.method = method;
this.body = body;
}
public void execute(System.QueueableContext ctx) {
HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod(method);
req.setBody(body);
Http http = new Http();
HttpResponse res = http.send(req);
}
}
}
public class with sharing ClassA {
public static void addA(String a, String b) {
ObjA a = new ObjA();
a.a = a;
a.b = b;
insert(a);
}
}
I'm trying to write a testclass for ClassA and it's erroring with message at top. How do I write tests for WebHook and QueueableCall to complete this test?