You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
5.8 KiB

  1. /**
  2. * @description :
  3. * @author : Adam White, CapTech Consulting
  4. * @group :
  5. * @last modified on : 08-18-2020
  6. * @last modified by : Adam White, CapTech Consulting
  7. * Modifications Log
  8. * Ver Date Author Modification
  9. * 1.0 08-18-2020 Adam White, CapTech Consulting Initial Version
  10. **/
  11. @IsTest
  12. global with sharing class MassTransactorActionTest{
  13. @TestSetup
  14. static void makeData(){
  15. List<Account> accounts = new List<Account>();
  16. // insert 10 accounts
  17. for (Integer i=0;i<10;i++) {
  18. accounts.add(new Account(name='Account '+i,
  19. billingcity='New York',
  20. billingcountry='United States',
  21. billingState = 'Virginia',
  22. billingPostalCode = '23113',
  23. BillingStreet = '12345 Hello Lane'));
  24. }
  25. insert accounts;
  26. }
  27. @IsTest
  28. static void createRecords(){
  29. List<Account> accounts = new List<Account>();
  30. // insert 10 accounts
  31. for (Integer i=0;i<10;i++) {
  32. accounts.add(new Account(name='Account '+i,
  33. billingcity='New York',
  34. billingcountry='United States',
  35. billingState = 'Virginia',
  36. billingPostalCode = '23113',
  37. BillingStreet = '12345 Hello Lane'));
  38. }
  39. List<MassTransactorAction.InvocableApexAsyncBatchRequest> flowRequests = new List<MassTransactorAction.InvocableApexAsyncBatchRequest>();
  40. MassTransactorAction.InvocableApexAsyncBatchRequest flowRequest = new MassTransactorAction.InvocableApexAsyncBatchRequest();
  41. flowRequest.BatchSize = 220;
  42. flowRequest.OperationType = 'Create';
  43. flowRequest.RequestList = accounts;
  44. flowRequests.add(flowRequest);
  45. Test.startTest();
  46. MassTransactorAction.InvocableApexCreateAsyncController(flowRequests);
  47. Test.stopTest();
  48. }
  49. @IsTest
  50. static void deleteRecords(){
  51. List<Account> accounts = [SELECT Id from Account Where Name like '%Account%'];
  52. List<MassTransactorAction.InvocableApexAsyncBatchRequest> flowRequests = new List<MassTransactorAction.InvocableApexAsyncBatchRequest>();
  53. MassTransactorAction.InvocableApexAsyncBatchRequest flowRequest = new MassTransactorAction.InvocableApexAsyncBatchRequest();
  54. flowRequest.BatchSize = 220;
  55. flowRequest.OperationType = 'Delete';
  56. flowRequest.RequestList = accounts;
  57. flowRequests.add(flowRequest);
  58. Test.startTest();
  59. MassTransactorAction.InvocableApexCreateAsyncController(flowRequests);
  60. Test.stopTest();
  61. }
  62. @IsTest
  63. static void testBatchLimit(){
  64. List<Account> accounts = [SELECT Id from Account Where Name like '%Account%'];
  65. List<MassTransactorAction.InvocableApexAsyncBatchRequest> flowRequests = new List<MassTransactorAction.InvocableApexAsyncBatchRequest>();
  66. MassTransactorAction.InvocableApexAsyncBatchRequest flowRequest = new MassTransactorAction.InvocableApexAsyncBatchRequest();
  67. flowRequest.BatchSize = 2220;
  68. flowRequest.OperationType = 'Delete';
  69. flowRequest.RequestList = accounts;
  70. flowRequests.add(flowRequest);
  71. Test.startTest();
  72. MassTransactorAction.InvocableApexCreateAsyncController(flowRequests);
  73. Test.stopTest();
  74. }
  75. @IsTest
  76. // Test creating some records where records already exist
  77. static void testBatchWrongDMLCreate(){
  78. List<Account> accounts = [SELECT Id from Account Where Name like '%Account%'];
  79. List<MassTransactorAction.InvocableApexAsyncBatchRequest> flowRequests = new List<MassTransactorAction.InvocableApexAsyncBatchRequest>();
  80. MassTransactorAction.InvocableApexAsyncBatchRequest flowRequest = new MassTransactorAction.InvocableApexAsyncBatchRequest();
  81. flowRequest.BatchSize = 200;
  82. flowRequest.OperationType = 'Create';
  83. flowRequest.RequestList = accounts;
  84. flowRequests.add(flowRequest);
  85. Test.startTest();
  86. MassTransactorAction.InvocableApexCreateAsyncController(flowRequests);
  87. Test.stopTest();
  88. }
  89. @IsTest
  90. // Test creating some records where records dont exist
  91. static void testBatchWrongDMLDelete(){
  92. List<Account> accounts = new List<Account>();
  93. // insert 10 accounts
  94. for (Integer i=0;i<10;i++) {
  95. accounts.add(new Account(name='Account '+i,
  96. billingcity='New York',
  97. billingcountry='United States',
  98. billingState = 'Virginia',
  99. billingPostalCode = '23113',
  100. BillingStreet = '12345 Hello Lane'));
  101. }
  102. List<MassTransactorAction.InvocableApexAsyncBatchRequest> flowRequests = new List<MassTransactorAction.InvocableApexAsyncBatchRequest>();
  103. MassTransactorAction.InvocableApexAsyncBatchRequest flowRequest = new MassTransactorAction.InvocableApexAsyncBatchRequest();
  104. flowRequest.BatchSize = 200;
  105. flowRequest.OperationType = 'Delete';
  106. flowRequest.RequestList = accounts;
  107. flowRequests.add(flowRequest);
  108. Test.startTest();
  109. MassTransactorAction.InvocableApexCreateAsyncController(flowRequests);
  110. Test.stopTest();
  111. }
  112. @IsTest
  113. // Test creating some records where records dont exist
  114. static void testBatchNull(){
  115. List<Account> accounts = new List<Account>();
  116. List<MassTransactorAction.InvocableApexAsyncBatchRequest> flowRequests = new List<MassTransactorAction.InvocableApexAsyncBatchRequest>();
  117. MassTransactorAction.InvocableApexAsyncBatchRequest flowRequest = new MassTransactorAction.InvocableApexAsyncBatchRequest();
  118. flowRequest.BatchSize = 200;
  119. flowRequest.OperationType = 'Delete';
  120. flowRequest.RequestList = accounts;
  121. flowRequests.add(flowRequest);
  122. Test.startTest();
  123. MassTransactorAction.InvocableApexCreateAsyncController(flowRequests);
  124. Test.stopTest();
  125. }
  126. }