Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VIH-11037 Fix for 400 error when no hearings #2269

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading