-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified Apex Test classes to include User with GGW Permission Set.
- Loading branch information
Showing
8 changed files
with
512 additions
and
61 deletions.
There are no files selected for viewing
242 changes: 230 additions & 12 deletions
242
force-app/main/default/classes/GGW_ApplicationCtrlTest.cls
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -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>(); | ||
|
@@ -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>(); | ||
|
@@ -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'); | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -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 | ||
|
@@ -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'); | ||
} | ||
} | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -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(); | ||
|
@@ -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(); | ||
|
@@ -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'); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -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'; | ||
|
@@ -28,5 +49,6 @@ public class GGW_GrantApplicationWrapperTest { | |
Test.stopTest(); | ||
|
||
System.assertNotEquals(null, app, 'Default constructor faild to create wrapper grant object'); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -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(); | ||
|
@@ -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(); | ||
|
@@ -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'); | ||
|
||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -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 | ||
|
@@ -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'); | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.