Skip to content

Commit

Permalink
Merge branch 'Onlineberatung:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mebo4b authored Jul 4, 2022
2 parents 384296e + f3f1144 commit 4dbc3c4
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 15 deletions.
2 changes: 2 additions & 0 deletions api/videoservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ components:
sessionId:
type: integer
format: int64
initiatorDisplayName:
type: string
CreateVideoCallResponseDTO:
type: object
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class VideoController implements VideocallsApi {
@Override
public ResponseEntity<CreateVideoCallResponseDTO> createVideoCall(@RequestHeader String rcUserId,
@Valid CreateVideoCallDTO createVideoCallDto) {
var response = startVideoCallFacade.startVideoCall(createVideoCallDto.getSessionId(), rcUserId);
var response = startVideoCallFacade.startVideoCall(createVideoCallDto, rcUserId);

return new ResponseEntity<>(response, HttpStatus.CREATED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import static de.caritas.cob.videoservice.api.service.session.SessionStatus.IN_PROGRESS;
import static java.util.Collections.singletonList;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

import de.caritas.cob.videoservice.api.authorization.VideoUser;
import de.caritas.cob.videoservice.api.exception.httpresponse.BadRequestException;
import de.caritas.cob.videoservice.api.model.CreateVideoCallDTO;
import de.caritas.cob.videoservice.api.model.CreateVideoCallResponseDTO;
import de.caritas.cob.videoservice.api.service.LogService;
import de.caritas.cob.videoservice.api.service.UuidRegistry;
Expand Down Expand Up @@ -39,13 +41,17 @@ public class StartVideoCallFacade {
/**
* Generates unique video call URLs and triggers a live event to inform the receiver of the call.
*
* @param sessionId session ID
* @param initiatorRcUserId initiator Rocket.Chat user ID
* @param createVideoCallRequest The requested DTO containing session id and optional initiators
* username
* @param initiatorRcUserId initiator Rocket.Chat user ID
* @return {@link CreateVideoCallResponseDTO}
*/
public CreateVideoCallResponseDTO startVideoCall(Long sessionId, String initiatorRcUserId) {
public CreateVideoCallResponseDTO startVideoCall(CreateVideoCallDTO createVideoCallRequest,
String initiatorRcUserId) {

var consultantSessionDto = this.sessionService.findSessionOfCurrentConsultant(sessionId);
var sessionId = createVideoCallRequest.getSessionId();
var consultantSessionDto = this.sessionService
.findSessionOfCurrentConsultant(sessionId);
verifySessionStatus(consultantSessionDto);

var videoCallUuid = uuidRegistry.generateUniqueUuid();
Expand All @@ -54,7 +60,8 @@ public CreateVideoCallResponseDTO startVideoCall(Long sessionId, String initiato

this.liveEventNotificationService
.sendVideoCallRequestLiveEvent(buildLiveEventMessage(consultantSessionDto,
videoCallUrls.getUserVideoUrl(), initiatorRcUserId),
videoCallUrls.getUserVideoUrl(), initiatorRcUserId,
createVideoCallRequest.getInitiatorDisplayName()),
singletonList(consultantSessionDto.getAskerId()));

var createVideoCallResponseDto = new CreateVideoCallResponseDTO()
Expand All @@ -77,12 +84,15 @@ private void verifySessionStatus(ConsultantSessionDTO consultantSessionDto) {
}

private LiveEventMessage buildLiveEventMessage(ConsultantSessionDTO consultantSessionDto,
String videoChatUrl, String initiatorRcUserId) {
String videoChatUrl, String initiatorRcUserId, String initiatorDisplayName) {
var username =
isNotBlank(initiatorDisplayName) ? initiatorDisplayName : authenticatedUser.getUsername();

var videoCallRequestDto = new VideoCallRequestDTO()
.videoCallUrl(videoChatUrl)
.rcGroupId(consultantSessionDto.getGroupId())
.initiatorRcUserId(initiatorRcUserId)
.initiatorUsername(authenticatedUser.getUsername());
.initiatorUsername(username);

return new LiveEventMessage()
.eventType(EventType.VIDEOCALLREQUEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class VideoControllerAuthorizationIT {
@WithMockUser(authorities = AUTHORITY_CONSULTANT)
public void createVideoCall_Should_ReturnCreated_When_EverythingSucceeded() throws Exception {

when(startVideoCallFacade.startVideoCall(eq(SESSION_ID), anyString())).thenReturn(
when(startVideoCallFacade.startVideoCall(any(), anyString())).thenReturn(
CREATE_VIDEO_CALL_RESPONSE_DTO);

mvc.perform(post(PATH_START_VIDEO_CALL)
Expand All @@ -86,7 +86,7 @@ public void createVideoCall_Should_ReturnCreated_When_EverythingSucceeded() thro
public void createVideoCall_Should_ReturnUnauthorized_When_AuthorizationIsMissing()
throws Exception {

when(startVideoCallFacade.startVideoCall(eq(SESSION_ID), anyString())).thenReturn(
when(startVideoCallFacade.startVideoCall(any(), anyString())).thenReturn(
CREATE_VIDEO_CALL_RESPONSE_DTO);

mvc.perform(post(PATH_START_VIDEO_CALL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class VideoControllerIT {
@Test
public void createVideoCall_Should_ReturnCreated_When_EverythingSucceeded() throws Exception {

when(startVideoCallFacade.startVideoCall(eq(SESSION_ID), anyString())).thenReturn(
when(startVideoCallFacade.startVideoCall(any(), anyString())).thenReturn(
CREATE_VIDEO_CALL_RESPONSE_DTO);

mvc.perform(post(PATH_START_VIDEO_CALL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import de.caritas.cob.videoservice.api.authorization.VideoUser;
import de.caritas.cob.videoservice.api.exception.httpresponse.BadRequestException;
import de.caritas.cob.videoservice.api.model.CreateVideoCallDTO;
import de.caritas.cob.videoservice.api.model.CreateVideoCallResponseDTO;
import de.caritas.cob.videoservice.api.service.UuidRegistry;
import de.caritas.cob.videoservice.api.service.liveevent.LiveEventNotificationService;
Expand Down Expand Up @@ -71,7 +72,8 @@ public void startVideoCall_Should_ReturnCorrectVideoCallUrl_When_UrlWasGenerated
.thenReturn(consultantSessionDto);
when(videoCallUrlGeneratorService.generateVideoCallUrls(any())).thenReturn(videoCallUrls);

CreateVideoCallResponseDTO result = startVideoCallFacade.startVideoCall(SESSION_ID, "rcUserId");
CreateVideoCallResponseDTO result = startVideoCallFacade
.startVideoCall(new CreateVideoCallDTO().sessionId(SESSION_ID), "rcUserId");

assertThat(result.getModeratorVideoCallUrl(), is(videoCallUrls.getModeratorVideoUrl()));
}
Expand All @@ -93,7 +95,7 @@ public void startVideoCall_Should_CallLiveServiceAndBuildCorrectLiveEventMessage
when(authenticatedUser.getUsername()).thenReturn(USERNAME);
ArgumentCaptor<LiveEventMessage> argument = ArgumentCaptor.forClass(LiveEventMessage.class);

startVideoCallFacade.startVideoCall(SESSION_ID, "rcUserId");
startVideoCallFacade.startVideoCall(new CreateVideoCallDTO().sessionId(SESSION_ID), "rcUserId");

verify(liveEventNotificationService).sendVideoCallRequestLiveEvent(argument.capture(), any());
verify(liveEventNotificationService, times(1))
Expand All @@ -117,7 +119,7 @@ public void startVideoCall_Should_throwBadRequestException_When_sessionIsNotInPr
when(sessionService.findSessionOfCurrentConsultant(SESSION_ID))
.thenReturn(consultantSessionDto);

startVideoCallFacade.startVideoCall(SESSION_ID, "");
startVideoCallFacade.startVideoCall(new CreateVideoCallDTO().sessionId(SESSION_ID), "");
}

@Test
Expand All @@ -133,7 +135,8 @@ public void startVideoCall_Should_FireAssignSessionStatisticsEvent() {
.thenReturn(consultantSessionDto);
when(videoCallUrlGeneratorService.generateVideoCallUrls(any())).thenReturn(videoCallUrls);

CreateVideoCallResponseDTO result = startVideoCallFacade.startVideoCall(SESSION_ID, "rcUserId");
CreateVideoCallResponseDTO result = startVideoCallFacade
.startVideoCall(new CreateVideoCallDTO().sessionId(SESSION_ID), "rcUserId");

ArgumentCaptor<StartVideoCallStatisticsEvent> captor = ArgumentCaptor.forClass(
StartVideoCallStatisticsEvent.class);
Expand All @@ -153,4 +156,29 @@ public void startVideoCall_Should_FireAssignSessionStatisticsEvent() {
assertThat(videoCallUuid, is(VIDEO_CALL_UUID));
}

@Test
public void startVideoCall_Should_FireAssignSessionStatisticsEventWithDisplayName_When_initiatorDisplayNameIsSet() {

when(authenticatedUser.getUserId()).thenReturn(CONSULTANT_ID);
when(uuidRegistry.generateUniqueUuid()).thenReturn(VIDEO_CALL_UUID);
ConsultantSessionDTO consultantSessionDto = mock(ConsultantSessionDTO.class);
when(consultantSessionDto.getStatus()).thenReturn(IN_PROGRESS.getValue());
VideoCallUrls videoCallUrls = new EasyRandom().nextObject(VideoCallUrls.class);

when(sessionService.findSessionOfCurrentConsultant(SESSION_ID))
.thenReturn(consultantSessionDto);
when(videoCallUrlGeneratorService.generateVideoCallUrls(any())).thenReturn(videoCallUrls);

startVideoCallFacade
.startVideoCall(new CreateVideoCallDTO().sessionId(SESSION_ID)
.initiatorDisplayName("initiator display name"), "rcUserId");

var argument = ArgumentCaptor.forClass(LiveEventMessage.class);
verify(liveEventNotificationService).sendVideoCallRequestLiveEvent(argument.capture(), any());
verify(liveEventNotificationService).sendVideoCallRequestLiveEvent(any(), any());
assertThat(argument.getValue(), instanceOf(LiveEventMessage.class));
assertThat(((VideoCallRequestDTO) argument.getValue().getEventContent()).getInitiatorUsername(),
is("initiator display name"));
}

}

0 comments on commit 4dbc3c4

Please sign in to comment.