diff --git a/force-app/main/default/classes/GGW_ApplicationCtrlTest.cls b/force-app/main/default/classes/GGW_ApplicationCtrlTest.cls index b80f417..615adca 100644 --- a/force-app/main/default/classes/GGW_ApplicationCtrlTest.cls +++ b/force-app/main/default/classes/GGW_ApplicationCtrlTest.cls @@ -11,12 +11,36 @@ public class GGW_ApplicationCtrlTest { @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='grantuser@labsorg.com', + 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 includeLogoTest(){ + + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + // Query all suggested sections List lst = GGW_ApplicationCtrl.getSections(); List sections = new List(); @@ -36,8 +60,20 @@ public class GGW_ApplicationCtrlTest { GGW_GrantApplicationWrapper grant = GGW_ApplicationCtrl.getApplication(app.Id); System.assertEquals(app.Id, grant.recordid, 'Invalid grant application Id'); System.assertEquals(true, grant.logostate, 'Logo include state is not valid'); + } } + static void excludeLogoTest(){ + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + // Query all suggested sections List lst = GGW_ApplicationCtrl.getSections(); List sections = new List(); @@ -45,6 +81,7 @@ public class GGW_ApplicationCtrlTest { if(gww.selected){ sections.add(gww.recordid); } + } GGW_Grant_Application__c app = GGW_ApplicationCtrl.newGrant('MyTest Grant', sections); @@ -57,10 +94,22 @@ public class GGW_ApplicationCtrlTest { GGW_GrantApplicationWrapper grant = GGW_ApplicationCtrl.getApplication(app.Id); System.assertEquals(app.Id, grant.recordid, 'Invalid grant application Id'); System.assertEquals(false, grant.logostate, 'Logo exclude state is not valid'); + } } @isTest static void deleteLogoTest(){ + + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + // Query all suggested sections List lst = GGW_ApplicationCtrl.getSections(); List sections = new List(); @@ -98,10 +147,20 @@ public class GGW_ApplicationCtrlTest { Test.stopTest(); System.assertEquals('Logo image deleted', result, 'Logo delete is not valid'); - + } } @isTest static void createContentDistributionTest(){ + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + // Query all suggested sections List lst = GGW_ApplicationCtrl.getSections(); List sections = new List(); @@ -130,10 +189,20 @@ public class GGW_ApplicationCtrlTest { System.assertNotEquals(null, downloadURL, 'Contenet distribution is invalid'); GGW_GrantApplicationWrapper grant = GGW_ApplicationCtrl.getApplication(app.Id); System.assertEquals(downloadURL, grant.logodisplayurl, 'Logo download URL is not valid'); - + } } @isTest static void testNewGrant(){ + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + // Query all suggested sections List lst = GGW_ApplicationCtrl.getSections(); List sections = new List(); @@ -155,9 +224,21 @@ public class GGW_ApplicationCtrlTest { List selectedItems = [SELECT Id, Name, Grant_Application__c, GGW_Section__c, Sort_Order__c FROM GGW_Selected_Item__c WHERE Grant_Application__c =:app.Id]; System.assertEquals(sections.size(), selectedItems.size(), 'Clone for grant sections to items did not complete'); + } } @isTest static void testFindSections(){ + + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + String searchKey = 'Test'; Test.startTest(); List sw = GGW_ApplicationCtrl.findSections(searchKey); @@ -170,16 +251,40 @@ public class GGW_ApplicationCtrlTest { searchKey = 'fail'; List swfail = GGW_ApplicationCtrl.findSections(searchKey); System.assertEquals(0, swfail.size(), 'Section search for hidden section did not return valid data'); + } } @isTest static void testGetSections(){ + + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + Test.startTest(); List sw = GGW_ApplicationCtrl.getSections(); Test.stopTest(); System.assertEquals(3, sw.size(), 'No sample section data found'); + } } @isTest static void testContentBlocks(){ + + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + List sectionList = [SELECT Id, Name FROM GGW_Section__c WHERE Name = 'Statement of need']; String sectionid = sectionList[0].Id; Test.startTest(); @@ -187,9 +292,21 @@ public class GGW_ApplicationCtrlTest { Test.stopTest(); // TODO add detailed assertions System.assertNotEquals(0, blockList.size(), 'No sample data content blocks are found'); + } } @isTest static void testAddTextBlockToLibrary(){ + + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + List sectionList = [SELECT Id, Name FROM GGW_Section__c WHERE Name = 'Statement of need']; String sectionid = sectionList[0].Id; String richtext = 'Adding new block text content to section to reuse. Example text'; @@ -201,9 +318,20 @@ public class GGW_ApplicationCtrlTest { System.assertEquals('Test block', block.Name, 'Block name not matching'); System.assertEquals(str, block.Id, 'No Block ID found'); System.assertEquals(sectionList[0].Id, block.Section__c, 'Block link to Section missing'); - } + } + } @isTest static void testCreateNewSection(){ + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + String name = 'Test section'; Test.startTest(); GGW_SectionWrapper sw = GGW_ApplicationCtrl.createNewSection(name); @@ -218,10 +346,21 @@ public class GGW_ApplicationCtrlTest { System.assertEquals(newSec.Recommended__c,sw.selected, 'Recommended section vs selected not matching'); System.assertEquals(true, newSec.Recommended__c, 'Default recommended section not valid'); System.assertEquals(true, newSec.Suggested__c, 'Default suggested section not set'); + } } @isTest static void testGetApplication(){ + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + // Query all suggested sections List lst = GGW_ApplicationCtrl.getSections(); List sections = new List(); @@ -241,9 +380,20 @@ public class GGW_ApplicationCtrlTest { System.assertEquals('In Progress', appWrapper.status, 'Default grant status did not match expected - In Progress'); // Check selected Items created as content blocks wraper to number of sections System.assertEquals(sections.size(),appWrapper.selectedContentBlock.size(), 'The copy of created blocks from template did not match expected number'); - } + } + } @isTest static void testSaveSelectedSectionText(){ + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + // Query all suggested sections List lst = GGW_ApplicationCtrl.getSections(); List sections = new List(); @@ -266,9 +416,20 @@ public class GGW_ApplicationCtrlTest { // assertion checks that item saved the Block text List savedItemList = GGW_SectionSelector.querySelectedItemsByGrant(app.Id); System.assertEquals(blocktext, savedItemList[0].Text_Block__c, 'Block text did not match template'); - } + } + } @isTest static void testReorderSections(){ + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + // Query all suggested sections List lst = GGW_ApplicationCtrl.getSections(); List sections = new List(); @@ -296,9 +457,20 @@ public class GGW_ApplicationCtrlTest { List selOrderedList = GGW_SectionSelector.querySelectedItemsByGrant(app.Id); System.assertEquals(last, selOrderedList[0].Id, 'Last seleected section item did not match expected'); System.assertEquals(first, selOrderedList[selOrderedList.size()-1].Id, 'First seleectd section item did not match selected'); - } + } + } @isTest static void testUpdateSelectedItemText(){ + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + // Query all suggested sections List lst = GGW_ApplicationCtrl.getSections(); List sections = new List(); @@ -322,10 +494,21 @@ public class GGW_ApplicationCtrlTest { GGW_Selected_Item__c selItem = [SELECT Id, Name, Text_Block__c, GGW_Section__c, Grant_Application__c, Sort_Order__c FROM GGW_Selected_Item__c WHERE Id =:itemid]; System.assertEquals(richtext, selItem.Text_Block__c, 'Rich text in block not matching expected text'); - } + } + } @isTest static void testDeleteSectionItem(){ + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + // Query all suggested sections List lst = GGW_ApplicationCtrl.getSections(); List sections = new List(); @@ -348,17 +531,40 @@ public class GGW_ApplicationCtrlTest { // Check that item was deleted System.assertEquals(sectionCount-1, newItemList.size(),'Assert failed DeleteSectionItem'); - } + } + } @isTest static void testGetSupportedLanguages(){ + + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + Test.startTest(); List pl = GGW_ApplicationCtrl.getSupportedLanguages(); Test.stopTest(); System.assertEquals(pl.size()>0, true, 'Supported langauges found'); + } } @isTest static void testGetLanguageSelection(){ - // Query all suggested sections + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + + // Query all suggested sections List lst = GGW_ApplicationCtrl.getSections(); List sections = new List(); for (GGW_SectionWrapper gww : lst){ @@ -378,9 +584,20 @@ public class GGW_ApplicationCtrlTest { // NO application ID System.assertEquals(strNoApp, 'en_US', 'Negative test failed to get language selectino'); System.assertEquals(strLngWire, 'en_US', 'Failed to get application language in wired method'); - } + } + } @isTest static void testSaveLanguageSelection(){ + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + // Query all suggested sections List lst = GGW_ApplicationCtrl.getSections(); List sections = new List(); @@ -398,5 +615,6 @@ public class GGW_ApplicationCtrlTest { System.assertEquals(str, 'NEW Language state is inserted', 'Language select was not saved'); String lang = GGW_ApplicationCtrl.getLanguageSelection(app.Id); System.assertEquals(lang, 'en_US', 'Failed to get saved language'); + } } } diff --git a/force-app/main/default/classes/GGW_ApplicationSelectorTest.cls b/force-app/main/default/classes/GGW_ApplicationSelectorTest.cls index c62d2f6..85e32f7 100644 --- a/force-app/main/default/classes/GGW_ApplicationSelectorTest.cls +++ b/force-app/main/default/classes/GGW_ApplicationSelectorTest.cls @@ -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='grantuser@labsorg.com', + 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + // Query all suggested sections List lst = GGW_ApplicationCtrl.getSections(); List sections = new List(); @@ -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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + // Query all suggested sections List lst = GGW_ApplicationCtrl.getSections(); List sections = new List(); @@ -63,5 +100,6 @@ private class GGW_ApplicationSelectorTest { List grantList = GGW_ApplicationSelector.getGrantApplications(); Test.stopTest(); System.assertEquals(2, grantList.size(), 'Query grant application invalid'); - } + } + } } \ No newline at end of file diff --git a/force-app/main/default/classes/GGW_ContentBlockWrapperTest.cls b/force-app/main/default/classes/GGW_ContentBlockWrapperTest.cls index 13c6ec1..cd19408 100644 --- a/force-app/main/default/classes/GGW_ContentBlockWrapperTest.cls +++ b/force-app/main/default/classes/GGW_ContentBlockWrapperTest.cls @@ -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='grantuser@labsorg.com', + 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + List 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'); - } + } + } } \ No newline at end of file diff --git a/force-app/main/default/classes/GGW_ExportCtrlTest.cls b/force-app/main/default/classes/GGW_ExportCtrlTest.cls index f7c567a..fa10f72 100644 --- a/force-app/main/default/classes/GGW_ExportCtrlTest.cls +++ b/force-app/main/default/classes/GGW_ExportCtrlTest.cls @@ -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='grantuser@labsorg.com', + 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 = 'grantuser@labsorg.com' 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 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 = 'grantuser@labsorg.com' 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 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'); + } } } diff --git a/force-app/main/default/classes/GGW_GrantApplicationWrapperTest.cls b/force-app/main/default/classes/GGW_GrantApplicationWrapperTest.cls index 2214103..1394d48 100644 --- a/force-app/main/default/classes/GGW_GrantApplicationWrapperTest.cls +++ b/force-app/main/default/classes/GGW_GrantApplicationWrapperTest.cls @@ -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='grantuser@labsorg.com', + 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 = 'grantuser@labsorg.com' 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'); + } } } \ No newline at end of file diff --git a/force-app/main/default/classes/GGW_SampleDataTest.cls b/force-app/main/default/classes/GGW_SampleDataTest.cls index cf47e35..d1387ab 100644 --- a/force-app/main/default/classes/GGW_SampleDataTest.cls +++ b/force-app/main/default/classes/GGW_SampleDataTest.cls @@ -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='grantuser@labsorg.com', + 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 = 'grantuser@labsorg.com' 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 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 = 'grantuser@labsorg.com' 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'); - + } } } diff --git a/force-app/main/default/classes/GGW_SectionWrapperTest.cls b/force-app/main/default/classes/GGW_SectionWrapperTest.cls index ad737f7..03f22fb 100644 --- a/force-app/main/default/classes/GGW_SectionWrapperTest.cls +++ b/force-app/main/default/classes/GGW_SectionWrapperTest.cls @@ -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='grantuser@labsorg.com', + 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + List 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'); - + } } } \ No newline at end of file diff --git a/force-app/main/default/classes/GGW_UtilTest.cls b/force-app/main/default/classes/GGW_UtilTest.cls index c2e70c2..da2c37f 100644 --- a/force-app/main/default/classes/GGW_UtilTest.cls +++ b/force-app/main/default/classes/GGW_UtilTest.cls @@ -13,13 +13,13 @@ public class GGW_UtilTest { @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='grantuser@labsorg.com', EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', LocaleSidKey='en_US', ProfileId = p.Id, @@ -27,10 +27,22 @@ public class GGW_UtilTest { UserName=uniqueUserName); insert u; + insert new PermissionSetAssignment(AssigneeId = u.id, PermissionSetId = ps.Id); } @isTest static void testNewsaveGrantState(){ + + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + // Query all suggested sections List lst = GGW_ApplicationCtrl.getSections(); List sections = new List(); @@ -40,14 +52,6 @@ public class GGW_UtilTest { } } - // This code runs as the system user - PermissionSet ps = [SELECT Id FROM PermissionSet WHERE Name = 'GGW_User_Permissions']; - User u = [SELECT Alias, Email, EmailEncodingKey, LastName, LanguageLocaleKey, - LocaleSidKey, ProfileId, TimeZoneSidKey, UserName - FROM User WHERE Email = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; - insert new PermissionSetAssignment(AssigneeId = u.id, PermissionSetId = ps.Id); - - System.runAs(u) { GGW_Grant_Application__c app = GGW_ApplicationCtrl.newGrant('Grant App', sections); Test.startTest(); @@ -70,6 +74,18 @@ public class GGW_UtilTest { @isTest static void testExistingGrantState(){ + + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + // Query all suggested sections List lst = GGW_ApplicationCtrl.getSections(); List sections = new List(); @@ -78,14 +94,6 @@ public class GGW_UtilTest { sections.add(gww.recordid); } } - // This code runs as the system user - PermissionSet ps = [SELECT Id FROM PermissionSet WHERE Name = 'GGW_User_Permissions']; - User u = [SELECT Alias, Email, EmailEncodingKey, LastName, LanguageLocaleKey, - LocaleSidKey, ProfileId, TimeZoneSidKey, UserName - FROM User WHERE Email = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; - insert new PermissionSetAssignment(AssigneeId = u.id, PermissionSetId = ps.Id); - - System.runAs(u) { GGW_Grant_Application__c app = GGW_ApplicationCtrl.newGrant('Grant App', sections); GGW_Util.saveGrantState(app.Id); @@ -102,6 +110,17 @@ public class GGW_UtilTest { @isTest static void testGetSelectedItems(){ + + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + // Query all suggested sections List lst = GGW_ApplicationCtrl.getSections(); List sections = new List(); @@ -116,10 +135,22 @@ public class GGW_UtilTest { List lstItems = GGW_Util.getSelectedItems(app.Id); Test.stopTest(); System.assertEquals(sections.size(), lstItems.size(), 'Grant app missing selected items'); - + } } @isTest static void testSelectOptionFromPicklist(){ + + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + + Test.startTest(); List picList = GGW_Util.getSelectOptionFromPicklist(ggGtSteObj, ggGtStLanField, true); Test.stopTest(); @@ -132,9 +163,22 @@ public class GGW_UtilTest { } } System.assertEquals(lcode, 'en_US', 'Supported Language not found in metadata'); + } } @isTest static void testToLanguageLabel(){ + + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + + Test.startTest(); // Translate ISO language code to language label en_US -> English String lang = GGW_Util.toLanguageLabel('en_US'); @@ -143,9 +187,21 @@ public class GGW_UtilTest { Test.stopTest(); System.assertEquals(lang, 'English', 'No language label found for code en_US'); System.assertEquals(lang, 'English', 'No language label found for code pi_NG'); // Defalt to English + } } @isTest static void testGetValueMapFromPicklist(){ + + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + + System.runAs(u) { + + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + Test.startTest(); Map valMap = GGW_Util.getValueMapFromPicklist(ggGtSteObj, ggGtStLanField); Test.stopTest(); @@ -154,27 +210,30 @@ public class GGW_UtilTest { String ln = valMap.get('en_US'); System.assertEquals(ln, 'English', 'No language label found for code en_US'); } + } } @isTest static void saveGrantLanguage(){ - // Query all suggested sections - List lst = GGW_ApplicationCtrl.getSections(); - List sections = new List(); - for (GGW_SectionWrapper gww : lst){ - if(gww.selected){ - sections.add(gww.recordid); - } - } - - // This code runs as the system user - PermissionSet ps = [SELECT Id FROM PermissionSet WHERE Name = 'GGW_User_Permissions']; + + // 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 = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; - insert new PermissionSetAssignment(AssigneeId = u.id, PermissionSetId = ps.Id); - + LocaleSidKey, ProfileId, TimeZoneSidKey, UserName + FROM User WHERE Email = 'grantuser@labsorg.com' AND Alias='standt' LIMIT 1]; + System.runAs(u) { + //Create sample data + GGW_TestDataFactory.createGrantContentTestData(); + + // Query all suggested sections + List lst = GGW_ApplicationCtrl.getSections(); + List sections = new List(); + for (GGW_SectionWrapper gww : lst){ + if(gww.selected){ + sections.add(gww.recordid); + } + } + GGW_Grant_Application__c app = GGW_ApplicationCtrl.newGrant('Grant App', sections); Test.startTest(); String str = GGW_Util.saveGrantLanguage('en_US', app.Id);