-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix v2 toggle issues * Reinstate api tests * Update search service * Added null coalesc for non populated johs * Check fo null judicary participant before mapping --------- Co-authored-by: William Craig <[email protected]> (cherry picked from commit 89f8d85)
- Loading branch information
1 parent
78b58d0
commit 2a3c9d0
Showing
8 changed files
with
265 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using AdminWebsite.Configuration; | ||
using System; | ||
using AdminWebsite.Configuration; | ||
using AdminWebsite.Contracts.Responses; | ||
using AdminWebsite.Services; | ||
using AdminWebsite.UnitTests.Helper; | ||
|
@@ -8,6 +9,7 @@ | |
using Moq; | ||
using NUnit.Framework; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text.Encodings.Web; | ||
using System.Threading.Tasks; | ||
|
@@ -323,5 +325,96 @@ public void Should_pass_on_exception_request_from_bookings_api_for_judiciary_per | |
Assert.ThrowsAsync<BookingsApiException>(() => _controller.PostJudiciaryPersonBySearchTermAsync(term)); | ||
_bookingsApiClient.Verify(x => x.PostJudiciaryPersonBySearchTermAsync(It.IsAny<SearchTermRequest>()), Times.Once); | ||
} | ||
|
||
[Test] | ||
[TestCase(false, false)] | ||
[TestCase(false, true)] | ||
[TestCase(true, false)] | ||
[TestCase(true, true)] | ||
public async Task PostJudgesBySearchTerm_should_return_judiciary_and_courtroom_accounts_if_match_to_search_term(bool withJudiciary, bool withCourtroom) | ||
{ | ||
_judiciaryResponse = new List<JudiciaryPersonResponse> | ||
{ | ||
new() | ||
{ | ||
Email = "[email protected]", | ||
FirstName = "Jack", | ||
LastName = "Mann", | ||
WorkPhone = "", | ||
Title = "Mr", | ||
FullName = "Mr Jack Mann", | ||
PersonalCode = "12345678" | ||
} | ||
}; | ||
_bookingsApiClient.Setup(x => x.PostJudiciaryPersonBySearchTermAsync(It.IsAny<SearchTermRequest>())) | ||
.ReturnsAsync(withJudiciary ? _judiciaryResponse : new List<JudiciaryPersonResponse>()); | ||
|
||
var _courtRoomResponse = new List<JudgeResponse> | ||
{ | ||
new JudgeResponse | ||
{ | ||
FirstName = "FirstName1", | ||
LastName = "FirstName2", | ||
Email = "[email protected]", | ||
ContactEmail = "[email protected]" | ||
}, | ||
new JudgeResponse | ||
{ | ||
FirstName = "FirstName3", | ||
LastName = "LastName3", | ||
Email = "[email protected]", | ||
ContactEmail = "[email protected]" | ||
}, | ||
new JudgeResponse | ||
{ | ||
FirstName = "FirstName2", | ||
LastName = "LastName2", | ||
Email = "[email protected]", // Out of order to test order | ||
ContactEmail = "[email protected]" | ||
} | ||
}; | ||
|
||
_userAccountService.Setup(x => x.SearchJudgesByEmail(It.IsAny<string>())) | ||
.ReturnsAsync(withCourtroom ? _courtRoomResponse : new List<JudgeResponse>()); | ||
|
||
|
||
var searchTerm = "judici"; | ||
var result = await _controller.PostJudgesBySearchTermAsync(searchTerm); | ||
|
||
var okRequestResult = (OkObjectResult)result.Result; | ||
okRequestResult.StatusCode.Should().NotBeNull(); | ||
var personRespList = (List<JudgeResponse>)okRequestResult.Value; | ||
|
||
var expectedJudiciaryCount = withJudiciary ? _judiciaryResponse.Count : 0; | ||
var expectedCourtRoomCount = withCourtroom ? _courtRoomResponse.Count : 0; | ||
|
||
var expectedTotal = expectedJudiciaryCount + expectedCourtRoomCount; | ||
|
||
personRespList.Count.Should().Be(expectedTotal); | ||
if(!withJudiciary && withCourtroom) // Only courtroom is set up to test order | ||
{ | ||
Assert.That(personRespList, Is.EquivalentTo(_courtRoomResponse)); | ||
Assert.That(personRespList, Is.Not.EqualTo(_courtRoomResponse)); | ||
Assert.That(personRespList, Is.EqualTo(_courtRoomResponse.OrderBy(x => x.Email))); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task PostJudgesBySearchTerm_should_pass_on_bad_request_from_bookings_api_for_judge_accounts() | ||
{ | ||
_bookingsApiClient.Setup(x => x.PostJudiciaryPersonBySearchTermAsync(It.IsAny<SearchTermRequest>())) | ||
.ThrowsAsync(ClientException.ForBookingsAPI(HttpStatusCode.BadRequest)); | ||
|
||
var response = await _controller.PostJudgesBySearchTermAsync("term"); | ||
response.Result.Should().BeOfType<BadRequestObjectResult>(); | ||
} | ||
|
||
[Test] | ||
public void PostJudgesBySearchTerm_should_pass_on_exception_request_from_bookings_api_for_judges_accounts() | ||
{ | ||
_bookingsApiClient.Setup(x => x.PostJudiciaryPersonBySearchTermAsync(It.IsAny<SearchTermRequest>())) | ||
.ThrowsAsync(ClientException.ForBookingsAPI(HttpStatusCode.InternalServerError)); | ||
Assert.ThrowsAsync<BookingsApiException>(() => _controller.PostJudgesBySearchTermAsync("term")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters