Skip to content

Instantly share code, notes, and snippets.

@Walletau
Last active April 1, 2017 17:55
Show Gist options
  • Save Walletau/4a14e740fbf562ad9eb0ee0cad78c367 to your computer and use it in GitHub Desktop.
Save Walletau/4a14e740fbf562ad9eb0ee0cad78c367 to your computer and use it in GitHub Desktop.
RH Snip5
@isTest
public static void testObjectAOwnership() {
Account owningAccount = Build.anAccount()
.withRecordType(Build.AccountRecordType.Account)
.withName('testOwningAccount')
.build();
insert owningAccount;
Account secondOwningAccount = Build.anAccount()
.withRecordType(Build.AccountRecordType.Account)
.withName('testOwningAccount2')
.build();
insert secondOwningAccount;
SecHelp.GroupCalculationActive = false;
List<SecHelp.PublicGroupAccountWrapper> publicGroupWrapperList = SecHelp.createPublicGroupSet(new Set<Id>{
owningAccount.Id,
secondOwningAccount.Id
});
publicGroupWrapperList = SecHelp.insertPublicGroupsFromWrapperList(publicGroupWrapperList);
SecHelp.mapPublicGroupsToAccounts(publicGroupWrapperList);
SecurityDictionary__c objectASecurity = Build.aSecurityDictionary()
.withName('ObjectA')
.withParentAccess('Edit')
.withChildAccess('Read')
.withPrimaryAccess('Read')
.build();
insert objectASecurity;
ObjectA__c childObjectA = Build.aObjectA()
.withAccount(owningAccount)
.build();
Test.startTest();
insert childObjectA;
Test.stopTest();
owningAccount = [
SELECT Id,
ChildrenPublicGroupId__c,
ParentPublicGroupId__c,
PublicGroupId__c
FROM Account
WHERE Id = :owningAccount.Id
];
secondOwningAccount = [
SELECT Id,
ChildrenPublicGroupId__c,
ParentPublicGroupId__c,
PublicGroupId__c
FROM Account
WHERE Id = :secondOwningAccount.Id
];
List<ObjectA__Share> objectAShares = [
SELECT Id,
UserOrGroupId
FROM ObjectA__Share
WHERE ParentId = :childObjectA.Id
AND RowCause = :Schema.ObjectA__Share.rowCause.DefaultExternalSharingConfiguration__c
];
System.assert(objectAShares.size() == 3, 'ObjectA Shares did not create correctly');
Boolean parentPublicGroup = false;
Boolean childPublicGroup = false;
Boolean primaryPublicGroup = false;
for (ObjectA__Share objectAShare : objectAShares) {
if (objectAShare.UserOrGroupId == owningAccount.PublicGroupId__c)
primaryPublicGroup = true;
if (objectAShare.UserOrGroupId == owningAccount.ChildrenPublicGroupId__c)
childPublicGroup = true;
if (objectAShare.UserOrGroupId == owningAccount.ParentPublicGroupId__c)
parentPublicGroup = true;
}
System.assert(primaryPublicGroup && parentPublicGroup && childPublicGroup, 'Not all public groups created correctly');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment