diff --git a/dlrs/main/classes/AsyncApexJobsSelectorTest.cls b/dlrs/main/classes/AsyncApexJobsSelectorTest.cls new file mode 100644 index 00000000..132c6a24 --- /dev/null +++ b/dlrs/main/classes/AsyncApexJobsSelectorTest.cls @@ -0,0 +1,68 @@ +@isTest +private class AsyncApexJobsSelectorTest { + @isTest + static void testGetScheduledInstancesOfType() { + List 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( + 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'); + } +} diff --git a/dlrs/main/classes/AsyncApexJobsSelectorTest.cls-meta.xml b/dlrs/main/classes/AsyncApexJobsSelectorTest.cls-meta.xml new file mode 100644 index 00000000..3a10d2eb --- /dev/null +++ b/dlrs/main/classes/AsyncApexJobsSelectorTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 60.0 + Active + \ No newline at end of file diff --git a/dlrs/main/classes/CustomMetadataService.cls b/dlrs/main/classes/CustomMetadataService.cls index f9e97b9e..9fe5eb12 100644 --- a/dlrs/main/classes/CustomMetadataService.cls +++ b/dlrs/main/classes/CustomMetadataService.cls @@ -273,6 +273,7 @@ public class CustomMetadataService { ); } + @TestVisible class ApexMdApiDeployCallback implements Metadata.DeployCallback { public void handleResult( Metadata.DeployResult result, @@ -286,6 +287,7 @@ public class CustomMetadataService { } } + @TestVisible class DeleteMetadataQueueable implements Queueable, Database.AllowsCallouts { SObjectType qualifiedMetadataType; List customMetadataFullNames; diff --git a/dlrs/main/classes/CustomMetadataServiceTest.cls b/dlrs/main/classes/CustomMetadataServiceTest.cls index e865209e..71e4dbdd 100644 --- a/dlrs/main/classes/CustomMetadataServiceTest.cls +++ b/dlrs/main/classes/CustomMetadataServiceTest.cls @@ -26,4 +26,131 @@ @IsTest private class CustomMetadataServiceTest { + @IsTest + static void testInitiateMetadataSave() { + try { + CustomMetadataService.initiateMetadataSave( + new List{ + new LookupRollupSummary2__mdt( + DeveloperName = 'TestRec', + Label = 'Test Rec', + Active__c = true, + RowLimit__c = 100 + ) + } + ); + Assert.fail('Expected to fail starting the deployment'); + } catch (System.AsyncException e) { + Assert.areEqual( + 'Metadata cannot be deployed from within a test', + e.getMessage() + ); + } + } + + @IsTest + static void testDeleteMetadataAsync() { + Test.startTest(); + Test.setMock( + WebServiceMock.class, + new MetadataServiceDeleteSuccessCalloutMock() + ); + CustomMetadataService.deleteMetadataAsync( + LookupRollupSummary2__mdt.getSObjectType(), + new List{ 'LookupRollupSummary2__mdt.Test123' } + ); + Test.stopTest(); + } + + @IsTest + static void testDeleteMetadataAsyncFailed() { + Test.startTest(); + Test.setMock( + WebServiceMock.class, + new MetadataServiceDeleteFailureCalloutMock() + ); + CustomMetadataService.deleteMetadataAsync( + LookupRollupSummary2__mdt.getSObjectType(), + new List{ 'LookupRollupSummary2__mdt.Test123' } + ); + Test.stopTest(); + } + + @IsTest + static void testApexMdApiDeployCallback() { + CustomMetadataService.ApexMdApiDeployCallback cb = new CustomMetadataService.ApexMdApiDeployCallback(); + Metadata.DeployResult result = new Metadata.DeployResult(); + result.status = Metadata.DeployStatus.Succeeded; + Metadata.DeployMessage messageObj = new Metadata.DeployMessage(); + messageObj.changed = true; + messageObj.success = true; + messageObj.fullName = 'TestRec'; + messageObj.componentType = 'CustomMetadata'; + messageObj.fullName = 'LookupRollupSummary2__mdt.TestRec'; + Metadata.DeployDetails deployDetailsObj = new Metadata.DeployDetails(); + deployDetailsObj.componentSuccesses.add(messageObj); + result.details = deployDetailsObj; + Metadata.DeployCallbackContext context = new Metadata.DeployCallbackContext(); + + // Invoke the callback's handleResult method. + cb.handleResult(result, context); + + // expected Platform Event publishing DML + Assert.areEqual(1, Limits.getDmlStatements()); + Assert.areEqual(1, Limits.getDmlRows()); + } + + public class MetadataServiceDeleteSuccessCalloutMock implements WebServiceMock { + public void doInvoke( + Object stub, + Object request, + Map response, + String endpoint, + String soapAction, + String requestName, + String responseNS, + String responseName, + String responseType + ) { + System.debug(request); + MetadataService.deleteMetadataResponse_element responseElement = new MetadataService.deleteMetadataResponse_element(); + // MetadataService.createMetadataResponse_element responseElement = new MetadataService.createMetadataResponse_element(); + MetadataService.DeleteResult res = new MetadataService.DeleteResult(); + res.success = true; + res.fullName = 'myTestResult'; + responseElement.result = new List{ res }; + + response.put('response_x', responseElement); + } + } + + public class MetadataServiceDeleteFailureCalloutMock implements WebServiceMock { + public void doInvoke( + Object stub, + Object request, + Map response, + String endpoint, + String soapAction, + String requestName, + String responseNS, + String responseName, + String responseType + ) { + System.debug(request); + MetadataService.deleteMetadataResponse_element responseElement = new MetadataService.deleteMetadataResponse_element(); + // MetadataService.createMetadataResponse_element responseElement = new MetadataService.createMetadataResponse_element(); + MetadataService.DeleteResult res = new MetadataService.DeleteResult(); + res.success = false; + res.errors = new List(); + MetadataService.Error err = new MetadataService.Error(); + err.message = 'Test Error'; + err.statusCode = 'Error Code'; + err.fields = new List{ 'Field__1', 'Field_2' }; + res.errors.add(err); + res.fullName = 'myTestResult'; + responseElement.result = new List{ res }; + + response.put('response_x', responseElement); + } + } } diff --git a/dlrs/main/classes/LookupRollupStatusCheckControllerTest.cls b/dlrs/main/classes/LookupRollupStatusCheckControllerTest.cls new file mode 100644 index 00000000..70586cd3 --- /dev/null +++ b/dlrs/main/classes/LookupRollupStatusCheckControllerTest.cls @@ -0,0 +1,106 @@ +@IsTest +public with sharing class LookupRollupStatusCheckControllerTest { + @IsTest + static void testGetOutstandingScheduledItemsForLookup() { + List 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 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 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); + } +} diff --git a/dlrs/main/classes/LookupRollupStatusCheckControllerTest.cls-meta.xml b/dlrs/main/classes/LookupRollupStatusCheckControllerTest.cls-meta.xml new file mode 100644 index 00000000..3a10d2eb --- /dev/null +++ b/dlrs/main/classes/LookupRollupStatusCheckControllerTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 60.0 + Active + \ No newline at end of file diff --git a/dlrs/main/classes/ObjectSelectorController.cls b/dlrs/main/classes/ObjectSelectorController.cls index a786ade9..aa209a2a 100644 --- a/dlrs/main/classes/ObjectSelectorController.cls +++ b/dlrs/main/classes/ObjectSelectorController.cls @@ -9,7 +9,7 @@ public with sharing class ObjectSelectorController { return objects; } - class SObjectInfo { + public class SObjectInfo { @AuraEnabled public String fullName; @AuraEnabled diff --git a/dlrs/main/classes/ObjectSelectorControllerTest.cls b/dlrs/main/classes/ObjectSelectorControllerTest.cls new file mode 100644 index 00000000..ad38215c --- /dev/null +++ b/dlrs/main/classes/ObjectSelectorControllerTest.cls @@ -0,0 +1,20 @@ +@IsTest +public with sharing class ObjectSelectorControllerTest { + @IsTest + static void testGetParentObjList() { + List objects = ObjectSelectorController.getParentObjList(); + Assert.isFalse(objects.isEmpty()); + + Set expected = new Set{ + '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()); + } +} diff --git a/dlrs/main/classes/ObjectSelectorControllerTest.cls-meta.xml b/dlrs/main/classes/ObjectSelectorControllerTest.cls-meta.xml new file mode 100644 index 00000000..3a10d2eb --- /dev/null +++ b/dlrs/main/classes/ObjectSelectorControllerTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 60.0 + Active + \ No newline at end of file diff --git a/dlrs/main/classes/RollupEditorControllerTest.cls b/dlrs/main/classes/RollupEditorControllerTest.cls new file mode 100644 index 00000000..5a595017 --- /dev/null +++ b/dlrs/main/classes/RollupEditorControllerTest.cls @@ -0,0 +1,212 @@ +@IsTest +public with sharing class RollupEditorControllerTest { + static LookupRollupSummary2__mdt lup = new LookupRollupSummary2__mdt( + Id = Schema.LookupRollupSummary2__mdt.getSObjectType() + .getDescribe() + .getKeyPrefix() + '000000000aaa', + Label = 'TestLabel', + DeveloperName = 'TestDevName', + Active__c = true, + AggregateAllRows__c = true, + AggregateOperation__c = 'Count', + AggregateResultField__c = 'ResultField', + CalculationMode__c = 'CalcMode', + CalculationSharingMode__c = 'SharingMode', + ChildObject__c = 'ChildObject', + ConcatenateDelimiter__c = 'Delim', + Description__c = 'Desc', + FieldToAggregate__c = 'FieldToAgg', + FieldToOrderBy__c = 'FieldToOrder', + ParentObject__c = 'ParentObject', + RelationshipCriteria__c = 'RelCriteria', + RelationshipCriteriaFields__c = 'Field1\nField2', + RelationshipField__c = 'RelField', + RowLimit__c = 100, + TestCode2__c = 'TestCode', + TestCodeParent__c = 'ParentTestCode', + TestCodeSeeAllData__c = true + ); + + @IsTest + static void testGetAllRollupConfigs() { + List lookups = [ + SELECT Id + FROM LookupRollupSummary2__mdt + ]; + List configs = RollupEditorController.getAllRollupConfigs(); + Assert.areEqual(lookups.size(), configs.size()); + } + + @IsTest + static void testGetRollupConfig() { + List lookups = [ + SELECT + Id, + Label, + DeveloperName, + Active__c, + AggregateAllRows__c, + AggregateOperation__c, + AggregateResultField__c, + CalculationMode__c, + CalculationSharingMode__c, + ChildObject__c, + ConcatenateDelimiter__c, + Description__c, + FieldToAggregate__c, + FieldToOrderBy__c, + ParentObject__c, + RelationshipCriteria__c, + RelationshipCriteriaFields__c, + RelationshipField__c, + RowLimit__c, + TestCode__c, + TestCodeParent__c, + TestCodeSeeAllData__c + FROM LookupRollupSummary2__mdt + ]; + if (lookups.isEmpty()) { + return; + } + LookupRollupSummary2__mdt lup = lookups[0]; + RollupEditorController.RollupConfig cfg = RollupEditorController.getRollupConfig( + lup.DeveloperName + ); + Assert.areEqual(lup.Id, cfg.id); + Assert.areEqual(lup.Label, cfg.label); + Assert.areEqual(lup.DeveloperName, cfg.developerName); + } + + @IsTest + static void testGetFieldOptions() { + List fields = RollupEditorController.getFieldOptions( + 'User' + ); + Assert.isFalse(fields.isEmpty()); + } + + @IsTest + static void testValidateRollupConfig() { + RollupEditorController.RollupConfig cfg = new RollupEditorController.RollupConfig( + lup + ); + Map> errors = RollupEditorController.validateRollupConfig( + JSON.serialize(cfg) + ); + Assert.areEqual( + '{"rowLimit":["Row Limit is only supported on Last and Concatentate operators."],"parentObject":["Object does not exist."],"childObject":["Object does not exist."]}', + JSON.serialize(errors) + ); + } + + @IsTest + static void testSaveRollupConfig() { + RollupEditorController.RollupConfig cfg = new RollupEditorController.RollupConfig( + lup + ); + try { + Id depId = RollupEditorController.saveRollupConfig(JSON.serialize(cfg)); + Assert.fail('Should throw an exception'); + } catch (System.AsyncException e) { + Assert.areEqual( + 'Metadata cannot be deployed from within a test', + e.getMessage() + ); + } + } + + @IsTest + static void testDeleteRollupConfig() { + Id queueableId = RollupEditorController.deleteRollupConfig('Hello'); + AsyncApexJob queueJob = [ + SELECT Id + FROM AsyncApexJob + WHERE Id = :queueableId + ]; + Assert.areEqual(queueableId, queueJob.Id); + System.abortJob(queueJob.Id); + } + + @IsTest + static void testGetManageTriggerPageUrl() { + String url = RollupEditorController.getManageTriggerPageUrl(lup.Id); + PageReference pageRef = Page.managetriggermdt; + Assert.areEqual(pageRef.getUrl() + '?id=' + lup.Id, url); + } + + @IsTest + static void testGetFullCalculatePageUrl() { + String url = RollupEditorController.getFullCalculatePageUrl(lup.Id); + PageReference pageRef = Page.rollupcalculatemdt; + Assert.areEqual(pageRef.getUrl() + '?id=' + lup.Id, url); + } + + @IsTest + static void testGetScheduleCalculatePageUrl() { + String url = RollupEditorController.getScheduleCalculatePageUrl(lup.Id); + PageReference pageRef = Page.rollupscheduledcalculatemdt; + Assert.areEqual(pageRef.getUrl() + '?id=' + lup.Id, url); + } + + @IsTest + static void testRollupConfig() { + RollupEditorController.RollupConfig cfg = new RollupEditorController.RollupConfig( + lup + ); + Assert.areEqual(lup.Id, cfg.id); + Assert.areEqual(lup.Label, cfg.label); + Assert.areEqual(lup.DeveloperName, cfg.developerName); + Assert.areEqual(lup.Active__c, cfg.active); + Assert.areEqual(lup.AggregateAllRows__c, cfg.aggregateAllRows); + Assert.areEqual(lup.AggregateOperation__c, cfg.aggregateOperation); + Assert.areEqual(lup.AggregateResultField__c, cfg.aggregateResultField); + Assert.areEqual(lup.CalculationMode__c, cfg.calculationMode); + Assert.areEqual(lup.CalculationSharingMode__c, cfg.calculationSharingMode); + Assert.areEqual(lup.ChildObject__c, cfg.childObject); + Assert.areEqual(lup.ConcatenateDelimiter__c, cfg.concatenateDelimiter); + Assert.areEqual(lup.Description__c, cfg.description); + Assert.areEqual(lup.FieldToAggregate__c, cfg.fieldToAggregate); + Assert.areEqual(lup.FieldToOrderBy__c, cfg.fieldToOrderBy); + Assert.areEqual(lup.ParentObject__c, cfg.parentObject); + Assert.areEqual(lup.RelationshipCriteria__c, cfg.relationshipCriteria); + Assert.areEqual( + lup.RelationshipCriteriaFields__c, + cfg.relationshipCriteriaFields + ); + Assert.areEqual(lup.RelationshipField__c, cfg.relationshipField); + Assert.areEqual(lup.RowLimit__c, cfg.rowLimit); + Assert.areEqual(lup.TestCode2__c, cfg.testCode); + Assert.areEqual(lup.TestCodeParent__c, cfg.testCodeParent); + Assert.areEqual(lup.TestCodeSeeAllData__c, cfg.testCodeSeeAllData); + LookupRollupSummary2__mdt newLup = cfg.getRecord(); + + Assert.areEqual(cfg.id, newLup.Id); + Assert.areEqual(cfg.label, newLup.Label); + Assert.areEqual(cfg.developerName, newLup.DeveloperName); + Assert.areEqual(cfg.active, newLup.Active__c); + Assert.areEqual(cfg.aggregateAllRows, newLup.AggregateAllRows__c); + Assert.areEqual(cfg.aggregateOperation, newLup.AggregateOperation__c); + Assert.areEqual(cfg.aggregateResultField, newLup.AggregateResultField__c); + Assert.areEqual(cfg.calculationMode, newLup.CalculationMode__c); + Assert.areEqual( + cfg.calculationSharingMode, + newLup.CalculationSharingMode__c + ); + Assert.areEqual(cfg.childObject, newLup.ChildObject__c); + Assert.areEqual(cfg.concatenateDelimiter, newLup.ConcatenateDelimiter__c); + Assert.areEqual(cfg.description, newLup.Description__c); + Assert.areEqual(cfg.fieldToAggregate, newLup.FieldToAggregate__c); + Assert.areEqual(cfg.fieldToOrderBy, newLup.FieldToOrderBy__c); + Assert.areEqual(cfg.parentObject, newLup.ParentObject__c); + Assert.areEqual(cfg.relationshipCriteria, newLup.RelationshipCriteria__c); + Assert.areEqual( + cfg.relationshipCriteriaFields, + newLup.RelationshipCriteriaFields__c + ); + Assert.areEqual(cfg.relationshipField, newLup.RelationshipField__c); + Assert.areEqual(cfg.rowLimit, newLup.RowLimit__c); + Assert.areEqual(cfg.testCode, newLup.TestCode2__c); + Assert.areEqual(cfg.testCodeParent, newLup.TestCodeParent__c); + Assert.areEqual(cfg.testCodeSeeAllData, newLup.TestCodeSeeAllData__c); + } +} diff --git a/dlrs/main/classes/RollupEditorControllerTest.cls-meta.xml b/dlrs/main/classes/RollupEditorControllerTest.cls-meta.xml new file mode 100644 index 00000000..3a10d2eb --- /dev/null +++ b/dlrs/main/classes/RollupEditorControllerTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 60.0 + Active + \ No newline at end of file diff --git a/dlrs/main/classes/SchedulerController.cls b/dlrs/main/classes/SchedulerController.cls index cee555ed..53cce962 100644 --- a/dlrs/main/classes/SchedulerController.cls +++ b/dlrs/main/classes/SchedulerController.cls @@ -13,8 +13,12 @@ public with sharing class SchedulerController { } @AuraEnabled - public static void scheduleJobs(String className, List newSchedules) { + public static List scheduleJobs( + String className, + List newSchedules + ) { Integer counter = 1; + List jobIds = new List(); Schedulable clsInstance = (Schedulable) Type.forName(className) .newInstance(); List currentJobs = new AsyncApexJobsSelector() @@ -29,8 +33,9 @@ public with sharing class SchedulerController { // if this name is taken, get the next scheduledName = className + ' ' + counter++; } - System.schedule(scheduledName, cron, clsInstance); + jobIds.add(System.schedule(scheduledName, cron, clsInstance)); } + return jobIds; } @AuraEnabled diff --git a/dlrs/main/classes/SchedulerControllerTest.cls b/dlrs/main/classes/SchedulerControllerTest.cls new file mode 100644 index 00000000..d54072d8 --- /dev/null +++ b/dlrs/main/classes/SchedulerControllerTest.cls @@ -0,0 +1,83 @@ +@IsTest +public with sharing class SchedulerControllerTest { + @IsTest + static void testGetCurrentJobsAndCancelSched() { + List jobsStart = SchedulerController.getCurrentJobs( + 'RollupJob' + ); + + String jobId = System.schedule( + 'TestJob112233', + '0 0 * * * ? 2100', + new RollupJob() + ); + + List jobs = SchedulerController.getCurrentJobs('RollupJob'); + Assert.isFalse( + jobs.isEmpty(), + 'Expected jobs to return at least one result' + ); + Assert.areEqual(1, jobs.size() - jobsStart.size()); + + Boolean includesJob = false; + for (AsyncApexJob j : jobs) { + if (j.CronTriggerId == jobId) { + includesJob = true; + } + } + Assert.isTrue( + includesJob, + 'Expected jobs list to include temp scheduled job' + ); + + SchedulerController.cancelScheduledJob(jobId); + + jobs = SchedulerController.getCurrentJobs('RollupJob'); + + includesJob = false; + for (AsyncApexJob j : jobs) { + if (j.CronTriggerId == jobId) { + includesJob = true; + } + } + Assert.isFalse(includesJob, 'Expected job to be cancelled'); + + System.abortJob(jobId); + } + + @IsTest + static void testGetAllScheduledJobs() { + List jobsStart = SchedulerController.getAllScheduledJobs(); + String jobId = System.schedule( + 'TestJob112233', + '0 0 * * * ? 2100', + new RollupJob() + ); + + List jobsAfter = SchedulerController.getAllScheduledJobs(); + Assert.areEqual(1, jobsAfter.size() - jobsStart.size()); + System.abortJob(jobId); + } + + @IsTest + static void testScheduleJobs() { + List jobsStart = SchedulerController.getAllScheduledJobs(); + List jobIds = SchedulerController.scheduleJobs( + 'RollupJob', + new List{ '0 0 * * * ? 2100', '0 0 * * * ? 2101' } + ); + jobIds.addAll( + SchedulerController.scheduleJobs( + 'RollupJob', + new List{ '0 0 * * * ? 2100', '0 0 * * * ? 2101' } + ) + ); + List jobsAfter = SchedulerController.getAllScheduledJobs(); + + Assert.areEqual(4, jobsAfter.size() - jobsStart.size()); + + for (Id jId : jobIds) { + System.abortJob(jId); + } + } +} diff --git a/dlrs/main/classes/SchedulerControllerTest.cls-meta.xml b/dlrs/main/classes/SchedulerControllerTest.cls-meta.xml new file mode 100644 index 00000000..3a10d2eb --- /dev/null +++ b/dlrs/main/classes/SchedulerControllerTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 60.0 + Active + \ No newline at end of file