-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1454 from SFDO-Community/feature/tests-for-new-lw…
…c-wizard Add tests for new LWC Wizard Apex
- Loading branch information
Showing
14 changed files
with
649 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
@isTest | ||
private class AsyncApexJobsSelectorTest { | ||
@isTest | ||
static void testGetScheduledInstancesOfType() { | ||
List<AsyncApexJob> jobs = new AsyncApexJobsSelector().getAllScheduledJobs(); | ||
Integer jobCountStart = jobs.size(); | ||
if (jobCountStart > 98) { | ||
System.debug('not enough capacity to schedule new, exiting early'); | ||
return; | ||
} | ||
|
||
// we don't get database isolation here | ||
// ensure tests here don't break if extra jobs are scheduled | ||
String jobId1 = System.schedule( | ||
'TestJob112233', | ||
'0 0 * * * ? 2100', | ||
new RollupJob() | ||
); | ||
String jobId2 = System.schedule( | ||
'TestJob998877', | ||
'0 0 * * * ? 2101', | ||
new RollupJob() | ||
); | ||
|
||
jobs = new AsyncApexJobsSelector().getAllScheduledJobs(); | ||
Assert.areEqual( | ||
2, | ||
jobs.size() - jobCountStart, | ||
'Expected total scheduled jobs to have increased by two' | ||
); | ||
|
||
jobs = new List<AsyncApexJob>( | ||
new AsyncApexJobsSelector().getScheduledInstancesOfType(RollupJob.class) | ||
); | ||
|
||
Assert.isTrue( | ||
jobs.size() >= 2, | ||
'Exepcted at least 2 jobs, found ' + jobs.size() | ||
); | ||
|
||
Boolean hasJob1 = false; | ||
Boolean hasJob2 = false; | ||
|
||
for (AsyncApexJob job : jobs) { | ||
if (job.CronTriggerId == (Id) jobId1) { | ||
hasJob1 = true; | ||
} | ||
if (job.CronTriggerId == (Id) jobId2) { | ||
hasJob2 = true; | ||
} | ||
} | ||
|
||
Assert.isTrue( | ||
hasJob1, | ||
'Expected ' + jobId1 + ' to be included in jobs list:' + jobs | ||
); | ||
Assert.isTrue( | ||
hasJob2, | ||
'Expected ' + jobId2 + ' to be included in jobs list:' + jobs | ||
); | ||
|
||
// clear jobs | ||
System.abortJob(jobId1); | ||
System.abortJob(jobId2); | ||
|
||
Assert.isTrue(jobs.size() >= 2, 'Expected at least two jobs scheduled'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>60.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
dlrs/main/classes/LookupRollupStatusCheckControllerTest.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
@IsTest | ||
public with sharing class LookupRollupStatusCheckControllerTest { | ||
@IsTest | ||
static void testGetOutstandingScheduledItemsForLookup() { | ||
List<LookupRollupSummary2__mdt> summaries = [ | ||
SELECT Id | ||
FROM LookupRollupSummary2__mdt | ||
LIMIT 1 | ||
]; | ||
if (summaries.isEmpty()) { | ||
return; | ||
} | ||
Integer val = LookupRollupStatusCheckController.getOutstandingScheduledItemsForLookup( | ||
summaries[0].Id | ||
); | ||
Assert.isTrue(val >= 0, 'Expected a value, even zero'); | ||
} | ||
|
||
@IsTest | ||
static void testgetScheduledFullCalculates() { | ||
List<LookupRollupSummary2__mdt> summaries = [ | ||
SELECT Id, DeveloperName | ||
FROM LookupRollupSummary2__mdt | ||
LIMIT 1 | ||
]; | ||
if (summaries.isEmpty()) { | ||
return; | ||
} | ||
|
||
// Build the CRON string | ||
// Kickoff the calculate job for this lookup | ||
|
||
String uniqueNameForJob = | ||
'rollup_' + | ||
summaries[0].DeveloperName + | ||
'(' + | ||
summaries[0].Id.to15() + | ||
')'; | ||
|
||
String jobId; | ||
try { | ||
jobId = System.schedule( | ||
uniqueNameForJob, | ||
'0 0 * * * ? 2100', | ||
new RollupCalculateJobSchedulable(summaries[0].Id, '') | ||
); | ||
} catch (Exception e) { | ||
System.debug( | ||
'Failed to schedule, probably because it is already scheduled:' + | ||
e.getMessage() | ||
); | ||
} | ||
|
||
Datetime nextRunDate = LookupRollupStatusCheckController.getScheduledFullCalculates( | ||
summaries[0].Id | ||
); | ||
Assert.isNotNull(nextRunDate); | ||
if (String.isNotBlank(jobId)) { | ||
System.abortJob(jobId); | ||
} | ||
} | ||
|
||
@IsTest | ||
static void testHasChildTriggerDeployed() { | ||
// limited to records in the org, would have to mock things | ||
LookupRollupStatusCheckController.hasChildTriggerDeployed(null); | ||
|
||
List<LookupRollupSummary2__mdt> rec = [ | ||
SELECT Id | ||
FROM LookupRollupSummary2__mdt | ||
WHERE Active__c = TRUE AND CalculationMode__c IN ('Realtime', 'Scheduled') | ||
LIMIT 1 | ||
]; | ||
if (rec.size() == 0) { | ||
return; | ||
} | ||
|
||
Boolean isDeployed = LookupRollupStatusCheckController.hasChildTriggerDeployed( | ||
rec[0].Id | ||
); | ||
// Assume anything active and needing a trigger should have one | ||
// this test could fail for silly reasons | ||
Assert.areEqual( | ||
true, | ||
isDeployed, | ||
'Expected a rollup that requires a trigger to have one, could be false-positive' | ||
); | ||
} | ||
|
||
@IsTest | ||
static void testGetScheduledJobs() { | ||
Integer startVal = LookupRollupStatusCheckController.getScheduledJobs(); | ||
String jobId = System.schedule( | ||
'Test Job 2000', | ||
'0 0 * * * ? 2100', | ||
new RollupJob() | ||
); | ||
Integer endVal = LookupRollupStatusCheckController.getScheduledJobs(); | ||
Assert.areEqual( | ||
1, | ||
endVal - startVal, | ||
'Expected class to report an additional scheduled job' | ||
); | ||
System.abortJob(jobId); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
dlrs/main/classes/LookupRollupStatusCheckControllerTest.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>60.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@IsTest | ||
public with sharing class ObjectSelectorControllerTest { | ||
@IsTest | ||
static void testGetParentObjList() { | ||
List<ObjectSelectorController.SObjectInfo> objects = ObjectSelectorController.getParentObjList(); | ||
Assert.isFalse(objects.isEmpty()); | ||
|
||
Set<String> expected = new Set<String>{ | ||
'Account', | ||
'Opportunity', | ||
Schema.LookupRollupSummary2__mdt.getSObjectType().getDescribe().getName() | ||
}; | ||
for (ObjectSelectorController.SObjectInfo sobj : objects) { | ||
expected.remove(sobj.fullName); | ||
} | ||
|
||
// expected items should have been removed | ||
Assert.isTrue(expected.isEmpty()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>60.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
Oops, something went wrong.