/**
* @description Test class to test the functionality of class CaseServiceHlpr.
*/
@isTest
private class CaseServiceHlprTest {
@isTest
private static void storeSloInformationInMemory() {
Account acc = ServicesTestUtil.createAccount('test account 1', null, true);
Case caseWithoutEntitlement = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, acc.Id, null, false);
Case caseWithEntitlement = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, acc.Id, null, false);
List<Case> caseList = new List<Case>{caseWithEntitlement, caseWithoutEntitlement};
insert caseList;
//reset the map before the actual test.
MilestoneTimeCalculator.casesById = new Map<Id, Case>();
caseWithEntitlement.EntitlementId = '000000000000000000';
caseWithoutEntitlement.EntitlementId = null;
Test.startTest();
CaseServiceHlpr.storeSloInformationInMemory(caseList);
Test.stopTest();
Assert.isNotNull(MilestoneTimeCalculator.casesById, 'Expected Milestone Case Map to be populated.');
Assert.isTrue(MilestoneTimeCalculator.casesById.containsKey(caseWithEntitlement.Id), 'Expected Case with entitlement to be stored in memory.');
Assert.isFalse(MilestoneTimeCalculator.casesById.containsKey(caseWithoutEntitlement.Id), 'Expected Case without entitlement to not be stored in memory.');
}
@isTest
private static void validateMergeActionRelatedAccount() {
// test merge of two cases related to the same account
Account acc = ServicesTestUtil.createAccount('test account 1', null, true);
Case masterCase = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, acc.Id, null, false);
Case mergedCase = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, acc.Id, null, false);
insert new List<Case> {masterCase, mergedCase};
try {
merge masterCase mergedCase;
} catch (Exception ex) {
// error NOT expected
Assert.fail('Merge should NOT throw an exception; ' + ex.getMessage());
}
}
@isTest
private static void validateCaseCommentOnStatusChange() {
Account acc = ServicesTestUtil.createAccount('test account 1', null, true);
Case caseRecord = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, acc.Id, null, true);
caseRecord.Status = 'In Progress';
caseRecord.Comments = 'In Progress Comment';
Test.startTest();
update caseRecord;
Test.stopTest();
//Can't filter on body
Boolean feedItemFound = false;
for (FeedItem fi : [SELECT Id, Body FROM FeedItem WHERE ParentId =: caseRecord.Id]) {
if (fi.Body.Equals(caseRecord.Comments)) {
feedItemFound = true;
}
}
Assert.isTrue(feedItemFound, 'Internal Comment');
}
@isTest
private static void validateCaseCommentNonStatusChange() {
Account acc = ServicesTestUtil.createAccount('test account 1', null, true);
Case caseRecord = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, acc.Id, null, true);
caseRecord.Comments = 'Internal Comment';
Test.startTest();
update caseRecord;
Test.stopTest();
//Can't filter on body
Boolean feedItemFound = false;
for (FeedItem fi : [SELECT Id, Body FROM FeedItem WHERE ParentId =: caseRecord.Id]) {
if (fi.Body.Equals(caseRecord.Comments)) {
feedItemFound = true;
}
}
Assert.isFalse(feedItemFound, 'The internal comment should not have been found as a regular feeditem.');
}
@isTest
private static void validateMergeActionNotRelatedAccount() {
// test merge of two cases NOT related to the same account
Account acc1 = ServicesTestUtil.createAccount('test account 1', null, false);
Account acc2 = ServicesTestUtil.createAccount('test account 2', null, false);
insert new List<Account> {acc1, acc2};
Case masterCase = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, acc1.Id, null, false);
Case mergedCase = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, acc2.Id, null, false);
insert new List<Case> {masterCase, mergedCase};
try {
merge masterCase mergedCase;
Assert.fail('Merge should throw an exception');
} catch (Exception ex) {
// error expected
Assert.isTrue(ex.getMessage().contains(System.Label.CaseMergeDifferentAccountsNotAllowed), 'Error message');
}
}
@isTest
private static void stampTaxonomyValuesTestCaseUnclassifiedOnUpdate() {
// update on an unclassified case
Case c = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, null, null, false);
c.Type = null;
c.SubType__c = null;
c.ServiceTopic__c = null;
c.Status = 'New';
insert c;
Test.startTest();
c.Subject = 'Subject update';
update c;
test.stopTest();
c = [SELECT Id, OwnerId FROM Case WHERE Id = :c.Id];
Assert.areEqual(UserInfo.getUserId(), c.OwnerId, 'Case owner should be the running user');
}
@isTest
private static void stampTaxonomyValuesTestCaseClassifiedOnUpdate() {
// classify an unclassified case
Case c = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, null, null, false);
c.Type = null;
c.SubType__c = null;
c.ServiceTopic__c = null;
c.Status = 'New';
insert c;
CaseComplexity__mdt caseComplexity = [
SELECT Id, Type__c, SubType__c, ServiceTopic__c
FROM CaseComplexity__mdt
WHERE Type__c != null AND SubType__c != null AND ServiceTopic__c != null
AND Team__c != null AND Team__r.DeveloperName != :CaseServiceHlpr.SERVICE_TEAM_AM_POOL AND Team__r.QueueDeveloperName__c != null
LIMIT 1];
Test.startTest();
c.Type = caseComplexity.Type__c;
c.SubType__c = caseComplexity.SubType__c;
c.ServiceTopic__c = caseComplexity.ServiceTopic__c;
update c;
Test.stopTest();
// verify if the saved owner is a queue
c = [SELECT Id, OwnerId FROM Case WHERE Id = :c.Id];
Assert.isTrue(String.valueOf(c.OwnerId).startsWith('00G'), 'Case owner should be a queue');
}
@isTest
private static void stampTaxonomyValuesTestIrrelevantUpdate() {
CaseComplexity__mdt caseComplexity = [
SELECT Id, Type__c, SubType__c, ServiceTopic__c
FROM CaseComplexity__mdt
WHERE Type__c != null
AND SubType__c != null
AND ServiceTopic__c != null
AND Team__c != null
AND Team__r.DeveloperName != :CaseServiceHlpr.SERVICE_TEAM_AM_POOL
AND Team__r.QueueDeveloperName__c != null
AND Team__r.BaseSkill__c != null
LIMIT 1];
Case c = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, null, null, false);
c.Type = caseComplexity.Type__c;
c.SubType__c = caseComplexity.SubType__c;
c.ServiceTopic__c = caseComplexity.ServiceTopic__c;
c.Priority = 'Normal';
c.Status = 'New';
insert c;
Test.startTest();
c.Priority = 'Urgent';
update c;
Test.stopTest();
// verify if the taxonomy data is still there
c = [SELECT Id, ComplexityNumber__c, ServiceTeam__c, OmniBaseSkill__c FROM Case WHERE Id = :c.Id];
Assert.areNotEqual(null, c.ComplexityNumber__c, 'Complexity number');
Assert.areNotEqual(null, c.ServiceTeam__c, 'Service team');
Assert.areNotEqual(null, c.OmniBaseSkill__c, 'Base skill');
}
@isTest
private static void stampTaxonomyValuesTestChangeTaxonomy() {
// change taxonomy when case is not in new state
CaseComplexity__mdt caseComplexity = [
SELECT Id, Type__c, SubType__c, ServiceTopic__c
FROM CaseComplexity__mdt
WHERE Type__c != null
AND SubType__c != null
AND ServiceTopic__c != null
AND Team__c != null
AND Team__r.DeveloperName != :CaseServiceHlpr.SERVICE_TEAM_AM_POOL
AND Team__r.QueueDeveloperName__c != null
AND Team__r.BaseSkill__c != null
LIMIT 1];
Case c = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, null, null, false);
c.Type = caseComplexity.Type__c;
c.SubType__c = caseComplexity.SubType__c;
c.ServiceTopic__c = caseComplexity.ServiceTopic__c;
c.Priority = 'Normal';
c.Status = 'In Progress';
insert c;
Test.startTest();
c.Priority = 'Urgent';
update c;
Test.stopTest();
// verify if the taxonomy data is there
c = [SELECT Id, ComplexityNumber__c, ServiceTeam__c, OmniBaseSkill__c FROM Case WHERE Id = :c.Id];
Assert.areNotEqual(null, c.ComplexityNumber__c, 'Complexity number');
Assert.areNotEqual(null, c.ServiceTeam__c, 'Service team');
Assert.areNotEqual(null, c.OmniBaseSkill__c, 'Base skill');
}
@isTest
private static void stampTaxonomyValuesOnInsertBulk() {
// assign the case to an existing queue
CaseComplexity__mdt caseComplexity = [
SELECT
Id,
Type__c,
SubType__c,
ServiceTopic__c,
Complexity__c,
RecordTypeDevelopername__c,
Team__r.DeveloperName,
Team__r.BaseSkill__c,
Team__r.OmniFlowRouting__c
FROM CaseComplexity__mdt
WHERE Type__c != null AND SubType__c != null AND ServiceTopic__c != null
AND Team__c != null
AND Team__r.DeveloperName != :CaseServiceHlpr.SERVICE_TEAM_AM_POOL
AND Team__r.QueueDeveloperName__c != null
AND Team__r.BaseSkill__c != null
AND Team__r.OmniFlowRouting__c = true
LIMIT 1];
Case c1 = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, null, null, false);
c1.Type = caseComplexity.Type__c;
c1.SubType__c = caseComplexity.SubType__c;
c1.ServiceTopic__c = caseComplexity.ServiceTopic__c;
Case c2 = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, null, null, false);
c2.Type = caseComplexity.Type__c;
c2.SubType__c = caseComplexity.SubType__c;
c2.ServiceTopic__c = caseComplexity.ServiceTopic__c;
Test.startTest();
insert new List<Case> {c1, c2};
Test.stopTest();
// verify if the saved owner is a queue
List<Case> resultList = [
SELECT Id, OwnerId, ExpectedRecordType__c, ComplexityNumber__c, ServiceTeam__c, OmniBaseSkill__c, OmniFlowRouting__c
FROM Case
WHERE Id IN (:c1.Id, :c2.Id)
];
// first case
Case resultCase = resultList[0];
Assert.isTrue(String.valueOf(resultCase.OwnerId).startsWith('00G'), '1st Case - Case owner should be a queue');
Assert.areEqual(caseComplexity.RecordTypeDevelopername__c, resultCase.ExpectedRecordType__c, '1st Case - Expected record type');
Assert.areEqual(caseComplexity.Complexity__c, resultCase.ComplexityNumber__c, '1st Case - Complexity number');
Assert.areEqual(caseComplexity.Team__r.DeveloperName, resultCase.ServiceTeam__c, '1st Case - Service team');
Assert.areEqual(caseComplexity.Team__r.BaseSkill__c, resultCase.OmniBaseSkill__c, '1st Case - Omni base skill');
Assert.areEqual(caseComplexity.Team__r.OmniFlowRouting__c, resultCase.OmniFlowRouting__c, '1st Case - Omni flow routing');
// second case should have the same updates
resultCase = resultList[1];
Assert.isTrue(String.valueOf(resultCase.OwnerId).startsWith('00G'), '2nd Case - Case owner should be a queue');
Assert.areEqual(caseComplexity.RecordTypeDevelopername__c, resultCase.ExpectedRecordType__c, '2nd Case - Expected record type');
Assert.areEqual(caseComplexity.Complexity__c, resultCase.ComplexityNumber__c, '2nd Case - Complexity number');
Assert.areEqual(caseComplexity.Team__r.DeveloperName, resultCase.ServiceTeam__c, '2nd Case - Service team');
Assert.areEqual(caseComplexity.Team__r.BaseSkill__c, resultCase.OmniBaseSkill__c, '2nd Case - Omni base skill');
Assert.areEqual(caseComplexity.Team__r.OmniFlowRouting__c, resultCase.OmniFlowRouting__c, '2nd Case - Omni flow routing');
}
@isTest
private static void stampTaxonomyValuesBasedOnOrigin() {
// retrieve taxonomy details based on type, subtype, topic and origin
CaseComplexity__mdt caseComplexity = [
SELECT Id, Type__c, SubType__c, ServiceTopic__c, CaseOrigin__c, RecordTypeDevelopername__c
FROM CaseComplexity__mdt
WHERE Type__c != null AND SubType__c != null AND ServiceTopic__c != null AND CaseOrigin__c != null
AND Team__c != null AND Team__r.QueueDeveloperName__c != null
LIMIT 1];
Case c = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, null, null, false);
c.Type = caseComplexity.Type__c;
c.SubType__c = caseComplexity.SubType__c;
c.ServiceTopic__c = caseComplexity.ServiceTopic__c;
c.Origin = caseComplexity.CaseOrigin__c;
Test.startTest();
insert c;
Test.stopTest();
// verify if the saved owner is a queue
c = [SELECT Id, OwnerId, ExpectedRecordType__c FROM Case WHERE Id = :c.Id];
Assert.isTrue(String.valueOf(c.OwnerId).startsWith('00G'), 'Case owner should be a queue');
Assert.areEqual(caseComplexity.RecordTypeDevelopername__c, c.ExpectedRecordType__c, 'ExpectedRecordType__c');
}
@isTest
private static void stampTaxonomyValuesTestOperationalSupportCase() {
// assign the case to Operational Support queue
CaseComplexity__mdt caseComplexity = [
SELECT Id, Type__c, SubType__c, ServiceTopic__c, Team__r.QueueDeveloperName__c
FROM CaseComplexity__mdt
WHERE Type__c != null AND SubType__c != null AND ServiceTopic__c != null
AND Team__c != null AND Team__r.DeveloperName = :CaseServiceHlpr.SERVICE_TEAM_AM_POOL
LIMIT 1];
Case c = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, null, null, false);
c.Type = caseComplexity.Type__c;
c.SubType__c = caseComplexity.SubType__c;
c.ServiceTopic__c = caseComplexity.ServiceTopic__c;
Test.startTest();
insert c;
Test.stopTest();
// verify if the saved owner is the service support queue
c = [SELECT Id, OwnerId FROM Case WHERE Id = :c.Id];
ServiceTeam__mdt serviceTeamOperationalSupport = ServiceTeam__mdt.getInstance(CaseTaxonomyAction.SERVICE_TEAM_OPERATIONAL_SUPPORT);
Set<String> queueNamesSet = new Set<String> {serviceTeamOperationalSupport.QueueDeveloperName__c};
Group serviceSupportQueue = [SELECT Id FROM Group WHERE Type = 'Queue' AND DeveloperName IN :queueNamesSet];
Assert.areEqual(serviceSupportQueue.Id, c.OwnerId, 'Case owner should be the operational support queue');
}
@isTest
private static void stampTaxonomyValuesTestAMPoolCase() {
// assign the case to AM Pool queue
CaseComplexity__mdt caseComplexity = [
SELECT Id, Type__c, SubType__c, ServiceTopic__c, Team__r.QueueDeveloperName__c
FROM CaseComplexity__mdt
WHERE Type__c != null AND SubType__c != null AND ServiceTopic__c != null
AND Team__c != null AND Team__r.DeveloperName = :CaseServiceHlpr.SERVICE_TEAM_AM_POOL
LIMIT 1];
Account amPoolAccount = ServicesTestUtil.createAccount('test account 1', null, false);
amPoolAccount.ownerId = [SELECT Id FROM User WHERE FirstName = 'AM Pool' LIMIT 1].Id;
insert amPoolAccount;
Case c = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, null, null, false);
c.AccountId = amPoolAccount.Id;
c.Type = caseComplexity.Type__c;
c.SubType__c = caseComplexity.SubType__c;
c.ServiceTopic__c = caseComplexity.ServiceTopic__c;
Test.startTest();
insert c;
Test.stopTest();
// verify if the saved owner is the service support queue
c = [SELECT Id, OwnerId FROM Case WHERE Id = :c.Id];
Group amPoolQueue = [SELECT Id FROM Group WHERE Type = 'Queue' AND DeveloperName = :caseComplexity.Team__r.QueueDeveloperName__c];
Assert.areEqual(amPoolQueue.Id, c.OwnerId, 'Case owner should be the AM Pool queue');
}
@isTest
private static void setEntitlement() {
SLAProcess entitlementProcess = [SELECT Id FROM SLAProcess WHERE IsActive = true LIMIT 1];
// don't select complexity of team 'Platform Monitoring' as their entitlement is always 'Critical Priority Handling'
CaseComplexity__mdt caseComplexity = [
SELECT Id, Type__c, SubType__c, ServiceTopic__c, CaseOrigin__c, Team__c
FROM CaseComplexity__mdt
WHERE Team__r.DeveloperName != 'PlatformMonitoring' AND RecordTypeDevelopername__c = 'ServiceCase'
LIMIT 1
];
MilestoneCompletionTime__mdt expectedMctOnInsert = [
SELECT
Id,
CaseRecordType__c,
ServiceTeam__c,
ServiceTeam__r.DeveloperName,
ServiceLevel__c,
Priority__c,
EntitlementRecordName__c
FROM MilestonecompletionTime__mdt
WHERE
(ServiceTeam__c = :caseComplexity.Team__c OR ServiceTeam__c = NULL)
AND CaseRecordType__c = 'ServiceCase'
AND ServiceLevel__c != NULL
LIMIT 1
];
MilestoneCompletionTime__mdt expectedMctOnUpdate = [
SELECT
Id,
CaseRecordType__c,
ServiceTeam__c,
ServiceTeam__r.DeveloperName,
ServiceLevel__c,
Priority__c,
EntitlementRecordName__c
FROM MilestonecompletionTime__mdt
WHERE
(ServiceTeam__c = :caseComplexity.Team__c OR ServiceTeam__c = NULL)
AND CaseRecordType__c = 'ServiceCase'
AND EntitlementRecordName__c != :expectedMctOnInsert.EntitlementRecordName__c
LIMIT 1
];
Account entitlementAccount = ServicesTestUtil.createAccount('test account 1', null, true);
Entitlement expectedEntitlementOnInsert = new Entitlement (
Name = expectedMctOnInsert.EntitlementRecordName__c,
AccountId = entitlementAccount.Id,
SlaProcessId = entitlementProcess.Id
);
Entitlement expectedEntitlementOnUpdate = new Entitlement (
Name = expectedMctOnUpdate.EntitlementRecordName__c,
AccountId = entitlementAccount.Id,
SlaProcessId = entitlementProcess.Id
);
insert new List<Entitlement> {expectedEntitlementOnInsert, expectedEntitlementOnUpdate};
Account testAccount = ServicesTestUtil.createAccount('test account 1', null, false);
testAccount.ServiceLevel__c = expectedMctOnInsert.ServiceLevel__c;
insert testAccount;
Case testCase = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, testAccount.Id, null, false);
testCase.Type = caseComplexity.Type__c;
testCase.SubType__c = caseComplexity.SubType__c;
testCase.ServiceTopic__c = caseComplexity.ServiceTopic__c;
testCase.Origin = caseComplexity.CaseOrigin__c;
testCase.RecordTypeId = Constants.rtCaseByDevNameMap.get(expectedMctOnInsert.CaseRecordType__c).getRecordTypeId();
testCase.Priority = expectedMctOnInsert.Priority__c;
testCase.RouteToServiceTeamOnCreate__c = false;
testCase.IsVisibleInPortal__c = true;
Case nonPortalCase = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, testAccount.Id, null, false);
nonPortalCase.Type = caseComplexity.Type__c;
nonPortalCase.SubType__c = caseComplexity.SubType__c;
nonPortalCase.ServiceTopic__c = caseComplexity.ServiceTopic__c;
nonPortalCase.Origin = caseComplexity.CaseOrigin__c;
nonPortalCase.RecordTypeId = Constants.rtCaseByDevNameMap.get(expectedMctOnInsert.CaseRecordType__c).getRecordTypeId();
nonPortalCase.Priority = expectedMctOnInsert.Priority__c;
nonPortalCase.RouteToServiceTeamOnCreate__c = false;
nonPortalCase.IsVisibleInPortal__c = false;
List<Case> cases = new List<Case>();
cases.add(testCase);
cases.add(nonPortalCase);
Test.startTest();
// verify insert value
insert cases;
for (Case c : [SELECT Id, EntitlementId, Priority, CustomerSegmentation__c, SLOTargetResolutionDate__c, SLOResolutionTime__c FROM Case WHERE Id in :cases]) {
if (c.Id == testCase.Id){
testCase = c;
Assert.areEqual(expectedEntitlementOnInsert.Id, testCase.EntitlementId, 'Entitlement ID after insert');
Assert.isNotNull(testCase.SLOTargetResolutionDate__c, 'SLOTargetResolutionDate__c is empty');
Assert.isNotNull(testCase.SLOResolutionTime__c, 'SLOResolutionTime__c is empty');
// update in the way entitlement process changes
testCase.Priority = expectedMctOnUpdate.Priority__c;
testCase.CustomerSegmentation__c = expectedMctOnUpdate.ServiceLevel__c;
testCase.ServiceTeam__c = expectedMctOnUpdate.ServiceTeam__c;
}
else if (c.Id == nonPortalCase.Id){
Assert.isNull(c.EntitlementId, 'Service Cases not visible in the portal should not have an Entitlement Record.');
Assert.isNull(c.SLOTargetResolutionDate__c, 'SLOTargetResolutionDate__c should be empty');
Assert.isNull(c.SLOResolutionTime__c, 'SLOResolutionTime__c should be empty');
}
}
update testCase;
Test.stopTest();
// verify update value
testCase = [SELECT Id, EntitlementId FROM Case WHERE Id = :testCase.Id];
Assert.areEqual(expectedEntitlementOnUpdate.Id, testCase.EntitlementId, 'Entitlement ID after update');
}
@IsTest
private static void getCorrectQueueUnclassifiedQueue() {
String unclassifiedQueueName = 'Unclassified';
String classifiedQueueName = 'classified';
CaseTaxonomyAction.CaseTaxonomyCollection taxonomyDetails = new CaseTaxonomyAction.CaseTaxonomyCollection();
taxonomyDetails.unclassifiedQueue = new Group(DeveloperName = unclassifiedQueueName);
taxonomyDetails.classifiedQueue = new Group(DeveloperName = classifiedQueueName);
Case testCase = new Case ();
Test.startTest();
Group resultNotClassified = CaseServiceHlpr.getCorrectQueue(testCase, taxonomyDetails);
testCase.type = 'Accounts';
Group resultOnlyTypePopulated = CaseServiceHlpr.getCorrectQueue(testCase, taxonomyDetails);
testCase.SubType__c = 'Payout Account';
Group resultNoTopic = CaseServiceHlpr.getCorrectQueue(testCase, taxonomyDetails);
Test.stopTest();
Assert.areEqual(unclassifiedQueueName, resultNotClassified.DeveloperName, 'Case 1 - Not classified: Unclassified queue should be selected');
Assert.areEqual(unclassifiedQueueName, resultOnlyTypePopulated.DeveloperName, 'Case 2 - Only type populated: Unclassified queue should be selected');
Assert.areEqual(unclassifiedQueueName, resultNoTopic.DeveloperName, 'Case 3 - Missing topic: Unclassified queue should be selected');
}
@IsTest
private static void getCorrectQueueStandardQueue() {
String unclassifiedQueueName = 'Unclassified';
String classifiedQueueName = 'classified';
CaseTaxonomyAction.CaseTaxonomyCollection taxonomyDetails = new CaseTaxonomyAction.CaseTaxonomyCollection();
taxonomyDetails.unclassifiedQueue = new Group(DeveloperName = unclassifiedQueueName);
taxonomyDetails.classifiedQueue = new Group(DeveloperName = classifiedQueueName);
Case testCase = new Case (
Type = 'Accounts',
SubType__c = 'Payout Account',
ServiceTopic__c = 'N/A'
);
Test.startTest();
Group resultQueue = CaseServiceHlpr.getCorrectQueue(testCase, taxonomyDetails);
Test.stopTest();
Assert.areEqual(classifiedQueueName, resultQueue.DeveloperName, 'Standard queue should be selected');
}
@IsTest
private static void getCorrectQueueNotUsingUnclassifiedQueue() {
String classifiedQueueName = 'classified';
CaseTaxonomyAction.CaseTaxonomyCollection taxonomyDetails = new CaseTaxonomyAction.CaseTaxonomyCollection();
taxonomyDetails.unclassifiedQueue = null;
taxonomyDetails.classifiedQueue = new Group(DeveloperName = classifiedQueueName);
Case testCase = new Case (
Type = 'Accounts'
);
Test.startTest();
Group resultQueue = CaseServiceHlpr.getCorrectQueue(testCase, taxonomyDetails);
Test.stopTest();
Assert.areEqual(classifiedQueueName, resultQueue.DeveloperName, 'Standard queue should be selected');
}
@isTest
private static void cloneCase() {
Case originalCase = new Case(AccountId = '001000000000000000', Origin = 'Email');
Case clonedCase = new Case();
Test.startTest();
CaseServiceHlpr.cloneCase(clonedCase, originalCase);
Test.stopTest();
Assert.areEqual(originalCase.AccountId, clonedCase.AccountId);
Assert.areEqual(originalCase.Origin, clonedCase.Origin);
}
@isTest
private static void cloneCaseTestLimitedUser() {
// make sure that the account owner has a role
update new User(Id = UserInfo.getUserId(), UserRoleId = ServicesTestUtil.getUserRoleId('Management CEO/CCO/CFO/COO'));
User portalUser;
System.runAs(new User(Id = UserInfo.getUserId())) {
Account acc = ServicesTestUtil.createAccount('Test account', Constants.RT_ID_ACC_BUSINESS, true);
Contact con = ServicesTestUtil.createContact(acc.Id, 'Jones', 'jones@adyen.com.fake', true);
portalUser = ServicesTestUtil.createPortalUser(con.Id, true);
ServicesTestUtil.assignPermissionsToUser(
new List<User>{portalUser},
new Set<String> (),
new Set<String> {ServicesTestUtil.SERVICE_PORTAL_PERMISSION_SET_NAME},
true);
}
Case originalCase = new Case (
RecordTypeId = Constants.RT_ID_CASE_SERVICECASE,
Origin = 'Email'
);
Case clonedCase = new Case ();
System.runAs(portalUser) {
Test.startTest();
CaseServiceHlpr.cloneCase(clonedCase, originalCase);
Test.stopTest();
}
Assert.isNull(clonedCase.RecordTypeId, 'User should not have create rights on record type');
Assert.isNull(clonedCase.Origin, 'User should not have create rights on case origin');
}
@isTest
private static void cloneCaseFullAccess() {
// make sure that the account owner has a role
update new User(Id = UserInfo.getUserId(), UserRoleId = ServicesTestUtil.getUserRoleId('Management CEO/CCO/CFO/COO'));
User portalUser;
System.runAs(new User(Id = UserInfo.getUserId())) {
Account acc = ServicesTestUtil.createAccount('Test account', Constants.RT_ID_ACC_BUSINESS, true);
Contact con = ServicesTestUtil.createContact(acc.Id, 'Jones', 'jones@adyen.com.fake', true);
portalUser = ServicesTestUtil.createPortalUser(con.Id, true);
ServicesTestUtil.assignPermissionsToUser(
new List<User>{portalUser},
new Set<String> (),
new Set<String> {ServicesTestUtil.SERVICE_PORTAL_PERMISSION_SET_NAME},
true);
}
Case originalCase = new Case (
RecordTypeId = Constants.RT_ID_CASE_SERVICECASE,
Origin = 'Email'
);
Case clonedCase = new Case ();
System.runAs(portalUser) {
Test.startTest();
CaseServiceHlpr.cloneCaseFullAccess(clonedCase, originalCase);
Test.stopTest();
}
Assert.areEqual(originalCase.RecordTypeId, clonedCase.RecordTypeId, 'User should have create rights on record type');
Assert.areEqual(originalCase.Origin, clonedCase.Origin, 'User should have create rights on case origin');
}
@isTest
private static void queryForCloneCase(){
Account acc1 = ServicesTestUtil.createAccount('test account 1', null, true);
Case originalCase = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, acc1.Id, null, false);
originalCase.Origin = 'Email';
originalCase.SuppliedPhone = '0123456789';
insert originalCase;
Test.startTest();
Case queriedCase = CaseServiceHlpr.queryCasesForCloning(new Set<Id>{originalCase.Id}, new Set<String>{'SuppliedPhone'})[0];
Test.stopTest();
Assert.areEqual(originalCase.AccountId, queriedCase.AccountId);
Assert.areEqual(originalCase.Origin, queriedCase.Origin);
Assert.areEqual(originalCase.SuppliedPhone, queriedCase.SuppliedPhone);
}
@IsTest
private static void testHandleCaseStopUnstop() {
SLAProcess entitlementProcess = [SELECT Id FROM SLAProcess WHERE IsActive = true LIMIT 1];
CaseComplexity__mdt caseComplexity = [SELECT Team__c
FROM CaseComplexity__mdt
WHERE Team__r.DeveloperName != 'PlatformMonitoring'
AND RecordTypeDevelopername__c = 'ServiceCase'
AND Team__r.BusinessHoursName__c = '15/7'
LIMIT 1];
MilestoneCompletionTime__mdt milestoneMapping = [SELECT ServiceLevel__c,
EntitlementRecordName__c
FROM MilestonecompletionTime__mdt
WHERE (ServiceTeam__c = :caseComplexity.Team__c OR ServiceTeam__c = null)
AND CaseRecordType__c = 'ServiceCase'
AND ServiceLevel__c != null
LIMIT 1];
Account entitlementAccount = ServicesTestUtil.createAccount('test account 1', null, true);
insert new Entitlement (
Name = milestoneMapping.EntitlementRecordName__c,
AccountId = entitlementAccount.Id,
SlaProcessId = entitlementProcess.Id
);
Account testAccount = ServicesTestUtil.createAccount('test account 1', null, false);
testAccount.ServiceLevel__c = milestoneMapping.ServiceLevel__c;
insert testAccount;
Case testCase = ServicesTestUtil.createCase(Constants.RT_ID_CASE_SERVICECASE, testAccount.Id, null, false);
testCase.Type = 'Non-Merchant Request';
testCase.SubType__c = 'Sub-Merchants';
testCase.ServiceTopic__c = 'KYC Check';
testCase.Origin = 'Salesforce';
testCase.Priority = 'Medium';
testCase.RouteToServiceTeamOnCreate__c = false;
testCase.IsVisibleInPortal__c = true;
insert testCase;
testCase.Status = 'Waiting For Merchant';
Test.startTest();
update testCase;
Test.stopTest();
testCase = [SELECT SLORemainingResolutionTime__c,
SLOTargetResolutionDate__c,
SLOTargetResolutionDateNoBH__c
FROM Case
WHERE Id = :testCase.Id];
Assert.isNotNull(testCase.SLORemainingResolutionTime__c, 'The field SLORemainingResolutionTime__c should not be null');
Assert.isNull(testCase.SLOTargetResolutionDate__c, 'The field SLOTargetResolutionDate__c should be set to null');
Assert.isNull(testCase.SLOTargetResolutionDateNoBH__c, 'The field SLOTargetResolutionDateNoBH__c should be set to null');
testCase.Status = 'In Progress';
update testCase;
testCase = [SELECT SLORemainingResolutionTime__c,
SLOTargetResolutionDate__c,
SLOTargetResolutionDateNoBH__c
FROM Case
WHERE Id = :testCase.Id];
Assert.isNull(testCase.SLORemainingResolutionTime__c, 'The field SLORemainingResolutionTime__c should be set to null');
Assert.isNotNull(testCase.SLOTargetResolutionDate__c, 'The field SLOTargetResolutionDate__c should not be null');
Assert.isNotNull(testCase.SLOTargetResolutionDateNoBH__c, 'The field SLOTargetResolutionDateNoBH__c should not be null');
}
/**
* Execute the calculateRemainingResTime method passing an amount of minutes that is less than an hour in value
* @result The time value is returned formatted in its minutes value
*/
@IsTest
private static void testCalculateRemainingResMinutes() {
Long thirtyMinutes = 30;
Test.startTest();
String result = CaseServiceHlpr.calculateRemainingResTime(thirtyMinutes);
Test.stopTest();
Assert.areEqual('30m', result, 'The expected value is 30m');
}
/**
* Execute the calculateRemainingResTime method passing an amount of minutes that is more than an hour and less
* than a day in value
* @result The time value is returned formatted in its hours value
*/
@IsTest
private static void testCalculateRemainingResHours() {
Long twoHoursInMinutes = 120;
Test.startTest();
String result = CaseServiceHlpr.calculateRemainingResTime(twoHoursInMinutes);
Test.stopTest();
Assert.areEqual('2h', result, 'The expected value is 2h');
}
/**
* Execute the calculateRemainingResTime method passing an amount of minutes that is more than an hour and less
* than a day in value
* @result The time value is returned formatted in its hours value, rounded down to the nearest hour
*/
@IsTest
private static void testCalculateRemainingResHoursRounded() {
Long twoHoursAndMoreInMinutes = 130;
Test.startTest();
String result = CaseServiceHlpr.calculateRemainingResTime(twoHoursAndMoreInMinutes);
Test.stopTest();
Assert.areEqual('2h', result, 'The expected value is 2h');
}
/**
* Execute the calculateRemainingResTime method passing an amount of minutes that is more than an hour and less
* than a day in value
* @result The time value is returned formatted in its hours value
*/
@IsTest
private static void testCalculateRemainingResDays() {
Long twoDaysInMinutes = 2880;
Test.startTest();
String result = CaseServiceHlpr.calculateRemainingResTime(twoDaysInMinutes);
Test.stopTest();
Assert.areEqual('2d', result, 'The expected value is 2d');
}
/**
* Execute the calculateRemainingResTime method passing an amount of minutes that is more than a full day in value
* @result The time value is returned formatted in its days value
*/
@IsTest
private static void testCalculateRemainingResDaysRounded() {
Long twoDaysAndMoreInMinutes = 2900;
Test.startTest();
String result = CaseServiceHlpr.calculateRemainingResTime(twoDaysAndMoreInMinutes);
Test.stopTest();
Assert.areEqual('2d', result, 'The expected value is 2d');
}
}