Skip to content

Commit

Permalink
Merge pull request #521 from Onlineberatung/fix/OBI-840_statistics_co…
Browse files Browse the repository at this point in the history
…unt_direct_session

fix: direct session assignment to be counted for statistics
  • Loading branch information
PhilippFr authored Oct 11, 2022
2 parents 74b96d7 + d9cdc76 commit 583405b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
import de.caritas.cob.userservice.api.exception.httpresponses.BadRequestException;
import de.caritas.cob.userservice.api.manager.consultingtype.ConsultingTypeManager;
import de.caritas.cob.userservice.api.model.User;
import de.caritas.cob.userservice.api.service.statistics.StatisticsService;
import de.caritas.cob.userservice.api.service.statistics.event.AssignSessionStatisticsEvent;
import de.caritas.cob.userservice.consultingtypeservice.generated.web.model.ExtendedConsultingTypeResponseDTO;
import de.caritas.cob.userservice.statisticsservice.generated.web.model.UserRole;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand All @@ -27,6 +30,7 @@ public class CreateNewConsultingTypeFacade {
private final @NonNull ConsultingTypeManager consultingTypeManager;
private final @NonNull CreateUserChatRelationFacade createUserChatRelationFacade;
private final @NonNull CreateSessionFacade createSessionFacade;
private final @NonNull StatisticsService statisticsService;

/**
* Initializes the new consulting type settings and creates a session or a chat-agency relation
Expand Down Expand Up @@ -76,11 +80,18 @@ private NewRegistrationResponseDto createSessionOrChat(
RocketChatCredentials rocketChatCredentials) {

if (isNotBlank(userRegistrationDTO.getConsultantId())) {
return createSessionFacade.createDirectUserSession(
userRegistrationDTO.getConsultantId(),
fromUserRegistrationDTO(userRegistrationDTO),
user,
extendedConsultingTypeResponseDTO);
NewRegistrationResponseDto newRegistrationResponseDto =
createSessionFacade.createDirectUserSession(
userRegistrationDTO.getConsultantId(),
fromUserRegistrationDTO(userRegistrationDTO),
user,
extendedConsultingTypeResponseDTO);
statisticsService.fireEvent(
new AssignSessionStatisticsEvent(
userRegistrationDTO.getConsultantId(),
UserRole.CONSULTANT,
newRegistrationResponseDto.getSessionId()));
return newRegistrationResponseDto;
}

Long sessionId = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ public void assignAnonymousEnquiry(Session session, Consultant consultant) {
this.rocketChatFacade.addUserToRocketChatGroup(
consultant.getRocketChatId(), session.getGroupId());
this.rocketChatFacade.removeSystemMessagesFromRocketChatGroup(session.getGroupId());
statisticsService.fireEvent(
new AssignSessionStatisticsEvent(
consultant.getId(), UserRole.CONSULTANT, session.getId()));
} catch (Exception e) {
rollbackSessionUpdate(session);
throw new InternalServerErrorException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.http.HttpStatus.CREATED;

import de.caritas.cob.userservice.api.adapters.rocketchat.RocketChatCredentials;
import de.caritas.cob.userservice.api.adapters.web.dto.NewRegistrationResponseDto;
import de.caritas.cob.userservice.api.adapters.web.dto.UserDTO;
import de.caritas.cob.userservice.api.exception.MissingConsultingTypeException;
import de.caritas.cob.userservice.api.exception.httpresponses.BadRequestException;
import de.caritas.cob.userservice.api.manager.consultingtype.ConsultingTypeManager;
import de.caritas.cob.userservice.api.model.User;
import de.caritas.cob.userservice.api.service.statistics.StatisticsService;
import de.caritas.cob.userservice.consultingtypeservice.generated.web.model.ExtendedConsultingTypeResponseDTO;
import org.jeasy.random.EasyRandom;
import org.junit.Test;
Expand All @@ -37,6 +40,7 @@ public class CreateNewConsultingTypeFacadeTest {
@Mock private ConsultingTypeManager consultingTypeManager;
@Mock private CreateUserChatRelationFacade createUserChatRelationFacade;
@Mock private CreateSessionFacade createSessionFacade;
@Mock private StatisticsService statisticsService;

@Test
public void
Expand Down Expand Up @@ -154,9 +158,15 @@ public class CreateNewConsultingTypeFacadeTest {
when(consultingTypeManager.getConsultingTypeSettings("15"))
.thenReturn(CONSULTING_TYPE_SETTINGS_KREUZBUND);

NewRegistrationResponseDto mockResult = mock(NewRegistrationResponseDto.class);
when(mockResult.getSessionId()).thenReturn(1L);
when(createSessionFacade.createDirectUserSession(any(), any(), any(), any()))
.thenReturn(mockResult);

createNewConsultingTypeFacade.initializeNewConsultingType(userDTO, user, rocketChatCredentials);

verify(createSessionFacade)
.createDirectUserSession("consultantId", userDTO, user, CONSULTING_TYPE_SETTINGS_KREUZBUND);
verify(this.statisticsService, times(1)).fireEvent(any());
}
}

0 comments on commit 583405b

Please sign in to comment.