diff --git a/src/classes/EscalationCaseUtils_Test.cls b/src/classes/EscalationCaseUtils_Test.cls index a4bf2ad..485417e 100644 --- a/src/classes/EscalationCaseUtils_Test.cls +++ b/src/classes/EscalationCaseUtils_Test.cls @@ -203,4 +203,4 @@ private class EscalationCaseUtils_Test { System.assert(expectedResults.isEmpty(), 'Did not get back all the Ids we expected'); } -} \ No newline at end of file +} diff --git a/src/classes/EscalationTeamTrigger.cls b/src/classes/EscalationTeamTrigger.cls index 2131210..ea1f5b7 100644 --- a/src/classes/EscalationTeamTrigger.cls +++ b/src/classes/EscalationTeamTrigger.cls @@ -99,23 +99,25 @@ public with sharing class EscalationTeamTrigger extends BaseTrigger { Set members = escalToMembers.get(team.rh_escal__Escalation__c); Set emails = escalToEmails.get(team.rh_escal__Escalation__c); - Boolean isContactNull = team.rh_escal__Contact__c == null; - Boolean isUserNull = team.rh_escal__User__c == null; - Boolean isEmailNull = team.rh_escal__Email__c == null; + Boolean contactIsNotNull = team.rh_escal__Contact__c != null; + Boolean userIsNotNull = team.rh_escal__User__c != null; + Boolean emailIsNotNull = team.rh_escal__Email__c != null; + + Boolean contactSetAndInTeam = contactIsNotNull && members.contains(team.rh_escal__Contact__c); + Boolean userSetAndInTeam = userIsNotNull && members.contains(team.rh_escal__User__c); + Boolean emailSetAndInTeam = emailIsNotNull && emails.contains(team.rh_escal__Email__c); if ( ( - !isContactNull && members.contains(team.rh_escal__Contact__c) - ) || ( - !isUserNull && members.contains(team.rh_escal__User__c) - ) || ( - !isEmailNull && emails.contains(team.rh_escal__Email__c) - ) && (this.isInsert - || ( - this.oldMap.get(team.Id).rh_escal__Contact__c != team.rh_escal__Contact__c || - this.oldMap.get(team.Id).rh_escal__User__c != team.rh_escal__User__c || - this.oldMap.get(team.Id).rh_escal__Email__c != team.rh_escal__Email__c - ) + contactSetAndInTeam || userSetAndInTeam || emailSetAndInTeam + ) && + ( + this.isInsert || + ( + this.oldMap.get(team.Id).rh_escal__Contact__c != team.rh_escal__Contact__c || + this.oldMap.get(team.Id).rh_escal__User__c != team.rh_escal__User__c || + this.oldMap.get(team.Id).rh_escal__Email__c != team.rh_escal__Email__c + ) ) ) { team.addError(EscalationTeamUtils.TEAM_MEMBER_ALREADY_LINKED); @@ -134,4 +136,4 @@ public with sharing class EscalationTeamTrigger extends BaseTrigger { this.teamDupCheck(); } } -} \ No newline at end of file +} diff --git a/src/classes/EscalationTeamTrigger_Test.cls b/src/classes/EscalationTeamTrigger_Test.cls index c7502d0..5ac1a7a 100644 --- a/src/classes/EscalationTeamTrigger_Test.cls +++ b/src/classes/EscalationTeamTrigger_Test.cls @@ -477,4 +477,92 @@ public with sharing class EscalationTeamTrigger_Test { System.assertEquals(testUser.Id, testEscalationTeam2.rh_escal__User__c, 'The team member should not have been added'); } + + static testMethod void changeInternalDoesNotTriggerDupeExceptionForEmailContact() { + Account testAccount = TestUtils.getAccount(); + insert testAccount; + + String email = 'testEmail1@redHat.com'; + + rh_escal__Escalation__c testEscalation = TestUtils.getEscalation(); + insert testEscalation; + + testEscalation = TestUtils.fetchEscalation(testEscalation); + + rh_escal__EscalationTeam__c testEscalationTeam = TestUtils.getEscalationTeam(testEscalation, email); + testEscalationTeam.rh_escal__Internal__c =false; + insert testEscalationTeam; + + testEscalationTeam.rh_escal__Internal__c = true; + + BaseTrigger.triggerNameToInfoMap.clear(); + + Test.startTest(); + + update testEscalationTeam; + + Test.stopTest(); + + testEscalationTeam = TestUtils.fetchEscalationTeam(testEscalationTeam); + System.assert(testEscalationTeam.rh_escal__Internal__c, 'Internal should be true'); + } + + static testMethod void changeInternalDoesNotTriggerDupeExceptionForContact() { + Account testAccount = TestUtils.getAccount(); + insert testAccount; + + Contact testContact = TestUtils.getContact(testAccount, 'testContact1'); + insert testContact; + + rh_escal__Escalation__c testEscalation = TestUtils.getEscalation(); + insert testEscalation; + + testEscalation = TestUtils.fetchEscalation(testEscalation); + + rh_escal__EscalationTeam__c testEscalationTeam = TestUtils.getEscalationTeam(testEscalation, testContact, false); + insert testEscalationTeam; + + testEscalationTeam.rh_escal__Internal__c = true; + + BaseTrigger.triggerNameToInfoMap.clear(); + + Test.startTest(); + + update testEscalationTeam; + + Test.stopTest(); + + testEscalationTeam = TestUtils.fetchEscalationTeam(testEscalationTeam); + System.assert(testEscalationTeam.rh_escal__Internal__c, 'Internal should be true'); + } + + static testMethod void changeInternalDoesNotTriggerDupeExceptionForUser() { + Account testAccount = TestUtils.getAccount(); + insert testAccount; + + Contact testContact = TestUtils.getContact(testAccount, 'testContact1'); + insert testContact; + + rh_escal__Escalation__c testEscalation = TestUtils.getEscalation(); + insert testEscalation; + + testEscalation = TestUtils.fetchEscalation(testEscalation); + + rh_escal__EscalationTeam__c testEscalationTeam = TestUtils.getEscalationTeam(testEscalation, TestUtils.getAdminUser()); + testEscalationTeam.rh_escal__Internal__c =false; + insert testEscalationTeam; + + testEscalationTeam.rh_escal__Internal__c = true; + + BaseTrigger.triggerNameToInfoMap.clear(); + + Test.startTest(); + + update testEscalationTeam; + + Test.stopTest(); + + testEscalationTeam = TestUtils.fetchEscalationTeam(testEscalationTeam); + System.assert(testEscalationTeam.rh_escal__Internal__c, 'Internal should be true'); + } } \ No newline at end of file