From ed89c32524d4a65af4266bd4e341f5c25cc29ef8 Mon Sep 17 00:00:00 2001 From: Oliver Scott Date: Tue, 12 Dec 2023 13:02:06 +0000 Subject: [PATCH] VIH-10362 Fix issue with judge display name not auto populating for ejud and V1 API (#1317) * Fix issue with judge display name not auto populating * Add tests for mapper --- .../JudiciaryAccountsControllerTest.cs | 23 ++++++++++++++-- .../Mappers/JudgeResponseMapperTest.cs | 27 ++++++++++++++++++- .../JudiciaryAccountsController.cs | 23 ++++++++++------ .../Mappers/JudgeResponseMapper.cs | 13 +++++++++ 4 files changed, 75 insertions(+), 11 deletions(-) diff --git a/AdminWebsite/AdminWebsite.UnitTests/Controllers/JudiciaryAccountsControllerTest.cs b/AdminWebsite/AdminWebsite.UnitTests/Controllers/JudiciaryAccountsControllerTest.cs index 5a2500bea..fa1f87a17 100644 --- a/AdminWebsite/AdminWebsite.UnitTests/Controllers/JudiciaryAccountsControllerTest.cs +++ b/AdminWebsite/AdminWebsite.UnitTests/Controllers/JudiciaryAccountsControllerTest.cs @@ -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; @@ -385,8 +386,24 @@ public async Task PostJudgesBySearchTerm_should_return_judiciary_and_courtroom_a okRequestResult.StatusCode.Should().NotBeNull(); var personRespList = (List)okRequestResult.Value; - var expectedJudiciaryCount = withJudiciary ? _judiciaryResponse.Count : 0; - var expectedCourtRoomCount = withCourtroom ? _courtRoomResponse.Count : 0; + var expectedResponse = new List(); + var expectedJudiciaryResponses = new List(); + var expectedCourtRoomResponses = new List(); + + 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; @@ -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] diff --git a/AdminWebsite/AdminWebsite.UnitTests/Mappers/JudgeResponseMapperTest.cs b/AdminWebsite/AdminWebsite.UnitTests/Mappers/JudgeResponseMapperTest.cs index b68fb65bb..6caefb487 100644 --- a/AdminWebsite/AdminWebsite.UnitTests/Mappers/JudgeResponseMapperTest.cs +++ b/AdminWebsite/AdminWebsite.UnitTests/Mappers/JudgeResponseMapperTest.cs @@ -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; @@ -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@email.com", + 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); + } } } diff --git a/AdminWebsite/AdminWebsite/Controllers/JudiciaryAccountsController.cs b/AdminWebsite/AdminWebsite/Controllers/JudiciaryAccountsController.cs index 6eb0a4045..5d2ba0b25 100644 --- a/AdminWebsite/AdminWebsite/Controllers/JudiciaryAccountsController.cs +++ b/AdminWebsite/AdminWebsite/Controllers/JudiciaryAccountsController.cs @@ -46,6 +46,8 @@ public JudiciaryAccountsController(IUserAccountService userAccountService, JavaS [ProducesResponseType((int)HttpStatusCode.BadRequest)] public async Task>> PostJudgesBySearchTermAsync([FromBody] string term) { + // This is the v1 ejud search for judges + try { term = _encoder.Encode(term); @@ -86,20 +88,24 @@ public async Task>> PostJudgesBySearchTermAsyn [ProducesResponseType((int)HttpStatusCode.BadRequest)] public async Task>> 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(); @@ -126,6 +132,8 @@ public async Task>> PostJudiciaryPersonBySear [ProducesResponseType((int)HttpStatusCode.BadRequest)] public async Task>> SearchForJudiciaryPersonAsync([FromBody] string term) { + // This is the v2 search for judicial office holders + try { term = _encoder.Encode(term); @@ -146,11 +154,10 @@ public async Task>> SearchForJudiciaryPersonA throw; } } - - private async Task> GetEjudiciaryJudgesBySearchTermAsync(SearchTermRequest term) + + private async Task> GetEjudiciaryJudgesBySearchTermAsync(SearchTermRequest term) { - var judiciaryPersonResponses = (await _bookingsApiClient.PostJudiciaryPersonBySearchTermAsync(term)).ToList(); - return judiciaryPersonResponses.Select(x => x.MapToPersonResponse()).ToList(); + return (await _bookingsApiClient.PostJudiciaryPersonBySearchTermAsync(term)).ToList(); } } } diff --git a/AdminWebsite/AdminWebsite/Mappers/JudgeResponseMapper.cs b/AdminWebsite/AdminWebsite/Mappers/JudgeResponseMapper.cs index 0a8a0ae4f..b856354ef 100644 --- a/AdminWebsite/AdminWebsite/Mappers/JudgeResponseMapper.cs +++ b/AdminWebsite/AdminWebsite/Mappers/JudgeResponseMapper.cs @@ -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 + }; + } } }