Skip to content

Commit 0c52f78

Browse files
committed
fixing test failure only encountered when run by API Only users (ex., CICD/integrations)
1 parent c7d2423 commit 0c52f78

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

flow_screen_components/datatable/force-app/main/default/classes/ers_DatatableControllerTest.cls

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,27 @@ private with sharing class ers_DatatableControllerTest {
8888

8989
@IsTest
9090
private static void testGetIconName() {
91-
System.assertEquals('standard:account', ers_DatatableController.getIconName('Account'));
92-
System.assertEquals('standard:contact', ers_DatatableController.getIconName('Contact'));
91+
List<SObject> apiOnlyPerms = [
92+
SELECT Id
93+
FROM PermissionSetAssignment
94+
WHERE AssigneeId = :UserInfo.getUserId()
95+
AND PermissionSet.PermissionsApiUserOnly = true
96+
LIMIT 1
97+
];
98+
99+
Test.startTest();
100+
String accountIcon = ers_DatatableController.getIconName('Account');
101+
String contactIcon = ers_DatatableController.getIconName('Contact');
102+
Test.stopTest();
103+
104+
if (apiOnlyPerms?.isEmpty()) {
105+
Assert.areEqual('standard:account', accountIcon);
106+
Assert.areEqual('standard:contact', contactIcon);
107+
} else {
108+
// API Only users don't have access to view tabs; this method will return null
109+
// Necessary to prevent this test from failing when run by CICD/integrations
110+
Assert.isNull(accountIcon);
111+
Assert.isNull(contactIcon);
112+
}
93113
}
94114
}

0 commit comments

Comments
 (0)