Skip to content

Commit

Permalink
Check for no duplicate rules enabled in PotentialDuplicates_TEST
Browse files Browse the repository at this point in the history
  • Loading branch information
npsp-reedestockton committed Nov 17, 2023
1 parent 3266e56 commit 5ed8096
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions force-app/main/default/classes/PotentialDuplicates_TEST.cls
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,53 @@ private with sharing class PotentialDuplicates_TEST {
private static void shouldReturnNullWhenNoDuplicatesAreFound() {
Id recordId = UTIL_UnitTestData_TEST.mockId(Contact.getSObjectType());
Map<String, Object> data = PotentialDuplicates.getDuplicates(recordId);
System.assertEquals('', data.get('setOfMatches'),
'There should be no duplicates');
String setOfMatches = (String) data.get('setOfMatches');

List<DuplicateRule> 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<Contact> 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<DuplicateRule> activeContactRules = [
SELECT Id
from DuplicateRule
WHERE SObjectType = 'Contact'
AND isActive = TRUE
];

Map<String, Object> 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');
}
}
}

0 comments on commit 5ed8096

Please sign in to comment.