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-10361 Fix for unable to update judge last minute #1318

Merged
merged 7 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -102,8 +102,8 @@
},
"BookingsApi.Client": {
"type": "Transitive",
"resolved": "1.49.15",
"contentHash": "ye+s7y4jeNSgVd7sgbRee0dnx4HZIegmBxYlWHENPNv5u8zSH15dENPmLX8BODkUKOLpwHiIxQyRMh8KKzlcFQ==",
"resolved": "1.50.4-pr-0788-0003",
oliver-scott marked this conversation as resolved.
Show resolved Hide resolved
"contentHash": "A/VDJHlJM82MzrM0RdaZEvPwyFUQGe5fxq86dBKVCh4Iy0gfJhOV4myVYVdtFyPzVeRO5ObxyGuGM7Tmam4gJg==",
"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.49.15, )",
"BookingsApi.Client": "[1.50.4-pr-0788-0003, )",
"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 @@ -614,17 +614,16 @@ public async Task Should_return_updated_hearingV2()
}
},
});
_addNewParticipantRequest.JudiciaryParticipants = new List<JudiciaryParticipantRequest>()
var existingJudiciaryParticipants = updatedHearing.JudiciaryParticipants.ToList();
_addNewParticipantRequest.JudiciaryParticipants = existingJudiciaryParticipants.Select(x => new JudiciaryParticipantRequest
{
new()
{
PersonalCode = "4567", DisplayName = "Jane Doe 2", Role = JudiciaryParticipantHearingRoleCode.PanelMember.ToString()
},
new()
{
PersonalCode = "5678", DisplayName = "New Judge Fudge", Role = JudiciaryParticipantHearingRoleCode.Judge.ToString()
}
};
PersonalCode = x.PersonalCode,
DisplayName = x.DisplayName,
Role = x.HearingRoleCode.ToString()
}).ToList();
var panelMemberToRemove = _addNewParticipantRequest.JudiciaryParticipants.Find(x => x.Role == "PanelMember");
_addNewParticipantRequest.JudiciaryParticipants.Remove(panelMemberToRemove);

var result = await _controller.EditHearing(_validId, _addNewParticipantRequest);
var hearing = (AdminWebsite.Contracts.Responses.HearingDetailsResponse)((OkObjectResult)result.Result).Value;
hearing.Id.Should().Be(updatedHearing.Id);
Expand All @@ -633,17 +632,239 @@ public async Task Should_return_updated_hearingV2()
!u.Cases.IsNullOrEmpty())),
Times.Once);

_bookingsApiClient.Verify(x => x.RemoveJudiciaryParticipantFromHearingAsync(hearing.Id, "1234"),
var existingJudge = _addNewParticipantRequest.JudiciaryParticipants.Find(x => x.Role == "Judge");

_bookingsApiClient.Verify(x => x.RemoveJudiciaryParticipantFromHearingAsync(hearing.Id, panelMemberToRemove.PersonalCode),
Times.Once);

_bookingsApiClient.Verify(x => x.UpdateJudiciaryParticipantAsync(hearing.Id, "4567", It.IsAny<UpdateJudiciaryParticipantRequest>()),
_bookingsApiClient.Verify(x => x.UpdateJudiciaryParticipantAsync(hearing.Id, existingJudge.PersonalCode, It.IsAny<UpdateJudiciaryParticipantRequest>()),
Times.Once);
}

[Test]
public async Task Should_return_updated_hearingV2_with_no_participants_provided()
{
_featureToggle.Setup(e => e.UseV2Api()).Returns(true);
var updatedHearing = _v2HearingDetailsResponse;
updatedHearing.Participants.Clear();
_bookingsApiClient.SetupSequence(x => x.GetHearingDetailsByIdV2Async(It.IsAny<Guid>()))
.ReturnsAsync(updatedHearing)
.ReturnsAsync(updatedHearing)
.ReturnsAsync(updatedHearing);

var existingJudge = updatedHearing.JudiciaryParticipants
.Find(x => x.HearingRoleCode == JudiciaryParticipantHearingRoleCode.Judge);

var request = new EditHearingRequest
{
Case = new EditCaseRequest
{
Name = updatedHearing.Cases[0].Name,
Number = updatedHearing.Cases[0].Number
},
JudiciaryParticipants = new List<JudiciaryParticipantRequest>
{
new()
{
DisplayName = existingJudge.DisplayName,
PersonalCode = existingJudge.PersonalCode,
Role = existingJudge.HearingRoleCode.ToString()
}
}
};

var result = await _controller.EditHearing(_validId, request);

((OkObjectResult)result.Result).StatusCode.Should().Be(200);

_bookingsApiClient.Verify(x => x.UpdateHearingParticipants2Async(
It.IsAny<Guid>(),
It.IsAny<UpdateHearingParticipantsRequestV2>()),
Times.Never);
}

[Test]
public async Task Should_return_updated_hearingV2_with_no_judiciary_participants_provided()
{
_featureToggle.Setup(e => e.UseV2Api()).Returns(true);
var updatedHearing = _v2HearingDetailsResponse;
updatedHearing.Participants.Clear();
updatedHearing.JudiciaryParticipants.Clear();
_bookingsApiClient.SetupSequence(x => x.GetHearingDetailsByIdV2Async(It.IsAny<Guid>()))
.ReturnsAsync(updatedHearing)
.ReturnsAsync(updatedHearing)
.ReturnsAsync(updatedHearing);

var request = new EditHearingRequest
{
Case = new EditCaseRequest
{
Name = updatedHearing.Cases[0].Name,
Number = updatedHearing.Cases[0].Number
}
};

var result = await _controller.EditHearing(_validId, request);

((OkObjectResult)result.Result).StatusCode.Should().Be(200);

_bookingsApiClient.Verify(x => x.UpdateHearingParticipants2Async(
It.IsAny<Guid>(),
It.IsAny<UpdateHearingParticipantsRequestV2>()),
Times.Never);
_bookingsApiClient.Verify(x => x.ReassignJudiciaryJudgeAsync(
It.IsAny<Guid>(),
It.IsAny<ReassignJudiciaryJudgeRequest>()),
Times.Never);
}

_bookingsApiClient.Verify(
x => x.AddJudiciaryParticipantsToHearingAsync(hearing.Id,
It.IsAny<IEnumerable<BookingsApi.Contract.V1.Requests.JudiciaryParticipantRequest>>()), Times.Once);
[Test]
public async Task Should_return_updated_hearingV2_with_new_judge_different_to_old_judge()
{
_featureToggle.Setup(e => e.UseV2Api()).Returns(true);
var updatedHearing = _v2HearingDetailsResponse;
updatedHearing.Participants.Clear();
_bookingsApiClient.SetupSequence(x => x.GetHearingDetailsByIdV2Async(It.IsAny<Guid>()))
.ReturnsAsync(updatedHearing)
.ReturnsAsync(updatedHearing)
.ReturnsAsync(updatedHearing);

var newJudge = new JudiciaryParticipantRequest
{
DisplayName = "NewJudgeDisplayName",
PersonalCode = "NewJudgePersonalCode",
Role = JudiciaryParticipantHearingRoleCode.Judge.ToString()
};

var existingPanelMember = updatedHearing.JudiciaryParticipants
.Find(x => x.HearingRoleCode == JudiciaryParticipantHearingRoleCode.PanelMember);

var request = new EditHearingRequest
{
Case = new EditCaseRequest
{
Name = updatedHearing.Cases[0].Name,
Number = updatedHearing.Cases[0].Number
},
JudiciaryParticipants = new List<JudiciaryParticipantRequest>
{
newJudge,
new()
{
DisplayName = existingPanelMember.DisplayName,
PersonalCode = existingPanelMember.PersonalCode,
Role = existingPanelMember.HearingRoleCode.ToString()
}
}
};

var result = await _controller.EditHearing(_validId, request);

((OkObjectResult)result.Result).StatusCode.Should().Be(200);

AssertJudiciaryJudgeReassigned(updatedHearing, newJudge);
}

[Test]
public async Task Should_return_updated_hearingV2_with_new_judge_and_no_old_judge()
{
_featureToggle.Setup(e => e.UseV2Api()).Returns(true);
var updatedHearing = _v2HearingDetailsResponse;
updatedHearing.Participants.Clear();
updatedHearing.JudiciaryParticipants.Clear();
_bookingsApiClient.SetupSequence(x => x.GetHearingDetailsByIdV2Async(It.IsAny<Guid>()))
.ReturnsAsync(updatedHearing)
.ReturnsAsync(updatedHearing)
.ReturnsAsync(updatedHearing);

var newJudge = new JudiciaryParticipantRequest
{
DisplayName = "NewJudgeDisplayName",
PersonalCode = "NewJudgePersonalCode",
Role = JudiciaryParticipantHearingRoleCode.Judge.ToString()
};

var request = new EditHearingRequest
{
Case = new EditCaseRequest
{
Name = updatedHearing.Cases[0].Name,
Number = updatedHearing.Cases[0].Number
},
JudiciaryParticipants = new List<JudiciaryParticipantRequest>
{
newJudge
}
};

var result = await _controller.EditHearing(_validId, request);

((OkObjectResult)result.Result).StatusCode.Should().Be(200);

AssertJudiciaryJudgeReassigned(updatedHearing, newJudge);
}

[Test]
public async Task Should_return_updated_hearingV2_with_old_judge_and_no_new_judge()
{
_featureToggle.Setup(e => e.UseV2Api()).Returns(true);
var updatedHearing = _v2HearingDetailsResponse;
updatedHearing.Participants.Clear();
_bookingsApiClient.SetupSequence(x => x.GetHearingDetailsByIdV2Async(It.IsAny<Guid>()))
.ReturnsAsync(updatedHearing)
.ReturnsAsync(updatedHearing)
.ReturnsAsync(updatedHearing);

var newJudge = new JudiciaryParticipantRequest
{
DisplayName = "NewJudgeDisplayName",
PersonalCode = "NewJudgePersonalCode",
Role = JudiciaryParticipantHearingRoleCode.Judge.ToString()
};

var request = new EditHearingRequest
{
Case = new EditCaseRequest
{
Name = updatedHearing.Cases[0].Name,
Number = updatedHearing.Cases[0].Number
}
};

var result = await _controller.EditHearing(_validId, request);

((OkObjectResult)result.Result).StatusCode.Should().Be(200);

_bookingsApiClient.Verify(x => x.ReassignJudiciaryJudgeAsync(
It.IsAny<Guid>(),
It.IsAny<ReassignJudiciaryJudgeRequest>()),
Times.Never);
}

private void AssertJudiciaryJudgeReassigned(
HearingDetailsResponseV2 hearing,
JudiciaryParticipantRequest newJudge)
{
// Removing judges is not supported - they should be reassigned instead

_bookingsApiClient.Verify(x => x.ReassignJudiciaryJudgeAsync(
hearing.Id,
It.Is<ReassignJudiciaryJudgeRequest>(x =>
x.DisplayName == newJudge.DisplayName &&
x.PersonalCode == newJudge.PersonalCode)),
Times.Once);

_bookingsApiClient.Verify(x => x.RemoveJudiciaryParticipantFromHearingAsync(
It.IsAny<Guid>(),
It.IsAny<string>()),
Times.Never);

_bookingsApiClient.Verify(x => x.AddJudiciaryParticipantsToHearingAsync(
It.IsAny<Guid>(),
It.IsAny<List<BookingsApi.Contract.V1.Requests.JudiciaryParticipantRequest>>()),
Times.Never);
}

[Test]
public async Task Should_pass_on_bad_request_from_bookings_api()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,9 @@ private HearingDetailsResponse InitHearing()
.With(x => x.Id = Guid.NewGuid())
.With(x => x.UserRoleName = "Staff Member")
.Build();
var telephoneParticipant = Builder<TelephoneParticipantResponse>.CreateNew()
.With(x => x.Id = Guid.NewGuid())
.Build();

return Builder<HearingDetailsResponse>.CreateNew()
.With(h => h.Participants = new List<ParticipantResponse> { rep, ind, joh, judge, staffMember })
.With(h => h.TelephoneParticipants = new List<TelephoneParticipantResponse> { telephoneParticipant })
.With(x => x.Cases = cases)
.With(x => x.Id = Guid.NewGuid())
.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AdminWebsite.Contracts.Requests;

namespace AdminWebsite.UnitTests.Validators
{
Expand Down Expand Up @@ -47,6 +48,17 @@ public void Should_validate_participants_as_valid()
var result = _validator.Validate(testRequest);
Assert.That(!result.Errors.Any(o => o.PropertyName == "Participants"));
}

[Test]
public void Should_validate_participants_as_valid_when_judiciary_participants_are_provided()
{
var testRequest = new EditHearingRequest {
JudiciaryParticipants = new List<JudiciaryParticipantRequest> { new() },
Case = new EditCaseRequest(),
};
var result = _validator.Validate(testRequest);
Assert.That(!result.Errors.Any(o => o.PropertyName == "Participants"));
}

[Test]
public void Should_validate_scheduled_date_time_as_error_when_time_is_thirty_minutes_or_more()
Expand Down
6 changes: 3 additions & 3 deletions AdminWebsite/AdminWebsite.UnitTests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@
},
"BookingsApi.Client": {
"type": "Transitive",
"resolved": "1.49.15",
"contentHash": "ye+s7y4jeNSgVd7sgbRee0dnx4HZIegmBxYlWHENPNv5u8zSH15dENPmLX8BODkUKOLpwHiIxQyRMh8KKzlcFQ==",
"resolved": "1.50.4-pr-0788-0003",
"contentHash": "A/VDJHlJM82MzrM0RdaZEvPwyFUQGe5fxq86dBKVCh4Iy0gfJhOV4myVYVdtFyPzVeRO5ObxyGuGM7Tmam4gJg==",
"dependencies": {
"Microsoft.AspNetCore.Mvc.Core": "2.2.5"
}
Expand Down Expand Up @@ -1979,7 +1979,7 @@
"type": "Project",
"dependencies": {
"AspNetCore.HealthChecks.Uris": "[6.0.3, )",
"BookingsApi.Client": "[1.49.15, )",
"BookingsApi.Client": "[1.50.4-pr-0788-0003, )",
"FluentValidation.AspNetCore": "[10.4.0, )",
"LaunchDarkly.ServerSdk": "[7.0.3, )",
"MicroElements.Swashbuckle.FluentValidation": "[5.7.0, )",
Expand Down
2 changes: 1 addition & 1 deletion AdminWebsite/AdminWebsite/AdminWebsite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="6.0.3" />
<PackageReference Include="BookingsApi.Client" Version="1.49.15" />
<PackageReference Include="BookingsApi.Client" Version="1.50.4-pr-0788-0003" />
<PackageReference Include="LaunchDarkly.ServerSdk" Version="7.0.3" />
<PackageReference Include="MicroElements.Swashbuckle.FluentValidation" Version="5.7.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.51.0" />
Expand Down
Loading
Loading