Skip to content

Commit

Permalink
Modified Apex Test classes to include User with GGW Permission Set.
Browse files Browse the repository at this point in the history
  • Loading branch information
cidarm committed Sep 30, 2024
1 parent a1fac17 commit 9245d39
Show file tree
Hide file tree
Showing 8 changed files with 512 additions and 61 deletions.
242 changes: 230 additions & 12 deletions force-app/main/default/classes/GGW_ApplicationCtrlTest.cls

Large diffs are not rendered by default.

42 changes: 40 additions & 2 deletions force-app/main/default/classes/GGW_ApplicationSelectorTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,36 @@
*/
@isTest
private class GGW_ApplicationSelectorTest {
@TestSetup
static void makeData(){

String uniqueUserName = 'grantuser' + DateTime.now().getTime() + '@labsorg.com';
// This code runs as the system user
Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];

PermissionSet ps = [SELECT Id FROM PermissionSet WHERE Name = 'GGW_User_Permissions'];

User u = new User(Alias = 'standt', Email='[email protected]',
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/Los_Angeles',
UserName=uniqueUserName);
insert u;

insert new PermissionSetAssignment(AssigneeId = u.id, PermissionSetId = ps.Id);
}
@isTest
static void testQueryGrantApp(){
// This code runs as the Grant Guide User with GGW Permission Set from the TestSetup makeData() method.
User u = [SELECT Alias, Email, EmailEncodingKey, LastName, LanguageLocaleKey,
LocaleSidKey, ProfileId, TimeZoneSidKey, UserName
FROM User WHERE Email = '[email protected]' AND Alias='standt' LIMIT 1];

System.runAs(u) {

//Create sample data
GGW_TestDataFactory.createGrantContentTestData();

// Query all suggested sections
List<GGW_SectionWrapper> lst = GGW_ApplicationCtrl.getSections();
List<String> sections = new List<String>();
Expand All @@ -43,10 +70,20 @@ private class GGW_ApplicationSelectorTest {
GGW_Grant_Application__c grant = GGW_ApplicationSelector.queryGrantApp(app.Id);
Test.stopTest();
System.assertEquals(grant.Name, 'Grant App', 'Could not create a new grant application');

}
}
@isTest
static void getGrantApplicationsTest(){
// This code runs as the Grant Guide User with GGW Permission Set from the TestSetup makeData() method.
User u = [SELECT Alias, Email, EmailEncodingKey, LastName, LanguageLocaleKey,
LocaleSidKey, ProfileId, TimeZoneSidKey, UserName
FROM User WHERE Email = '[email protected]' AND Alias='standt' LIMIT 1];

System.runAs(u) {

//Create sample data
GGW_TestDataFactory.createGrantContentTestData();

// Query all suggested sections
List<GGW_SectionWrapper> lst = GGW_ApplicationCtrl.getSections();
List<String> sections = new List<String>();
Expand All @@ -63,5 +100,6 @@ private class GGW_ApplicationSelectorTest {
List<GGW_Grant_Application__c> grantList = GGW_ApplicationSelector.getGrantApplications();
Test.stopTest();
System.assertEquals(2, grantList.size(), 'Query grant application invalid');
}
}
}
}
31 changes: 28 additions & 3 deletions force-app/main/default/classes/GGW_ContentBlockWrapperTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,36 @@
public class GGW_ContentBlockWrapperTest {
@TestSetup
static void makeData(){
// Samlple content data for testing methods
GGW_TestDataFactory.createGrantContentTestData();

String uniqueUserName = 'grantuser' + DateTime.now().getTime() + '@labsorg.com';
// This code runs as the system user
Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];

PermissionSet ps = [SELECT Id FROM PermissionSet WHERE Name = 'GGW_User_Permissions'];

User u = new User(Alias = 'standt', Email='[email protected]',
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/Los_Angeles',
UserName=uniqueUserName);
insert u;

insert new PermissionSetAssignment(AssigneeId = u.id, PermissionSetId = ps.Id);
}

@isTest
static void testBlockWrapperConstructors(){

// This code runs as the Grant Guide User with GGW Permission Set from the TestSetup makeData() method.
User u = [SELECT Alias, Email, EmailEncodingKey, LastName, LanguageLocaleKey,
LocaleSidKey, ProfileId, TimeZoneSidKey, UserName
FROM User WHERE Email = '[email protected]' AND Alias='standt' LIMIT 1];

System.runAs(u) {

//Create sample data
GGW_TestDataFactory.createGrantContentTestData();

List<GGW_Content_Block__c> cbList = [SELECT Id, Name, Description__c, Short_Description__c,
Section__c, Section__r.Name, CreatedDate,
Language__c
Expand All @@ -33,6 +57,7 @@ public class GGW_ContentBlockWrapperTest {
System.assertEquals(2, textBlock.totalblocks, 'Expected total block 2 did not match');
System.assertEquals(firstBlock.Name, textBlock.title, 'Expected block name to tile did not match');
System.assertEquals(firstBlock.Section__c, textBlock.sectionid, 'Block parent section not valid');
}
}
}

}
44 changes: 40 additions & 4 deletions force-app/main/default/classes/GGW_ExportCtrlTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,36 @@
public class GGW_ExportCtrlTest {
@TestSetup
static void makeData(){
// Create test sections
// Samlple content data for testing methods
GGW_TestDataFactory.createGrantContentTestData();

String uniqueUserName = 'grantuser' + DateTime.now().getTime() + '@labsorg.com';
// This code runs as the system user
Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];

PermissionSet ps = [SELECT Id FROM PermissionSet WHERE Name = 'GGW_User_Permissions'];

User u = new User(Alias = 'standt', Email='[email protected]',
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/Los_Angeles',
UserName=uniqueUserName);
insert u;

insert new PermissionSetAssignment(AssigneeId = u.id, PermissionSetId = ps.Id);
}

@isTest
static void testExportCtrl(){

// This code runs as the Grant Guide User with GGW Permission Set from the TestSetup makeData() method.
User u = [SELECT Alias, Email, EmailEncodingKey, LastName, LanguageLocaleKey,
LocaleSidKey, ProfileId, TimeZoneSidKey, UserName
FROM User WHERE Email = '[email protected]' AND Alias='standt' LIMIT 1];

System.runAs(u) {

//Create sample data
GGW_TestDataFactory.createGrantContentTestData();

// Unit test for conroller extention when used as part of record page context
// Query all suggested sections
List<GGW_SectionWrapper> lst = GGW_ApplicationCtrl.getSections();
Expand All @@ -41,10 +64,22 @@ public class GGW_ExportCtrlTest {
System.assertEquals(app.Name, grantExportController.appName, 'Grant name selected for export does not exist - MyTest Grant');
// 3 section expected to be added to grand
System.assertEquals(3, grantExportController.items.size(), 'Grant expected 3 items for export, size did not match test.');
}
}
}

@isTest
static void testExportWithPage(){

// This code runs as the Grant Guide User with GGW Permission Set from the TestSetup makeData() method.
User u = [SELECT Alias, Email, EmailEncodingKey, LastName, LanguageLocaleKey,
LocaleSidKey, ProfileId, TimeZoneSidKey, UserName
FROM User WHERE Email = '[email protected]' AND Alias='standt' LIMIT 1];

System.runAs(u) {

//Create sample data
GGW_TestDataFactory.createGrantContentTestData();

// Unit test for conroller extention when NOT Record page but pass parameter recordId
// Query all suggested sections
List<GGW_SectionWrapper> lst = GGW_ApplicationCtrl.getSections();
Expand All @@ -70,5 +105,6 @@ public class GGW_ExportCtrlTest {

System.assertEquals(null, grantExportController.recordId, 'Negative test with empty Grant for export expected null value');
System.assertEquals('This view requires a Grant record, missing.', grantExportController.appName, 'Negative test empty Grant expect missing name error message');
}
}
}
26 changes: 24 additions & 2 deletions force-app/main/default/classes/GGW_GrantApplicationWrapperTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,34 @@
public class GGW_GrantApplicationWrapperTest {
@TestSetup
static void makeData(){
// Samlple content data for testing methods
GGW_TestDataFactory.createGrantContentTestData();

String uniqueUserName = 'grantuser' + DateTime.now().getTime() + '@labsorg.com';
// This code runs as the system user
Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];

PermissionSet ps = [SELECT Id FROM PermissionSet WHERE Name = 'GGW_User_Permissions'];

User u = new User(Alias = 'standt', Email='[email protected]',
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/Los_Angeles',
UserName=uniqueUserName);
insert u;

insert new PermissionSetAssignment(AssigneeId = u.id, PermissionSetId = ps.Id);

}

@isTest
static void testGrantApplicationWrapperConstructor(){

// This code runs as the Grant Guide User with GGW Permission Set from the TestSetup makeData() method.
User u = [SELECT Alias, Email, EmailEncodingKey, LastName, LanguageLocaleKey,
LocaleSidKey, ProfileId, TimeZoneSidKey, UserName
FROM User WHERE Email = '[email protected]' AND Alias='standt' LIMIT 1];
System.runAs(u) {
// Samlple content data for testing methods
GGW_TestDataFactory.createGrantContentTestData();
Test.startTest();
GGW_GrantApplicationWrapper app = new GGW_GrantApplicationWrapper();
app.name = 'Test Grant';
Expand All @@ -28,5 +49,6 @@ public class GGW_GrantApplicationWrapperTest {
Test.stopTest();

System.assertNotEquals(null, app, 'Default constructor faild to create wrapper grant object');
}
}
}
32 changes: 31 additions & 1 deletion force-app/main/default/classes/GGW_SampleDataTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,32 @@
*/
@IsTest
public class GGW_SampleDataTest {
@TestSetup
static void makeData(){

String uniqueUserName = 'grantuser' + DateTime.now().getTime() + '@labsorg.com';
// This code runs as the system user
Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];

PermissionSet ps = [SELECT Id FROM PermissionSet WHERE Name = 'GGW_User_Permissions'];

User u = new User(Alias = 'standt', Email='[email protected]',
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/Los_Angeles',
UserName=uniqueUserName);
insert u;

insert new PermissionSetAssignment(AssigneeId = u.id, PermissionSetId = ps.Id);
}
@isTest
static void testInsertSampleSections(){
// This code runs as the Grant Guide User with GGW Permission Set from the TestSetup makeData() method.
User u = [SELECT Alias, Email, EmailEncodingKey, LastName, LanguageLocaleKey,
LocaleSidKey, ProfileId, TimeZoneSidKey, UserName
FROM User WHERE Email = '[email protected]' AND Alias='standt' LIMIT 1];

System.runAs(u) {
// POSITIVE Test validation
// Call this method to insert Sections & Content Block sample data
Test.startTest();
Expand All @@ -25,10 +48,17 @@ public class GGW_SampleDataTest {
System.assertEquals(10, lstSection.size(), 'Sections list is expected to have records');
List<GGW_Content_Block__c> lstContentBlock = [SELECT Id, Name FROM GGW_Content_Block__c WITH SECURITY_ENFORCED];
System.assertEquals(13, lstContentBlock.size(), 'Block list is expected to have records');
}
}

@isTest
static void testInsertSampleSectionsWithExisting(){
// This code runs as the Grant Guide User with GGW Permission Set from the TestSetup makeData() method.
User u = [SELECT Alias, Email, EmailEncodingKey, LastName, LanguageLocaleKey,
LocaleSidKey, ProfileId, TimeZoneSidKey, UserName
FROM User WHERE Email = '[email protected]' AND Alias='standt' LIMIT 1];

System.runAs(u) {
// NEGATIVE Fail test validation
// Create sample sections before test
GGW_Section__c gs = new GGW_Section__c();
Expand All @@ -46,6 +76,6 @@ public class GGW_SampleDataTest {
Test.stopTest();
System.assertNotEquals(null, str, 'Result string should not be null');
System.assertEquals('Section data already exists. IMPORT CANCELLED', str, 'Result string is expected as IMPORT CANCELED message');

}
}
}
29 changes: 26 additions & 3 deletions force-app/main/default/classes/GGW_SectionWrapperTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,35 @@
public class GGW_SectionWrapperTest {
@TestSetup
static void makeData(){
// Samlple content data for testing methods
GGW_TestDataFactory.createGrantContentTestData();

String uniqueUserName = 'grantuser' + DateTime.now().getTime() + '@labsorg.com';
// This code runs as the system user
Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];

PermissionSet ps = [SELECT Id FROM PermissionSet WHERE Name = 'GGW_User_Permissions'];

User u = new User(Alias = 'standt', Email='[email protected]',
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/Los_Angeles',
UserName=uniqueUserName);
insert u;

insert new PermissionSetAssignment(AssigneeId = u.id, PermissionSetId = ps.Id);
}

@isTest
static void testSectionWrapperConstructors(){
// This code runs as the Grant Guide User with GGW Permission Set from the TestSetup makeData() method.
User u = [SELECT Alias, Email, EmailEncodingKey, LastName, LanguageLocaleKey,
LocaleSidKey, ProfileId, TimeZoneSidKey, UserName
FROM User WHERE Email = '[email protected]' AND Alias='standt' LIMIT 1];

System.runAs(u) {

//Create sample data
GGW_TestDataFactory.createGrantContentTestData();

List<GGW_Section__c> sectionList = [SELECT Id, Name, CreatedDate, Recommended__c, Suggested__c,
Sort_Order__c, Language__c
FROM GGW_Section__c
Expand All @@ -34,6 +57,6 @@ public class GGW_SectionWrapperTest {
System.assertNotEquals(null, swBlock, 'Default constructor faild to create wrapper section object');
System.assertEquals(firstSection.Name, swSection.label, 'Default constructor section label name not valid');
System.assertEquals(true, swSection.hasblocks, 'Default constructor section has no blocks');

}
}
}
Loading

0 comments on commit 9245d39

Please sign in to comment.