Skip to content

Commit

Permalink
Merge pull request #398 from DFE-Digital/FHB-1189
Browse files Browse the repository at this point in the history
feat(connect): FHB-1189 : Feature Flag VCFS Services
  • Loading branch information
Zac-Digital authored Jan 24, 2025
2 parents 84bb69b + b0b8f58 commit 4ec0b14
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ namespace FamilyHubs.SharedKernel.Razor.FeatureFlags;
public static class FeatureFlag
{
public const string ConnectDashboard = "ConnectDashboard";
public const string VcfsServices = "VcfsServices";
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using FamilyHubs.ServiceDirectory.Shared.Dto.Metrics;
using FamilyHubs.ServiceDirectory.Shared.Enums;
using FamilyHubs.ServiceDirectory.Shared.Models;
using FamilyHubs.SharedKernel.Razor.FeatureFlags;
using Microsoft.FeatureManagement;

namespace FamilyHubs.Referral.Core.ApiClients;

Expand Down Expand Up @@ -37,8 +39,11 @@ Guid correlationId

public class OrganisationClientService : ApiService, IOrganisationClientService
{
public OrganisationClientService(HttpClient client) : base(client)
private readonly IFeatureManager _featureManager;

public OrganisationClientService(HttpClient client, IFeatureManager featureManager) : base(client)
{
_featureManager = featureManager;
}

public async Task<List<KeyValuePair<TaxonomyDto, List<TaxonomyDto>>>> GetCategories()
Expand Down Expand Up @@ -80,6 +85,13 @@ public async Task<List<KeyValuePair<TaxonomyDto, List<TaxonomyDto>>>> GetCategor
HttpResponseMessage? response
)> GetLocalOffers(LocalOfferFilter filter)
{
if (!await _featureManager.IsEnabledAsync(FeatureFlag.VcfsServices))
{
// TODO: Will need to be adjusted once we implement LA Services in Connect
// TODO: Ticket: https://dfedigital.atlassian.net.mcas.ms/browse/FHB-1245
return (new PaginatedList<ServiceDto>(), new HttpResponseMessage(HttpStatusCode.OK));
}

if (string.IsNullOrEmpty(filter.Status))
filter.Status = "Active";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<ItemGroup>
<PackageReference Include="libphonenumber-csharp" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" />
<PackageReference Include="Microsoft.FeatureManagement" />
<PackageReference Include="Polly.Contrib.WaitAndRetry" />
<PackageReference Include="SonarAnalyzer.CSharp">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -24,6 +25,7 @@
<ProjectReference Include="..\..\..\..\shared\referral-shared\src\FamilyHubs.ReferralService.Shared\FamilyHubs.ReferralService.Shared.csproj" />
<ProjectReference Include="..\..\..\..\shared\service-directory-shared\src\FamilyHubs.ServiceDirectory.Shared\FamilyHubs.ServiceDirectory.Shared.csproj" />
<ProjectReference Include="..\..\..\..\shared\shared-kernel\src\fh-shared-kernel.shared-kernel\FamilyHubs.SharedKernel.csproj" />
<ProjectReference Include="..\..\..\..\shared\web-components\src\FamilyHubs.SharedKernel.Razor\FamilyHubs.SharedKernel.Razor.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using FamilyHubs.ServiceDirectory.Shared.Dto;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Microsoft.AspNetCore.Authorization;
using FamilyHubs.Referral.Web.Pages.Shared;
using FamilyHubs.SharedKernel.Identity;
using FamilyHubs.ServiceDirectory.Shared.Enums;
Expand Down Expand Up @@ -44,6 +43,11 @@ public async Task<IActionResult> OnGetAsync(string serviceId)
ReturnUrl = StringValues.IsNullOrEmpty(referer) ? Url.Page("Search") : referer.ToString();
LocalOffer = await _organisationClientService.GetLocalOfferById(serviceId);

if (await ShouldDisableServiceDetailPage())
{
return RedirectToPage("/Error/404");
}

(ServiceScheduleAttendingTypes, ServiceSchedule) = GetServiceSchedule();

ShowConnectionRequestButton = await ShouldShowConnectionRequestButton();
Expand Down Expand Up @@ -77,6 +81,9 @@ public async Task<IActionResult> OnGetAsync(string serviceId)
return (serviceScheduleAttendingTypes, LocalOffer.Schedules.FirstOrDefault());
}

private async Task<bool> ShouldDisableServiceDetailPage() =>
!await _featureManager.IsEnabledAsync(FeatureFlag.VcfsServices) && LocalOffer.ServiceType == ServiceType.InformationSharing;

private async Task<bool> ShouldShowConnectionRequestButton()
{
if (! await _featureManager.IsEnabledAsync(FeatureFlag.ConnectDashboard))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
}
},
"FeatureManagement": {
"ConnectDashboard": true
"ConnectDashboard": true,
"VcfsServices": true
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FamilyHubs.Referral.Core.ApiClients;
using System.Net;
using FamilyHubs.Referral.Core.ApiClients;
using FamilyHubs.Referral.Core.Models;
using FamilyHubs.ReferralService.Shared.Models;
using FamilyHubs.ServiceDirectory.Shared.Dto;
Expand All @@ -7,11 +8,22 @@
using System.Text;
using System.Text.Json;
using FamilyHubs.ReferralUi.UnitTests.Helpers;
using FamilyHubs.SharedKernel.Razor.FeatureFlags;
using Microsoft.FeatureManagement;
using NSubstitute;

namespace FamilyHubs.ReferralUi.UnitTests.Core.ApiClients;

public class WhenUsingOrganisationClientService
{
private readonly IFeatureManager _featureManager;

public WhenUsingOrganisationClientService()
{
_featureManager = Substitute.For<IFeatureManager>();
_featureManager.IsEnabledAsync(FeatureFlag.VcfsServices).Returns(true);
}

[Fact]
public async Task ThenGetCategoryList()
{
Expand All @@ -22,7 +34,7 @@ public async Task ThenGetCategoryList()

var httpClient = TestHelpers.GetMockClient(jsonString);

var organisationClientService = new OrganisationClientService(httpClient);
var organisationClientService = new OrganisationClientService(httpClient, _featureManager);

//Act
var result = await organisationClientService.GetCategories();
Expand All @@ -41,7 +53,7 @@ public async Task ThenGetLocalOffers()
var jsonString = JsonSerializer.Serialize(expectedPaginatedList);
var httpClient = TestHelpers.GetMockClient(jsonString);

var organisationClientService = new OrganisationClientService(httpClient);
var organisationClientService = new OrganisationClientService(httpClient, _featureManager);

var filter = new LocalOfferFilter
{
Expand All @@ -62,6 +74,38 @@ public async Task ThenGetLocalOffers()
result.Items[0].Should().BeEquivalentTo(expectedPaginatedList.Items[0]);
response.Should().NotBeNull();
}

[Fact]
public async Task ThenGetLocalOffers_WithFeatureFlag_VcfsServices_Disabled()
{
_featureManager.IsEnabledAsync(FeatureFlag.VcfsServices).Returns(false);

//Arrange
var expectedPaginatedList = new PaginatedList<ServiceDto>([], 0, 0, 0);
var jsonString = JsonSerializer.Serialize(expectedPaginatedList);
var httpClient = TestHelpers.GetMockClient(jsonString);

var organisationClientService = new OrganisationClientService(httpClient, _featureManager);

var filter = new LocalOfferFilter
{
Status = "active",
ServiceDeliveries = AttendingType.Online.ToString(),
IsPaidFor = true,
TaxonomyIds = "1,2",
LanguageCode = "en",
CanFamilyChooseLocation = true,
DistrictCode = "ABC"
};

//Act
var (result, response) = await organisationClientService.GetLocalOffers(filter);

//Assert
response.Should().NotBeNull();
response!.StatusCode.Should().Be(HttpStatusCode.OK);
result.Items.Count.Should().Be(0);
}

[Fact]
public async Task ThenGetLocalOfferById()
Expand All @@ -71,7 +115,7 @@ public async Task ThenGetLocalOfferById()
var jsonString = JsonSerializer.Serialize(expectedService);
var httpClient = TestHelpers.GetMockClient(jsonString);

var organisationClientService = new OrganisationClientService(httpClient);
var organisationClientService = new OrganisationClientService(httpClient, _featureManager);

//Act
var result = await organisationClientService.GetLocalOfferById(expectedService.Id.ToString());
Expand All @@ -89,7 +133,7 @@ public async Task GetOrganisationDtobyId()
var jsonString = JsonSerializer.Serialize(expectedOrganisation);
var httpClient = TestHelpers.GetMockClient(jsonString);

var organisationClientService = new OrganisationClientService(httpClient);
var organisationClientService = new OrganisationClientService(httpClient, _featureManager);

//Act
var result = await organisationClientService.GetOrganisationDtoByIdAsync(expectedOrganisation.Id);
Expand All @@ -104,7 +148,7 @@ public void ThenCreateAddAgeToUrl()
{
//Arrange
const string expected = "&givenAge=18";
var organisationClientService = new OrganisationClientService(new HttpClient());
var organisationClientService = new OrganisationClientService(new HttpClient(), _featureManager);
var url = new StringBuilder();

//Act
Expand All @@ -120,7 +164,7 @@ public void ThenAddTextToUrl()
{
//Arrange
const string expected = "&text=Test";
var organisationClientService = new OrganisationClientService(new HttpClient());
var organisationClientService = new OrganisationClientService(new HttpClient(), _featureManager);
var url = new StringBuilder();

//Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
using FamilyHubs.ServiceDirectory.Shared.Enums;
using FamilyHubs.ServiceDirectory.Shared.Models;
using FluentAssertions;
using Microsoft.FeatureManagement;
using Newtonsoft.Json;
using NSubstitute;

namespace FamilyHubs.ReferralUi.UnitTests.Services;

Expand All @@ -24,7 +26,7 @@ public async Task ThenGetCategories()

var json = JsonConvert.SerializeObject(paginatedList);
var mockClient = TestHelpers.GetMockClient(json);
var organisationClientService = new OrganisationClientService(mockClient);
var organisationClientService = new OrganisationClientService(mockClient, Substitute.For<IFeatureManager>());

//Act
var result = await organisationClientService.GetCategories();
Expand Down
Loading

0 comments on commit 4ec0b14

Please sign in to comment.