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-10362 Fix issue with judge display name not auto populating for ejud and V1 API #1317

Merged
merged 3 commits into from
Dec 12, 2023
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 @@ -13,6 +13,7 @@
using System.Net;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using AdminWebsite.Mappers;
using BookingsApi.Client;
using BookingsApi.Contract.V1.Requests;
using BookingsApi.Contract.V1.Responses;
Expand Down Expand Up @@ -385,8 +386,24 @@ public async Task PostJudgesBySearchTerm_should_return_judiciary_and_courtroom_a
okRequestResult.StatusCode.Should().NotBeNull();
var personRespList = (List<JudgeResponse>)okRequestResult.Value;

var expectedJudiciaryCount = withJudiciary ? _judiciaryResponse.Count : 0;
var expectedCourtRoomCount = withCourtroom ? _courtRoomResponse.Count : 0;
var expectedResponse = new List<JudgeResponse>();
var expectedJudiciaryResponses = new List<JudgeResponse>();
var expectedCourtRoomResponses = new List<JudgeResponse>();

if (withJudiciary)
{
expectedJudiciaryResponses = _judiciaryResponse.Select(JudgeResponseMapper.MapTo).ToList();
expectedResponse.AddRange(expectedJudiciaryResponses);
}

if (withCourtroom)
{
expectedCourtRoomResponses = _courtRoomResponse.ToList();
expectedResponse.AddRange(_courtRoomResponse);
}

var expectedJudiciaryCount = withJudiciary ? expectedJudiciaryResponses.Count : 0;
var expectedCourtRoomCount = withCourtroom ? expectedCourtRoomResponses.Count : 0;

var expectedTotal = expectedJudiciaryCount + expectedCourtRoomCount;

Expand All @@ -397,6 +414,8 @@ public async Task PostJudgesBySearchTerm_should_return_judiciary_and_courtroom_a
Assert.That(personRespList, Is.Not.EqualTo(_courtRoomResponse));
Assert.That(personRespList, Is.EqualTo(_courtRoomResponse.OrderBy(x => x.Email)));
}

personRespList.Should().BeEquivalentTo(expectedResponse);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AdminWebsite.Contracts.Responses;
using AdminWebsite.Contracts.Enums;
using AdminWebsite.Contracts.Responses;
using AdminWebsite.Mappers;
using BookingsApi.Contract.V1.Responses;
using FluentAssertions;
Expand Down Expand Up @@ -26,5 +27,29 @@ public void Should_map_person_response_to_judge_response()
judgeResponse.Email.Should().Be(personResponse.Email);
judgeResponse.ContactEmail.Should().Be(personResponse.ContactEmail);
}

[Test]
public void Should_map_judiciary_person_response_to_judge_response()
{
var judiciaryPersonResponse = new JudiciaryPersonResponse
{
Title = "Mr",
FirstName = "FirstName",
LastName = "LastName",
FullName = "FirstName LastName",
Email = "[email protected]",
WorkPhone = "123",
PersonalCode = "PersonalCode"
};

var judgeResponse = JudgeResponseMapper.MapTo(judiciaryPersonResponse);

judgeResponse.FirstName.Should().Be(judiciaryPersonResponse.FirstName);
judgeResponse.LastName.Should().Be(judiciaryPersonResponse.LastName);
judgeResponse.DisplayName.Should().Be(judiciaryPersonResponse.FullName);
judgeResponse.Email.Should().Be(judiciaryPersonResponse.Email);
judgeResponse.ContactEmail.Should().Be(judiciaryPersonResponse.Email);
judgeResponse.AccountType.Should().Be(JudgeAccountType.Judiciary);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public JudiciaryAccountsController(IUserAccountService userAccountService, JavaS
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
public async Task<ActionResult<IList<JudgeResponse>>> PostJudgesBySearchTermAsync([FromBody] string term)
{
// This is the v1 ejud search for judges

try
{
term = _encoder.Encode(term);
Expand Down Expand Up @@ -86,20 +88,24 @@ public async Task<ActionResult<IList<JudgeResponse>>> PostJudgesBySearchTermAsyn
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
public async Task<ActionResult<IList<PersonResponse>>> PostJudiciaryPersonBySearchTermAsync([FromBody] string term)
{
// This is the v1 ejud search for panel members and wingers

try
{
term = _encoder.Encode(term);
var searchTerm = new SearchTermRequest(term);
var courtRoomJudgesTask = _userAccountService.SearchEjudiciaryJudgesByEmailUserResponse(searchTerm.Term);
var eJudiciaryJudgesTask = GetEjudiciaryJudgesBySearchTermAsync(searchTerm);

await Task.WhenAll(courtRoomJudgesTask, eJudiciaryJudgesTask);

var eJudiciaryJudges = (await eJudiciaryJudgesTask)
.Where(p => !p.Username.Contains(_testSettings.TestUsernameStem)).ToList();
.Where(p => !p.Email.Contains(_testSettings.TestUsernameStem))
.Select(p => p.MapToPersonResponse())
.ToList();
var courtRoomJudges = (await courtRoomJudgesTask)
.Where(x => !eJudiciaryJudges.Select(e => e.Username).Contains(x.ContactEmail))
.Select(x => UserResponseMapper.MapFrom(x));
.Select(UserResponseMapper.MapFrom);

var allJudges = courtRoomJudges.Concat(eJudiciaryJudges)
.OrderBy(x => x.ContactEmail).Take(20).ToList();
Expand All @@ -126,6 +132,8 @@ public async Task<ActionResult<IList<PersonResponse>>> PostJudiciaryPersonBySear
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
public async Task<ActionResult<List<JudiciaryPerson>>> SearchForJudiciaryPersonAsync([FromBody] string term)
{
// This is the v2 search for judicial office holders

try
{
term = _encoder.Encode(term);
Expand All @@ -146,11 +154,10 @@ public async Task<ActionResult<List<JudiciaryPerson>>> SearchForJudiciaryPersonA
throw;
}
}
private async Task<List<PersonResponse>> GetEjudiciaryJudgesBySearchTermAsync(SearchTermRequest term)

private async Task<List<JudiciaryPersonResponse>> GetEjudiciaryJudgesBySearchTermAsync(SearchTermRequest term)
{
var judiciaryPersonResponses = (await _bookingsApiClient.PostJudiciaryPersonBySearchTermAsync(term)).ToList();
return judiciaryPersonResponses.Select(x => x.MapToPersonResponse()).ToList();
return (await _bookingsApiClient.PostJudiciaryPersonBySearchTermAsync(term)).ToList();
}
}
}
13 changes: 13 additions & 0 deletions AdminWebsite/AdminWebsite/Mappers/JudgeResponseMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,18 @@ public static JudgeResponse MapTo(PersonResponse personResponse)
ContactEmail = personResponse.ContactEmail
};
}

public static JudgeResponse MapTo(JudiciaryPersonResponse personResponse)
{
return new JudgeResponse
{
FirstName = personResponse.FirstName,
LastName = personResponse.LastName,
DisplayName = personResponse.FullName,
Email = personResponse.Email,
ContactEmail = personResponse.Email,
AccountType = JudgeAccountType.Judiciary
};
}
}
}
Loading