diff --git a/Childrens-Social-Care-CPD-Tests/Controllers/ResourcesControllerTests.cs b/Childrens-Social-Care-CPD-Tests/Controllers/ResourcesControllerTests.cs index bf011a98..16ca995e 100644 --- a/Childrens-Social-Care-CPD-Tests/Controllers/ResourcesControllerTests.cs +++ b/Childrens-Social-Care-CPD-Tests/Controllers/ResourcesControllerTests.cs @@ -1,4 +1,5 @@ -using Childrens_Social_Care_CPD.Controllers; +using Childrens_Social_Care_CPD.Configuration; +using Childrens_Social_Care_CPD.Controllers; using Childrens_Social_Care_CPD.Core.Resources; using Childrens_Social_Care_CPD.Models; using FluentAssertions; @@ -14,6 +15,7 @@ namespace Childrens_Social_Care_CPD_Tests.Controllers; public class ResourcesControllerTests { + private IFeaturesConfig _featuresConfig; private IResourcesSearchStrategy _searchStrategy; private ResourcesController _resourcesController; private IRequestCookieCollection _cookies; @@ -32,8 +34,10 @@ public void SetUp() _httpContext.Request.Returns(_httpRequest); controllerContext.HttpContext = _httpContext; + _featuresConfig = Substitute.For(); + _featuresConfig.IsEnabled(Features.ResourcesAndLearning).Returns(true); _searchStrategy = Substitute.For(); - _resourcesController = new ResourcesController(_searchStrategy) + _resourcesController = new ResourcesController(_featuresConfig, _searchStrategy) { ControllerContext = controllerContext, TempData = Substitute.For() @@ -53,4 +57,19 @@ public async Task Search_Returns_Strategy_Model() // assert actual.Model.Should().Be(model); } + + [Test] + public async Task Disabling_Resources_Feature_Returns_NotFoundResult() + { + // arrange + _featuresConfig.IsEnabled(Features.ResourcesAndLearning).Returns(false); + var model = new ResourcesListViewModel(null, null, null, null); + _searchStrategy.SearchAsync(Arg.Any(), Arg.Any()).Returns(model); + + // act + var actual = await _resourcesController.Search(query: null); + + // assert + actual.Should().BeOfType(); + } } \ No newline at end of file diff --git a/Childrens-Social-Care-CPD/Configuration/Features.cs b/Childrens-Social-Care-CPD/Configuration/Features.cs index 772980a5..8bc52dc5 100644 --- a/Childrens-Social-Care-CPD/Configuration/Features.cs +++ b/Childrens-Social-Care-CPD/Configuration/Features.cs @@ -2,5 +2,6 @@ public static class Features { + public const string ResourcesAndLearning = "resources-learning"; public const string ResourcesUseDynamicTags = "resources-search-use-dynamic-tags"; } diff --git a/Childrens-Social-Care-CPD/Controllers/ResourcesController.cs b/Childrens-Social-Care-CPD/Controllers/ResourcesController.cs index f8e26575..aeca1730 100644 --- a/Childrens-Social-Care-CPD/Controllers/ResourcesController.cs +++ b/Childrens-Social-Care-CPD/Controllers/ResourcesController.cs @@ -1,4 +1,5 @@ -using Childrens_Social_Care_CPD.Core.Resources; +using Childrens_Social_Care_CPD.Configuration; +using Childrens_Social_Care_CPD.Core.Resources; using Childrens_Social_Care_CPD.Models; using Microsoft.AspNetCore.Mvc; @@ -17,12 +18,13 @@ public ResourcesQuery() public class ResourcesController : Controller { + private readonly IFeaturesConfig _featuresConfig; private readonly IResourcesSearchStrategy _strategy; - public ResourcesController(IResourcesSearchStrategy strategy) + public ResourcesController(IFeaturesConfig featuresConfig, IResourcesSearchStrategy strategy) { ArgumentNullException.ThrowIfNull(strategy); - + _featuresConfig = featuresConfig; _strategy = strategy; } @@ -30,6 +32,11 @@ public ResourcesController(IResourcesSearchStrategy strategy) [HttpGet] public async Task Search([FromQuery] ResourcesQuery query, bool preferencesSet = false, CancellationToken cancellationToken = default) { + if (!_featuresConfig.IsEnabled(Features.ResourcesAndLearning)) + { + return NotFound(); + } + var contextModel = new ContextModel(string.Empty, "Resources", "Resources", "Resources", true, preferencesSet); ViewData["ContextModel"] = contextModel; diff --git a/Childrens-Social-Care-CPD/Views/Shared/_ErrorLayout.cshtml b/Childrens-Social-Care-CPD/Views/Shared/_ErrorLayout.cshtml index 0ca54d9e..87080ef8 100644 --- a/Childrens-Social-Care-CPD/Views/Shared/_ErrorLayout.cshtml +++ b/Childrens-Social-Care-CPD/Views/Shared/_ErrorLayout.cshtml @@ -1,4 +1,7 @@ -@inject ICookieHelper _cookieHelper; +@using Childrens_Social_Care_CPD.Configuration; + +@inject ICookieHelper cookieHelper; +@inject IFeaturesConfig featuresConfig; @@ -6,7 +9,7 @@ @ViewBag.Title - @if (_cookieHelper.GetRequestAnalyticsCookieState(Context) == AnalyticsConsentState.Accepted) + @if (cookieHelper.GetRequestAnalyticsCookieState(Context) == AnalyticsConsentState.Accepted) { } @@ -78,14 +81,17 @@ -
  • - - Resources - - -
  • + @if (featuresConfig.IsEnabled(Features.ResourcesAndLearning)) + { +
  • + + Resources and learning + + +
  • + } diff --git a/Childrens-Social-Care-CPD/Views/Shared/_Header.cshtml b/Childrens-Social-Care-CPD/Views/Shared/_Header.cshtml index 10fabfc9..62677d8a 100644 --- a/Childrens-Social-Care-CPD/Views/Shared/_Header.cshtml +++ b/Childrens-Social-Care-CPD/Views/Shared/_Header.cshtml @@ -1,4 +1,8 @@ -@{ +@using Childrens_Social_Care_CPD.Configuration; + +@inject IFeaturesConfig featuresConfig + +@{ ContextModel viewModel = ViewBag.ContextModel; var category = viewModel.Category ?? "Home"; } @@ -53,8 +57,11 @@ RenderMenuItem("career", "Career stages", "career-stages", category == "Career information"); RenderMenuItem("developmentProgrammes", "Development programmes", "development-programmes", category == "Development programmes"); RenderMenuItem("exploreRoles", "Explore roles", "explore-roles", category == "Explore roles"); - RenderMenuItem("resources", "Resources", "resources", category == "Resources"); - + + if (featuresConfig.IsEnabled(Features.ResourcesAndLearning)) + { + RenderMenuItem("resources", "Resources and learning", "resources", category == "Resources"); + } }