diff --git a/force-app/main/default/classes/PotentialDuplicates_TEST.cls b/force-app/main/default/classes/PotentialDuplicates_TEST.cls index 27987c7076a..6f81d20c876 100644 --- a/force-app/main/default/classes/PotentialDuplicates_TEST.cls +++ b/force-app/main/default/classes/PotentialDuplicates_TEST.cls @@ -5,30 +5,53 @@ private with sharing class PotentialDuplicates_TEST { private static void shouldReturnNullWhenNoDuplicatesAreFound() { Id recordId = UTIL_UnitTestData_TEST.mockId(Contact.getSObjectType()); Map data = PotentialDuplicates.getDuplicates(recordId); - System.assertEquals('', data.get('setOfMatches'), - 'There should be no duplicates'); + String setOfMatches = (String) data.get('setOfMatches'); + + List activeContactRules = [ + SELECT Id + from DuplicateRule + WHERE SObjectType = 'Contact' + AND isActive = TRUE + ]; + + if (activeContactRules.isEmpty()) { + System.assertEquals(null, setOfMatches, + 'PotentialDuplicates.getDuplicates() should return null if there are no active Duplicate Rules for Contact'); + } else { + System.assertEquals('', setOfMatches, 'There should be no duplicates'); + } } @IsTest private static void shouldReturnIdsWhenDuplicatesAreFound() { List contactList = UTIL_UnitTestData_TEST.getContacts(3); - for(Contact c : contactList) { + for (Contact c : contactList) { c.FirstName = 'Test'; c.LastName = 'LastName'; c.Email = 'tester@example.com'; } insert contactList; + List activeContactRules = [ + SELECT Id + from DuplicateRule + WHERE SObjectType = 'Contact' + AND isActive = TRUE + ]; + Map data = PotentialDuplicates.getDuplicates(contactList[0].Id); - String setOfMatches = (String)data.get('setOfMatches'); - Integer numberOfMatches = setOfMatches.split(',').size(); + String setOfMatches = (String) data.get('setOfMatches'); - // Duplicates will not be found if encryption is enabled / standard rules deactivated - if (sObjectType.Contact.fields.Name.isEncrypted()) { + if (activeContactRules.isEmpty()) { + System.assertEquals(null, setOfMatches, + 'PotentialDuplicates.getDuplicates() should return null if there are no active Duplicate Rules for Contact'); + } else if (sObjectType.Contact.fields.Name.isEncrypted()) { + // Duplicates will not be found if encryption is enabled / standard rules deactivated System.assertEquals('', setOfMatches, 'No duplicate Ids should be returned if encryption is enabled'); - } - else { + } else { + Integer numberOfMatches = setOfMatches.split(',').size(); System.assertNotEquals('', setOfMatches, 'Duplicate Ids should be returned'); - System.assertEquals(2, numberOfMatches, 'There should be 2 duplicates returned'); } + System.assertEquals(2, numberOfMatches, 'There should be 2 duplicates returned'); + } } } \ No newline at end of file