Skip to content

Commit

Permalink
Merge pull request #78 from virtualidentityag/VIC-1676-fix-consultant…
Browse files Browse the repository at this point in the history
…-removal-if-group-chat-null

fix: do not execute removal steps if rcGroupId is null
  • Loading branch information
tkuzynow authored Oct 4, 2022
2 parents 8e78c7b + 1e9037c commit dddc4e7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ void removeConsultantsFromSessionGroup(String rcGroupId, List<Consultant> consul

private void removeConsultantsFromRocketChatGroup(
String rcGroupId, List<Consultant> consultants) {
List<String> groupMemberList = obtainRocketChatGroupMemberIds(rcGroupId);
if (rcGroupId != null) {
List<String> groupMemberList = obtainRocketChatGroupMemberIds(rcGroupId);

rocketChatFacade.addTechnicalUserToGroup(rcGroupId);
consultants.stream()
.map(Consultant::getRocketChatId)
.filter(groupMemberList::contains)
.forEach(rcUserId -> rocketChatFacade.removeUserFromGroup(rcUserId, rcGroupId));
rocketChatFacade.removeTechnicalUserFromGroup(rcGroupId);
rocketChatFacade.addTechnicalUserToGroup(rcGroupId);
consultants.stream()
.map(Consultant::getRocketChatId)
.filter(groupMemberList::contains)
.forEach(rcUserId -> rocketChatFacade.removeUserFromGroup(rcUserId, rcGroupId));
rocketChatFacade.removeTechnicalUserFromGroup(rcGroupId);
}
}

private List<String> obtainRocketChatGroupMemberIds(String groupId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,22 @@ public void removeFromGroupOrRollbackOnFailure_Should_executeRemoveForRocketChat
}
}

@Test
public void removeFromGroupsOrRollbackOnFailure_Should_doNothing_When_rcGroupIdIsNull() {
when(this.session.getGroupId()).thenReturn("group");
when(this.session.getFeedbackGroupId()).thenReturn("feedback");
when(this.consultant.getRocketChatId()).thenReturn("rcId");
GroupMemberDTO groupMemberDTO = new GroupMemberDTO();
groupMemberDTO.set_id(this.consultant.getRocketChatId());
when(this.rocketChatFacade.retrieveRocketChatMembers(any()))
.thenReturn(singletonList(groupMemberDTO));

this.removeService.removeFromGroupsOrRollbackOnFailure();

verify(this.rocketChatFacade, never()).removeUserFromGroup("rcId", null);
verify(this.rocketChatFacade, never()).removeUserFromGroup("rcId", null);
}

@Test
public void
removeFromGroupOrRollbackOnFailure_Should_throwInternalServerErrorAndPerformRollback_When_error() {
Expand Down

0 comments on commit dddc4e7

Please sign in to comment.