diff --git a/AdminWebsite/AdminWebsite.UnitTests/Controllers/HearingsController/EditHearingTests.cs b/AdminWebsite/AdminWebsite.UnitTests/Controllers/HearingsController/EditHearingTests.cs index 16833f5ca..ab5e6306d 100644 --- a/AdminWebsite/AdminWebsite.UnitTests/Controllers/HearingsController/EditHearingTests.cs +++ b/AdminWebsite/AdminWebsite.UnitTests/Controllers/HearingsController/EditHearingTests.cs @@ -15,13 +15,11 @@ using AdminWebsite.Configuration; using AdminWebsite.Contracts.Enums; using AdminWebsite.Extensions; -using AdminWebsite.Mappers; using AdminWebsite.Models; using AdminWebsite.Security; using AdminWebsite.Services; using AdminWebsite.UnitTests.Helper; using BookingsApi.Client; -using BookingsApi.Contract.V1.Configuration; using BookingsApi.Contract.V1.Requests; using BookingsApi.Contract.V1.Responses; using BookingsApi.Contract.V2.Enums; @@ -97,7 +95,7 @@ public void Setup() _participantGroupLogger = new Mock>(); _hearingsService = new HearingsService(_bookingsApiClient.Object, _participantGroupLogger.Object, _featureToggle.Object); - _bookingsApiClient.Setup(x => x.GetFeatureFlagAsync(It.Is(f => f == nameof(FeatureFlags.EJudFeature)))).ReturnsAsync(true); + _featureToggle.Setup(x => x.EJudEnabled()).Returns(true); _controller = new AdminWebsite.Controllers.HearingsController(_bookingsApiClient.Object, _userIdentity.Object, diff --git a/AdminWebsite/AdminWebsite.UnitTests/Controllers/HearingsController/PostHearingTests.cs b/AdminWebsite/AdminWebsite.UnitTests/Controllers/HearingsController/PostHearingTests.cs index 46375b9a9..2083be166 100644 --- a/AdminWebsite/AdminWebsite.UnitTests/Controllers/HearingsController/PostHearingTests.cs +++ b/AdminWebsite/AdminWebsite.UnitTests/Controllers/HearingsController/PostHearingTests.cs @@ -18,7 +18,6 @@ using AdminWebsite.Contracts.Responses; using BookingsApi.Client; using Autofac.Extras.Moq; -using BookingsApi.Contract.V1.Configuration; using BookingsApi.Contract.V1.Requests; using BookingsApi.Contract.V1.Requests.Enums; using VideoApi.Contract.Responses; @@ -61,7 +60,7 @@ public void Setup() }, CaseTypeName = "Generic" }); - _mocker.Mock().Setup(x => x.GetFeatureFlagAsync(It.Is(f => f == nameof(FeatureFlags.EJudFeature)))).ReturnsAsync(true); + _mocker.Mock().Setup(x => x.EJudEnabled()).Returns(true); _mocker.Mock().Setup(e => e.BookAndConfirmToggle()).Returns(true); _controller = _mocker.Create(); } diff --git a/AdminWebsite/AdminWebsite.UnitTests/Services/HearingServiceTests.cs b/AdminWebsite/AdminWebsite.UnitTests/Services/HearingServiceTests.cs index 73dc24b15..4aaeb7faf 100644 --- a/AdminWebsite/AdminWebsite.UnitTests/Services/HearingServiceTests.cs +++ b/AdminWebsite/AdminWebsite.UnitTests/Services/HearingServiceTests.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using AdminWebsite.Configuration; using AdminWebsite.Contracts.Enums; @@ -9,7 +8,6 @@ using AdminWebsite.Services; using Autofac.Extras.Moq; using BookingsApi.Client; -using BookingsApi.Contract.V1.Configuration; using BookingsApi.Contract.V1.Requests; using BookingsApi.Contract.V1.Requests.Enums; using BookingsApi.Contract.V1.Responses; @@ -20,7 +18,6 @@ using NUnit.Framework; using VideoApi.Contract.Responses; using CaseResponse = BookingsApi.Contract.V1.Responses.CaseResponse; -using EndpointResponse = BookingsApi.Contract.V1.Responses.EndpointResponse; namespace AdminWebsite.UnitTests.Services { @@ -36,7 +33,7 @@ public class HearingServiceTests public void Setup() { _mocker = AutoMock.GetLoose(); - _mocker.Mock>().Setup(opt => opt.Value).Returns(new KinlyConfiguration() + _mocker.Mock>().Setup(opt => opt.Value).Returns(new KinlyConfiguration { ConferencePhoneNumber = ExpectedTeleConferencePhoneNumber }); @@ -58,8 +55,7 @@ public void Setup() _mocker.Mock() .Setup(c => c.GetHearingsByGroupIdAsync(It.IsAny())) .ReturnsAsync(new List { _hearing }); - _mocker.Mock() - .Setup(x => x.GetFeatureFlagAsync(It.Is(f => f == nameof(FeatureFlags.EJudFeature)))).ReturnsAsync(true); + _mocker.Mock().Setup(x => x.EJudEnabled()).Returns(true); _mocker.Mock() .Setup(x => x.BookAndConfirmToggle()).Returns(true); _service = _mocker.Create(); @@ -110,7 +106,7 @@ public void Should_have_one_added_participant() public async Task Should_process_participants() { var existingParticipants = new List(); - var newParticipants = new List(); + var newParticipants = new List(); var removedParticipantIds = new List(); var linkedParticipants = new List(); @@ -134,7 +130,7 @@ public async Task Should_process_participants() public async Task Should_process_new_joh_participant_EJudFeature_Is_ON(string hearingRole) { // Arrange - var participant = new EditParticipantRequest() + var participant = new EditParticipantRequest { Id = Guid.NewGuid(), HearingRoleName = hearingRole, @@ -155,15 +151,14 @@ public async Task Should_process_new_joh_participant_EJudFeature_Is_ON(string he public async Task Should_process_new_joh_participant_EJudFeature_Is_OFF(string hearingRole) { // Arrange - var participant = new EditParticipantRequest() + var participant = new EditParticipantRequest { Id = Guid.NewGuid(), HearingRoleName = hearingRole, ContactEmail = "contact@email.com" }; var removedParticipantIds = new List(); - _mocker.Mock() - .Setup(x => x.GetFeatureFlagAsync(It.Is(f => f == nameof(FeatureFlags.EJudFeature)))).ReturnsAsync(false); + _mocker.Mock().Setup(x => x.EJudEnabled()).Returns(false); // Act var newParticipant = await _service.ProcessNewParticipant(_hearing.Id, participant, removedParticipantIds, _hearing.Map()); @@ -177,15 +172,14 @@ public async Task Should_process_new_joh_participant_EJudFeature_Is_OFF(string h public async Task Should_process_new_judge_participant_EJudFeature_Is_OFF() { // Arrange - var participant = new EditParticipantRequest() + var participant = new EditParticipantRequest { Id = Guid.NewGuid(), CaseRoleName = "Judge", ContactEmail = "contact@email.com" }; var removedParticipantIds = new List(); - _mocker.Mock() - .Setup(x => x.GetFeatureFlagAsync(It.Is(f => f == nameof(FeatureFlags.EJudFeature)))).ReturnsAsync(false); + _mocker.Mock().Setup(x => x.EJudEnabled()).Returns(false); // Act var newParticipant = await _service.ProcessNewParticipant(_hearing.Id, participant, removedParticipantIds, _hearing.Map()); @@ -199,14 +193,14 @@ public async Task Should_process_new_judge_participant_EJudFeature_Is_OFF() public async Task Should_NOT_process_new_joh_participant_when_participant_is_in_list_and_NOT_removed() { // Arrange - var participant = new EditParticipantRequest() + var participant = new EditParticipantRequest { Id = Guid.NewGuid(), HearingRoleName = "Panel Member", ContactEmail = "contact@email.com" }; - _hearing.Participants.Add(new ParticipantResponse() + _hearing.Participants.Add(new ParticipantResponse { Id = participant.Id.Value, Username = participant.ContactEmail, @@ -226,14 +220,14 @@ public async Task Should_NOT_process_new_joh_participant_when_participant_is_in_ public async Task Should_process_new_joh_participant_when_participant_is_in_list_and_is_removed() { // Arrange - var participant = new EditParticipantRequest() + var participant = new EditParticipantRequest { Id = Guid.NewGuid(), CaseRoleName = "Judge", ContactEmail = "contact@email.com" }; - _hearing.Participants.Add(new ParticipantResponse() + _hearing.Participants.Add(new ParticipantResponse { Id = participant.Id.Value, Username = participant.ContactEmail, @@ -257,7 +251,7 @@ public async Task Should_process_new_joh_participant_when_participant_is_in_list public async Task Should_process_non_joh_participant() { // Arrange - var participant = new EditParticipantRequest() + var participant = new EditParticipantRequest { Id = Guid.NewGuid(), CaseRoleName = "NOT JUDGE", diff --git a/AdminWebsite/AdminWebsite/Configuration/FeatureToggles.cs b/AdminWebsite/AdminWebsite/Configuration/FeatureToggles.cs index 21e7b8aa2..a5e4e8dee 100644 --- a/AdminWebsite/AdminWebsite/Configuration/FeatureToggles.cs +++ b/AdminWebsite/AdminWebsite/Configuration/FeatureToggles.cs @@ -11,6 +11,7 @@ public interface IFeatureToggles public bool BookAndConfirmToggle(); public bool Dom1Enabled(); public bool ReferenceDataToggle(); + public bool EJudEnabled(); } public class FeatureToggles : IFeatureToggles @@ -21,6 +22,7 @@ public class FeatureToggles : IFeatureToggles private const string BookAndConfirmToggleKey = "Book_and_Confirm"; private const string Dom1EnabledToggleKey = "dom1"; private const string ReferenceDataToggleKey = "reference-data"; + private const string EJudFeatureToggleKey = "ejud-feature"; public FeatureToggles(string sdkKey, string environmentName) { @@ -32,32 +34,32 @@ public FeatureToggles(string sdkKey, string environmentName) public bool BookAndConfirmToggle() { - if (!_ldClient.Initialized) - { - throw new InvalidOperationException("LaunchDarkly client not initialized"); - } - - return _ldClient.BoolVariation(BookAndConfirmToggleKey, _context); + return GetBoolValueWithKey(BookAndConfirmToggleKey); } public bool Dom1Enabled() { - if (!_ldClient.Initialized) - { - throw new InvalidOperationException("LaunchDarkly client not initialized"); - } - - return _ldClient.BoolVariation(Dom1EnabledToggleKey, _context); + return GetBoolValueWithKey(Dom1EnabledToggleKey); } public bool ReferenceDataToggle() + { + return GetBoolValueWithKey(ReferenceDataToggleKey); + } + + public bool EJudEnabled() + { + return GetBoolValueWithKey(EJudFeatureToggleKey); + } + + private bool GetBoolValueWithKey(string key) { if (!_ldClient.Initialized) { throw new InvalidOperationException("LaunchDarkly client not initialized"); } - return _ldClient.BoolVariation(ReferenceDataToggleKey, _context); + return _ldClient.BoolVariation(key, _context); } } } \ No newline at end of file diff --git a/AdminWebsite/AdminWebsite/Services/HearingsService.cs b/AdminWebsite/AdminWebsite/Services/HearingsService.cs index fbcc7a39e..0141afdd1 100644 --- a/AdminWebsite/AdminWebsite/Services/HearingsService.cs +++ b/AdminWebsite/AdminWebsite/Services/HearingsService.cs @@ -10,7 +10,6 @@ using AdminWebsite.Configuration; using AdminWebsite.Contracts.Responses; using BookingsApi.Contract.Interfaces.Requests; -using BookingsApi.Contract.V1.Configuration; using BookingsApi.Contract.V1.Requests; using BookingsApi.Contract.V2.Requests; @@ -30,12 +29,14 @@ public interface IHearingsService public class HearingsService : IHearingsService { private readonly IBookingsApiClient _bookingsApiClient; + private readonly IFeatureToggles _featureToggles; private readonly ILogger _logger; #pragma warning disable S107 - public HearingsService(IBookingsApiClient bookingsApiClient, ILogger logger, IFeatureToggles featureFlag) + public HearingsService(IBookingsApiClient bookingsApiClient, ILogger logger, IFeatureToggles featureToggles) { _bookingsApiClient = bookingsApiClient; _logger = logger; + _featureToggles = featureToggles; } public void AssignEndpointDefenceAdvocates(List endpointsWithDa, IReadOnlyCollection participants) @@ -107,7 +108,7 @@ public async Task ProcessNewParticipant( return (ParticipantRequest)await ProcessNewParticipant(hearingId, participant, newParticipant, removedParticipantIds, hearing); } - public async Task ProcessNewParticipant( + public Task ProcessNewParticipant( Guid hearingId, EditParticipantRequest participant, IParticipantRequest newParticipant, @@ -116,7 +117,7 @@ public async Task ProcessNewParticipant( { // Add a new participant // Map the request except the username - var ejudFeatureFlag = await _bookingsApiClient.GetFeatureFlagAsync(nameof(FeatureFlags.EJudFeature)); + var ejudFeatureFlag = _featureToggles.EJudEnabled(); if ((ejudFeatureFlag && (participant.CaseRoleName == RoleNames.Judge || participant.HearingRoleName == RoleNames.PanelMember @@ -127,7 +128,7 @@ public async Task ProcessNewParticipant( hearing.Participants.Exists(p => p.ContactEmail.Equals(participant.ContactEmail) && removedParticipantIds.TrueForAll(removedParticipantId => removedParticipantId != p.Id))) { //If the judge already exists in the database, there is no need to add again. - return null; + return Task.FromResult(null); } if (newParticipant is ParticipantRequest v1Request) @@ -138,7 +139,7 @@ public async Task ProcessNewParticipant( _logger.LogDebug("Adding participant {Participant} to hearing {Hearing}", newParticipant.DisplayName, hearingId); - return newParticipant; + return Task.FromResult(newParticipant); } public async Task ProcessEndpoints(Guid hearingId, EditHearingRequest request, HearingDetailsResponse hearing,