Skip to content

Commit

Permalink
WIP refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
shaed-parkar committed Nov 22, 2024
1 parent bedf8dc commit 44c72e7
Show file tree
Hide file tree
Showing 85 changed files with 379 additions and 1,921 deletions.
25 changes: 16 additions & 9 deletions AdminWebsite/AdminWebsite.IntegrationTests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,20 @@
},
"BookingsApi.Client": {
"type": "Transitive",
"resolved": "2.3.9",
"contentHash": "Bzwufird9sw4QpyCuJBQpcNDuAZXmZWCjLMdoYyFUDdRlJm1xE9uMXaaOyYK2FFPE5WfLAftC/o0nYhhSgFeiQ==",
"resolved": "3.1.2-pr-0919-0010",
"contentHash": "uTjHes/RCMLANtbDLm2sfQTdqSA/90fwUGb2KthKSsZWpjoYdZtJYDjLtTNFqeH7qAKQTV0herli/gAyAAP0hg==",
"dependencies": {
"Microsoft.AspNetCore.Mvc.Core": "2.2.5"
"BookingsApi.Common.DotNet6": "3.1.2-pr-0919-0010",
"Microsoft.AspNetCore.Mvc.Core": "2.2.5",
"System.Text.Json": "8.0.5"
}
},
"BookingsApi.Common.DotNet6": {
"type": "Transitive",
"resolved": "3.1.2-pr-0919-0010",
"contentHash": "JBKWH0dvKUOBh9AnUV0C6ExjeV0Wem3bfmk7Gkxrqnc+Iz5cUvz6zyMMnGVX1mFlsEgrxVeJXj/DoTV0YCyN0Q==",
"dependencies": {
"System.Text.Json": "8.0.5"
}
},
"Castle.Core": {
Expand Down Expand Up @@ -2026,11 +2036,8 @@
},
"System.Text.Json": {
"type": "Transitive",
"resolved": "8.0.0",
"contentHash": "OdrZO2WjkiEG6ajEFRABTRCi/wuXQPxeV6g8xvUJqdxMvvuCCEk86zPla8UiIQJz3durtUEbNyY/3lIhS0yZvQ==",
"dependencies": {
"System.Text.Encodings.Web": "8.0.0"
}
"resolved": "8.0.5",
"contentHash": "0f1B50Ss7rqxXiaBJyzUu9bWFOO2/zSlifZ/UNMdiIpDYe4cY4LQQicP4nirK1OS31I43rn062UIJ1Q9bpmHpg=="
},
"System.Text.RegularExpressions": {
"type": "Transitive",
Expand Down Expand Up @@ -2154,7 +2161,7 @@
"type": "Project",
"dependencies": {
"AspNetCore.HealthChecks.Uris": "[8.0.1, )",
"BookingsApi.Client": "[2.3.9, )",
"BookingsApi.Client": "[3.1.2-pr-0919-0010, )",
"FluentValidation.AspNetCore": "[11.3.0, )",
"LaunchDarkly.ServerSdk": "[8.5.0, )",
"MicroElements.Swashbuckle.FluentValidation": "[6.0.0, )",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Microsoft.AspNetCore.Routing;
using AdminWebsite.Models;
using AdminWebsite.UnitTests.Controllers;
using BookingsApi.Contract.V1.Requests;
using BookingsApi.Contract.V2.Requests;

namespace AdminWebsite.UnitTests.Attributes
{
Expand All @@ -29,12 +29,11 @@ public void OnActionExecuting_Strips_Out_Invalid_Characters_BookNewHearingReques
var request = context.ActionArguments
.Should().NotBeNull()
.And.ContainKey("request")
.WhoseValue.As<BookNewHearingRequest>()
.WhoseValue.As<BookNewHearingRequestV2>()
.Should().NotBeNull()
.And.Subject.As<BookNewHearingRequest>();
.And.Subject.As<BookNewHearingRequestV2>();

request.HearingRoomName.Should().BeEquivalentTo(expectedText);
request.HearingVenueName.Should().BeEquivalentTo(expectedText);
request.OtherInformation.Should().BeEquivalentTo(expectedText);
request.Cases.Should().OnlyContain(x => x.Name == expectedText && x.Number == expectedText);
request.Participants.Should().OnlyContain
Expand Down Expand Up @@ -90,9 +89,9 @@ public void OnActionExecuting_invalid_request_will_not_sanitizer(string inputTex
var request = context.ActionArguments
.Should().NotBeNull()
.And.ContainKey("nothing")
.WhoseValue.As<BookNewHearingRequest>()
.WhoseValue.As<BookNewHearingRequestV2>()
.Should().NotBeNull()
.And.Subject.As<BookNewHearingRequest>();
.And.Subject.As<BookNewHearingRequestV2>();

request.HearingRoomName.Should().BeEquivalentTo(inputText);

Expand All @@ -102,18 +101,17 @@ private static ActionExecutingContext CreateBookNewHearingRequestContext(string
{
var actionArguments = new Dictionary<string, object>
{
{ requestKey, new BookNewHearingRequest
{ requestKey, new BookNewHearingRequestV2
{
HearingRoomName = text,
HearingVenueName = text,
OtherInformation = text,
Cases = new List<CaseRequest>
Cases = new List<CaseRequestV2>
{
new CaseRequest{Name = text, Number = text}
new(){Name = text, Number = text}
},
Participants = new List<BookingsApi.Contract.V1.Requests.ParticipantRequest>
Participants = new List<ParticipantRequestV2>
{
new BookingsApi.Contract.V1.Requests.ParticipantRequest
new()
{
Title = text,
FirstName = text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.AspNetCore.Mvc;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using BookingsApi.Contract.V2.Responses;

namespace AdminWebsite.UnitTests.Controllers
{
Expand Down Expand Up @@ -56,7 +57,7 @@ public async Task Should_return_booking_list_if_cursor_is_not_null()
.ReturnsAsync(new BookingsResponse());
_userIdentity.Setup(x => x.GetGroupDisplayNames()).Returns(new List<string> { "type1", "type2" });

_bookingsApiClient.Setup(s => s.GetCaseTypesAsync(true)).ReturnsAsync(new List<CaseTypeResponse>());
_bookingsApiClient.Setup(s => s.GetCaseTypesV2Async(true)).ReturnsAsync(new List<CaseTypeResponseV2>());

var request = new BookingSearchRequest
{
Expand Down Expand Up @@ -115,8 +116,8 @@ public async Task Should_throw_exception_for_booking_list_and_returns_bad_result
public async Task Should_return_ok_for_booking_list_with_null_types_in_database()
{
SetupTestCase();
List<CaseTypeResponse> response = null;
_bookingsApiClient.Setup(s => s.GetCaseTypesAsync(true)).ReturnsAsync(response);
List<CaseTypeResponseV2> response = null;
_bookingsApiClient.Setup(s => s.GetCaseTypesV2Async(true)).ReturnsAsync(response);

var request = new BookingSearchRequest
{
Expand All @@ -135,8 +136,8 @@ public async Task Should_return_ok_for_booking_list_with_empty_list_of_types()
{
SetupTestCase();

var response = new List<CaseTypeResponse>();
_bookingsApiClient.Setup(s => s.GetCaseTypesAsync(true)).ReturnsAsync(response);
var response = new List<CaseTypeResponseV2>();
_bookingsApiClient.Setup(s => s.GetCaseTypesV2Async(true)).ReturnsAsync(response);

var request = new BookingSearchRequest
{
Expand All @@ -156,19 +157,19 @@ public async Task
{
SetupTestCase();

var response = new List<CaseTypeResponse>
var response = new List<CaseTypeResponseV2>
{
new CaseTypeResponse
new CaseTypeResponseV2()
{
HearingTypes = new List<HearingTypeResponse>(), Id = 1, Name = "type3"
Id = 1, Name = "type3"
},
new CaseTypeResponse
new CaseTypeResponseV2
{
HearingTypes = new List<HearingTypeResponse>(), Id = 2, Name = "type4"
Id = 2, Name = "type4"
}
};

_bookingsApiClient.Setup(s => s.GetCaseTypesAsync(true)).ReturnsAsync(response);
_bookingsApiClient.Setup(s => s.GetCaseTypesV2Async(true)).ReturnsAsync(response);

var request = new BookingSearchRequest
{
Expand All @@ -194,7 +195,7 @@ public async Task Should_return_ok_for_booking_list_with_defined_types_list()

_userIdentity.Setup(x => x.GetGroupDisplayNames()).Returns(new List<string> { "type1", "type2" });

_bookingsApiClient.Setup(s => s.GetCaseTypesAsync(true)).ReturnsAsync(() => GetCaseTypesList());
_bookingsApiClient.Setup(s => s.GetCaseTypesV2Async(true)).ReturnsAsync(() => GetCaseTypesList());

var request = new BookingSearchRequest
{
Expand All @@ -207,7 +208,7 @@ public async Task Should_return_ok_for_booking_list_with_defined_types_list()
okResult.StatusCode.Should().Be(200);

_userIdentity.Verify(x => x.IsATeamLead(), Times.Once);
_bookingsApiClient.Verify(s => s.GetCaseTypesAsync(true), Times.Once);
_bookingsApiClient.Verify(s => s.GetCaseTypesV2Async(true), Times.Once);
_bookingsApiClient.Verify(x => x.GetHearingsByTypesAsync(It.IsAny<GetHearingRequest>()), Times.Once);
}

Expand All @@ -224,7 +225,7 @@ public async Task Should_return_ok_for_booking_list_and_exclude_repeated_types()

_userIdentity.Setup(x => x.GetGroupDisplayNames()).Returns(new List<string> { "type1", "type2", "type2" });

_bookingsApiClient.Setup(s => s.GetCaseTypesAsync(true)).ReturnsAsync(() => GetCaseTypesList());
_bookingsApiClient.Setup(s => s.GetCaseTypesV2Async(true)).ReturnsAsync(() => GetCaseTypesList());

var request = new BookingSearchRequest
{
Expand All @@ -238,7 +239,7 @@ public async Task Should_return_ok_for_booking_list_and_exclude_repeated_types()
okResult.StatusCode.Should().Be(200);

_userIdentity.Verify(x => x.IsATeamLead(), Times.Once);
_bookingsApiClient.Verify(s => s.GetCaseTypesAsync(true), Times.Once);
_bookingsApiClient.Verify(s => s.GetCaseTypesV2Async(true), Times.Once);
_bookingsApiClient.Verify(x => x.GetHearingsByTypesAsync(It.IsAny<GetHearingRequest>()), Times.Once);
}

Expand All @@ -247,7 +248,7 @@ public async Task Should_return_booking_list_when_admin_search_by_case_number()
{
SetupTestCase();

_bookingsApiClient.Setup(s => s.GetCaseTypesAsync(true)).ReturnsAsync(default(List<CaseTypeResponse>));
_bookingsApiClient.Setup(s => s.GetCaseTypesV2Async(true)).ReturnsAsync(default(List<CaseTypeResponseV2>));

var request = new BookingSearchRequest
{
Expand All @@ -268,7 +269,7 @@ public async Task Should_return_booking_list_when_admin_search_by_venue_ids()
{
SetupTestCase();

_bookingsApiClient.Setup(s => s.GetCaseTypesAsync(true)).ReturnsAsync(default(List<CaseTypeResponse>));
_bookingsApiClient.Setup(s => s.GetCaseTypesV2Async(true)).ReturnsAsync(default(List<CaseTypeResponseV2>));

var request = new BookingSearchRequest
{
Expand All @@ -288,7 +289,7 @@ public async Task Should_return_booking_list_when_admin_search_by_last_name()
{
SetupTestCase();

_bookingsApiClient.Setup(s => s.GetCaseTypesAsync(true)).ReturnsAsync(default(List<CaseTypeResponse>));
_bookingsApiClient.Setup(s => s.GetCaseTypesV2Async(true)).ReturnsAsync(default(List<CaseTypeResponseV2>));

var request = new BookingSearchRequest
{
Expand All @@ -311,7 +312,7 @@ public async Task Should_return_booking_list_when_admin_search_by_case_types()
{
SetupTestCase();

_bookingsApiClient.Setup(s => s.GetCaseTypesAsync(true)).ReturnsAsync(default(List<CaseTypeResponse>));
_bookingsApiClient.Setup(s => s.GetCaseTypesV2Async(true)).ReturnsAsync(default(List<CaseTypeResponseV2>));

var request = new BookingSearchRequest
{
Expand All @@ -334,7 +335,7 @@ public async Task Should_return_bookings_list_when_admin_search_by_start_date()

var startDate = new DateTime(2022, 3, 25, 0, 0, 0, DateTimeKind.Utc);

_bookingsApiClient.Setup(s => s.GetCaseTypesAsync(true)).ReturnsAsync(default(List<CaseTypeResponse>));
_bookingsApiClient.Setup(s => s.GetCaseTypesV2Async(true)).ReturnsAsync(default(List<CaseTypeResponseV2>));

var request = new BookingSearchRequest
{
Expand All @@ -359,7 +360,7 @@ public async Task Should_return_bookings_list_when_admin_search_by_end_date()

var endDate = new DateTime(2022, 3, 25, 0, 0, 0, DateTimeKind.Utc);

_bookingsApiClient.Setup(s => s.GetCaseTypesAsync(true)).ReturnsAsync(default(List<CaseTypeResponse>));
_bookingsApiClient.Setup(s => s.GetCaseTypesV2Async(true)).ReturnsAsync(default(List<CaseTypeResponseV2>));

var request = new BookingSearchRequest
{
Expand All @@ -384,7 +385,7 @@ public async Task Should_return_bookings_list_when_admin_search_by_start_and_end
var startDate = new DateTime(2022, 3, 24, 0, 0, 0, DateTimeKind.Utc);
var endDate = new DateTime(2022, 3, 25, 0, 0, 0, DateTimeKind.Utc);

_bookingsApiClient.Setup(s => s.GetCaseTypesAsync(true)).ReturnsAsync(default(List<CaseTypeResponse>));
_bookingsApiClient.Setup(s => s.GetCaseTypesV2Async(true)).ReturnsAsync(default(List<CaseTypeResponseV2>));

var request = new BookingSearchRequest
{
Expand All @@ -411,7 +412,7 @@ public async Task Should_return_bad_request_when_admin_search_with_start_date_af
var startDate = new DateTime(2022, 3, 25, 0, 0, 0, DateTimeKind.Utc);
var endDate = new DateTime(2022, 3, 24, 0, 0, 0, DateTimeKind.Utc);

_bookingsApiClient.Setup(s => s.GetCaseTypesAsync(true)).ReturnsAsync(default(List<CaseTypeResponse>));
_bookingsApiClient.Setup(s => s.GetCaseTypesV2Async(true)).ReturnsAsync(default(List<CaseTypeResponseV2>));

var request = new BookingSearchRequest
{
Expand All @@ -433,7 +434,7 @@ public async Task Should_return_booking_list_when_admin_search_by_multiple_crite
{
SetupTestCase();

_bookingsApiClient.Setup(s => s.GetCaseTypesAsync(true)).ReturnsAsync(default(List<CaseTypeResponse>));
_bookingsApiClient.Setup(s => s.GetCaseTypesV2Async(true)).ReturnsAsync(default(List<CaseTypeResponseV2>));

var request = new BookingSearchRequest
{
Expand All @@ -452,21 +453,21 @@ public async Task Should_return_booking_list_when_admin_search_by_multiple_crite
okResult.StatusCode.Should().Be(200);
}

private static List<CaseTypeResponse> GetCaseTypesList()
private static List<CaseTypeResponseV2> GetCaseTypesList()
{
return new List<CaseTypeResponse>
return new List<CaseTypeResponseV2>
{
new CaseTypeResponse
new()
{
HearingTypes = new List<HearingTypeResponse>(), Id = 1, Name = "type1"
Id = 1, Name = "type1"
},
new CaseTypeResponse
new()
{
HearingTypes = new List<HearingTypeResponse>(), Id = 2, Name = "type2"
Id = 2, Name = "type2"
},
new CaseTypeResponse
new()
{
HearingTypes = new List<HearingTypeResponse>(), Id = 3, Name = "type3"
Id = 3, Name = "type3"
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using BookingsApi.Contract.V2.Requests;
using Microsoft.AspNetCore.Mvc;
using VideoApi.Contract.Responses;
using JudiciaryParticipantRequest = AdminWebsite.Contracts.Requests.JudiciaryParticipantRequest;
using LinkedParticipantType = AdminWebsite.Contracts.Enums.LinkedParticipantType;

namespace AdminWebsite.UnitTests.Controllers.HearingsController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using BookingsApi.Client;
using BookingsApi.Contract.V1.Requests.Enums;
using Autofac.Extras.Moq;
using BookingsApi.Contract.V1.Requests;
using BookingsApi.Contract.V1.Responses;
using BookingsApi.Contract.V2.Responses;
using VideoApi.Contract.Consts;
using VideoApi.Contract.Responses;
using ParticipantResponse = BookingsApi.Contract.V1.Responses.ParticipantResponse;

namespace AdminWebsite.UnitTests.Controllers.HearingsController
{
Expand All @@ -36,10 +35,10 @@ public void Setup()
TelephoneConferenceId = "expected_conference_phone_id"
}
});
_mocker.Mock<IBookingsApiClient>().Setup(bs => bs.GetHearingDetailsByIdAsync(It.IsAny<Guid>()))
.ReturnsAsync(new HearingDetailsResponse
_mocker.Mock<IBookingsApiClient>().Setup(bs => bs.GetHearingDetailsByIdV2Async(It.IsAny<Guid>()))
.ReturnsAsync(new HearingDetailsResponseV2()
{
Participants = [new ParticipantResponse { HearingRoleName = "Judge" }]
Participants = [new ParticipantResponseV2 { HearingRoleName = HearingRoleName.Representative }]
});
_controller = _mocker.Create<AdminWebsite.Controllers.HearingsController>();
}
Expand Down
Loading

0 comments on commit 44c72e7

Please sign in to comment.