From c24e8a4ee1eadd5b73e6f882517f17138bd81d96 Mon Sep 17 00:00:00 2001 From: Steve Saunders Date: Tue, 7 Jan 2025 17:00:18 +0000 Subject: [PATCH] chore(sonarcloud): Fix failing IDAM maintenance tests - missing mock setup --- .../FamilyHubs.Idams.Maintenance.UI.sln | 7 +++++++ .../Pages/DeleteUser.cshtml | 4 ++-- .../Pages/DeleteUser.cshtml.cs | 3 ++- .../UI/DeleteUserWebTests.cs | 17 +++++++++++++++-- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/ui/idam-maintenance-ui/FamilyHubs.Idams.Maintenance.UI.sln b/src/ui/idam-maintenance-ui/FamilyHubs.Idams.Maintenance.UI.sln index aec8621d0..eb38abe52 100644 --- a/src/ui/idam-maintenance-ui/FamilyHubs.Idams.Maintenance.UI.sln +++ b/src/ui/idam-maintenance-ui/FamilyHubs.Idams.Maintenance.UI.sln @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FamilyHubs.Idams.Maintenanc EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FamilyHubs.Idams.Maintenance.Data", "src\FamilyHubs.Idams.Maintenance.Data\FamilyHubs.Idams.Maintenance.Data.csproj", "{F2B53CDD-7D07-4266-80B4-EF762C77B376}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FamilyHubs.Idams.Maintenance.UnitTests", "tests\FamilyHubs.Idams.Maintenance.UnitTests\FamilyHubs.Idams.Maintenance.UnitTests.csproj", "{12079D2F-F42D-4B86-A50F-E4D0118B1138}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -31,6 +33,10 @@ Global {F2B53CDD-7D07-4266-80B4-EF762C77B376}.Debug|Any CPU.Build.0 = Debug|Any CPU {F2B53CDD-7D07-4266-80B4-EF762C77B376}.Release|Any CPU.ActiveCfg = Release|Any CPU {F2B53CDD-7D07-4266-80B4-EF762C77B376}.Release|Any CPU.Build.0 = Release|Any CPU + {12079D2F-F42D-4B86-A50F-E4D0118B1138}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {12079D2F-F42D-4B86-A50F-E4D0118B1138}.Debug|Any CPU.Build.0 = Debug|Any CPU + {12079D2F-F42D-4B86-A50F-E4D0118B1138}.Release|Any CPU.ActiveCfg = Release|Any CPU + {12079D2F-F42D-4B86-A50F-E4D0118B1138}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -39,6 +45,7 @@ Global {CB6D66EE-E5A0-4E6C-895A-97B1D6692E88} = {4988CDF2-ECFB-47DA-B9F6-A4DF3138E8CA} {47D73AD1-2441-42C7-A6CF-C4EA143ABF5C} = {4988CDF2-ECFB-47DA-B9F6-A4DF3138E8CA} {F2B53CDD-7D07-4266-80B4-EF762C77B376} = {4988CDF2-ECFB-47DA-B9F6-A4DF3138E8CA} + {12079D2F-F42D-4B86-A50F-E4D0118B1138} = {9C7D8127-6A9A-4AD7-ADCC-0C6DBD186166} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {A3C58AC5-822F-4BAD-961F-0382482F2F22} diff --git a/src/ui/idam-maintenance-ui/src/FamilyHubs.Idams.Maintenance.UI/Pages/DeleteUser.cshtml b/src/ui/idam-maintenance-ui/src/FamilyHubs.Idams.Maintenance.UI/Pages/DeleteUser.cshtml index 275ffdaca..b1fa1445a 100644 --- a/src/ui/idam-maintenance-ui/src/FamilyHubs.Idams.Maintenance.UI/Pages/DeleteUser.cshtml +++ b/src/ui/idam-maintenance-ui/src/FamilyHubs.Idams.Maintenance.UI/Pages/DeleteUser.cshtml @@ -32,13 +32,13 @@
- +
- + diff --git a/src/ui/idam-maintenance-ui/src/FamilyHubs.Idams.Maintenance.UI/Pages/DeleteUser.cshtml.cs b/src/ui/idam-maintenance-ui/src/FamilyHubs.Idams.Maintenance.UI/Pages/DeleteUser.cshtml.cs index 9d9aa4118..39cd81ad6 100644 --- a/src/ui/idam-maintenance-ui/src/FamilyHubs.Idams.Maintenance.UI/Pages/DeleteUser.cshtml.cs +++ b/src/ui/idam-maintenance-ui/src/FamilyHubs.Idams.Maintenance.UI/Pages/DeleteUser.cshtml.cs @@ -15,7 +15,7 @@ public class DeleteUserModel : PageModel [BindProperty] [Required] - public bool? DeleteUser { get; set; } = null; + public bool? DeleteUser { get; set; } public string Error { get; set; } = string.Empty; @@ -23,6 +23,7 @@ public DeleteUserModel(IIdamService idamService) { _idamService = idamService; } + public async Task OnGet(long accountId) { AccountId = accountId; diff --git a/src/ui/idam-maintenance-ui/tests/FamilyHubs.Idams.Maintenance.UnitTests/UI/DeleteUserWebTests.cs b/src/ui/idam-maintenance-ui/tests/FamilyHubs.Idams.Maintenance.UnitTests/UI/DeleteUserWebTests.cs index bcf4b6edc..e30ef96ea 100644 --- a/src/ui/idam-maintenance-ui/tests/FamilyHubs.Idams.Maintenance.UnitTests/UI/DeleteUserWebTests.cs +++ b/src/ui/idam-maintenance-ui/tests/FamilyHubs.Idams.Maintenance.UnitTests/UI/DeleteUserWebTests.cs @@ -1,5 +1,8 @@ +using FamilyHubs.Idams.Maintenance.Core.Services; using FamilyHubs.Idams.Maintenance.UnitTests.Support; using FluentAssertions; +using Microsoft.Extensions.DependencyInjection; +using NSubstitute; using Xunit; namespace FamilyHubs.Idams.Maintenance.UnitTests.UI; @@ -7,10 +10,18 @@ namespace FamilyHubs.Idams.Maintenance.UnitTests.UI; [Collection("WebTests")] public class DeleteUserWebTests : BaseWebTest { + private readonly IIdamService _idamService = Substitute.For(); + + protected override void Configure(IServiceCollection services) + { + services.AddSingleton(_idamService); + } + [Fact] public async Task NavigateToRoot_Index_HasRemoveUserRadioButton() { var account1 = TestAccounts.GetAccount1(); + _idamService.GetAccountById(account1.Id).Returns(account1); var page = await Navigate($"/DeleteUser?accountId={account1.Id}"); var removeUserButton = page.QuerySelector("[id=\"remove-user\"]"); @@ -21,6 +32,7 @@ public async Task NavigateToRoot_Index_HasRemoveUserRadioButton() public async Task NavigateToRoot_Index_HasDotNotRemoveUserRadioButton() { var account1 = TestAccounts.GetAccount1(); + _idamService.GetAccountById(account1.Id).Returns(account1); var page = await Navigate($"/DeleteUser?accountId={account1.Id}"); var dotNotRemoveUserButton = page.QuerySelector("[id=\"remove-user-2\"]"); @@ -31,9 +43,10 @@ public async Task NavigateToRoot_Index_HasDotNotRemoveUserRadioButton() public async Task NavigateToRoot_Index_HasContinueRadioButton() { var account1 = TestAccounts.GetAccount1(); + _idamService.GetAccountById(account1.Id).Returns(account1); var page = await Navigate($"/DeleteUser?accountId={account1.Id}"); - var dotNotRemoveUserButton = page.QuerySelector("[data-testid=\"continue-button\"]"); - dotNotRemoveUserButton.Should().NotBeNull(); + var continueButton = page.QuerySelector("[data-testid=\"continue-button\"]"); + continueButton.Should().NotBeNull(); } } \ No newline at end of file