Skip to content

Commit

Permalink
Make test namespace aware
Browse files Browse the repository at this point in the history
  • Loading branch information
aheber committed Nov 25, 2024
1 parent 2630f7b commit 71aa434
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dlrs/main/classes/Utilities.cls
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public class Utilities {
WHERE Id IN :customPermIds
]) {
String permName = perm.DeveloperName;
if (!String.isBlank(perm.NamespacePrefix)) {
if (String.isNotBlank(perm.NamespacePrefix)) {
// if this has a namespace prefix we should build a unified string
permName = String.format(
'{0}__{1}',
Expand Down
13 changes: 11 additions & 2 deletions dlrs/main/classes/UtilitiesTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class UtilitiesTest {
static void testUserHasCustomPermission() {
// find the permission set that has access to the Custom Permission we want to use to check (if it even exists in the system)
List<SetupEntityAccess> permSetsWithAccess = [
SELECT ParentId
SELECT ParentId, SetupEntityId
FROM SetupEntityAccess
WHERE
SetupEntityId IN (
Expand All @@ -15,6 +15,11 @@ public class UtilitiesTest {
AND Parent.IsOwnedByProfile = FALSE
];
if (!permSetsWithAccess.isEmpty()) {
CustomPermission perm = [
SELECT DeveloperName, NamespacePrefix
FROM CustomPermission
WHERE Id = :permSetsWithAccess[0].SetupEntityId
];
// there is a compatible permission set that we can use for testing
// see if the running user already has that permission set
List<PermissionSetAssignment> assignments = [
Expand All @@ -35,7 +40,11 @@ public class UtilitiesTest {
}
// make sure the utility can see the perm set correctly
// (we do it here because any earlier and the utility would have built the cache already)
Assert.areEqual(false, Utilities.userHasCustomPermission('DisableDLRS'));
String permName = perm.DeveloperName;
if (String.isNotBlank(perm.NamespacePrefix)) {
permName = perm.NamespacePrefix + '__' + perm.DeveloperName;
}
Assert.areEqual(false, Utilities.userHasCustomPermission(permName));
}

Assert.areEqual(false, Utilities.userHasCustomPermission(null));
Expand Down

0 comments on commit 71aa434

Please sign in to comment.