fork download
  1. /**
  2. * @description Test class to test the functionality of class CaseServiceHlpr.
  3. */
  4. @isTest
  5. private class CaseServiceHlprTest {
  6.  
  7. @isTest
  8. private static void storeSloInformationInMemory() {
  9. Account acc = ServicesTestUtil.createAccount('test account 1', null, true);
  10. Case caseWithoutEntitlement = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, acc.Id, null, false);
  11. Case caseWithEntitlement = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, acc.Id, null, false);
  12. List<Case> caseList = new List<Case>{caseWithEntitlement, caseWithoutEntitlement};
  13. insert caseList;
  14. //reset the map before the actual test.
  15. MilestoneTimeCalculator.casesById = new Map<Id, Case>();
  16. caseWithEntitlement.EntitlementId = '000000000000000000';
  17. caseWithoutEntitlement.EntitlementId = null;
  18. Test.startTest();
  19. CaseServiceHlpr.storeSloInformationInMemory(caseList);
  20. Test.stopTest();
  21. Assert.isNotNull(MilestoneTimeCalculator.casesById, 'Expected Milestone Case Map to be populated.');
  22. Assert.isTrue(MilestoneTimeCalculator.casesById.containsKey(caseWithEntitlement.Id), 'Expected Case with entitlement to be stored in memory.');
  23. Assert.isFalse(MilestoneTimeCalculator.casesById.containsKey(caseWithoutEntitlement.Id), 'Expected Case without entitlement to not be stored in memory.');
  24.  
  25. }
  26.  
  27. @isTest
  28. private static void validateMergeActionRelatedAccount() {
  29. // test merge of two cases related to the same account
  30. Account acc = ServicesTestUtil.createAccount('test account 1', null, true);
  31. Case masterCase = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, acc.Id, null, false);
  32. Case mergedCase = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, acc.Id, null, false);
  33. insert new List<Case> {masterCase, mergedCase};
  34.  
  35. try {
  36. merge masterCase mergedCase;
  37. } catch (Exception ex) {
  38. // error NOT expected
  39. Assert.fail('Merge should NOT throw an exception; ' + ex.getMessage());
  40. }
  41. }
  42.  
  43. @isTest
  44. private static void validateCaseCommentOnStatusChange() {
  45. Account acc = ServicesTestUtil.createAccount('test account 1', null, true);
  46. Case caseRecord = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, acc.Id, null, true);
  47. caseRecord.Status = 'In Progress';
  48. caseRecord.Comments = 'In Progress Comment';
  49.  
  50. Test.startTest();
  51. update caseRecord;
  52. Test.stopTest();
  53.  
  54. //Can't filter on body
  55. Boolean feedItemFound = false;
  56. for (FeedItem fi : [SELECT Id, Body FROM FeedItem WHERE ParentId =: caseRecord.Id]) {
  57. if (fi.Body.Equals(caseRecord.Comments)) {
  58. feedItemFound = true;
  59. }
  60. }
  61. Assert.isTrue(feedItemFound, 'Internal Comment');
  62. }
  63.  
  64. @isTest
  65. private static void validateCaseCommentNonStatusChange() {
  66. Account acc = ServicesTestUtil.createAccount('test account 1', null, true);
  67. Case caseRecord = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, acc.Id, null, true);
  68. caseRecord.Comments = 'Internal Comment';
  69.  
  70. Test.startTest();
  71. update caseRecord;
  72. Test.stopTest();
  73.  
  74. //Can't filter on body
  75. Boolean feedItemFound = false;
  76. for (FeedItem fi : [SELECT Id, Body FROM FeedItem WHERE ParentId =: caseRecord.Id]) {
  77. if (fi.Body.Equals(caseRecord.Comments)) {
  78. feedItemFound = true;
  79. }
  80. }
  81. Assert.isFalse(feedItemFound, 'The internal comment should not have been found as a regular feeditem.');
  82. }
  83.  
  84.  
  85. @isTest
  86. private static void validateMergeActionNotRelatedAccount() {
  87. // test merge of two cases NOT related to the same account
  88. Account acc1 = ServicesTestUtil.createAccount('test account 1', null, false);
  89. Account acc2 = ServicesTestUtil.createAccount('test account 2', null, false);
  90. insert new List<Account> {acc1, acc2};
  91. Case masterCase = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, acc1.Id, null, false);
  92. Case mergedCase = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, acc2.Id, null, false);
  93. insert new List<Case> {masterCase, mergedCase};
  94.  
  95. try {
  96. merge masterCase mergedCase;
  97. Assert.fail('Merge should throw an exception');
  98. } catch (Exception ex) {
  99. // error expected
  100. Assert.isTrue(ex.getMessage().contains(System.Label.CaseMergeDifferentAccountsNotAllowed), 'Error message');
  101. }
  102. }
  103.  
  104. @isTest
  105. private static void stampTaxonomyValuesTestCaseUnclassifiedOnUpdate() {
  106. // update on an unclassified case
  107. Case c = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, null, null, false);
  108. c.Type = null;
  109. c.SubType__c = null;
  110. c.ServiceTopic__c = null;
  111. c.Status = 'New';
  112. insert c;
  113.  
  114. Test.startTest();
  115. c.Subject = 'Subject update';
  116. update c;
  117. test.stopTest();
  118.  
  119. c = [SELECT Id, OwnerId FROM Case WHERE Id = :c.Id];
  120. Assert.areEqual(UserInfo.getUserId(), c.OwnerId, 'Case owner should be the running user');
  121. }
  122.  
  123. @isTest
  124. private static void stampTaxonomyValuesTestCaseClassifiedOnUpdate() {
  125. // classify an unclassified case
  126. Case c = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, null, null, false);
  127. c.Type = null;
  128. c.SubType__c = null;
  129. c.ServiceTopic__c = null;
  130. c.Status = 'New';
  131. insert c;
  132.  
  133. CaseComplexity__mdt caseComplexity = [
  134. SELECT Id, Type__c, SubType__c, ServiceTopic__c
  135. FROM CaseComplexity__mdt
  136. WHERE Type__c != null AND SubType__c != null AND ServiceTopic__c != null
  137. AND Team__c != null AND Team__r.DeveloperName != :CaseServiceHlpr.SERVICE_TEAM_AM_POOL AND Team__r.QueueDeveloperName__c != null
  138. LIMIT 1];
  139.  
  140. Test.startTest();
  141. c.Type = caseComplexity.Type__c;
  142. c.SubType__c = caseComplexity.SubType__c;
  143. c.ServiceTopic__c = caseComplexity.ServiceTopic__c;
  144. update c;
  145. Test.stopTest();
  146.  
  147. // verify if the saved owner is a queue
  148. c = [SELECT Id, OwnerId FROM Case WHERE Id = :c.Id];
  149. Assert.isTrue(String.valueOf(c.OwnerId).startsWith('00G'), 'Case owner should be a queue');
  150. }
  151.  
  152. @isTest
  153. private static void stampTaxonomyValuesTestIrrelevantUpdate() {
  154. CaseComplexity__mdt caseComplexity = [
  155. SELECT Id, Type__c, SubType__c, ServiceTopic__c
  156. FROM CaseComplexity__mdt
  157. WHERE Type__c != null
  158. AND SubType__c != null
  159. AND ServiceTopic__c != null
  160. AND Team__c != null
  161. AND Team__r.DeveloperName != :CaseServiceHlpr.SERVICE_TEAM_AM_POOL
  162. AND Team__r.QueueDeveloperName__c != null
  163. AND Team__r.BaseSkill__c != null
  164. LIMIT 1];
  165.  
  166. Case c = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, null, null, false);
  167. c.Type = caseComplexity.Type__c;
  168. c.SubType__c = caseComplexity.SubType__c;
  169. c.ServiceTopic__c = caseComplexity.ServiceTopic__c;
  170. c.Priority = 'Normal';
  171. c.Status = 'New';
  172. insert c;
  173.  
  174. Test.startTest();
  175. c.Priority = 'Urgent';
  176. update c;
  177. Test.stopTest();
  178.  
  179. // verify if the taxonomy data is still there
  180. c = [SELECT Id, ComplexityNumber__c, ServiceTeam__c, OmniBaseSkill__c FROM Case WHERE Id = :c.Id];
  181. Assert.areNotEqual(null, c.ComplexityNumber__c, 'Complexity number');
  182. Assert.areNotEqual(null, c.ServiceTeam__c, 'Service team');
  183. Assert.areNotEqual(null, c.OmniBaseSkill__c, 'Base skill');
  184. }
  185.  
  186. @isTest
  187. private static void stampTaxonomyValuesTestChangeTaxonomy() {
  188. // change taxonomy when case is not in new state
  189. CaseComplexity__mdt caseComplexity = [
  190. SELECT Id, Type__c, SubType__c, ServiceTopic__c
  191. FROM CaseComplexity__mdt
  192. WHERE Type__c != null
  193. AND SubType__c != null
  194. AND ServiceTopic__c != null
  195. AND Team__c != null
  196. AND Team__r.DeveloperName != :CaseServiceHlpr.SERVICE_TEAM_AM_POOL
  197. AND Team__r.QueueDeveloperName__c != null
  198. AND Team__r.BaseSkill__c != null
  199. LIMIT 1];
  200.  
  201. Case c = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, null, null, false);
  202. c.Type = caseComplexity.Type__c;
  203. c.SubType__c = caseComplexity.SubType__c;
  204. c.ServiceTopic__c = caseComplexity.ServiceTopic__c;
  205. c.Priority = 'Normal';
  206. c.Status = 'In Progress';
  207. insert c;
  208.  
  209. Test.startTest();
  210. c.Priority = 'Urgent';
  211. update c;
  212. Test.stopTest();
  213.  
  214. // verify if the taxonomy data is there
  215. c = [SELECT Id, ComplexityNumber__c, ServiceTeam__c, OmniBaseSkill__c FROM Case WHERE Id = :c.Id];
  216. Assert.areNotEqual(null, c.ComplexityNumber__c, 'Complexity number');
  217. Assert.areNotEqual(null, c.ServiceTeam__c, 'Service team');
  218. Assert.areNotEqual(null, c.OmniBaseSkill__c, 'Base skill');
  219. }
  220.  
  221. @isTest
  222. private static void stampTaxonomyValuesOnInsertBulk() {
  223. // assign the case to an existing queue
  224. CaseComplexity__mdt caseComplexity = [
  225. SELECT
  226. Id,
  227. Type__c,
  228. SubType__c,
  229. ServiceTopic__c,
  230. Complexity__c,
  231. RecordTypeDevelopername__c,
  232. Team__r.DeveloperName,
  233. Team__r.BaseSkill__c,
  234. Team__r.OmniFlowRouting__c
  235. FROM CaseComplexity__mdt
  236. WHERE Type__c != null AND SubType__c != null AND ServiceTopic__c != null
  237. AND Team__c != null
  238. AND Team__r.DeveloperName != :CaseServiceHlpr.SERVICE_TEAM_AM_POOL
  239. AND Team__r.QueueDeveloperName__c != null
  240. AND Team__r.BaseSkill__c != null
  241. AND Team__r.OmniFlowRouting__c = true
  242. LIMIT 1];
  243.  
  244. Case c1 = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, null, null, false);
  245. c1.Type = caseComplexity.Type__c;
  246. c1.SubType__c = caseComplexity.SubType__c;
  247. c1.ServiceTopic__c = caseComplexity.ServiceTopic__c;
  248. Case c2 = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, null, null, false);
  249. c2.Type = caseComplexity.Type__c;
  250. c2.SubType__c = caseComplexity.SubType__c;
  251. c2.ServiceTopic__c = caseComplexity.ServiceTopic__c;
  252.  
  253. Test.startTest();
  254. insert new List<Case> {c1, c2};
  255. Test.stopTest();
  256.  
  257. // verify if the saved owner is a queue
  258. List<Case> resultList = [
  259. SELECT Id, OwnerId, ExpectedRecordType__c, ComplexityNumber__c, ServiceTeam__c, OmniBaseSkill__c, OmniFlowRouting__c
  260. FROM Case
  261. WHERE Id IN (:c1.Id, :c2.Id)
  262. ];
  263. // first case
  264. Case resultCase = resultList[0];
  265. Assert.isTrue(String.valueOf(resultCase.OwnerId).startsWith('00G'), '1st Case - Case owner should be a queue');
  266. Assert.areEqual(caseComplexity.RecordTypeDevelopername__c, resultCase.ExpectedRecordType__c, '1st Case - Expected record type');
  267. Assert.areEqual(caseComplexity.Complexity__c, resultCase.ComplexityNumber__c, '1st Case - Complexity number');
  268. Assert.areEqual(caseComplexity.Team__r.DeveloperName, resultCase.ServiceTeam__c, '1st Case - Service team');
  269. Assert.areEqual(caseComplexity.Team__r.BaseSkill__c, resultCase.OmniBaseSkill__c, '1st Case - Omni base skill');
  270. Assert.areEqual(caseComplexity.Team__r.OmniFlowRouting__c, resultCase.OmniFlowRouting__c, '1st Case - Omni flow routing');
  271. // second case should have the same updates
  272. resultCase = resultList[1];
  273. Assert.isTrue(String.valueOf(resultCase.OwnerId).startsWith('00G'), '2nd Case - Case owner should be a queue');
  274. Assert.areEqual(caseComplexity.RecordTypeDevelopername__c, resultCase.ExpectedRecordType__c, '2nd Case - Expected record type');
  275. Assert.areEqual(caseComplexity.Complexity__c, resultCase.ComplexityNumber__c, '2nd Case - Complexity number');
  276. Assert.areEqual(caseComplexity.Team__r.DeveloperName, resultCase.ServiceTeam__c, '2nd Case - Service team');
  277. Assert.areEqual(caseComplexity.Team__r.BaseSkill__c, resultCase.OmniBaseSkill__c, '2nd Case - Omni base skill');
  278. Assert.areEqual(caseComplexity.Team__r.OmniFlowRouting__c, resultCase.OmniFlowRouting__c, '2nd Case - Omni flow routing');
  279. }
  280.  
  281. @isTest
  282. private static void stampTaxonomyValuesBasedOnOrigin() {
  283. // retrieve taxonomy details based on type, subtype, topic and origin
  284. CaseComplexity__mdt caseComplexity = [
  285. SELECT Id, Type__c, SubType__c, ServiceTopic__c, CaseOrigin__c, RecordTypeDevelopername__c
  286. FROM CaseComplexity__mdt
  287. WHERE Type__c != null AND SubType__c != null AND ServiceTopic__c != null AND CaseOrigin__c != null
  288. AND Team__c != null AND Team__r.QueueDeveloperName__c != null
  289. LIMIT 1];
  290.  
  291. Case c = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, null, null, false);
  292. c.Type = caseComplexity.Type__c;
  293. c.SubType__c = caseComplexity.SubType__c;
  294. c.ServiceTopic__c = caseComplexity.ServiceTopic__c;
  295. c.Origin = caseComplexity.CaseOrigin__c;
  296.  
  297. Test.startTest();
  298. insert c;
  299. Test.stopTest();
  300.  
  301. // verify if the saved owner is a queue
  302. c = [SELECT Id, OwnerId, ExpectedRecordType__c FROM Case WHERE Id = :c.Id];
  303. Assert.isTrue(String.valueOf(c.OwnerId).startsWith('00G'), 'Case owner should be a queue');
  304. Assert.areEqual(caseComplexity.RecordTypeDevelopername__c, c.ExpectedRecordType__c, 'ExpectedRecordType__c');
  305. }
  306.  
  307. @isTest
  308. private static void stampTaxonomyValuesTestOperationalSupportCase() {
  309. // assign the case to Operational Support queue
  310. CaseComplexity__mdt caseComplexity = [
  311. SELECT Id, Type__c, SubType__c, ServiceTopic__c, Team__r.QueueDeveloperName__c
  312. FROM CaseComplexity__mdt
  313. WHERE Type__c != null AND SubType__c != null AND ServiceTopic__c != null
  314. AND Team__c != null AND Team__r.DeveloperName = :CaseServiceHlpr.SERVICE_TEAM_AM_POOL
  315. LIMIT 1];
  316.  
  317. Case c = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, null, null, false);
  318. c.Type = caseComplexity.Type__c;
  319. c.SubType__c = caseComplexity.SubType__c;
  320. c.ServiceTopic__c = caseComplexity.ServiceTopic__c;
  321.  
  322. Test.startTest();
  323. insert c;
  324. Test.stopTest();
  325.  
  326. // verify if the saved owner is the service support queue
  327. c = [SELECT Id, OwnerId FROM Case WHERE Id = :c.Id];
  328. ServiceTeam__mdt serviceTeamOperationalSupport = ServiceTeam__mdt.getInstance(CaseTaxonomyAction.SERVICE_TEAM_OPERATIONAL_SUPPORT);
  329. Set<String> queueNamesSet = new Set<String> {serviceTeamOperationalSupport.QueueDeveloperName__c};
  330. Group serviceSupportQueue = [SELECT Id FROM Group WHERE Type = 'Queue' AND DeveloperName IN :queueNamesSet];
  331.  
  332. Assert.areEqual(serviceSupportQueue.Id, c.OwnerId, 'Case owner should be the operational support queue');
  333. }
  334.  
  335. @isTest
  336. private static void stampTaxonomyValuesTestAMPoolCase() {
  337. // assign the case to AM Pool queue
  338. CaseComplexity__mdt caseComplexity = [
  339. SELECT Id, Type__c, SubType__c, ServiceTopic__c, Team__r.QueueDeveloperName__c
  340. FROM CaseComplexity__mdt
  341. WHERE Type__c != null AND SubType__c != null AND ServiceTopic__c != null
  342. AND Team__c != null AND Team__r.DeveloperName = :CaseServiceHlpr.SERVICE_TEAM_AM_POOL
  343. LIMIT 1];
  344.  
  345. Account amPoolAccount = ServicesTestUtil.createAccount('test account 1', null, false);
  346. amPoolAccount.ownerId = [SELECT Id FROM User WHERE FirstName = 'AM Pool' LIMIT 1].Id;
  347. insert amPoolAccount;
  348.  
  349. Case c = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, null, null, false);
  350. c.AccountId = amPoolAccount.Id;
  351. c.Type = caseComplexity.Type__c;
  352. c.SubType__c = caseComplexity.SubType__c;
  353. c.ServiceTopic__c = caseComplexity.ServiceTopic__c;
  354.  
  355. Test.startTest();
  356. insert c;
  357. Test.stopTest();
  358.  
  359. // verify if the saved owner is the service support queue
  360. c = [SELECT Id, OwnerId FROM Case WHERE Id = :c.Id];
  361. Group amPoolQueue = [SELECT Id FROM Group WHERE Type = 'Queue' AND DeveloperName = :caseComplexity.Team__r.QueueDeveloperName__c];
  362.  
  363. Assert.areEqual(amPoolQueue.Id, c.OwnerId, 'Case owner should be the AM Pool queue');
  364. }
  365.  
  366. @isTest
  367. private static void setEntitlement() {
  368. SLAProcess entitlementProcess = [SELECT Id FROM SLAProcess WHERE IsActive = true LIMIT 1];
  369. // don't select complexity of team 'Platform Monitoring' as their entitlement is always 'Critical Priority Handling'
  370. CaseComplexity__mdt caseComplexity = [
  371. SELECT Id, Type__c, SubType__c, ServiceTopic__c, CaseOrigin__c, Team__c
  372. FROM CaseComplexity__mdt
  373. WHERE Team__r.DeveloperName != 'PlatformMonitoring' AND RecordTypeDevelopername__c = 'ServiceCase'
  374. LIMIT 1
  375. ];
  376. MilestoneCompletionTime__mdt expectedMctOnInsert = [
  377. SELECT
  378. Id,
  379. CaseRecordType__c,
  380. ServiceTeam__c,
  381. ServiceTeam__r.DeveloperName,
  382. ServiceLevel__c,
  383. Priority__c,
  384. EntitlementRecordName__c
  385. FROM MilestonecompletionTime__mdt
  386. WHERE
  387. (ServiceTeam__c = :caseComplexity.Team__c OR ServiceTeam__c = NULL)
  388. AND CaseRecordType__c = 'ServiceCase'
  389. AND ServiceLevel__c != NULL
  390. LIMIT 1
  391. ];
  392. MilestoneCompletionTime__mdt expectedMctOnUpdate = [
  393. SELECT
  394. Id,
  395. CaseRecordType__c,
  396. ServiceTeam__c,
  397. ServiceTeam__r.DeveloperName,
  398. ServiceLevel__c,
  399. Priority__c,
  400. EntitlementRecordName__c
  401. FROM MilestonecompletionTime__mdt
  402. WHERE
  403. (ServiceTeam__c = :caseComplexity.Team__c OR ServiceTeam__c = NULL)
  404. AND CaseRecordType__c = 'ServiceCase'
  405. AND EntitlementRecordName__c != :expectedMctOnInsert.EntitlementRecordName__c
  406. LIMIT 1
  407. ];
  408. Account entitlementAccount = ServicesTestUtil.createAccount('test account 1', null, true);
  409. Entitlement expectedEntitlementOnInsert = new Entitlement (
  410. Name = expectedMctOnInsert.EntitlementRecordName__c,
  411. AccountId = entitlementAccount.Id,
  412. SlaProcessId = entitlementProcess.Id
  413. );
  414. Entitlement expectedEntitlementOnUpdate = new Entitlement (
  415. Name = expectedMctOnUpdate.EntitlementRecordName__c,
  416. AccountId = entitlementAccount.Id,
  417. SlaProcessId = entitlementProcess.Id
  418. );
  419. insert new List<Entitlement> {expectedEntitlementOnInsert, expectedEntitlementOnUpdate};
  420.  
  421. Account testAccount = ServicesTestUtil.createAccount('test account 1', null, false);
  422. testAccount.ServiceLevel__c = expectedMctOnInsert.ServiceLevel__c;
  423. insert testAccount;
  424.  
  425. Case testCase = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, testAccount.Id, null, false);
  426. testCase.Type = caseComplexity.Type__c;
  427. testCase.SubType__c = caseComplexity.SubType__c;
  428. testCase.ServiceTopic__c = caseComplexity.ServiceTopic__c;
  429. testCase.Origin = caseComplexity.CaseOrigin__c;
  430. testCase.RecordTypeId = Constants.rtCaseByDevNameMap.get(expectedMctOnInsert.CaseRecordType__c).getRecordTypeId();
  431. testCase.Priority = expectedMctOnInsert.Priority__c;
  432. testCase.RouteToServiceTeamOnCreate__c = false;
  433. testCase.IsVisibleInPortal__c = true;
  434.  
  435. Case nonPortalCase = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, testAccount.Id, null, false);
  436. nonPortalCase.Type = caseComplexity.Type__c;
  437. nonPortalCase.SubType__c = caseComplexity.SubType__c;
  438. nonPortalCase.ServiceTopic__c = caseComplexity.ServiceTopic__c;
  439. nonPortalCase.Origin = caseComplexity.CaseOrigin__c;
  440. nonPortalCase.RecordTypeId = Constants.rtCaseByDevNameMap.get(expectedMctOnInsert.CaseRecordType__c).getRecordTypeId();
  441. nonPortalCase.Priority = expectedMctOnInsert.Priority__c;
  442. nonPortalCase.RouteToServiceTeamOnCreate__c = false;
  443. nonPortalCase.IsVisibleInPortal__c = false;
  444.  
  445. List<Case> cases = new List<Case>();
  446. cases.add(testCase);
  447. cases.add(nonPortalCase);
  448. Test.startTest();
  449. // verify insert value
  450. insert cases;
  451.  
  452. for (Case c : [SELECT Id, EntitlementId, Priority, CustomerSegmentation__c, SLOTargetResolutionDate__c, SLOResolutionTime__c FROM Case WHERE Id in :cases]) {
  453. if (c.Id == testCase.Id){
  454. testCase = c;
  455. Assert.areEqual(expectedEntitlementOnInsert.Id, testCase.EntitlementId, 'Entitlement ID after insert');
  456. Assert.isNotNull(testCase.SLOTargetResolutionDate__c, 'SLOTargetResolutionDate__c is empty');
  457. Assert.isNotNull(testCase.SLOResolutionTime__c, 'SLOResolutionTime__c is empty');
  458.  
  459. // update in the way entitlement process changes
  460. testCase.Priority = expectedMctOnUpdate.Priority__c;
  461. testCase.CustomerSegmentation__c = expectedMctOnUpdate.ServiceLevel__c;
  462. testCase.ServiceTeam__c = expectedMctOnUpdate.ServiceTeam__c;
  463. }
  464. else if (c.Id == nonPortalCase.Id){
  465. Assert.isNull(c.EntitlementId, 'Service Cases not visible in the portal should not have an Entitlement Record.');
  466. Assert.isNull(c.SLOTargetResolutionDate__c, 'SLOTargetResolutionDate__c should be empty');
  467. Assert.isNull(c.SLOResolutionTime__c, 'SLOResolutionTime__c should be empty');
  468. }
  469. }
  470.  
  471.  
  472. update testCase;
  473. Test.stopTest();
  474.  
  475. // verify update value
  476. testCase = [SELECT Id, EntitlementId FROM Case WHERE Id = :testCase.Id];
  477. Assert.areEqual(expectedEntitlementOnUpdate.Id, testCase.EntitlementId, 'Entitlement ID after update');
  478. }
  479.  
  480. @IsTest
  481. private static void getCorrectQueueUnclassifiedQueue() {
  482. String unclassifiedQueueName = 'Unclassified';
  483. String classifiedQueueName = 'classified';
  484.  
  485. CaseTaxonomyAction.CaseTaxonomyCollection taxonomyDetails = new CaseTaxonomyAction.CaseTaxonomyCollection();
  486. taxonomyDetails.unclassifiedQueue = new Group(DeveloperName = unclassifiedQueueName);
  487. taxonomyDetails.classifiedQueue = new Group(DeveloperName = classifiedQueueName);
  488.  
  489. Case testCase = new Case ();
  490.  
  491. Test.startTest();
  492. Group resultNotClassified = CaseServiceHlpr.getCorrectQueue(testCase, taxonomyDetails);
  493. testCase.type = 'Accounts';
  494. Group resultOnlyTypePopulated = CaseServiceHlpr.getCorrectQueue(testCase, taxonomyDetails);
  495. testCase.SubType__c = 'Payout Account';
  496. Group resultNoTopic = CaseServiceHlpr.getCorrectQueue(testCase, taxonomyDetails);
  497. Test.stopTest();
  498.  
  499. Assert.areEqual(unclassifiedQueueName, resultNotClassified.DeveloperName, 'Case 1 - Not classified: Unclassified queue should be selected');
  500. Assert.areEqual(unclassifiedQueueName, resultOnlyTypePopulated.DeveloperName, 'Case 2 - Only type populated: Unclassified queue should be selected');
  501. Assert.areEqual(unclassifiedQueueName, resultNoTopic.DeveloperName, 'Case 3 - Missing topic: Unclassified queue should be selected');
  502. }
  503.  
  504. @IsTest
  505. private static void getCorrectQueueStandardQueue() {
  506. String unclassifiedQueueName = 'Unclassified';
  507. String classifiedQueueName = 'classified';
  508.  
  509. CaseTaxonomyAction.CaseTaxonomyCollection taxonomyDetails = new CaseTaxonomyAction.CaseTaxonomyCollection();
  510. taxonomyDetails.unclassifiedQueue = new Group(DeveloperName = unclassifiedQueueName);
  511. taxonomyDetails.classifiedQueue = new Group(DeveloperName = classifiedQueueName);
  512.  
  513. Case testCase = new Case (
  514. Type = 'Accounts',
  515. SubType__c = 'Payout Account',
  516. ServiceTopic__c = 'N/A'
  517. );
  518.  
  519. Test.startTest();
  520. Group resultQueue = CaseServiceHlpr.getCorrectQueue(testCase, taxonomyDetails);
  521. Test.stopTest();
  522.  
  523. Assert.areEqual(classifiedQueueName, resultQueue.DeveloperName, 'Standard queue should be selected');
  524. }
  525.  
  526. @IsTest
  527. private static void getCorrectQueueNotUsingUnclassifiedQueue() {
  528. String classifiedQueueName = 'classified';
  529.  
  530. CaseTaxonomyAction.CaseTaxonomyCollection taxonomyDetails = new CaseTaxonomyAction.CaseTaxonomyCollection();
  531. taxonomyDetails.unclassifiedQueue = null;
  532. taxonomyDetails.classifiedQueue = new Group(DeveloperName = classifiedQueueName);
  533.  
  534. Case testCase = new Case (
  535. Type = 'Accounts'
  536. );
  537.  
  538. Test.startTest();
  539. Group resultQueue = CaseServiceHlpr.getCorrectQueue(testCase, taxonomyDetails);
  540. Test.stopTest();
  541.  
  542. Assert.areEqual(classifiedQueueName, resultQueue.DeveloperName, 'Standard queue should be selected');
  543. }
  544.  
  545. @isTest
  546. private static void cloneCase() {
  547. Case originalCase = new Case(AccountId = '001000000000000000', Origin = 'Email');
  548. Case clonedCase = new Case();
  549. Test.startTest();
  550. CaseServiceHlpr.cloneCase(clonedCase, originalCase);
  551. Test.stopTest();
  552. Assert.areEqual(originalCase.AccountId, clonedCase.AccountId);
  553. Assert.areEqual(originalCase.Origin, clonedCase.Origin);
  554. }
  555.  
  556. @isTest
  557. private static void cloneCaseTestLimitedUser() {
  558. // make sure that the account owner has a role
  559. update new User(Id = UserInfo.getUserId(), UserRoleId = ServicesTestUtil.getUserRoleId('Management CEO/CCO/CFO/COO'));
  560.  
  561. User portalUser;
  562. System.runAs(new User(Id = UserInfo.getUserId())) {
  563. Account acc = ServicesTestUtil.createAccount('Test account', Constants.RT_ID_ACC_BUSINESS, true);
  564. Contact con = ServicesTestUtil.createContact(acc.Id, 'Jones', 'jones@adyen.com.fake', true);
  565.  
  566. portalUser = ServicesTestUtil.createPortalUser(con.Id, true);
  567.  
  568. ServicesTestUtil.assignPermissionsToUser(
  569. new List<User>{portalUser},
  570. new Set<String> (),
  571. new Set<String> {ServicesTestUtil.SERVICE_PORTAL_PERMISSION_SET_NAME},
  572. true);
  573. }
  574.  
  575. Case originalCase = new Case (
  576. RecordTypeId = Constants.RT_ID_CASE_SERVICECASE,
  577. Origin = 'Email'
  578. );
  579. Case clonedCase = new Case ();
  580.  
  581. System.runAs(portalUser) {
  582. Test.startTest();
  583. CaseServiceHlpr.cloneCase(clonedCase, originalCase);
  584. Test.stopTest();
  585. }
  586.  
  587. Assert.isNull(clonedCase.RecordTypeId, 'User should not have create rights on record type');
  588. Assert.isNull(clonedCase.Origin, 'User should not have create rights on case origin');
  589. }
  590.  
  591. @isTest
  592. private static void cloneCaseFullAccess() {
  593. // make sure that the account owner has a role
  594. update new User(Id = UserInfo.getUserId(), UserRoleId = ServicesTestUtil.getUserRoleId('Management CEO/CCO/CFO/COO'));
  595.  
  596. User portalUser;
  597. System.runAs(new User(Id = UserInfo.getUserId())) {
  598. Account acc = ServicesTestUtil.createAccount('Test account', Constants.RT_ID_ACC_BUSINESS, true);
  599. Contact con = ServicesTestUtil.createContact(acc.Id, 'Jones', 'jones@adyen.com.fake', true);
  600.  
  601. portalUser = ServicesTestUtil.createPortalUser(con.Id, true);
  602.  
  603. ServicesTestUtil.assignPermissionsToUser(
  604. new List<User>{portalUser},
  605. new Set<String> (),
  606. new Set<String> {ServicesTestUtil.SERVICE_PORTAL_PERMISSION_SET_NAME},
  607. true);
  608. }
  609.  
  610. Case originalCase = new Case (
  611. RecordTypeId = Constants.RT_ID_CASE_SERVICECASE,
  612. Origin = 'Email'
  613. );
  614. Case clonedCase = new Case ();
  615.  
  616. System.runAs(portalUser) {
  617. Test.startTest();
  618. CaseServiceHlpr.cloneCaseFullAccess(clonedCase, originalCase);
  619. Test.stopTest();
  620. }
  621.  
  622. Assert.areEqual(originalCase.RecordTypeId, clonedCase.RecordTypeId, 'User should have create rights on record type');
  623. Assert.areEqual(originalCase.Origin, clonedCase.Origin, 'User should have create rights on case origin');
  624. }
  625.  
  626. @isTest
  627. private static void queryForCloneCase(){
  628. Account acc1 = ServicesTestUtil.createAccount('test account 1', null, true);
  629. Case originalCase = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, acc1.Id, null, false);
  630. originalCase.Origin = 'Email';
  631. originalCase.SuppliedPhone = '0123456789';
  632. insert originalCase;
  633. Test.startTest();
  634. Case queriedCase = CaseServiceHlpr.queryCasesForCloning(new Set<Id>{originalCase.Id}, new Set<String>{'SuppliedPhone'})[0];
  635. Test.stopTest();
  636. Assert.areEqual(originalCase.AccountId, queriedCase.AccountId);
  637. Assert.areEqual(originalCase.Origin, queriedCase.Origin);
  638. Assert.areEqual(originalCase.SuppliedPhone, queriedCase.SuppliedPhone);
  639. }
  640.  
  641. @IsTest
  642. private static void testHandleCaseStopUnstop() {
  643. SLAProcess entitlementProcess = [SELECT Id FROM SLAProcess WHERE IsActive = true LIMIT 1];
  644.  
  645. CaseComplexity__mdt caseComplexity = [SELECT Team__c
  646. FROM CaseComplexity__mdt
  647. WHERE Team__r.DeveloperName != 'PlatformMonitoring'
  648. AND RecordTypeDevelopername__c = 'ServiceCase'
  649. AND Team__r.BusinessHoursName__c = '15/7'
  650. LIMIT 1];
  651.  
  652. MilestoneCompletionTime__mdt milestoneMapping = [SELECT ServiceLevel__c,
  653. EntitlementRecordName__c
  654. FROM MilestonecompletionTime__mdt
  655. WHERE (ServiceTeam__c = :caseComplexity.Team__c OR ServiceTeam__c = null)
  656. AND CaseRecordType__c = 'ServiceCase'
  657. AND ServiceLevel__c != null
  658. LIMIT 1];
  659.  
  660. Account entitlementAccount = ServicesTestUtil.createAccount('test account 1', null, true);
  661.  
  662. insert new Entitlement (
  663. Name = milestoneMapping.EntitlementRecordName__c,
  664. AccountId = entitlementAccount.Id,
  665. SlaProcessId = entitlementProcess.Id
  666. );
  667.  
  668. Account testAccount = ServicesTestUtil.createAccount('test account 1', null, false);
  669. testAccount.ServiceLevel__c = milestoneMapping.ServiceLevel__c;
  670. insert testAccount;
  671.  
  672. Case testCase = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, testAccount.Id, null, false);
  673. testCase.Type = 'Non-Merchant Request';
  674. testCase.SubType__c = 'Sub-Merchants';
  675. testCase.ServiceTopic__c = 'KYC Check';
  676. testCase.Origin = 'Salesforce';
  677. testCase.Priority = 'Medium';
  678. testCase.RouteToServiceTeamOnCreate__c = false;
  679. testCase.IsVisibleInPortal__c = true;
  680.  
  681. insert testCase;
  682.  
  683. testCase.Status = 'Waiting For Merchant';
  684.  
  685. Test.startTest();
  686. update testCase;
  687. Test.stopTest();
  688.  
  689. testCase = [SELECT SLORemainingResolutionTime__c,
  690. SLOTargetResolutionDate__c,
  691. SLOTargetResolutionDateNoBH__c
  692. FROM Case
  693. WHERE Id = :testCase.Id];
  694.  
  695. Assert.isNotNull(testCase.SLORemainingResolutionTime__c, 'The field SLORemainingResolutionTime__c should not be null');
  696. Assert.isNull(testCase.SLOTargetResolutionDate__c, 'The field SLOTargetResolutionDate__c should be set to null');
  697. Assert.isNull(testCase.SLOTargetResolutionDateNoBH__c, 'The field SLOTargetResolutionDateNoBH__c should be set to null');
  698.  
  699. testCase.Status = 'In Progress';
  700.  
  701. update testCase;
  702.  
  703. testCase = [SELECT SLORemainingResolutionTime__c,
  704. SLOTargetResolutionDate__c,
  705. SLOTargetResolutionDateNoBH__c
  706. FROM Case
  707. WHERE Id = :testCase.Id];
  708.  
  709. Assert.isNull(testCase.SLORemainingResolutionTime__c, 'The field SLORemainingResolutionTime__c should be set to null');
  710. Assert.isNotNull(testCase.SLOTargetResolutionDate__c, 'The field SLOTargetResolutionDate__c should not be null');
  711. Assert.isNotNull(testCase.SLOTargetResolutionDateNoBH__c, 'The field SLOTargetResolutionDateNoBH__c should not be null');
  712. }
  713.  
  714. /**
  715. * Execute the calculateRemainingResTime method passing an amount of minutes that is less than an hour in value
  716. * @result The time value is returned formatted in its minutes value
  717. */
  718. @IsTest
  719. private static void testCalculateRemainingResMinutes() {
  720. Long thirtyMinutes = 30;
  721.  
  722. Test.startTest();
  723. String result = CaseServiceHlpr.calculateRemainingResTime(thirtyMinutes);
  724. Test.stopTest();
  725.  
  726. Assert.areEqual('30m', result, 'The expected value is 30m');
  727. }
  728.  
  729. /**
  730. * Execute the calculateRemainingResTime method passing an amount of minutes that is more than an hour and less
  731. * than a day in value
  732. * @result The time value is returned formatted in its hours value
  733. */
  734. @IsTest
  735. private static void testCalculateRemainingResHours() {
  736. Long twoHoursInMinutes = 120;
  737.  
  738. Test.startTest();
  739. String result = CaseServiceHlpr.calculateRemainingResTime(twoHoursInMinutes);
  740. Test.stopTest();
  741.  
  742. Assert.areEqual('2h', result, 'The expected value is 2h');
  743. }
  744.  
  745. /**
  746. * Execute the calculateRemainingResTime method passing an amount of minutes that is more than an hour and less
  747. * than a day in value
  748. * @result The time value is returned formatted in its hours value, rounded down to the nearest hour
  749. */
  750. @IsTest
  751. private static void testCalculateRemainingResHoursRounded() {
  752. Long twoHoursAndMoreInMinutes = 130;
  753.  
  754. Test.startTest();
  755. String result = CaseServiceHlpr.calculateRemainingResTime(twoHoursAndMoreInMinutes);
  756. Test.stopTest();
  757.  
  758. Assert.areEqual('2h', result, 'The expected value is 2h');
  759. }
  760.  
  761. /**
  762. * Execute the calculateRemainingResTime method passing an amount of minutes that is more than an hour and less
  763. * than a day in value
  764. * @result The time value is returned formatted in its hours value
  765. */
  766. @IsTest
  767. private static void testCalculateRemainingResDays() {
  768. Long twoDaysInMinutes = 2880;
  769.  
  770. Test.startTest();
  771. String result = CaseServiceHlpr.calculateRemainingResTime(twoDaysInMinutes);
  772. Test.stopTest();
  773.  
  774. Assert.areEqual('2d', result, 'The expected value is 2d');
  775. }
  776.  
  777. /**
  778. * Execute the calculateRemainingResTime method passing an amount of minutes that is more than a full day in value
  779. * @result The time value is returned formatted in its days value
  780. */
  781. @IsTest
  782. private static void testCalculateRemainingResDaysRounded() {
  783. Long twoDaysAndMoreInMinutes = 2900;
  784.  
  785. Test.startTest();
  786. String result = CaseServiceHlpr.calculateRemainingResTime(twoDaysAndMoreInMinutes);
  787. Test.stopTest();
  788.  
  789. Assert.areEqual('2d', result, 'The expected value is 2d');
  790. }
  791. }
Success #stdin #stdout #stderr 0.01s 7900KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
./prog:1: expected expression
./prog:136: expected expression
./prog:136: expected expression
./prog:136: expected expression
./prog:137: expected expression
./prog:137: expected expression
./prog:137: expected expression
./prog:157: expected expression
./prog:158: expected expression
./prog:159: expected expression
./prog:160: expected expression
./prog:161: expected expression
./prog:162: expected expression
./prog:163: expected expression
./prog:192: expected expression
./prog:193: expected expression
./prog:194: expected expression
./prog:195: expected expression
./prog:196: expected expression
./prog:197: expected expression
./prog:198: expected expression
./prog:236: expected expression
./prog:236: expected expression
./prog:236: expected expression
./prog:237: expected expression
./prog:238: expected expression
./prog:239: expected expression
./prog:240: expected expression
./prog:287: expected expression
./prog:287: expected expression
./prog:287: expected expression
./prog:287: expected expression
./prog:288: expected expression
./prog:288: expected expression
./prog:313: expected expression
./prog:313: expected expression
./prog:313: expected expression
./prog:314: expected expression
./prog:341: expected expression
./prog:341: expected expression
./prog:341: expected expression
./prog:342: expected expression
./prog:791: Unterminated string, attempting recovery