Guest User

Untitled

a guest
Nov 20th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. @isTest
  2. public static void testNewCaseInsert(){
  3.  
  4. Id user = [SELECT id FROM User WHERE FirstName = 'TestUser' LIMIT 1].id;
  5.  
  6. Id myPlusRTypeId = [SELECT id FROM RecordType WHERE developerName = 'Test_Plus' LIMIT 1].id;
  7.  
  8. Id contactId = [SELECT id FROM Contact WHERE FirstName = 'Contact' LIMIT 1].id;
  9.  
  10. Case caseMPlus = new Case(
  11.  
  12. RecordTypeId = myPlusRTypeId,
  13. OwnerId = user,
  14. Status = 'New',
  15. Priority = 'Medium',
  16. ContactId = contactId,
  17. Origin = 'Email',
  18. Subject = 'Subject Mail Plus',
  19. Description = 'watermelons',
  20. );
  21.  
  22. test.setMock(HttpCalloutMock.class, new MockResponse(caseMPlus.id));//I can't pass case Id without inserting it first
  23.  
  24. test.startTest();
  25. insert caseMPlus;
  26. test.stopTest();
  27.  
  28. }
  29.  
  30. @isTest
  31. public class LimitlessMockResponse implements HttpCalloutMock {
  32.  
  33. protected Id caseId;
  34.  
  35. public LimitlessMockResponse(Id caseId){
  36.  
  37. this.caseId = caseId;
  38.  
  39. }
  40.  
  41.  
  42. public HTTPResponse respond(HTTPRequest req) {
  43.  
  44. System.assertEquals('callout:Limitless', req.getEndpoint());
  45. System.assertEquals('POST', req.getMethod());
  46.  
  47. HttpResponse res = new HttpResponse();
  48. res.setHeader('Content-Type', 'application/json');
  49. //trying to pass the caseId into the body to assert against the response
  50. res.setBody('{"count": 1,"success": 1,"failed": 0,"messages": [{"tenantMsgId":'+'"'+caseId+'","rejectReasonCode": "no group found","processCode": "ACC"}]}');
  51. res.setStatusCode(200);
  52. return res;
  53. }
Add Comment
Please, Sign In to add comment