Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @isTest
- public static void testNewCaseInsert(){
- Id user = [SELECT id FROM User WHERE FirstName = 'TestUser' LIMIT 1].id;
- Id myPlusRTypeId = [SELECT id FROM RecordType WHERE developerName = 'Test_Plus' LIMIT 1].id;
- Id contactId = [SELECT id FROM Contact WHERE FirstName = 'Contact' LIMIT 1].id;
- Case caseMPlus = new Case(
- RecordTypeId = myPlusRTypeId,
- OwnerId = user,
- Status = 'New',
- Priority = 'Medium',
- ContactId = contactId,
- Origin = 'Email',
- Subject = 'Subject Mail Plus',
- Description = 'watermelons',
- );
- test.setMock(HttpCalloutMock.class, new MockResponse(caseMPlus.id));//I can't pass case Id without inserting it first
- test.startTest();
- insert caseMPlus;
- test.stopTest();
- }
- @isTest
- public class LimitlessMockResponse implements HttpCalloutMock {
- protected Id caseId;
- public LimitlessMockResponse(Id caseId){
- this.caseId = caseId;
- }
- public HTTPResponse respond(HTTPRequest req) {
- System.assertEquals('callout:Limitless', req.getEndpoint());
- System.assertEquals('POST', req.getMethod());
- HttpResponse res = new HttpResponse();
- res.setHeader('Content-Type', 'application/json');
- //trying to pass the caseId into the body to assert against the response
- res.setBody('{"count": 1,"success": 1,"failed": 0,"messages": [{"tenantMsgId":'+'"'+caseId+'","rejectReasonCode": "no group found","processCode": "ACC"}]}');
- res.setStatusCode(200);
- return res;
- }
Add Comment
Please, Sign In to add comment