Skip to content

Commit

Permalink
Merge branch 'EDRD-Sprint-11' of https://github.com/bcgov/MoH-SAT int…
Browse files Browse the repository at this point in the history
…o EDRD-952
  • Loading branch information
deepakmulamalla committed Jan 9, 2025
2 parents 28517c0 + 967a525 commit 1777413
Show file tree
Hide file tree
Showing 50 changed files with 1,487 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* @Date: 21/08/2024
* @Description: The purpose of this class is to cover Code coverage of AccountContactRelationTriggerHandler
* @Revision(s): [Date] - [Change Reference] - [Changed By] - [Description]
21 Aug - EDRD-911 - Accenture - Added Patient Share/delete With Provider User
20 Dec - EDRD-1150 - Accenture - The purpose of this method is to update Committee based on ACR insert of EDRD_Committee & Provider OR Committee_Reviewer.
20 Dec - EDRD-1150 - Accenture - The purpose of this method is to Remove Committee based on ACR delete of EDRD_Committee & Provider OR Committee_Reviewer.
***********************************************************************************************/
@isTest
public class AccountContactRelationTriggerHandlerTest {
Expand Down Expand Up @@ -124,4 +127,187 @@ public class AccountContactRelationTriggerHandlerTest {
Assert.areNotEqual(accShareList2.size(), NULL, 'AccountShare record should is not created');
Assert.areNotEqual(accShareList2.isEmpty(), true, 'AccountShare record list cannot be empty, after the ACR is updated');
}

/**
* @author: Deepak
* @date: 20 Dec 2024
* @description: The purpose of this method is to cover Testcoverage of updateCommitteeFieldOnACRInsert
* @Modification Log: [Date] - [Change Reference] - [Changed By] - [Description]
*/
@isTest
public static void updateCommitteeFieldOnACRInsertTest(){
List<Account> providerList = new List<Account>();
Account providerAcc = TestFactory.newProvider('Provider');
providerAcc.Provider_Type__pc = ESA_cls_constants.EDRD_PHYSICIAN;
providerList.add(providerAcc);
Account providerAcc2 = TestFactory.newProvider('Provider2');
providerAcc2.Provider_Identifier__pc = '111222';
providerAcc2.Provider_Type__pc = ESA_cls_constants.EDRD_PHYSICIAN;
providerList.add(providerAcc2);
Account providerAcc3 = TestFactory.newProvider('Provider3');
providerAcc3.Committee__pc = ESA_cls_constants.EDRD_PERSONACCOUNT_SC;
providerAcc3.Committee_Name__pc = ESA_cls_constants.EDRD_PERSONACCOUNT_SC_METABOLIC_SUBCOMMITTEE;
providerAcc3.Provider_Identifier__pc = '1112223';
providerAcc3.Provider_Type__pc = ESA_cls_constants.EDRD_PHYSICIAN;
providerList.add(providerAcc3);
Account providerAcc4 = TestFactory.newProvider('Provider4');
providerAcc4.Committee__pc = ESA_cls_constants.EDRD_PERSONACCOUNT_AC;
providerAcc4.Provider_Identifier__pc = '1112224';
providerAcc4.Provider_Type__pc = ESA_cls_constants.EDRD_PHYSICIAN;
providerList.add(providerAcc4);
Account providerAcc5 = TestFactory.newProvider('Provider5');
providerAcc5.Committee__pc = ESA_cls_constants.EDRD_PERSONACCOUNT_ACSC;
providerAcc5.Committee_Name__pc = 'Cystic Fibrosis Subcommittee;Ophthalmology Subcommittee';
providerAcc5.Provider_Identifier__pc = '1112225';
providerAcc5.Provider_Type__pc = ESA_cls_constants.EDRD_PHYSICIAN;
providerList.add(providerAcc5);
insert providerList;

List<Account> committeeList = new List<Account>();
Account sCBusinessAcc = TestFactory.createEDRDSCAccount(ESA_cls_constants.EDRD_PERSONACCOUNT_SC_METABOLIC_SUBCOMMITTEE);
committeeList.add(sCBusinessAcc);
Account sCBusinessAcc1 = TestFactory.createEDRDSCAccount('Cardiac Subcommittee');
committeeList.add(sCBusinessAcc1);
Account aCBusinessAcc = TestFactory.createEDRDACAccount(ESA_cls_constants.EDRD_PERSONACCOUNT_AC);
committeeList.add(aCBusinessAcc);
insert committeeList;

List<AccountContactRelation> aCRListTOInsert = new List<AccountContactRelation>();
Id providerContactId = [SELECT Id FROM Contact Where accountId =: providerAcc.Id].get(0).Id;
AccountContactRelation ACRObj = new AccountContactRelation();
ACRObj.AccountId = sCBusinessAcc.Id;
ACRObj.ContactId = providerContactId;
ACRObj.Roles = ESA_cls_constants.EDRD_ACR_ROLES_REVIEWER;
aCRListTOInsert.add(ACRObj);
Id provider2ContactId = [SELECT Id FROM Contact Where accountId =: providerAcc2.Id].get(0).Id;
AccountContactRelation ACRObj2 = new AccountContactRelation();
ACRObj2.AccountId = aCBusinessAcc.Id;
ACRObj2.ContactId = provider2ContactId;
ACRObj2.Roles = ESA_cls_constants.EDRD_ACR_ROLES_CHAIR;
aCRListTOInsert.add(ACRObj2);
Id provider3ContactId = [SELECT Id FROM Contact Where accountId =: providerAcc3.Id].get(0).Id;
AccountContactRelation ACRObj3 = new AccountContactRelation();
ACRObj3.AccountId = aCBusinessAcc.Id;
ACRObj3.ContactId = provider3ContactId;
ACRObj3.Roles = ESA_cls_constants.EDRD_ACR_ROLES_VICE_CHAIR;
aCRListTOInsert.add(ACRObj3);
Id provider4ContactId = [SELECT Id FROM Contact Where accountId =: providerAcc4.Id].get(0).Id;
AccountContactRelation ACRObj4 = new AccountContactRelation();
ACRObj4.AccountId = sCBusinessAcc1.Id;
ACRObj4.ContactId = provider4ContactId;
ACRObj4.Roles = ESA_cls_constants.EDRD_ACR_ROLES_VICE_CHAIR;
aCRListTOInsert.add(ACRObj4);
Id provider5ContactId = [SELECT Id FROM Contact Where accountId =: providerAcc5.Id].get(0).Id;
AccountContactRelation ACRObj5 = new AccountContactRelation();
ACRObj5.AccountId = sCBusinessAcc1.Id;
ACRObj5.ContactId = provider5ContactId;
ACRObj5.Roles = ESA_cls_constants.EDRD_ACR_ROLES_CHAIR;
aCRListTOInsert.add(ACRObj5);
AccountContactRelation ACRObj6 = new AccountContactRelation();
ACRObj6.AccountId = sCBusinessAcc1.Id;
ACRObj6.ContactId = provider3ContactId;
ACRObj6.Roles = ESA_cls_constants.EDRD_ACR_ROLES_REVIEWER;
aCRListTOInsert.add(ACRObj6);
AccountContactRelation ACRObj7 = new AccountContactRelation();
ACRObj7.AccountId = aCBusinessAcc.Id;
ACRObj7.ContactId = provider4ContactId;
ACRObj7.Roles = ESA_cls_constants.EDRD_ACR_ROLES_CHAIR;
aCRListTOInsert.add(ACRObj7);
AccountContactRelation ACRObj8 = new AccountContactRelation();
ACRObj8.AccountId = aCBusinessAcc.Id;
ACRObj8.ContactId = provider5ContactId;
ACRObj8.Roles = ESA_cls_constants.EDRD_ACR_ROLES_VICE_CHAIR;
aCRListTOInsert.add(ACRObj8);

Test.startTest();
insert aCRListTOInsert;
Test.stopTest();

Map<Id, Account> updatedProviders = new Map<Id, Account>([SELECT Id, Committee__pc, Committee_Name__pc FROM Account
WHERE Id IN (:providerAcc.Id, :providerAcc2.Id, :providerAcc3.Id)]);

Account updatedProviderAccount = updatedProviders.get(providerAcc.Id);
Assert.areEqual(updatedProviderAccount.Committee__pc, ESA_cls_constants.EDRD_PERSONACCOUNT_SC, 'Provider Record should be updated');
Assert.areNotEqual(updatedProviderAccount.Committee_Name__pc, NULL, 'Committee_Name__pc on provider field should not be NULL');
Assert.areEqual(updatedProviderAccount.Committee_Name__pc, 'Metabolic Subcommittee', 'Provider Committee_Name__pc should be updated');

Account updatedProviderAccount2 = updatedProviders.get(providerAcc2.Id);
Assert.areEqual(updatedProviderAccount2.Committee__pc, ESA_cls_constants.EDRD_PERSONACCOUNT_AC,'Provider Record should be updated');
Assert.areEqual(updatedProviderAccount2.Committee_Name__pc, NULL, 'Provider2 Committee_Name__pc should be NULL');

Account updatedProviderAccount3 = updatedProviders.get(providerAcc3.Id);
Assert.areEqual(updatedProviderAccount3.Committee__pc, ESA_cls_constants.EDRD_PERSONACCOUNT_ACSC, 'Provider3 Record should be updated');
Assert.areNotEqual(updatedProviderAccount3.Committee_Name__pc, NULL, 'Committee_Name__pc on provider3 field should not be NULL');
Assert.areEqual(updatedProviderAccount3.Committee_Name__pc, 'Cardiac Subcommittee;Metabolic Subcommittee', 'Provider Committee_Name__pc should be updated');
}

/**
* @author: Deepak
* @date: 20 Dec 2024
* @description: The purpose of this method is to cover Testcoverage of removeCommitteeFieldOnACRDelete
* @Modification Log: [Date] - [Change Reference] - [Changed By] - [Description]
*/
@isTest
public static void removeCommitteeFieldOnACRDeleteTest(){
List<Account> providerAccList = new List<Account>();
Account provider = TestFactory.newProvider('Provider');
provider.Provider_Type__pc = ESA_cls_constants.EDRD_PHYSICIAN;
providerAccList.add(provider);
Account provider2 = TestFactory.newProvider('Provider2');
provider2.Provider_Identifier__pc = '111222';
provider2.Provider_Type__pc = ESA_cls_constants.EDRD_PHYSICIAN;
providerAccList.add(provider2);
Account provider3 = TestFactory.newProvider('Provider3');
provider3.Committee__pc = ESA_cls_constants.EDRD_PERSONACCOUNT_SC;
provider3.Committee_Name__pc = ESA_cls_constants.EDRD_PERSONACCOUNT_SC_METABOLIC_SUBCOMMITTEE;
provider3.Provider_Identifier__pc = '1112223';
provider3.Provider_Type__pc = ESA_cls_constants.EDRD_PHYSICIAN;
providerAccList.add(provider3);
insert providerAccList;

List<Account> committeeList = new List<Account>();
Account sCBusinessAcc = TestFactory.createEDRDSCAccount(ESA_cls_constants.EDRD_PERSONACCOUNT_SC_METABOLIC_SUBCOMMITTEE);
committeeList.add(sCBusinessAcc);
Account aCBusinessAcc = TestFactory.createEDRDACAccount(ESA_cls_constants.EDRD_PERSONACCOUNT_AC);
committeeList.add(aCBusinessAcc);
insert committeeList;

List<AccountContactRelation> aCRListTOInsert = new List<AccountContactRelation>();
Id providerContactId = [SELECT Id FROM Contact Where accountId =: provider.Id].get(0).Id;
AccountContactRelation ACRObj = new AccountContactRelation();
ACRObj.AccountId = sCBusinessAcc.Id;
ACRObj.ContactId = providerContactId;
ACRObj.Roles = ESA_cls_constants.EDRD_ACR_ROLES_REVIEWER;
aCRListTOInsert.add(ACRObj);
Id provider2ContactId = [SELECT Id FROM Contact Where accountId =: provider2.Id].get(0).Id;
AccountContactRelation ACRObj2 = new AccountContactRelation();
ACRObj2.AccountId = aCBusinessAcc.Id;
ACRObj2.ContactId = provider2ContactId;
ACRObj2.Roles = ESA_cls_constants.EDRD_ACR_ROLES_CHAIR;
aCRListTOInsert.add(ACRObj2);
Id provider3ContactId = [SELECT Id FROM Contact Where accountId =: provider3.Id].get(0).Id;
AccountContactRelation ACRObj3 = new AccountContactRelation();
ACRObj3.AccountId = aCBusinessAcc.Id;
ACRObj3.ContactId = provider3ContactId;
ACRObj3.Roles = ESA_cls_constants.EDRD_ACR_ROLES_VICE_CHAIR;
aCRListTOInsert.add(ACRObj3);
insert aCRListTOInsert;

Test.startTest();
delete aCRListTOInsert;
Test.stopTest();

Map<Id, Account> accountMap = new Map<Id, Account>([SELECT Id, Committee__pc, Committee_Name__pc FROM Account
WHERE Id IN :new Set<Id>{provider2.Id, provider3.Id}]);

Account provider3AfterDelete = accountMap.get(provider3.Id);
Assert.areEqual(provider3AfterDelete.Committee__pc, ESA_cls_constants.EDRD_PERSONACCOUNT_SC, 'Committee should be null after deletion');
Assert.areEqual(provider3AfterDelete.Committee_Name__pc, ESA_cls_constants.EDRD_PERSONACCOUNT_SC_METABOLIC_SUBCOMMITTEE, 'Committee Name should be null after deletion');
Assert.areNotEqual(provider3AfterDelete.Committee__pc, NULL, 'Committee should not be null after deletion');
Assert.areNotEqual(provider3AfterDelete.Committee_Name__pc, NULL, 'Committee Name should not be null after deletion');

Account provider2AfterDelete = accountMap.get(provider2.Id);
Assert.areEqual(provider2AfterDelete.Committee__pc, NULL, 'Provider2 Committee should not be null');
Assert.areEqual(provider2AfterDelete.Committee_Name__pc, NULL, 'Provider2 Committee Name should remain unchanged');
}
}
43 changes: 43 additions & 0 deletions dev-app-post/main/default/classes/EDRD_cls_HandleGroupsTest.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**********************************************************************************************
* @Author: Accenture
* @Date: 20/12/2024
* @Description: The purpose of this class is to cover Code coverage of EDRD_cls_HandleGroups
* @Revision(s): [Date] - [Change Reference] - [Changed By] - [Description]
20 Dec - EDRD-1150 - Accenture - The purpose of this method is to Remove Committee based on ACR delete of EDRD_Committee & Provider OR Committee_Reviewer.
***********************************************************************************************/
@isTest
public class EDRD_cls_HandleGroupsTest {

/**
* @author:
* @date: 23 Dec 2024
* @description: The purpose of this method is to cover Testcoverage of handleGroupMembership
* @Modification Log: [Date] - [Change Reference] - [Changed By] - [Description]
*/
@isTest
public static void handleGroupMembershipTest(){
Account providerAcc = TestFactory.newProvider('Provider Test');
providerAcc.Committee__pc = ESA_cls_constants.EDRD_PERSONACCOUNT_SC;
providerAcc.Committee_Name__pc = ESA_cls_constants.EDRD_PERSONACCOUNT_SC_METABOLIC_SUBCOMMITTEE;
providerAcc.Provider_Identifier__pc = '1112223';
providerAcc.Provider_Type__pc = ESA_cls_constants.EDRD_PHYSICIAN;
insert providerAcc;

Id ContactId = [SELECT Id FROM Contact WHERE AccountID =: providerAcc.Id].get(0).Id;
Profile profileRec = [SELECT Id FROM Profile WHERE Name = 'EDRD Prescriber Community User'];
User communityUser = TestFactory.createCommunityUser(ContactId, profileRec.Id, 'Test1', 'Test');
insert communityUser;

providerAcc.Committee__pc = ESA_cls_constants.EDRD_PERSONACCOUNT_ACSC;

Test.startTest();
update providerAcc;
Test.stopTest();

List<GroupMember> groupMembers = [SELECT Id, GroupId FROM GroupMember WHERE UserOrGroupId = :communityUser.Id];

Assert.areEqual(TRUE, groupMembers.size() > 0, 'At least one GroupMember should exist for the user');
Assert.areEqual(2, groupMembers.size(), 'Exactly two GroupMember should exist for the user');
Assert.areNotEqual(null, groupMembers[0].GroupId, 'GroupMember should have a valid GroupId');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @Description: The purpose of this class is to cover Code coverage of ESA_cls_accountTriggerHandler
* @Revision(s): [Date] - [Change Reference] - [Changed By] - [Description]
11 Nov - EDRD-82 - Accenture - Added Close Case method on Account Inactive
20 Dec - EDRD-1150 - Accenture - Adding/Removing - Provider/Reviewer to public groups based on Committees.
***********************************************************************************************/

@isTest
Expand Down Expand Up @@ -86,4 +87,37 @@ public class ESA_cls_accountTriggerHandlerTest {
Assert.areEqual(caseList.get(0).EDRD_MOHFunding_Expiry_Date__c, System.Today(), 'Date should be Today');
Assert.areNotEqual(caseList.get(0).EDRD_MOHFunding_Expiry_Date__c, NULL, 'Date cannot be Null');
}

/**
* @author: Deepak
* @date: 20 Dec 2024
* @description: The purpose of this method is to cover Testcoverage of handlePublicGroupMemberships
* @Modification Log: [Date] - [Change Reference] - [Changed By] - [Description]
*/
@isTest
public static void handlePublicGroupMembershipsTest(){
Account providerAccount = TestFactory.newProvider('Provider Test');
providerAccount.Committee__pc = ESA_cls_constants.EDRD_PERSONACCOUNT_SC;
providerAccount.Committee_Name__pc = ESA_cls_constants.EDRD_PERSONACCOUNT_SC_METABOLIC_SUBCOMMITTEE;
providerAccount.Provider_Identifier__pc = '1112223';
providerAccount.Provider_Type__pc = ESA_cls_constants.EDRD_PHYSICIAN;
insert providerAccount;

Id ContactId = [SELECT Id FROM Contact WHERE AccountID =: providerAccount.Id].get(0).Id;
Profile profileRec = [SELECT Id FROM Profile WHERE Name = 'EDRD Prescriber Community User'];
User communityReviewer = TestFactory.createCommunityUser(ContactId, profileRec.Id, 'Test1', 'Test');
insert communityReviewer;

providerAccount.Committee__pc = ESA_cls_constants.EDRD_PERSONACCOUNT_ACSC;

Test.startTest();
update providerAccount;
Test.stopTest();

List<GroupMember> groupMembersList = [SELECT Id, GroupId FROM GroupMember WHERE UserOrGroupId = :communityReviewer.Id];

Assert.areEqual(TRUE, groupMembersList.size() > 0, 'At least one GroupMember should exist for the user');
Assert.areEqual(2, groupMembersList.size(), 'Exactly two GroupMember should exist for the user');
Assert.areNotEqual(null, groupMembersList[0].GroupId, 'GroupMember should have a valid GroupId');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<status>Active</status>
</ApexClass>
31 changes: 31 additions & 0 deletions dev-app-post/main/default/classes/UserTriggerHandlerTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @Description: The purpose of this class is to cover Code coverage of UserTriggerHandler
* @Revision(s): [Date] - [Change Reference] - [Changed By] - [Description]
24Sept - EDRD-911 - Deepak - Added activateACROnEDRDPortalEnable_Test method
07Jan - EDRD-1150 - Accenture - Added handleEDRDPublicGroupMemberTest method
***********************************************************************************************/
@isTest
public class UserTriggerHandlerTest {
Expand Down Expand Up @@ -57,4 +58,34 @@ public class UserTriggerHandlerTest {
Assert.areNotEqual(accShareList1.isEmpty(), true, 'AccountShare list should not be empty');
Assert.areNotEqual(accShareList1[0].UserOrGroupId, null, 'UserOrGroupId should not be null');
}

/**
* @author: Deepak
* @date: 07 Jan 2025
* @description: The purpose of this method is to cover Testcoverage of handleEDRDPublicGroupMember & handleGroupsForUsersAsync
* @Modification Log: [Date] - [Change Reference] - [Changed By] - [Description]
*/
@isTest
public static void handleEDRDPublicGroupMemberTest(){
Account providerAcc = TestFactory.newProvider('Provider Test');
providerAcc.Committee__pc = ESA_cls_constants.EDRD_PERSONACCOUNT_SC;
providerAcc.Committee_Name__pc = ESA_cls_constants.EDRD_PERSONACCOUNT_SC_METABOLIC_SUBCOMMITTEE;
providerAcc.Provider_Identifier__pc = '1112223';
providerAcc.Provider_Type__pc = ESA_cls_constants.EDRD_PHYSICIAN;
insert providerAcc;

Id ContactId = [SELECT Id FROM Contact WHERE AccountID =: providerAcc.Id].get(0).Id;
Profile profileRec = [SELECT Id FROM Profile WHERE Name = 'EDRD Prescriber Community User'];
User communityUser = TestFactory.createCommunityUser(ContactId, profileRec.Id, 'Test1', 'Test');

Test.startTest();
insert communityUser;
Test.stopTest();

List<GroupMember> groupMembers = [SELECT Id, GroupId, UserOrGroupId FROM GroupMember WHERE UserOrGroupId = :communityUser.Id];

Assert.areEqual(TRUE, groupMembers.size() > 0, 'At least one GroupMember should be created for the community user.');
Assert.areEqual(1, groupMembers.size(), 'Exactly one GroupMember should be created for the community user.');
Assert.areNotEqual(null, groupMembers[0].GroupId, 'GroupMember should have a valid GroupId.');
}
}
Loading

0 comments on commit 1777413

Please sign in to comment.