Skip to content

Commit

Permalink
Merge branch 'master' into VIH-10260---Support-audio-recording-search…
Browse files Browse the repository at this point in the history
…-with-old-and-new-file-names
  • Loading branch information
marcogagliardi committed Nov 17, 2023
2 parents a21afbd + ba8e361 commit 01f0429
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,23 +296,29 @@ public async Task Should_catch_bookings_api_exceptions_and_return_bad_request_if
BookingDetails = bookingDetails
};

const string expectedExceptionResponse = "exception";

_mocker.Mock<IUserAccountService>().Setup(x => x.GetAdUserIdForUsername(It.IsAny<string>())).ReturnsAsync(Guid.NewGuid().ToString());

const string key = "ScheduledDateTime";
const string errorMessage = "ScheduledDateTime cannot be in the past";
var validationProblemDetails = new ValidationProblemDetails(new Dictionary<string, string[]>
{
{key, new[] {errorMessage}},
});
_mocker.Mock<IBookingsApiClient>().Setup(x => x.BookNewHearingAsync(It.IsAny<V1.BookNewHearingRequest>()))
.Throws(new BookingsApiException("", (int) HttpStatusCode.BadRequest, expectedExceptionResponse, null, null));
.Throws(ClientException.ForBookingsAPIValidation(validationProblemDetails));


// Act
var result = await _controller.Post(bookingRequest);

// Assert
result.Result.Should().BeOfType<BadRequestObjectResult>();
var badRequestObjectResult = (BadRequestObjectResult) result.Result;
badRequestObjectResult.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
badRequestObjectResult.Value.Should().Be(expectedExceptionResponse);
result.Result.Should().NotBeNull();
var objectResult = (ObjectResult)result.Result;

var validationProblems = (ValidationProblemDetails)objectResult.Value;
validationProblems.Should().NotBeNull();
validationProblems!.Errors.ContainsKey(key).Should().BeTrue();
validationProblems.Errors[key][0].Should().Be(errorMessage);

_mocker.Mock<IHearingsService>().Verify(x => x.AssignEndpointDefenceAdvocates(It.IsAny<List<EndpointRequest>>(), It.Is<IReadOnlyCollection<AdminWebsite.Contracts.Requests.ParticipantRequest>>(x => x.SequenceEqual(bookingDetails.Participants.AsReadOnly()))), Times.Once);

_mocker.Mock<IBookingsApiClient>().Verify(x => x.BookNewHearingAsync(It.IsAny<V1.BookNewHearingRequest>()), Times.Once);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,14 @@ public async Task Should_pass_bad_request_from_bookings_api()
BookingDetails = hearing
};

const string key = "ScheduledDateTime";
const string errorMessage = "ScheduledDateTime cannot be in the past";
var validationProblemDetails = new ValidationProblemDetails(new Dictionary<string, string[]>
{
{key, new[] {errorMessage}},
});
_mocker.Mock<IBookingsApiClient>().Setup(x => x.BookNewHearingAsync(It.IsAny<BookNewHearingRequest>()))
.Throws(ClientException.ForBookingsAPI(HttpStatusCode.BadRequest));
.Throws(ClientException.ForBookingsAPIValidation(validationProblemDetails));

var result = await _controller.Post(bookingRequest);
result.Result.Should().BeOfType<BadRequestObjectResult>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ export class BHClient extends ApiClientBase {
_observableMergeMap((_responseText: string) => {
let result400: any = null;
let resultData400 = _responseText === '' ? null : JSON.parse(_responseText, this.jsonParseReviver);
result400 = ProblemDetails.fromJS(resultData400);
result400 = ValidationProblemDetails.fromJS(resultData400);
return throwException('Bad Request', status, _responseText, _headers, result400);
})
);
Expand Down
9 changes: 6 additions & 3 deletions AdminWebsite/AdminWebsite/Controllers/HearingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public HearingsController(IBookingsApiClient bookingsApiClient,
[HttpPost]
[SwaggerOperation(OperationId = "BookNewHearing")]
[ProducesResponseType(typeof(HearingDetailsResponse), (int)HttpStatusCode.Created)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType(typeof(ValidationProblemDetails),(int)HttpStatusCode.BadRequest)]
[HearingInputSanitizer]
public async Task<ActionResult<HearingDetailsResponse>> Post([FromBody] BookHearingRequest request)
{
Expand All @@ -101,8 +101,11 @@ public async Task<ActionResult<HearingDetailsResponse>> Post([FromBody] BookHear
{
_logger.LogError(e, "BookNewHearing - There was a problem saving the booking. Status Code {StatusCode} - Message {Message}",
e.StatusCode, e.Response);
if (e.StatusCode == (int)HttpStatusCode.BadRequest)
return BadRequest(e.Response);
if (e.StatusCode == (int)HttpStatusCode.BadRequest)
{
var typedException = e as BookingsApiException<ValidationProblemDetails>;
return ValidationProblem(typedException!.Result);
}
throw;
}
catch (Exception e)
Expand Down

0 comments on commit 01f0429

Please sign in to comment.