Skip to content

Commit

Permalink
Merge pull request #22 from preeti-preeti/JhirdChanges
Browse files Browse the repository at this point in the history
Jhird changes
  • Loading branch information
preeti-preeti authored Mar 2, 2018
2 parents e5b6dce + f6eb2ad commit 87d49c5
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/classes/EscalationCaseUtils_Test.cls
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,4 @@ private class EscalationCaseUtils_Test {

System.assert(expectedResults.isEmpty(), 'Did not get back all the Ids we expected');
}
}
}
32 changes: 17 additions & 15 deletions src/classes/EscalationTeamTrigger.cls
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,25 @@ public with sharing class EscalationTeamTrigger extends BaseTrigger {
Set<Id> members = escalToMembers.get(team.rh_escal__Escalation__c);
Set<String> 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);
Expand All @@ -134,4 +136,4 @@ public with sharing class EscalationTeamTrigger extends BaseTrigger {
this.teamDupCheck();
}
}
}
}
88 changes: 88 additions & 0 deletions src/classes/EscalationTeamTrigger_Test.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]';

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');
}
}

0 comments on commit 87d49c5

Please sign in to comment.