Skip to content

Commit

Permalink
Added Test Cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Larrimore committed Nov 5, 2020
1 parent d867512 commit 4ec4294
Show file tree
Hide file tree
Showing 25 changed files with 740 additions and 334 deletions.
450 changes: 267 additions & 183 deletions data/export-demo-Demo_Component__c.json

Large diffs are not rendered by default.

68 changes: 65 additions & 3 deletions force-app/main/default/classes/CpmComponentController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,78 @@ public with sharing class CpmComponentController {

@AuraEnabled(cacheable=true)
public static list<Demo_Component__c> getDemoComponents(){
return [SELECT Id, Title__c, Name, Description__c, Package_Name__c, Installation_Type__c, Install_Date__c, Update_Available__c, Installed__c, POC_Email__c, POC_Name__c, Github_Repository_URL__c, Installed_Version__c, Latest_Package_Version_Deprecated_Flag__c, SFDX_Package_Enabled_Flag__c FROM Demo_Component__c];
return [SELECT Id,
Title__c,
Name,
Description__c,
Dependencies_Met__c,
Package_Name__c,
Installation_Type__c,
Install_Date__c,
Update_Available__c,
Installed__c,
POC_Email__c,
POC_Name__c,
Github_Repository_URL__c,
Installed_Version__c,
Source_Install_Type_Flag__c,
Source_Install_Url__c,
Package_Install_Type_Flag__c,
Package_Install_Url__c,
Latest_Package_Version_Deprecated_Flag__c,
SFDX_Package_Enabled_Flag__c
FROM Demo_Component__c
];
}

@AuraEnabled
public static list<Demo_Component__c> getInstalledComponents(){
return [SELECT Id, Title__c, Name, Description__c, Package_Name__c, Installation_Type__c, Install_Date__c, Update_Available__c, Installed__c, POC_Email__c, POC_Name__c, Github_Repository_URL__c, Installed_Version__c, Latest_Package_Version_Deprecated_Flag__c, SFDX_Package_Enabled_Flag__c FROM Demo_Component__c WHERE Installed__c = true];
return [SELECT Id,
Title__c,
Name,
Description__c,
Dependencies_Met__c,
Package_Name__c,
Installation_Type__c,
Install_Date__c,
Update_Available__c,
Installed__c,
POC_Email__c,
POC_Name__c,
Github_Repository_URL__c,
Installed_Version__c,
Source_Install_Type_Flag__c,
Source_Install_Url__c,
Package_Install_Type_Flag__c,
Package_Install_Url__c,
Latest_Package_Version_Deprecated_Flag__c,
SFDX_Package_Enabled_Flag__c
FROM Demo_Component__c
WHERE Installed__c = true];
}

@AuraEnabled
public static list<Demo_Component__c> getAvailableComponents(){
return [SELECT Id, Title__c, Name, Description__c, Package_Name__c, Installation_Type__c, Install_Date__c, Update_Available__c, Installed__c, POC_Email__c, POC_Name__c, Github_Repository_URL__c, Latest_Package_Version_Deprecated_Flag__c, SFDX_Package_Enabled_Flag__c FROM Demo_Component__c WHERE Installed__c = false];
return [SELECT Id,
Title__c,
Name,
Description__c,
Dependencies_Met__c,
Package_Name__c,
Installation_Type__c,
Install_Date__c,
Update_Available__c,
Installed__c,
POC_Email__c,
POC_Name__c,
Github_Repository_URL__c,
Source_Install_Type_Flag__c,
Source_Install_Url__c,
Package_Install_Type_Flag__c,
Package_Install_Url__c,
Latest_Package_Version_Deprecated_Flag__c,
SFDX_Package_Enabled_Flag__c
FROM Demo_Component__c
WHERE Installed__c = false];
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,55 @@
public with sharing class CpmComponentInstallCheckerController {

@AuraEnabled
public static void runApex(){
public static void runApex(boolean forcedRefresh){
System.debug('Running CPMInstallCheckerController.runApex');
List<AsyncApexJob> existingJobs;

QueueGetInstalledPackages queueGetInstalledPackagesJob = new QueueGetInstalledPackages();
existingJobs = [SELECT Id, ApexClass.Name, Status FROM AsyncApexJob WHERE Status IN ('Holding','Queued','Preparing','Processing') AND ApexClass.Name = :queueGetInstalledPackagesJob.getJobInfo(QueuePlatformAsyncEventHelper.FIELD_APEX_CLASS_NAME) LIMIT 1];
if (existingJobs.size() == 0){
System.debug('Running queueGetInstalledPackagesJob');
System.enqueueJob(queueGetInstalledPackagesJob);
Demo_Component_Manager_Settings__c appSetting = new Demo_Component_Manager_Settings__c();
List<Demo_Component_Manager_Settings__c> appSettings = [SELECT Id, Last_Library_Refresh_Date__c FROM Demo_Component_Manager_Settings__c];

if(appSettings.size() == 0){
System.debug('Initializing appSettings');
insert appSetting;
}else{
appSetting = appSettings[0];
}

VersionHelper.getinstalledXTAGs(null);

DateTime now = datetime.now();
DateTime yesterday = now.addDays(-1);

if(appSetting.Last_Library_Refresh_Date__c == null || appSetting.Last_Library_Refresh_Date__c < yesterday || forcedRefresh){
System.debug('Running refresh');
appSetting.Last_Library_Refresh_Date__c = datetime.now();
update appSetting;

QueueGetInstalledPackages queueGetInstalledPackagesJob = new QueueGetInstalledPackages();
existingJobs = [SELECT Id, ApexClass.Name, Status FROM AsyncApexJob WHERE Status IN ('Holding','Queued','Preparing','Processing') AND ApexClass.Name = :queueGetInstalledPackagesJob.getJobInfo(QueuePlatformAsyncEventHelper.FIELD_APEX_CLASS_NAME) LIMIT 1];
if (existingJobs.size() == 0){
System.debug('Running queueGetInstalledPackagesJob');
System.enqueueJob(queueGetInstalledPackagesJob);
}
VersionHelper.getinstalledXTAGs(null);
}else{
System.debug('Not Running refresh');
}
}

@AuraEnabled
public static Demo_Component_Manager_Settings__c getAppSettings(){
System.debug('Running CPMInstallCheckerController.getAppSettings');
Demo_Component_Manager_Settings__c appSetting = new Demo_Component_Manager_Settings__c();
List<Demo_Component_Manager_Settings__c> appSettings = [SELECT Id, Last_Library_Refresh_Date__c, Initial_Config_Flag__c FROM Demo_Component_Manager_Settings__c];

if(appSettings.size() == 0){
System.debug('Initializing appSettings');
Demo_Component_Manager_Settings__c newAppSetting = new Demo_Component_Manager_Settings__c();
insert newAppSetting;
}else{
appSetting = appSettings[0];
}

return appSetting;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,52 @@ public with sharing class CpmComponentInstallCheckerControllerTest {
static testmethod void testrunApex() {
Test.setMock(HttpCalloutMock.class, new ApiCalloutMock());

Demo_Component_Manager_Settings__c newAppSetting = new Demo_Component_Manager_Settings__c();
insert newAppSetting;

Test.startTest();
CpmComponentInstallCheckerController.runApex();
CpmComponentInstallCheckerController.runApex(true);
Test.stopTest();

Demo_Component__C demoComponentVM = [SELECT Id, Title__c, Installed__c, Installed_Version_Tracking_Method__c, Update_Available__c, Latest_Package_Version_Deprecated_Flag__c, Source_Installed_Commit_Hash__c FROM Demo_Component__c where Github_Repository_URL__c =:ApiCalloutMock.VM_GITHUB_REPO_URL LIMIT 1];

System.assertEquals('gpbu visitor management', demoComponentVM.Title__c);
System.assertEquals('Github_Commit', demoComponentVM.Installed_Version_Tracking_Method__c);
}


static testmethod void testrunApexNoSetting() {
Test.setMock(HttpCalloutMock.class, new ApiCalloutMock());

Test.startTest();
CpmComponentInstallCheckerController.runApex(false);
Test.stopTest();

List<Demo_Component_Manager_Settings__c> appSettings = [SELECT Id, Last_Library_Refresh_Date__c, Initial_Config_Flag__c FROM Demo_Component_Manager_Settings__c];

System.assertEquals(1, appSettings.size());
}

static testmethod void testgetAppSettings() {

Demo_Component_Manager_Settings__c newAppSetting = new Demo_Component_Manager_Settings__c();
newAppSetting.Initial_Config_Flag__c = true;
insert newAppSetting;


Test.startTest();
Demo_Component_Manager_Settings__c demoComponentManagerSetting = CpmComponentInstallCheckerController.getAppSettings();
Test.stopTest();

System.assertEquals(true, demoComponentManagerSetting.Initial_Config_Flag__c);
}

static testmethod void testgetAppSettingsNoSetting() {

Test.startTest();
Demo_Component_Manager_Settings__c demoComponentManagerSetting = CpmComponentInstallCheckerController.getAppSettings();
Test.stopTest();

System.assertEquals(false, demoComponentManagerSetting.Initial_Config_Flag__c);
}
}
2 changes: 1 addition & 1 deletion force-app/main/default/classes/MetadataAPIHelper.cls
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,6 @@

public static String getSubscriberPackageQuery(){
system.debug('Running getSubscriberPackageQuery');
return EncodingUtil.urlEncode('SELECT Id, Name, IsPackageValid, NamespacePrefix, IsPackageValid, Description FROM SubscriberPackage', 'UTF-8');
return EncodingUtil.urlEncode('SELECT Id, Name, IsPackageValid, NamespacePrefix, Description FROM SubscriberPackage', 'UTF-8');
}
}
11 changes: 9 additions & 2 deletions force-app/main/default/classes/QueueProcessDependentPackages.cls
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class QueueProcessDependentPackages implements Queueable, Database.Allows
/*************STANDARD EXECUTE STARTER*************/
this.SetJobStage(QueuePlatformAsyncEventHelper.STAGE_PROCESSING);
QueuePlatformAsyncEventHelper.publishPlatformEvent(this.GetJobInfo());
system.debug(this.GetJobInfo(QueuePlatformAsyncEventHelper.FIELD_APEX_CLASS_NAME)+' has been is now processing');
system.debug(this.GetJobInfo(QueuePlatformAsyncEventHelper.FIELD_APEX_CLASS_NAME)+' is now processing');

doLater(this.jobInfo, this.parentDemoComponentId, this.dependentPackageVersionIds);
}
Expand Down Expand Up @@ -159,8 +159,15 @@ public class QueueProcessDependentPackages implements Queueable, Database.Allows
Dependent_Component__c = demoComponent.Id,
Demo_Component__c = parentDemoComponent.Id
);
parentDemoComponent.Dependencies_Met__c = false;
update parentDemoComponent;
}else{
System.debug('Existing Component Dependency ' + dependentComponentLookup[0].Id + ' Found, Ignoring.');
System.debug('Existing Component Dependency ' + dependentComponentLookup[0].Id + ' Found');
if(!dependentComponentLookup[0].Installed__c){
System.debug('Demo Component is not installed, thereforce depedendencies on parent dependent is not met');
parentDemoComponent.Dependencies_Met__c = false;
update parentDemoComponent;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class QueueUpdateComponentFromSFDX implements Queueable, Database.AllowsC
demoComponent.Package_Install_Type_Flag__c = true;
demoComponent.SFDX_Package_Enabled_Flag__c = true;
demoComponent.Title__c = thisPackageDirectory.packageName;
//TODO: ENABLE MERGING WHEN A COMPONENT DOESN'T HAVE A GITHUB PROJECT, BUT YOU ADD IT
demoComponent.SFDX_Package_Name__c = thisPackageDirectory.packageName;
demoComponent.Latest_SFDX_Package_Version_Name__c = thisPackageDirectory.versionName;
demoComponent.Latest_SFDX_Package_Version_Description__c = thisPackageDirectory.versionDescription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
<behavior>Edit</behavior>
<field>Installed__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Dependencies_Met__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>Number_of_Dependencies__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Admin_Permission_Set__c</field>
Expand Down Expand Up @@ -339,14 +347,14 @@
<platformActionList>
<actionListContext>Record</actionListContext>
<platformActionListItems>
<actionName>Delete</actionName>
<actionName>Edit</actionName>
<actionType>StandardButton</actionType>
<sortOrder>1</sortOrder>
<sortOrder>0</sortOrder>
</platformActionListItems>
<platformActionListItems>
<actionName>Edit</actionName>
<actionName>Delete</actionName>
<actionType>StandardButton</actionType>
<sortOrder>0</sortOrder>
<sortOrder>1</sortOrder>
</platformActionListItems>
</platformActionList>
<quickActionList/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<lightning-card title="Add Github based SFDX Package" icon-name="standard:merge">
<form class="slds-form_stacked slds-p-around_medium">
<lightning-input type="url" onchange={onGithubURLChange} name="githubURL" label="Github Repository Url" class="validateMe"
<lightning-input type="url" onchange={onGithubURLChange} name="githubURL" data-target-id="githubURL" label="Github Repository Url" class="validateMe"
required onblur={onBlur} message-when-value-missing="Please input a URL"></lightning-input>
</form>
<p slot="footer" class="slds-text-align_right">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export default class CmpAddGithubComponent extends LightningElement {
"error"
);
});
console.log(`Resetting form`);
this.template.querySelector("lightning-input[data-target-id=githubURL]").value = '';
this.githubURL = '';
}

onGithubURLChange(event) {
Expand Down
Loading

0 comments on commit 4ec4294

Please sign in to comment.