Skip to content

Commit

Permalink
Merge pull request #61 from hmcts/feature/VIH-4234-leave-private-cons…
Browse files Browse the repository at this point in the history
…ultation

Add consultation answer 'cancelled'
  • Loading branch information
shaed-parkar authored Aug 7, 2019
2 parents dadccf0 + 1c93aa6 commit 0974024
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
14 changes: 14 additions & 0 deletions VideoAPI/Video.API/Controllers/ConsultationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ public async Task<IActionResult> HandleConsultationRequest(ConsultationRequest r
$"Raising request between {requestedBy.Username} and {requestedFor.Username} in conference {conference.Id}");
await NotifyConsultationRequest(conference, requestedBy, requestedFor);
}
else if (request.Answer == ConsultationAnswer.Cancelled)
{
_logger.LogInformation(
$"Cancelled private consultation between {requestedBy.Username} and {requestedFor.Username} in conference {conference.Id}");
await NotifyConsultationCancelled(conference, requestedBy, requestedFor);
}
else
{
_logger.LogInformation(
Expand Down Expand Up @@ -188,6 +194,14 @@ await _hubContext.Clients.Group(EventHub.VhOfficersGroupName)
await StartPrivateConsultationAsync(conference, requestedBy, requestedFor);
}
}

private async Task NotifyConsultationCancelled(Conference conference, Participant requestedBy,
Participant requestedFor)
{
await _hubContext.Clients.Group(requestedFor.Username.ToLowerInvariant())
.ConsultationMessage(conference.Id, requestedBy.Username, requestedFor.Username,
ConsultationAnswer.Cancelled.ToString());
}

private async Task StartPrivateConsultationAsync(Conference conference, Participant requestedBy, Participant requestedFor)
{
Expand Down
6 changes: 5 additions & 1 deletion VideoAPI/VideoApi.Contract/Requests/ConsultationRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public enum ConsultationAnswer
/// <summary>
/// Reject a consultation request
/// </summary>
Rejected
Rejected,
/// <summary>
/// Cancel a consultation request
/// </summary>
Cancelled
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,32 @@ public async Task should_raise_notification_to_requester_and_admin_when_consulta
x.TransferParticipantAsync(conferenceId, requestedFor.Id, requestedFor.CurrentRoom.Value,
availableRoom), Times.Once);
}

[Test]
public async Task should_raise_notification_to_requestee_when_consultation_is_cancelled()
{
var conferenceId = _testConference.Id;
var requestedBy = _testConference.GetParticipants()[2];
var requestedFor = _testConference.GetParticipants()[3];

var request = new ConsultationRequest
{
ConferenceId = conferenceId,
RequestedBy = requestedBy.Id,
RequestedFor = requestedFor.Id,
Answer = ConsultationAnswer.Cancelled
};
await _controller.HandleConsultationRequest(request);

_hubContextMock.Verify(x => x.Clients.Group(requestedBy.Username.ToLowerInvariant()), Times.Never);
_hubContextMock.Verify(x => x.Clients.Group(requestedFor.Username.ToLowerInvariant()), Times.Once);
_hubContextMock.Verify(x => x.Clients.Group(EventHub.VhOfficersGroupName), Times.Never);

_eventHubClientMock.Verify(
x => x.ConsultationMessage(conferenceId, requestedBy.Username, requestedFor.Username,
ConsultationAnswer.Cancelled.ToString()),
Times.Once);
}

[Test]
public async Task should_return_error_when_consultation_accepted_but_no_room_is_available()
Expand Down

0 comments on commit 0974024

Please sign in to comment.