Skip to content

Commit

Permalink
VIH-11037 Fix for 400 error when no hearings (#2269)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-scott authored Oct 15, 2024
1 parent 7e613f7 commit 9f6f884
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,27 @@ public async Task Should_return_ok_with_list_of_conferences_where_hearings_and_c
conferencesForUser[i].CaseName.Should().Be($"CaseName{position}");
}
}

[Test]
public async Task Should_return_empty_list_when_no_hearings_found()
{
// Arrange
_mocker.Mock<IBookingsApiClient>()
.Setup(x => x.GetConfirmedHearingsByUsernameForTodayV2Async(It.IsAny<string>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new List<ConfirmedHearingsTodayResponseV2>());
_mocker.Mock<IVideoApiClient>()
.Setup(x => x.GetConferencesByHearingRefIdsAsync(It.IsAny<GetConferencesByHearingIdsRequest>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new List<ConferenceCoreResponse>());

// Act
var result = await _controller.GetConferencesForHostAsync(CancellationToken.None);

// Assert
var typedResult = (OkObjectResult)result.Result;
typedResult.Should().NotBeNull();
_mocker.Mock<IVideoApiClient>()
.Verify(x => x.GetConferencesByHearingRefIdsAsync(It.IsAny<GetConferencesByHearingIdsRequest>(), It.IsAny<CancellationToken>()), Times.Never);
var conferencesForUser = (List<ConferenceForHostResponse>) typedResult.Value;
conferencesForUser.Should().BeEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,30 @@ public async Task Should_return_ok_with_list_of_conferences()
conferencesForHost[0].Participants.Count.Should().Be(participants.Count);
}

[Test]
public async Task Should_return_empty_list_when_no_hearings_found()
{
// Arrange
var venueNames = new List<string>{ "Venue1"};
_mocker.Mock<IBookingsApiClient>()
.Setup(x => x.GetHearingsForTodayByVenueV2Async(It.IsAny<List<string>>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new List<HearingDetailsResponseV2>());
_mocker.Mock<IVideoApiClient>()
.Setup(x => x.GetConferencesByHearingRefIdsAsync(It.IsAny<GetConferencesByHearingIdsRequest>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new List<ConferenceCoreResponse>());

// Act
var result = await _controller.GetConferencesForStaffMemberAsync(venueNames, CancellationToken.None);

// Assert
var typedResult = (OkObjectResult)result.Result;
typedResult.Should().NotBeNull();
_mocker.Mock<IVideoApiClient>()
.Verify(x => x.GetConferencesByHearingRefIdsAsync(It.IsAny<GetConferencesByHearingIdsRequest>(), It.IsAny<CancellationToken>()), Times.Never);
var conferencesForUser = (List<ConferenceForHostResponse>) typedResult.Value;
conferencesForUser.Should().BeEmpty();
}

private ConferencesController SetupControllerWithClaims(System.Security.Claims.ClaimsPrincipal claimsPrincipal)
{
var context = new ControllerContext
Expand Down
9 changes: 7 additions & 2 deletions VideoWeb/VideoWeb/Controllers/ConferencesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Swashbuckle.AspNetCore.Annotations;
using VideoApi.Client;
using VideoApi.Contract.Requests;
using VideoApi.Contract.Responses;
using VideoWeb.Common;
using VideoWeb.Common.Models;
using VideoWeb.Contract.Request;
Expand Down Expand Up @@ -54,7 +55,9 @@ public async Task<ActionResult<List<ConferenceForHostResponse>>> GetConferencesF
var hearings =
await bookingApiClient.GetConfirmedHearingsByUsernameForTodayV2Async(username, cancellationToken);
var request = new GetConferencesByHearingIdsRequest { HearingRefIds = hearings.Select(x => x.Id).ToArray() };
var conferences = await videoApiClient.GetConferencesByHearingRefIdsAsync(request, cancellationToken);
ICollection<ConferenceCoreResponse> conferences = new List<ConferenceCoreResponse>();
if (hearings.Count > 0)
conferences = await videoApiClient.GetConferencesByHearingRefIdsAsync(request, cancellationToken);

if (conferences.Count != hearings.Count)
logger.LogError(
Expand Down Expand Up @@ -88,7 +91,9 @@ public async Task<ActionResult<List<ConferenceForHostResponse>>> GetConferencesF
await bookingApiClient.GetHearingsForTodayByVenueV2Async(hearingVenueNames, cancellationToken);
var request = new GetConferencesByHearingIdsRequest
{ HearingRefIds = hearingsForToday.Select(x => x.Id).ToArray() };
var conferences = await videoApiClient.GetConferencesByHearingRefIdsAsync(request, cancellationToken);
ICollection<ConferenceCoreResponse> conferences = new List<ConferenceCoreResponse>();
if (hearingsForToday.Count > 0)
conferences = await videoApiClient.GetConferencesByHearingRefIdsAsync(request, cancellationToken);
var response = hearingsForToday
.Select(hearing =>
BookingForHostResponseMapper.Map(hearing, conferences.First(c => hearing.Id == c.HearingId)))
Expand Down

0 comments on commit 9f6f884

Please sign in to comment.