Skip to content

Commit

Permalink
Correct tests for namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
aheber committed Nov 25, 2024
1 parent 71aa434 commit b340d9f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
16 changes: 14 additions & 2 deletions dlrs/main/classes/RollupCalculateJobTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ private class RollupCalculateJobTest {
if (permSetsWithAccess.isEmpty()) {
return; // this org doesn't have the necessary metadata to test this feature
}

CustomPermission perm = [
SELECT DeveloperName, NamespacePrefix
FROM CustomPermission
WHERE Id = :permSetsWithAccess[0].SetupEntityId
];

String permName = perm.DeveloperName;
if (String.isNotBlank(perm.NamespacePrefix)) {
permName = perm.NamespacePrefix + '__' + perm.DeveloperName;
}

// see if the running user already has that permission set
List<PermissionSetAssignment> assignments = [
SELECT Id
Expand Down Expand Up @@ -236,7 +248,7 @@ private class RollupCalculateJobTest {
CalculationMode__c = 'Realtime',
AggregateAllRows__c = false,
Active__c = true,
BypassPermissionApiName__c = 'DisableDLRS'
BypassPermissionApiName__c = permName
);
RollupSummariesSelector.setRollupCache(
false,
Expand All @@ -251,7 +263,7 @@ private class RollupCalculateJobTest {
String jobId;
System.runAs(new User(Id = UserInfo.getUserId())) {
Test.startTest();
Assert.isTrue(FeatureManagement.checkPermission('DisableDLRS'));
Assert.isTrue(FeatureManagement.checkPermission(permName));
// go into runAs because we need to get the perms recalculated
jobId = Database.executeBatch(job);
Test.stopTest();
Expand Down
19 changes: 17 additions & 2 deletions dlrs/main/classes/RollupJobTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ private class RollupJobTest {
if (permSetsWithAccess.isEmpty()) {
return; // this org doesn't have the necessary metadata to test this feature
}

CustomPermission perm = [
SELECT DeveloperName, NamespacePrefix
FROM CustomPermission
WHERE Id = :permSetsWithAccess[0].SetupEntityId
];

String permName = perm.DeveloperName;
if (String.isNotBlank(perm.NamespacePrefix)) {
permName = perm.NamespacePrefix + '__' + perm.DeveloperName;
}

// see if the running user already has that permission set
List<PermissionSetAssignment> assignments = [
SELECT Id
Expand Down Expand Up @@ -211,7 +223,7 @@ private class RollupJobTest {
CalculationMode__c = 'Realtime',
AggregateAllRows__c = false,
Active__c = true,
BypassPermissionApiName__c = 'DisableDLRS'
BypassPermissionApiName__c = permName
);

RollupSummariesSelector.setRollupCache(
Expand Down Expand Up @@ -241,7 +253,10 @@ private class RollupJobTest {
String jobId;
System.runAs(new User(Id = UserInfo.getUserId())) {
Test.startTest();
Assert.isTrue(FeatureManagement.checkPermission('DisableDLRS'));
Assert.isTrue(
FeatureManagement.checkPermission(permName),
'Expected user to have the ' + permName + ' permission set'
);
// go into runAs because we need to get the perms recalculated
jobId = Database.executeBatch(new RollupJob());
Test.stopTest();
Expand Down
6 changes: 5 additions & 1 deletion dlrs/main/classes/UtilitiesTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ public class UtilitiesTest {
if (String.isNotBlank(perm.NamespacePrefix)) {
permName = perm.NamespacePrefix + '__' + perm.DeveloperName;
}
Assert.areEqual(false, Utilities.userHasCustomPermission(permName));
Assert.areEqual(
true,
Utilities.userHasCustomPermission(permName),
'Expected user to have ' + permName
);
}

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

0 comments on commit b340d9f

Please sign in to comment.