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-10084 Change Case Role & Hearing Role dropdowns to a single list #1274

Merged
merged 20 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 15 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 @@ -161,8 +161,8 @@
},
"BookingsApi.Client": {
"type": "Transitive",
"resolved": "1.47.6",
"contentHash": "O9oihWH0vAm2A4l3SFRCyq/cyQR+in3JmkLLotnf0kvVk1Uk5MqScYcthHlCmIUa1EODQfFZBaMrkGKGl488bA==",
"resolved": "1.47.8-pr-0726-0016",
"contentHash": "QYLzU64i38OwB6vVBuDOcQPhsSYHte1SWhelH7eBdVA9XjcNxJwp+u2bf3FHAFjSLOORhRjwBZA2QjTZdLCfJA==",
"dependencies": {
"Microsoft.AspNetCore.Mvc.Core": "2.2.5"
}
Expand Down Expand Up @@ -2669,7 +2669,7 @@
"type": "Project",
"dependencies": {
"AspNetCore.HealthChecks.Uris": "[6.0.3, )",
"BookingsApi.Client": "[1.47.6, )",
"BookingsApi.Client": "[1.47.8-pr-0726-0016, )",
"FluentValidation.AspNetCore": "[10.4.0, )",
"LaunchDarkly.ServerSdk": "[7.0.3, )",
"MicroElements.Swashbuckle.FluentValidation": "[5.7.0, )",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@
},
"BookingsApi.Client": {
"type": "Transitive",
"resolved": "1.47.6",
"contentHash": "O9oihWH0vAm2A4l3SFRCyq/cyQR+in3JmkLLotnf0kvVk1Uk5MqScYcthHlCmIUa1EODQfFZBaMrkGKGl488bA==",
"resolved": "1.47.8-pr-0726-0016",
"contentHash": "QYLzU64i38OwB6vVBuDOcQPhsSYHte1SWhelH7eBdVA9XjcNxJwp+u2bf3FHAFjSLOORhRjwBZA2QjTZdLCfJA==",
"dependencies": {
"Microsoft.AspNetCore.Mvc.Core": "2.2.5"
}
Expand Down Expand Up @@ -2101,7 +2101,7 @@
"type": "Project",
"dependencies": {
"AspNetCore.HealthChecks.Uris": "[6.0.3, )",
"BookingsApi.Client": "[1.47.6, )",
"BookingsApi.Client": "[1.47.8-pr-0726-0016, )",
"FluentValidation.AspNetCore": "[10.4.0, )",
"LaunchDarkly.ServerSdk": "[7.0.3, )",
"MicroElements.Swashbuckle.FluentValidation": "[5.7.0, )",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using AdminWebsite.Controllers;
using BookingsApi.Client;
using BookingsApi.Contract.V2.Responses;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc;
using Moq;
using NUnit.Framework;

namespace AdminWebsite.UnitTests.Controllers
{
public class HearingRolesControllerTests
{
private Mock<IBookingsApiClient> _bookingsApiClient;
private HearingRolesController _controller;

[SetUp]
public void Setup()
{
_bookingsApiClient = new Mock<IBookingsApiClient>();
_controller = new HearingRolesController(_bookingsApiClient.Object);
}

[Test]
public async Task Should_return_list_of_hearing_roles()
{
// Arrange
var roles = new List<HearingRoleResponseV2>
{
new()
{
Code = "APPL",
Name = "Applicant",
UserRole = "Individual"
},
new()
{
Code = "JUDG",
Name = "Judge",
UserRole = "Judge"
},
new()
{
Code = "PANL",
Name = "Panel Member",
UserRole = "Judicial Office Holder"
}
};

_bookingsApiClient.Setup(x => x.GetHearingRolesAsync()).ReturnsAsync(roles);

// Act
var response = await _controller.GetHearingRoles();

// Assert
var okResult = (OkObjectResult)response;
okResult.StatusCode.Should().Be(200);
okResult.Value.Should().BeEquivalentTo(roles);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using Autofac.Extras.Moq;
using VideoApi.Contract.Responses;
using BookingsApi.Contract.V1.Enums;
using BookingsApi.Contract.V2.Requests;
using LinkedParticipantType = AdminWebsite.Contracts.Enums.LinkedParticipantType;
using V1 = BookingsApi.Contract.V1.Requests;

namespace AdminWebsite.UnitTests.Controllers.HearingsController
Expand Down Expand Up @@ -238,6 +240,51 @@ public async Task Should_book_hearing_for_multi_day()

_mocker.Mock<IBookingsApiClient>().Verify(x => x.BookNewHearingAsync(It.IsAny<V1.BookNewHearingRequest>()), Times.Once);
}

[Test]
public async Task Should_book_hearing_with_reference_data_flag_on()
{
// Arrange
_mocker.Mock<IFeatureToggles>().Setup(x => x.ReferenceDataToggle()).Returns(true);
var bookingDetails = InitHearingForV2Test();

var bookingRequest = new BookHearingRequest
{
BookingDetails = bookingDetails
};

var hearingDetailsResponse = HearingResponseV2Builder.Build()
.WithEndPoints(2)
.WithParticipant("Representative", "[email protected]")
.WithParticipant("Individual", "[email protected]")
.WithParticipant("Individual", "[email protected]")
.WithParticipant("Judicial Office Holder", "[email protected]")
.WithParticipant("Staff Member","[email protected]")
.WithParticipant("Judge", "[email protected]");
_mocker.Mock<IBookingsApiClient>().Setup(x => x.BookNewHearingWithCodeAsync(It.IsAny<BookNewHearingRequestV2>()))
.ReturnsAsync(hearingDetailsResponse);


_mocker.Mock<IUserIdentity>().Setup(x => x.GetUserIdentityName()).Returns(_expectedUserIdentityName);

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

// Assert
result.Result.Should().BeOfType<CreatedResult>();
var createdObjectResult = (CreatedResult) result.Result;
createdObjectResult.StatusCode.Should().Be(201);
createdObjectResult.Value.Should().BeEquivalentTo(hearingDetailsResponse,
options => options.ExcludingMissingMembers());

bookingDetails.Participants.Exists(x => string.IsNullOrWhiteSpace(x.Username)).Should().BeFalse();

bookingDetails.CreatedBy.Should().Be(_expectedUserIdentityName);

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

_mocker.Mock<IBookingsApiClient>().Verify(x => x.BookNewHearingWithCodeAsync(It.IsAny<BookNewHearingRequestV2>()), Times.Once);
}

[Test]
public async Task Should_catch_bookings_api_exceptions_and_return_bad_request_if_that_was_the_status_code()
Expand Down Expand Up @@ -358,6 +405,86 @@ private BookingDetailsRequest InitHearingForTest()
}
};

return SetUpRequest(bookNewHearingRequest);
}

private BookingDetailsRequest InitHearingForV2Test()
{
// request with existing person, new user, existing user in AD but not in persons table
var bookNewHearingRequest = new BookingDetailsRequest
{
Participants = new List<ParticipantRequest>
{
new ()
{
ContactEmail = "[email protected]",
HearingRoleCode = "APPL", DisplayName = "display name1",
FirstName = "fname", MiddleNames = "", LastName = "lname1", Username = "[email protected]",
OrganisationName = "", Representee = "", TelephoneNumber = ""
},
new ()
{
ContactEmail = "[email protected]",
HearingRoleCode = "APPL", DisplayName = "display name2",
FirstName = "fname2", MiddleNames = "", LastName = "lname2", OrganisationName = "",
Representee = "", TelephoneNumber = "", Username = "[email protected]"
},
new ()
{
ContactEmail = "[email protected]",
HearingRoleCode = "APPL", DisplayName = "display name3",
FirstName = "fname3", MiddleNames = "", LastName = "lname3", OrganisationName = "",
Representee = "", TelephoneNumber = "", Username = "[email protected]"
},
new ()
{
ContactEmail = "[email protected]",
HearingRoleCode = "PANL", DisplayName = "display name4",
FirstName = "fname4", MiddleNames = "", LastName = "lname4", OrganisationName = "",
Representee = "", TelephoneNumber = "", Username = "[email protected]"
},
new ()
{
ContactEmail = "[email protected]",
HearingRoleCode = "INTP", DisplayName = "display name2",
FirstName = "fname5", MiddleNames = "", LastName = "lname5", OrganisationName = "",
Representee = "", TelephoneNumber = "", Username = "[email protected]"
},
new ()
{
ContactEmail = "[email protected]",
HearingRoleCode = "JUDG", DisplayName = "Judge Fudge",
FirstName = "Jack", MiddleNames = "", LastName = "Fudge",
Username = "[email protected]", OrganisationName = "", Representee = "",
TelephoneNumber = ""
}
},
Endpoints = new List<EndpointRequest>
{
new ()
{DisplayName = "displayname1", DefenceAdvocateContactEmail = "[email protected]"},
new ()
{DisplayName = "displayname2", DefenceAdvocateContactEmail = "[email protected]"},
},
LinkedParticipants = new List<LinkedParticipantRequest>
{
new () { ParticipantContactEmail = "[email protected]", LinkedParticipantContactEmail = "[email protected]", Type = LinkedParticipantType.Interpreter },
new () { ParticipantContactEmail = "[email protected]", LinkedParticipantContactEmail = "[email protected]", Type = LinkedParticipantType.Interpreter }
},
Cases = new List<CaseRequest>
{
new ()
{
Name = "Case1", Number = "001", IsLeadCase = true
}
}
};

return SetUpRequest(bookNewHearingRequest);
}

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

foreach (var participant in bookNewHearingRequest.Participants.Where(x =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
using BookingsApi.Contract.V1.Requests;
using BookingsApi.Contract.V1.Responses;
using BookingsApi.Contract.V2.Enums;
using BookingsApi.Contract.V2.Requests;
using BookingsApi.Contract.V2.Responses;
using NotificationApi.Client;
using NotificationApi.Contract.Requests;
using VideoApi.Client;
using VideoApi.Contract.Consts;
using VideoApi.Contract.Responses;
using BookingStatus = BookingsApi.Contract.V1.Enums.BookingStatus;
Expand Down Expand Up @@ -758,11 +758,42 @@ public async Task Should_return_updated_hearingV2()
.ReturnsAsync(updatedHearing)
.ReturnsAsync(updatedHearing)
.ReturnsAsync(updatedHearing);
var existingParticipant = updatedHearing.Participants.First(x => x.ContactEmail == "[email protected]");
_addNewParticipantRequest.Participants.Add(new EditParticipantRequest
{
Id = Guid.NewGuid(),
ContactEmail = "[email protected]",
HearingRoleCode = "INTP",
LinkedParticipants = new List<LinkedParticipant>
{
new()
{
ParticipantContactEmail = "[email protected]",
LinkedParticipantContactEmail = existingParticipant.ContactEmail,
Type = AdminWebsite.Contracts.Enums.LinkedParticipantType.Interpreter
}
}
});
_addNewParticipantRequest.Participants.Add(new EditParticipantRequest
{
Id = existingParticipant.Id,
ContactEmail = existingParticipant.ContactEmail,
HearingRoleCode = "APPL",
LinkedParticipants = new List<LinkedParticipant>
{
new()
{
ParticipantContactEmail = existingParticipant.ContactEmail,
LinkedParticipantContactEmail = "[email protected]",
Type = AdminWebsite.Contracts.Enums.LinkedParticipantType.Interpreter
}
}
});
var result = await _controller.EditHearing(_validId, _addNewParticipantRequest);
var hearing = (AdminWebsite.Contracts.Responses.HearingDetailsResponse)((OkObjectResult)result.Result).Value;
hearing.Id.Should().Be(updatedHearing.Id);
_bookingsApiClient.Verify(x => x.UpdateHearingDetailsAsync(It.IsAny<Guid>(),
It.Is<UpdateHearingRequest>(u =>
_bookingsApiClient.Verify(x => x.UpdateHearingDetails2Async(It.IsAny<Guid>(),
It.Is<UpdateHearingRequestV2>(u =>
!u.Cases.IsNullOrEmpty())),
Times.Once);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using BookingsApi.Contract.V2.Responses;
using FizzWare.NBuilder;

namespace AdminWebsite.UnitTests.Helper
{
public static class HearingResponseV2Builder
{
public static HearingDetailsResponseV2 Build()
{
return Builder<HearingDetailsResponseV2>.CreateNew()
.With(x => x.Participants = new List<ParticipantResponseV2>())
.With(x => x.Cases = new List<CaseResponseV2> { Builder<CaseResponseV2>.CreateNew().Build() })
.Build();
}

public static HearingDetailsResponseV2 WithEndPoints(this HearingDetailsResponseV2 hearingDetailsResponse, int size)
{
var endPoints = Builder<EndpointResponseV2>.CreateListOfSize(size).Build().ToList();

hearingDetailsResponse.Endpoints = endPoints;

return hearingDetailsResponse;
}

public static HearingDetailsResponseV2 WithParticipant(this HearingDetailsResponseV2 hearingDetailsResponse, string userRoleName, string userName =null)
{
var participant = Builder<ParticipantResponseV2>.CreateNew()
.With(x => x.Id = Guid.NewGuid())
.With(x => x.UserRoleName = userRoleName);

if(!string.IsNullOrEmpty(userName))
{
participant.With(x => x.Username = userName);
}

hearingDetailsResponse.Participants.Add(participant.Build());

return hearingDetailsResponse;
}

}
}
Loading