From ffc35b050b63bfd44cfbb469a1de735bba694d9e Mon Sep 17 00:00:00 2001 From: Andrew Horth Date: Wed, 14 Aug 2024 14:32:34 +0100 Subject: [PATCH] Remove current alerts functionality backed by DQT (#1463) --- .../Dqt/Queries/CloseSanctionQuery.cs | 3 - .../Dqt/Queries/CreateSanctionQuery.cs | 10 - .../GetSanctionDetailsByContactIdQuery.cs | 5 - .../GetSanctionDetailsBySanctionIdQuery.cs | 3 - .../Dqt/QueryHandlers/CloseSanctionHandler.cs | 23 --- .../QueryHandlers/CreateSanctionHandler.cs | 23 --- .../GetSanctionDetailsByContactIdHandler.cs | 46 ----- .../GetSanctionDetailsBySanctionIdHandler.cs | 46 ----- .../JourneyNames.cs | 2 - .../Pages/Alerts/AddAlert/AddAlertState.cs | 19 -- .../Pages/Alerts/AddAlert/Confirm.cshtml | 41 ---- .../Pages/Alerts/AddAlert/Confirm.cshtml.cs | 86 --------- .../Pages/Alerts/AddAlert/Index.cshtml | 75 -------- .../Pages/Alerts/AddAlert/Index.cshtml.cs | 124 ------------ .../Pages/Alerts/Alert/Index.cshtml | 65 ------- .../Pages/Alerts/Alert/Index.cshtml.cs | 85 --------- .../Alerts/CloseAlert/CloseAlertState.cs | 13 -- .../Pages/Alerts/CloseAlert/Confirm.cshtml | 30 --- .../Pages/Alerts/CloseAlert/Confirm.cshtml.cs | 66 ------- .../Pages/Alerts/CloseAlert/Index.cshtml | 26 --- .../Pages/Alerts/CloseAlert/Index.cshtml.cs | 75 -------- .../Pages/Common/PersonSubNavigationTab.cs | 1 - .../Pages/Persons/Layout.cshtml | 4 - .../Pages/Persons/PersonDetail/Alerts.cshtml | 83 -------- .../Persons/PersonDetail/Alerts.cshtml.cs | 85 --------- .../Pages/Persons/PersonDetail/Index.cshtml | 10 - .../TeachingRecordSystem.SupportUi/Program.cs | 12 -- .../QueryTests/CloseSanctionTests.cs | 40 ---- .../QueryTests/CreateSanctionTests.cs | 49 ----- .../GetSanctionDetailsByContactIdTests.cs | 49 ----- .../GetSanctionDetailsBySanctionIdTests.cs | 33 ---- .../AlertTests.cs | 113 ----------- .../PageTests/Alerts/AddAlert/ConfirmTests.cs | 152 --------------- .../PageTests/Alerts/AddAlert/IndexTests.cs | 179 ------------------ .../PageTests/Alerts/Alert/IndexTests.cs | 85 --------- .../Alerts/CloseAlert/ConfirmTests.cs | 112 ----------- .../PageTests/Alerts/CloseAlert/IndexTests.cs | 171 ----------------- .../Persons/PersonDetail/AlertsTests.cs | 140 -------------- 38 files changed, 2184 deletions(-) delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/CloseSanctionQuery.cs delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/CreateSanctionQuery.cs delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/GetSanctionDetailsByContactIdQuery.cs delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/GetSanctionDetailsBySanctionIdQuery.cs delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/CloseSanctionHandler.cs delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/CreateSanctionHandler.cs delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/GetSanctionDetailsByContactIdHandler.cs delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/GetSanctionDetailsBySanctionIdHandler.cs delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/AddAlertState.cs delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Confirm.cshtml delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Confirm.cshtml.cs delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Index.cshtml delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Index.cshtml.cs delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/Alert/Index.cshtml delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/Alert/Index.cshtml.cs delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/CloseAlertState.cs delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/Confirm.cshtml delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/Confirm.cshtml.cs delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/Index.cshtml delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/Index.cshtml.cs delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/PersonDetail/Alerts.cshtml delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/PersonDetail/Alerts.cshtml.cs delete mode 100644 TeachingRecordSystem/tests/TeachingRecordSystem.Core.Dqt.CrmIntegrationTests/QueryTests/CloseSanctionTests.cs delete mode 100644 TeachingRecordSystem/tests/TeachingRecordSystem.Core.Dqt.CrmIntegrationTests/QueryTests/CreateSanctionTests.cs delete mode 100644 TeachingRecordSystem/tests/TeachingRecordSystem.Core.Dqt.CrmIntegrationTests/QueryTests/GetSanctionDetailsByContactIdTests.cs delete mode 100644 TeachingRecordSystem/tests/TeachingRecordSystem.Core.Dqt.CrmIntegrationTests/QueryTests/GetSanctionDetailsBySanctionIdTests.cs delete mode 100644 TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.EndToEndTests/AlertTests.cs delete mode 100644 TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/ConfirmTests.cs delete mode 100644 TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/IndexTests.cs delete mode 100644 TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/Alert/IndexTests.cs delete mode 100644 TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/CloseAlert/ConfirmTests.cs delete mode 100644 TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/CloseAlert/IndexTests.cs delete mode 100644 TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Persons/PersonDetail/AlertsTests.cs diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/CloseSanctionQuery.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/CloseSanctionQuery.cs deleted file mode 100644 index 17b60f9e0..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/CloseSanctionQuery.cs +++ /dev/null @@ -1,3 +0,0 @@ -namespace TeachingRecordSystem.Core.Dqt.Queries; - -public record CloseSanctionQuery(Guid SanctionId, DateOnly EndDate) : ICrmQuery; diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/CreateSanctionQuery.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/CreateSanctionQuery.cs deleted file mode 100644 index c634c387e..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/CreateSanctionQuery.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace TeachingRecordSystem.Core.Dqt.Queries; - -public record CreateSanctionQuery : ICrmQuery -{ - public required Guid ContactId { get; init; } - public required Guid SanctionCodeId { get; init; } - public required string Details { get; init; } - public required string? Link { get; init; } - public required DateOnly StartDate { get; init; } -} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/GetSanctionDetailsByContactIdQuery.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/GetSanctionDetailsByContactIdQuery.cs deleted file mode 100644 index c54badbd9..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/GetSanctionDetailsByContactIdQuery.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace TeachingRecordSystem.Core.Dqt.Queries; - -public record GetSanctionDetailsByContactIdQuery(Guid ContactId) : ICrmQuery; - -public record SanctionDetailResult(dfeta_sanction Sanction, string Description); diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/GetSanctionDetailsBySanctionIdQuery.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/GetSanctionDetailsBySanctionIdQuery.cs deleted file mode 100644 index c3007eba6..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/GetSanctionDetailsBySanctionIdQuery.cs +++ /dev/null @@ -1,3 +0,0 @@ -namespace TeachingRecordSystem.Core.Dqt.Queries; - -public record GetSanctionDetailsBySanctionIdQuery(Guid SanctionId) : ICrmQuery; diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/CloseSanctionHandler.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/CloseSanctionHandler.cs deleted file mode 100644 index 5b57dd7cd..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/CloseSanctionHandler.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Microsoft.PowerPlatform.Dataverse.Client; -using Microsoft.Xrm.Sdk.Messages; -using TeachingRecordSystem.Core.Dqt.Queries; - -namespace TeachingRecordSystem.Core.Dqt.QueryHandlers; - -public class CloseSanctionHandler : ICrmQueryHandler -{ - public async Task Execute(CloseSanctionQuery query, IOrganizationServiceAsync organizationService) - { - await organizationService.ExecuteAsync(new UpdateRequest() - { - Target = new dfeta_sanction() - { - Id = query.SanctionId, - dfeta_EndDate = query.EndDate.ToDateTimeWithDqtBstFix(isLocalTime: true), - dfeta_Spent = true - } - }); - - return true; - } -} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/CreateSanctionHandler.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/CreateSanctionHandler.cs deleted file mode 100644 index bc1a05374..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/CreateSanctionHandler.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Microsoft.PowerPlatform.Dataverse.Client; -using TeachingRecordSystem.Core.Dqt.Queries; - -namespace TeachingRecordSystem.Core.Dqt.QueryHandlers; - -public class CreateSanctionHandler : ICrmQueryHandler -{ - public async Task Execute(CreateSanctionQuery query, IOrganizationServiceAsync organizationService) - { - var sanction = new dfeta_sanction() - { - Id = Guid.NewGuid(), - dfeta_PersonId = query.ContactId.ToEntityReference(Contact.EntityLogicalName), - dfeta_SanctionCodeId = query.SanctionCodeId.ToEntityReference(dfeta_sanctioncode.EntityLogicalName), - dfeta_SanctionDetails = query.Details, - dfeta_DetailsLink = query.Link, - dfeta_StartDate = query.StartDate.ToDateTimeWithDqtBstFix(isLocalTime: true) - }; - - var sanctionId = await organizationService.CreateAsync(sanction); - return sanctionId; - } -} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/GetSanctionDetailsByContactIdHandler.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/GetSanctionDetailsByContactIdHandler.cs deleted file mode 100644 index f809537d4..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/GetSanctionDetailsByContactIdHandler.cs +++ /dev/null @@ -1,46 +0,0 @@ -using Microsoft.PowerPlatform.Dataverse.Client; -using Microsoft.Xrm.Sdk.Messages; -using Microsoft.Xrm.Sdk.Query; -using TeachingRecordSystem.Core.Dqt.Queries; - -namespace TeachingRecordSystem.Core.Dqt.QueryHandlers; - -public class GetSanctionDetailsByContactIdHandler : ICrmQueryHandler -{ - public async Task Execute(GetSanctionDetailsByContactIdQuery query, IOrganizationServiceAsync organizationService) - { - var filter = new FilterExpression(); - filter.AddCondition(dfeta_sanction.Fields.dfeta_PersonId, ConditionOperator.Equal, query.ContactId); - - var queryExpression = new QueryExpression(dfeta_sanction.EntityLogicalName) - { - ColumnSet = new ColumnSet( - dfeta_sanction.PrimaryIdAttribute, - dfeta_sanction.Fields.dfeta_SanctionDetails, - dfeta_sanction.Fields.dfeta_PersonId, - dfeta_sanction.Fields.dfeta_StartDate, - dfeta_sanction.Fields.dfeta_EndDate, - dfeta_sanction.Fields.dfeta_Spent, - dfeta_sanction.Fields.dfeta_DetailsLink, - dfeta_sanction.Fields.StateCode), - Criteria = filter - }; - - var sanctionCodeLink = queryExpression.AddLink( - dfeta_sanctioncode.EntityLogicalName, - dfeta_sanction.Fields.dfeta_SanctionCodeId, - dfeta_sanctioncode.PrimaryIdAttribute, - JoinOperator.Inner); - - sanctionCodeLink.Columns = new ColumnSet(dfeta_sanctioncode.PrimaryIdAttribute, dfeta_sanctioncode.Fields.dfeta_name); - sanctionCodeLink.EntityAlias = typeof(dfeta_sanctioncode).Name; - - var request = new RetrieveMultipleRequest() - { - Query = queryExpression - }; - - var result = (RetrieveMultipleResponse)await organizationService.ExecuteAsync(request); - return result.EntityCollection.Entities.Select(entity => new SanctionDetailResult(entity.ToEntity(), entity.Extract().dfeta_name)).ToArray(); - } -} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/GetSanctionDetailsBySanctionIdHandler.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/GetSanctionDetailsBySanctionIdHandler.cs deleted file mode 100644 index 9d9351d0c..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/GetSanctionDetailsBySanctionIdHandler.cs +++ /dev/null @@ -1,46 +0,0 @@ -using Microsoft.PowerPlatform.Dataverse.Client; -using Microsoft.Xrm.Sdk.Messages; -using Microsoft.Xrm.Sdk.Query; -using TeachingRecordSystem.Core.Dqt.Queries; - -namespace TeachingRecordSystem.Core.Dqt.QueryHandlers; - -public class GetSanctionDetailsBySanctionIdHandler : ICrmQueryHandler -{ - public async Task Execute(GetSanctionDetailsBySanctionIdQuery query, IOrganizationServiceAsync organizationService) - { - var filter = new FilterExpression(); - filter.AddCondition(dfeta_sanction.PrimaryIdAttribute, ConditionOperator.Equal, query.SanctionId); - - var queryExpression = new QueryExpression(dfeta_sanction.EntityLogicalName) - { - ColumnSet = new ColumnSet( - dfeta_sanction.PrimaryIdAttribute, - dfeta_sanction.Fields.dfeta_SanctionDetails, - dfeta_sanction.Fields.dfeta_PersonId, - dfeta_sanction.Fields.dfeta_StartDate, - dfeta_sanction.Fields.dfeta_EndDate, - dfeta_sanction.Fields.dfeta_Spent, - dfeta_sanction.Fields.dfeta_DetailsLink, - dfeta_sanction.Fields.StateCode), - Criteria = filter - }; - - var sanctionCodeLink = queryExpression.AddLink( - dfeta_sanctioncode.EntityLogicalName, - dfeta_sanction.Fields.dfeta_SanctionCodeId, - dfeta_sanctioncode.PrimaryIdAttribute, - JoinOperator.Inner); - - sanctionCodeLink.Columns = new ColumnSet(dfeta_sanctioncode.PrimaryIdAttribute, dfeta_sanctioncode.Fields.dfeta_name); - sanctionCodeLink.EntityAlias = typeof(dfeta_sanctioncode).Name; - - var request = new RetrieveMultipleRequest() - { - Query = queryExpression - }; - - var result = (RetrieveMultipleResponse)await organizationService.ExecuteAsync(request); - return result.EntityCollection.Entities.Select(entity => new SanctionDetailResult(entity.ToEntity(), entity.Extract().dfeta_name)).SingleOrDefault(); - } -} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/JourneyNames.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/JourneyNames.cs index 6dbc9e659..b8683a604 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/JourneyNames.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/JourneyNames.cs @@ -2,8 +2,6 @@ namespace TeachingRecordSystem.SupportUi; public static class JourneyNames { - public const string AddAlert = nameof(AddAlert); - public const string CloseAlert = nameof(CloseAlert); public const string EditName = nameof(EditName); public const string EditDateOfBirth = nameof(EditDateOfBirth); public const string AddMq = nameof(AddMq); diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/AddAlertState.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/AddAlertState.cs deleted file mode 100644 index 24119a84e..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/AddAlertState.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using System.Text.Json.Serialization; - -namespace TeachingRecordSystem.SupportUi.Pages.Alerts.AddAlert; - -public class AddAlertState -{ - public Guid? AlertTypeId { get; set; } - - public string? Details { get; set; } - - public string? Link { get; set; } - - public DateOnly? StartDate { get; set; } - - [JsonIgnore] - [MemberNotNullWhen(true, nameof(AlertTypeId), nameof(Details), nameof(StartDate))] - public bool IsComplete => AlertTypeId.HasValue && !string.IsNullOrWhiteSpace(Details) && StartDate.HasValue; -} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Confirm.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Confirm.cshtml deleted file mode 100644 index e92d59083..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Confirm.cshtml +++ /dev/null @@ -1,41 +0,0 @@ -@page "/alerts/add/confirm" -@model TeachingRecordSystem.SupportUi.Pages.Alerts.AddAlert.ConfirmModel -@{ - ViewBag.Title = "Confirm alert information"; -} - -@section BeforeContent { - Back -} - -

@ViewBag.Title

- -
-
-
- - - Alert type - @Model.AlertType - - - Details - - - @if (!string.IsNullOrWhiteSpace(Model.Link)) - { - - Link - @Model.Link - - } - - Start date - @Model.StartDate!.Value.ToString("dd/MM/yyyy") - - - - Confirm -
-
-
diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Confirm.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Confirm.cshtml.cs deleted file mode 100644 index 06e0f0028..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Confirm.cshtml.cs +++ /dev/null @@ -1,86 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.RazorPages; -using TeachingRecordSystem.Core.Dqt.Models; -using TeachingRecordSystem.Core.Dqt.Queries; - -namespace TeachingRecordSystem.SupportUi.Pages.Alerts.AddAlert; - -[Journey(JourneyNames.AddAlert), RequireJourneyInstance] -public class ConfirmModel : PageModel -{ - private readonly TrsLinkGenerator _linkGenerator; - private readonly ICrmQueryDispatcher _crmQueryDispatcher; - private readonly ReferenceDataCache _referenceDataCache; - - public ConfirmModel( - TrsLinkGenerator linkGenerator, - ICrmQueryDispatcher crmQueryDispatcher, - ReferenceDataCache referenceDataCache) - { - _linkGenerator = linkGenerator; - _crmQueryDispatcher = crmQueryDispatcher; - _referenceDataCache = referenceDataCache; - } - - public JourneyInstance? JourneyInstance { get; set; } - - [FromQuery] - public Guid PersonId { get; set; } - - public Guid? AlertTypeId { get; set; } - - public string? AlertType { get; set; } - - public string? Details { get; set; } - - public string? Link { get; set; } - - public DateOnly? StartDate { get; set; } - - public async Task OnPost() - { - await _crmQueryDispatcher.ExecuteQuery( - new CreateSanctionQuery() - { - ContactId = PersonId, - SanctionCodeId = AlertTypeId!.Value, - Details = Details!, - Link = Link, - StartDate = StartDate!.Value - }); - - await JourneyInstance!.CompleteAsync(); - - TempData.SetFlashSuccess("Alert added"); - - return Redirect(_linkGenerator.PersonAlerts(PersonId)); - } - - public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next) - { - var person = await _crmQueryDispatcher.ExecuteQuery(new GetActiveContactDetailByIdQuery(PersonId, new ColumnSet(Contact.Fields.Id))); - if (person is null) - { - context.Result = NotFound(); - return; - } - - if (!JourneyInstance!.State.IsComplete) - { - context.Result = Redirect(_linkGenerator.AlertAdd(PersonId, JourneyInstance!.InstanceId)); - return; - } - - var sanctionCodeId = JourneyInstance!.State.AlertTypeId!.Value; - var sanctionCode = await _referenceDataCache.GetSanctionCodeById(sanctionCodeId); - - AlertTypeId = sanctionCodeId; - AlertType = sanctionCode.dfeta_name; - Details = JourneyInstance!.State.Details; - Link = JourneyInstance!.State.Link; - StartDate = JourneyInstance!.State.StartDate; - - await next(); - } -} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Index.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Index.cshtml deleted file mode 100644 index 519d67aea..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Index.cshtml +++ /dev/null @@ -1,75 +0,0 @@ -@page "/alerts/add" -@model IndexModel -@addTagHelper *, Joonasw.AspNetCore.SecurityHeaders -@{ - ViewBag.Title = "Add an alert"; -} - -@section Styles { - -} - -@section Scripts { - - -} - -@section BeforeContent { - Back -} - -

@ViewBag.Title

- -
-
-
- - - @foreach (var alertType in Model.AlertTypes!) - { - @alertType.Name - } - - - - - - - - - - - - - Continue - -
-
diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Index.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Index.cshtml.cs deleted file mode 100644 index ad0a59b4c..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Index.cshtml.cs +++ /dev/null @@ -1,124 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.RazorPages; -using TeachingRecordSystem.Core.Dqt.Models; -using TeachingRecordSystem.Core.Dqt.Queries; -using TeachingRecordSystem.SupportUi.Pages.Common; - -namespace TeachingRecordSystem.SupportUi.Pages.Alerts.AddAlert; - -[Journey(JourneyNames.AddAlert), ActivatesJourney, RequireJourneyInstance] -public class IndexModel : PageModel -{ - private readonly TrsLinkGenerator _linkGenerator; - private readonly ICrmQueryDispatcher _crmQueryDispatcher; - private readonly ReferenceDataCache _referenceDataCache; - private readonly SanctionTextLookup _sanctionTextLookup; - - public IndexModel( - TrsLinkGenerator linkGenerator, - ICrmQueryDispatcher crmQueryDispatcher, - ReferenceDataCache referenceDataCache, - SanctionTextLookup sanctionTextLookup) - { - _linkGenerator = linkGenerator; - _crmQueryDispatcher = crmQueryDispatcher; - _referenceDataCache = referenceDataCache; - _sanctionTextLookup = sanctionTextLookup; - } - - public JourneyInstance? JourneyInstance { get; set; } - - [FromQuery] - public Guid PersonId { get; set; } - - [BindProperty] - [Display(Name = "Alert type")] - public Guid? AlertTypeId { get; set; } - - [BindProperty] - public string? Details { get; set; } - - [BindProperty] - [Display(Description = "Optional")] - public string? Link { get; set; } - - [BindProperty] - [Display(Name = "Start date")] - public DateOnly? StartDate { get; set; } - - public AlertType[]? AlertTypes { get; set; } - - public async Task OnPost() - { - if (AlertTypeId is null) - { - ModelState.AddModelError(nameof(AlertTypeId), "Add an alert type"); - } - - if (string.IsNullOrWhiteSpace(Details)) - { - ModelState.AddModelError(nameof(Details), "Add details"); - } - - if (!string.IsNullOrEmpty(Link) && - (!Uri.TryCreate(Link, UriKind.Absolute, out var uri) || - (uri.Scheme != "http" && uri.Scheme != "https"))) - { - ModelState.AddModelError(nameof(Link), "Enter a valid URL"); - } - - if (StartDate is null) - { - ModelState.AddModelError(nameof(StartDate), "Add a start date"); - } - - if (!ModelState.IsValid) - { - return this.PageWithErrors(); - } - - await JourneyInstance!.UpdateStateAsync(s => - { - s.AlertTypeId = AlertTypeId; - s.Details = Details; - s.Link = Link; - s.StartDate = StartDate; - }); - - return Redirect(_linkGenerator.AlertAddConfirm(PersonId, JourneyInstance!.InstanceId)); - } - - public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next) - { - var person = await _crmQueryDispatcher.ExecuteQuery(new GetActiveContactDetailByIdQuery(PersonId, new ColumnSet(Contact.Fields.Id))); - if (person is null) - { - context.Result = NotFound(); - return; - } - - var sanctionCodes = await _referenceDataCache.GetSanctionCodes(); - AlertTypes = sanctionCodes - .Select(MapSanctionCode) - .OrderBy(a => a.Name) - .ToArray(); - - AlertTypeId ??= JourneyInstance!.State.AlertTypeId; - Details ??= JourneyInstance!.State.Details; - Link ??= JourneyInstance!.State.Link; - StartDate ??= JourneyInstance!.State.StartDate; - - await next(); - } - - private AlertType MapSanctionCode(dfeta_sanctioncode sanctionCode) => - new AlertType() - { - AlertTypeId = sanctionCode.dfeta_sanctioncodeId!.Value, - Value = sanctionCode.dfeta_Value, - Name = sanctionCode.dfeta_name, - DefaultText = _sanctionTextLookup.GetSanctionDefaultText(sanctionCode.dfeta_Value) ?? string.Empty - }; -} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/Alert/Index.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/Alert/Index.cshtml deleted file mode 100644 index 0ae69793f..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/Alert/Index.cshtml +++ /dev/null @@ -1,65 +0,0 @@ -@page "/alerts/{alertId}" -@model IndexModel -@{ - ViewBag.Title = Model.Alert!.Description; -} - -@section BeforeContent { - Back -} - -

@ViewBag.Title

- -
-
- - - - - - - - - - - - - - - -
Start dateEnd dateStatus
@(Model.Alert.StartDate.HasValue ? Model.Alert.StartDate.Value.ToString("dd/MM/yyyy") : string.Empty)@(Model.Alert.EndDate.HasValue ? Model.Alert.EndDate.Value.ToString("dd/MM/yyyy") : string.Empty)@Model.Alert.Status
-
-
- -
- -
-
- @if (!string.IsNullOrEmpty(Model.Alert.Details) || !string.IsNullOrEmpty(Model.Alert.DetailsLink)) - { -

Details

- @if (!string.IsNullOrEmpty(Model.Alert.Details)) - { - - } - - @if (!string.IsNullOrEmpty(Model.Alert.DetailsLink)) - { - See full case details (opens in new tab) - } - } - - @if (Model.IsActive) - { -
- Mark alert as inactive -
- } - else - { -
- Remove inactive status -
- } -
-
diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/Alert/Index.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/Alert/Index.cshtml.cs deleted file mode 100644 index 870c952d0..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/Alert/Index.cshtml.cs +++ /dev/null @@ -1,85 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.RazorPages; -using TeachingRecordSystem.Core.Dqt.Models; -using TeachingRecordSystem.Core.Dqt.Queries; -using TeachingRecordSystem.SupportUi.Pages.Common; - -namespace TeachingRecordSystem.SupportUi.Pages.Alerts.Alert; - -public class IndexModel : PageModel -{ - private readonly TrsLinkGenerator _linkGenerator; - private readonly ICrmQueryDispatcher _crmQueryDispatcher; - - public IndexModel( - TrsLinkGenerator linkGenerator, - ICrmQueryDispatcher crmQueryDispatcher) - { - _linkGenerator = linkGenerator; - _crmQueryDispatcher = crmQueryDispatcher; - } - - [FromRoute] - public Guid AlertId { get; set; } - - public AlertInfo? Alert { get; set; } - - public bool IsActive { get; set; } - - public Guid? PersonId { get; set; } - - public async Task OnPostSetActive() - { - await _crmQueryDispatcher.ExecuteQuery(new UpdateSanctionStateQuery(AlertId, dfeta_sanctionState.Active)); - - IsActive = true; - TempData.SetFlashSuccess("Inactive status removed"); - - return Redirect(_linkGenerator.Alert(AlertId)); - } - - public async Task OnPostSetInactive() - { - await _crmQueryDispatcher.ExecuteQuery(new UpdateSanctionStateQuery(AlertId, dfeta_sanctionState.Inactive)); - - IsActive = false; - TempData.SetFlashSuccess("Status changed to inactive"); - - return Redirect(_linkGenerator.Alert(AlertId)); - } - - public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next) - { - var sanction = await _crmQueryDispatcher.ExecuteQuery(new GetSanctionDetailsBySanctionIdQuery(AlertId)); - if (sanction is null) - { - context.Result = NotFound(); - return; - } - - Alert = MapSanction(sanction); - IsActive = sanction.Sanction.StateCode == dfeta_sanctionState.Active; - PersonId = sanction.Sanction.dfeta_PersonId.Id; - - await next(); - } - - private AlertInfo MapSanction(SanctionDetailResult sanction) - { - var alertStatus = sanction.Sanction.StateCode == dfeta_sanctionState.Inactive ? AlertStatus.Inactive : - sanction.Sanction.dfeta_EndDate is null ? AlertStatus.Active : - AlertStatus.Closed; - - return new AlertInfo() - { - AlertId = sanction.Sanction.Id, - Description = sanction.Description, - Details = sanction.Sanction.dfeta_SanctionDetails, - DetailsLink = sanction.Sanction.dfeta_DetailsLink, - StartDate = sanction.Sanction.dfeta_StartDate.ToDateOnlyWithDqtBstFix(isLocalTime: true), - EndDate = sanction.Sanction.dfeta_EndDate.ToDateOnlyWithDqtBstFix(isLocalTime: true), - Status = alertStatus - }; - } -} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/CloseAlertState.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/CloseAlertState.cs deleted file mode 100644 index c7f6df702..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/CloseAlertState.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using System.Text.Json.Serialization; - -namespace TeachingRecordSystem.SupportUi.Pages.Alerts.CloseAlert; - -public class CloseAlertState -{ - public DateOnly? EndDate { get; set; } - - [JsonIgnore] - [MemberNotNullWhen(true, nameof(EndDate))] - public bool IsComplete => EndDate.HasValue; -} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/Confirm.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/Confirm.cshtml deleted file mode 100644 index 929c1738f..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/Confirm.cshtml +++ /dev/null @@ -1,30 +0,0 @@ -@page "/alerts/{alertId}/close/confirm" -@model TeachingRecordSystem.SupportUi.Pages.Alerts.CloseAlert.ConfirmModel -@{ - ViewBag.Title = "Confirm closing alert"; -} - -@section BeforeContent { - Back -} - -

@ViewBag.Title

- -
-
-
- - - Alert type - @Model.AlertType - - - End date - @Model.EndDate.ToString("dd/MM/yyyy") - - - - Confirm -
-
-
diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/Confirm.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/Confirm.cshtml.cs deleted file mode 100644 index 3edc8304e..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/Confirm.cshtml.cs +++ /dev/null @@ -1,66 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.RazorPages; -using TeachingRecordSystem.Core.Dqt.Queries; - -namespace TeachingRecordSystem.SupportUi.Pages.Alerts.CloseAlert; - -[Journey(JourneyNames.CloseAlert), RequireJourneyInstance] -public class ConfirmModel : PageModel -{ - private readonly TrsLinkGenerator _linkGenerator; - private readonly ICrmQueryDispatcher _crmQueryDispatcher; - - public ConfirmModel( - TrsLinkGenerator linkGenerator, - ICrmQueryDispatcher crmQueryDispatcher) - { - _linkGenerator = linkGenerator; - _crmQueryDispatcher = crmQueryDispatcher; - } - - public JourneyInstance? JourneyInstance { get; set; } - - [FromRoute] - public Guid AlertId { get; set; } - - public string? AlertType { get; set; } - - public Guid? PersonId { get; set; } - - public DateOnly EndDate { get; set; } - - public async Task OnPost() - { - await _crmQueryDispatcher.ExecuteQuery(new CloseSanctionQuery(AlertId, EndDate)); - await JourneyInstance!.CompleteAsync(); - - TempData.SetFlashSuccess("Alert closed"); - - return Redirect(_linkGenerator.PersonAlerts(PersonId!.Value)); - } - - public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next) - { - var alert = await _crmQueryDispatcher.ExecuteQuery(new GetSanctionDetailsBySanctionIdQuery(AlertId)); - if (alert is null - || alert.Sanction.StateCode != Core.Dqt.Models.dfeta_sanctionState.Active - || alert.Sanction.dfeta_EndDate is not null) - { - context.Result = NotFound(); - return; - } - - if (!JourneyInstance!.State.IsComplete) - { - context.Result = Redirect(_linkGenerator.AlertClose(AlertId, JourneyInstance!.InstanceId)); - return; - } - - AlertType = alert.Description; - PersonId = alert.Sanction.dfeta_PersonId.Id; - EndDate = JourneyInstance!.State.EndDate.Value; - - await next(); - } -} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/Index.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/Index.cshtml deleted file mode 100644 index a2b12f326..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/Index.cshtml +++ /dev/null @@ -1,26 +0,0 @@ -@page "/alerts/{alertId}/close" -@model IndexModel -@{ - ViewBag.Title = "Close alert"; -} - -@section BeforeContent { - Back -} - -

@ViewBag.Title

- -
-
-
- - - - - - - Continue -
-
-
- diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/Index.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/Index.cshtml.cs deleted file mode 100644 index 286783022..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/Index.cshtml.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.RazorPages; -using TeachingRecordSystem.Core.Dqt.Queries; - -namespace TeachingRecordSystem.SupportUi.Pages.Alerts.CloseAlert; - -[Journey(JourneyNames.CloseAlert), ActivatesJourney, RequireJourneyInstance] -public class IndexModel : PageModel -{ - private readonly TrsLinkGenerator _linkGenerator; - private readonly ICrmQueryDispatcher _crmQueryDispatcher; - - public IndexModel( - TrsLinkGenerator linkGenerator, - ICrmQueryDispatcher crmQueryDispatcher) - { - _linkGenerator = linkGenerator; - _crmQueryDispatcher = crmQueryDispatcher; - } - - public JourneyInstance? JourneyInstance { get; set; } - - [FromRoute] - public Guid AlertId { get; set; } - - [BindProperty] - [Display(Name = "End date")] - public DateOnly? EndDate { get; set; } - - public Guid? PersonId { get; set; } - - public DateOnly? StartDate { get; set; } - - public async Task OnPost() - { - if (EndDate is null) - { - ModelState.AddModelError(nameof(EndDate), "Add an end date"); - } - - if (EndDate <= StartDate) - { - ModelState.AddModelError(nameof(EndDate), "End date must be after the start date"); - } - - if (!ModelState.IsValid) - { - return this.PageWithErrors(); - } - - await JourneyInstance!.UpdateStateAsync(s => s.EndDate = EndDate); - - return Redirect(_linkGenerator.AlertCloseConfirm(AlertId, JourneyInstance!.InstanceId)); - } - - public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next) - { - var alert = await _crmQueryDispatcher.ExecuteQuery(new GetSanctionDetailsBySanctionIdQuery(AlertId)); - if (alert is null - || alert.Sanction.StateCode != Core.Dqt.Models.dfeta_sanctionState.Active - || alert.Sanction.dfeta_EndDate is not null) - { - context.Result = NotFound(); - return; - } - - PersonId = alert.Sanction.dfeta_PersonId.Id; - StartDate = alert.Sanction.dfeta_StartDate.ToDateOnlyWithDqtBstFix(isLocalTime: true); - EndDate ??= JourneyInstance!.State.EndDate; - - await next(); - } -} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Common/PersonSubNavigationTab.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Common/PersonSubNavigationTab.cs index b45ad621c..60d96d91e 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Common/PersonSubNavigationTab.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Common/PersonSubNavigationTab.cs @@ -4,6 +4,5 @@ public enum PersonSubNavigationTab { General, Qualifications, - Alerts, ChangeHistory } diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/Layout.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/Layout.cshtml index 3e1d77a83..0e61c4af2 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/Layout.cshtml +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/Layout.cshtml @@ -27,10 +27,6 @@ Qualifications -
  • - Alerts -
  • -
  • Change history
  • diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/PersonDetail/Alerts.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/PersonDetail/Alerts.cshtml deleted file mode 100644 index d08edd737..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/PersonDetail/Alerts.cshtml +++ /dev/null @@ -1,83 +0,0 @@ -@page "/persons/{personId}/alerts" -@using TeachingRecordSystem.SupportUi.Pages.Common; -@model TeachingRecordSystem.SupportUi.Pages.Persons.PersonDetail.AlertsModel -@{ - Layout = "Layout"; - ViewBag.SelectedTab = PersonSubNavigationTab.Alerts; - ViewBag.PersonId = Model.PersonId; - ViewBag.Search = Model.Search; - ViewBag.SortBy = Model.SortBy; - ViewBag.PageNumber = Model.PageNumber; - ViewBag.Title = Model.Name; -} - -

    Current alerts

    - -@if (Model.CurrentAlerts is null || Model.CurrentAlerts.Length == 0) -{ -

    No current alerts

    -} -else -{ - @foreach (var alert in Model.CurrentAlerts) - { - - @alert.Description - - Close - - - - Start date - @(alert.StartDate.HasValue ? alert.StartDate.Value.ToString("dd/MM/yyyy") : string.Empty) - - - Details - - @if (!string.IsNullOrEmpty(@alert.Details)) - { - - } - - - @if (!string.IsNullOrEmpty(@alert.DetailsLink)) - { - - Link - - See full case details (opens in new tab) - - - } - - - } -} - -Add an alert - -@if (Model.PreviousAlerts is not null && Model.PreviousAlerts.Length > 0) -{ - - - - - - - - - - - - @foreach (var alert in Model.PreviousAlerts) - { - - - - - - - } - -
    Previous alerts
    AlertStart dateEnd dateStatus
    @alert.Description@(alert.StartDate.HasValue ? alert.StartDate.Value.ToString("dd/MM/yyyy") : string.Empty)@(alert.EndDate.HasValue ? alert.EndDate.Value.ToString("dd/MM/yyyy") : string.Empty)@alert.Status
    -} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/PersonDetail/Alerts.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/PersonDetail/Alerts.cshtml.cs deleted file mode 100644 index 0426644c8..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/PersonDetail/Alerts.cshtml.cs +++ /dev/null @@ -1,85 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using TeachingRecordSystem.Core.Dqt.Models; -using TeachingRecordSystem.Core.Dqt.Queries; -using TeachingRecordSystem.SupportUi.Pages.Common; - -namespace TeachingRecordSystem.SupportUi.Pages.Persons.PersonDetail; - -public partial class AlertsModel : PageModel -{ - private readonly ICrmQueryDispatcher _crmQueryDispatcher; - - public AlertsModel(ICrmQueryDispatcher crmQueryDispatcher) - { - _crmQueryDispatcher = crmQueryDispatcher; - } - - [FromRoute] - public Guid PersonId { get; set; } - - [FromQuery] - public string? Search { get; set; } - - [FromQuery] - public int? PageNumber { get; set; } - - [FromQuery] - public ContactSearchSortByOption? SortBy { get; set; } - - public string? Name { get; set; } - - public AlertInfo[]? CurrentAlerts { get; set; } - - public AlertInfo[]? PreviousAlerts { get; set; } - - public async Task OnGet() - { - var contactDetail = await _crmQueryDispatcher.ExecuteQuery( - new GetActiveContactDetailByIdQuery( - PersonId, - new ColumnSet( - Contact.Fields.FirstName, - Contact.Fields.MiddleName, - Contact.Fields.LastName, - Contact.Fields.dfeta_StatedFirstName, - Contact.Fields.dfeta_StatedMiddleName, - Contact.Fields.dfeta_StatedLastName))); - - Name = contactDetail!.Contact.ResolveFullName(includeMiddleName: false); - - var sanctions = await _crmQueryDispatcher.ExecuteQuery(new GetSanctionDetailsByContactIdQuery(PersonId)); - - var allAlerts = sanctions!.Select(MapSanction); - - CurrentAlerts = allAlerts - .Where(alert => alert.Status == AlertStatus.Active) - .OrderBy(a => a.StartDate) - .ToArray(); - - PreviousAlerts = allAlerts - .Except(CurrentAlerts) - .OrderBy(a => a.StartDate) - .ToArray(); - - return Page(); - } - - private AlertInfo MapSanction(SanctionDetailResult sanction) - { - var alertStatus = sanction.Sanction.StateCode == dfeta_sanctionState.Inactive ? AlertStatus.Inactive : - sanction.Sanction.dfeta_EndDate is null ? AlertStatus.Active : - AlertStatus.Closed; - - return new AlertInfo() - { - AlertId = sanction.Sanction.Id, - Description = sanction.Description, - Details = sanction.Sanction.dfeta_SanctionDetails, - DetailsLink = sanction.Sanction.dfeta_DetailsLink, - StartDate = sanction.Sanction.dfeta_StartDate.ToDateOnlyWithDqtBstFix(isLocalTime: true), - EndDate = sanction.Sanction.dfeta_EndDate.ToDateOnlyWithDqtBstFix(isLocalTime: true), - Status = alertStatus - }; - } -} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/PersonDetail/Index.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/PersonDetail/Index.cshtml index 4e0455c61..bcbf5c506 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/PersonDetail/Index.cshtml +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/PersonDetail/Index.cshtml @@ -12,16 +12,6 @@ ViewBag.Title = Model.Person!.Name; } -@if (Model.Person.HasAlerts) -{ - -

    - Alert on record. - View alerts. -

    -
    -} - @{ var personDetailModel = new PersonDetailViewModel() { diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Program.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Program.cs index a15e379c2..b70adb9cc 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Program.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Program.cs @@ -198,18 +198,6 @@ .AddTransient() .AddFormFlow(options => { - options.JourneyRegistry.RegisterJourney(new JourneyDescriptor( - JourneyNames.AddAlert, - typeof(TeachingRecordSystem.SupportUi.Pages.Alerts.AddAlert.AddAlertState), - requestDataKeys: ["personId"], - appendUniqueKey: true)); - - options.JourneyRegistry.RegisterJourney(new JourneyDescriptor( - JourneyNames.CloseAlert, - typeof(TeachingRecordSystem.SupportUi.Pages.Alerts.CloseAlert.CloseAlertState), - requestDataKeys: ["alertId"], - appendUniqueKey: true)); - options.JourneyRegistry.RegisterJourney(new JourneyDescriptor( JourneyNames.EditName, typeof(TeachingRecordSystem.SupportUi.Pages.Persons.PersonDetail.EditName.EditNameState), diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Dqt.CrmIntegrationTests/QueryTests/CloseSanctionTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Dqt.CrmIntegrationTests/QueryTests/CloseSanctionTests.cs deleted file mode 100644 index 3e777a45c..000000000 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Dqt.CrmIntegrationTests/QueryTests/CloseSanctionTests.cs +++ /dev/null @@ -1,40 +0,0 @@ -namespace TeachingRecordSystem.Core.Dqt.CrmIntegrationTests.QueryTests; - -public class CloseSanctionTests : IAsyncLifetime -{ - private readonly CrmClientFixture.TestDataScope _dataScope; - private readonly CrmQueryDispatcher _crmQueryDispatcher; - - public CloseSanctionTests(CrmClientFixture crmClientFixture) - { - _dataScope = crmClientFixture.CreateTestDataScope(); - _crmQueryDispatcher = crmClientFixture.CreateQueryDispatcher(); - } - - public Task InitializeAsync() => Task.CompletedTask; - - public async Task DisposeAsync() => await _dataScope.DisposeAsync(); - - [Fact] - public async Task QueryExecutesSuccessfully() - { - // Arrange - var sanctionCode = "G1"; - var startDate = new DateOnly(2020, 01, 01); - var endDate = new DateOnly(2021, 03, 09); - var createPersonResult = await _dataScope.TestData.CreatePerson(x => x.WithSanction(sanctionCode, startDate: startDate)); - var sanction = createPersonResult.Sanctions.Single(); - - // Act - _ = await _crmQueryDispatcher.ExecuteQuery(new CloseSanctionQuery(sanction.SanctionId, endDate)); - - // Assert - using var ctx = new DqtCrmServiceContext(_dataScope.OrganizationService); - - var closedSanction = ctx.dfeta_sanctionSet.SingleOrDefault(s => s.GetAttributeValue(dfeta_sanction.PrimaryIdAttribute) == sanction.SanctionId); - Assert.NotNull(closedSanction); - Assert.Equal(dfeta_sanctionState.Active, closedSanction.StateCode); - Assert.Equal(endDate.ToDateTimeWithDqtBstFix(isLocalTime: true), closedSanction.dfeta_EndDate); - Assert.True(closedSanction.dfeta_Spent); - } -} diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Dqt.CrmIntegrationTests/QueryTests/CreateSanctionTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Dqt.CrmIntegrationTests/QueryTests/CreateSanctionTests.cs deleted file mode 100644 index 62b87216c..000000000 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Dqt.CrmIntegrationTests/QueryTests/CreateSanctionTests.cs +++ /dev/null @@ -1,49 +0,0 @@ -namespace TeachingRecordSystem.Core.Dqt.CrmIntegrationTests.QueryTests; - -public class CreateSanctionTests : IAsyncLifetime -{ - private readonly CrmClientFixture.TestDataScope _dataScope; - private readonly CrmQueryDispatcher _crmQueryDispatcher; - - public CreateSanctionTests(CrmClientFixture crmClientFixture) - { - _dataScope = crmClientFixture.CreateTestDataScope(); - _crmQueryDispatcher = crmClientFixture.CreateQueryDispatcher(); - } - - public Task InitializeAsync() => Task.CompletedTask; - - public async Task DisposeAsync() => await _dataScope.DisposeAsync(); - - [Fact] - public async Task QueryExecutesSuccessfully() - { - // Arrange - var sanctionCode = "G1"; - var sanctionCodeId = (await _dataScope.TestData.ReferenceDataCache.GetSanctionCodeByValue(sanctionCode)).dfeta_sanctioncodeId; - var startDate = new DateOnly(2020, 01, 01); - var createPersonResult = await _dataScope.TestData.CreatePerson(); - - // Act - var sanctionId = await _crmQueryDispatcher.ExecuteQuery(new CreateSanctionQuery() - { - ContactId = createPersonResult.PersonId, - SanctionCodeId = sanctionCodeId!.Value, - Details = "These are some test details", - Link = "http://www.gov.uk", - StartDate = startDate, - }); - - // Assert - using var ctx = new DqtCrmServiceContext(_dataScope.OrganizationService); - - var createdSanction = ctx.dfeta_sanctionSet.SingleOrDefault(s => s.GetAttributeValue(dfeta_sanction.PrimaryIdAttribute) == sanctionId); - Assert.NotNull(createdSanction); - Assert.Equal(dfeta_sanctionState.Active, createdSanction.StateCode); - Assert.Equal(createPersonResult.PersonId, createdSanction.dfeta_PersonId.Id); - Assert.Equal(sanctionCodeId, createdSanction.dfeta_SanctionCodeId.Id); - Assert.Equal("These are some test details", createdSanction.dfeta_SanctionDetails); - Assert.Equal("http://www.gov.uk", createdSanction.dfeta_DetailsLink); - Assert.Equal(startDate.ToDateTimeWithDqtBstFix(isLocalTime: true), createdSanction.dfeta_StartDate); - } -} diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Dqt.CrmIntegrationTests/QueryTests/GetSanctionDetailsByContactIdTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Dqt.CrmIntegrationTests/QueryTests/GetSanctionDetailsByContactIdTests.cs deleted file mode 100644 index 4ba9181a9..000000000 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Dqt.CrmIntegrationTests/QueryTests/GetSanctionDetailsByContactIdTests.cs +++ /dev/null @@ -1,49 +0,0 @@ -namespace TeachingRecordSystem.Core.Dqt.CrmIntegrationTests.QueryTests; - -public class GetSanctionDetailsByContactIdTests : IAsyncLifetime -{ - private readonly CrmClientFixture.TestDataScope _dataScope; - private readonly CrmQueryDispatcher _crmQueryDispatcher; - - public GetSanctionDetailsByContactIdTests(CrmClientFixture crmClientFixture) - { - _dataScope = crmClientFixture.CreateTestDataScope(); - _crmQueryDispatcher = crmClientFixture.CreateQueryDispatcher(); - } - - public Task InitializeAsync() => Task.CompletedTask; - - public async Task DisposeAsync() => await _dataScope.DisposeAsync(); - - [Fact] - public async Task WhenCalled_ForContactWithoutSanctions_ReturnsEmptyArray() - { - // Arrange - var person = await _dataScope.TestData.CreatePerson(); - - // Act - var sanctions = await _crmQueryDispatcher.ExecuteQuery(new GetSanctionDetailsByContactIdQuery(person.ContactId)); - - // Assert - Assert.Empty(sanctions); - } - - [Fact] - public async Task WhenCalled_ForContactWithSanctions_ReturnsSanctionsAsExpected() - { - // Arrange - var sanction1Code = "G1"; - var sanction1CodeName = (await _dataScope.TestData.ReferenceDataCache.GetSanctionCodeByValue(sanction1Code)).dfeta_name; - var sanction2Code = "A1"; - var sanction2CodeName = (await _dataScope.TestData.ReferenceDataCache.GetSanctionCodeByValue(sanction2Code)).dfeta_name; - var person = await _dataScope.TestData.CreatePerson(x => x.WithSanction(sanction1Code).WithSanction(sanction2Code)); - - // Act - var sanctions = await _crmQueryDispatcher.ExecuteQuery(new GetSanctionDetailsByContactIdQuery(person.ContactId)); - - // Assert - Assert.Equal(2, sanctions.Length); - Assert.Contains(sanction1CodeName, sanctions.Select(s => s.Description)); - Assert.Contains(sanction2CodeName, sanctions.Select(s => s.Description)); - } -} diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Dqt.CrmIntegrationTests/QueryTests/GetSanctionDetailsBySanctionIdTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Dqt.CrmIntegrationTests/QueryTests/GetSanctionDetailsBySanctionIdTests.cs deleted file mode 100644 index ac2835191..000000000 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Dqt.CrmIntegrationTests/QueryTests/GetSanctionDetailsBySanctionIdTests.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace TeachingRecordSystem.Core.Dqt.CrmIntegrationTests.QueryTests; - -public class GetSanctionDetailsBySanctionIdTests : IAsyncLifetime -{ - private readonly CrmClientFixture.TestDataScope _dataScope; - private readonly CrmQueryDispatcher _crmQueryDispatcher; - - public GetSanctionDetailsBySanctionIdTests(CrmClientFixture crmClientFixture) - { - _dataScope = crmClientFixture.CreateTestDataScope(); - _crmQueryDispatcher = crmClientFixture.CreateQueryDispatcher(); - } - - public Task InitializeAsync() => Task.CompletedTask; - - public async Task DisposeAsync() => await _dataScope.DisposeAsync(); - - [Fact] - public async Task WhenCalled_ForSanction_ReturnsSanctionAsExpected() - { - // Arrange - var sanctionCode = "G1"; - var sanctionCodeName = (await _dataScope.TestData.ReferenceDataCache.GetSanctionCodeByValue(sanctionCode)).dfeta_name; - var person = await _dataScope.TestData.CreatePerson(x => x.WithSanction(sanctionCode)); - - // Act - var sanction = await _crmQueryDispatcher.ExecuteQuery(new GetSanctionDetailsBySanctionIdQuery(person.Sanctions.Single().SanctionId)); - - // Assert - Assert.NotNull(sanction); - Assert.Equal(sanctionCodeName, sanction.Description); - } -} diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.EndToEndTests/AlertTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.EndToEndTests/AlertTests.cs deleted file mode 100644 index a81e1e930..000000000 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.EndToEndTests/AlertTests.cs +++ /dev/null @@ -1,113 +0,0 @@ -namespace TeachingRecordSystem.SupportUi.EndToEndTests; - -public class AlertTests : TestBase -{ - public AlertTests(HostFixture hostFixture) - : base(hostFixture) - { - } - - [Fact] - public async Task CloseAlert() - { - var startDate = new DateOnly(2021, 10, 01); - var endDate = new DateOnly(2023, 08, 02); - var createPersonResult = await TestData.CreatePerson(b => b.WithSanction("G1", startDate: startDate)); - var personId = createPersonResult.ContactId; - var alertId = createPersonResult.Sanctions.Single().SanctionId; - - await using var context = await HostFixture.CreateBrowserContext(); - var page = await context.NewPageAsync(); - - await page.GoToPersonAlertsPage(personId); - - await page.AssertOnPersonAlertsPage(personId); - - await page.ClickCloseAlertPersonAlertsPage(alertId); - - await page.AssertOnCloseAlertPage(alertId); - - await page.FillDateInput(endDate); - - await page.ClickContinueButton(); - - await page.AssertOnCloseAlertConfirmPage(alertId); - - await page.ClickConfirmButton(); - - await page.AssertOnPersonAlertsPage(personId); - - await page.AssertFlashMessage("Alert closed"); - } - - [Theory] - [InlineData(true, "Status changed to inactive")] - [InlineData(false, "Inactive status removed")] - public async Task ViewAlert(bool isActive, string expectedFlashMessage) - { - var startDate = new DateOnly(2021, 10, 01); - var endDate = new DateOnly(2023, 08, 02); - var createPersonResult = await TestData.CreatePerson(b => b.WithSanction("G1", startDate: startDate, endDate: endDate, spent: true, isActive: isActive)); - var personId = createPersonResult.ContactId; - var alertId = createPersonResult.Sanctions.Single().SanctionId; - - await using var context = await HostFixture.CreateBrowserContext(); - var page = await context.NewPageAsync(); - - await page.GoToPersonAlertsPage(personId); - - await page.AssertOnPersonAlertsPage(personId); - - await page.ClickViewAlertPersonAlertsPage(alertId); - - await page.AssertOnAlertDetailPage(alertId); - - if (isActive) - { - await page.ClickDeactivateButton(); - } - else - { - await page.ClickReactivateButton(); - } - - await page.AssertOnAlertDetailPage(alertId); - - await page.AssertFlashMessage(expectedFlashMessage); - } - - [Theory] - [InlineData(true)] - [InlineData(false)] - public async Task AddAlert(bool setDetailsManually) - { - var sanctionCodeValue = "G1"; - var sanctionCode = await TestData.ReferenceDataCache.GetSanctionCodeByValue(sanctionCodeValue); - var details = setDetailsManually ? "These are some test details" : null; - var link = "http://www.gov.uk"; - var startDate = new DateOnly(2021, 10, 01); - var createPersonResult = await TestData.CreatePerson(); - var personId = createPersonResult.ContactId; - - await using var context = await HostFixture.CreateBrowserContext(); - var page = await context.NewPageAsync(); - - await page.GoToPersonAlertsPage(personId); - - await page.AssertOnPersonAlertsPage(personId); - - await page.ClickAddAlertPersonAlertsPage(); - - await page.AssertOnAddAlertPage(); - - await page.SubmitAddAlertIndexPage(sanctionCode.dfeta_name, details, link, startDate); - - await page.AssertOnAddAlertConfirmPage(); - - await page.ClickConfirmButton(); - - await page.AssertOnPersonAlertsPage(personId); - - await page.AssertFlashMessage("Alert added"); - } -} diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/ConfirmTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/ConfirmTests.cs deleted file mode 100644 index 2efcdd261..000000000 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/ConfirmTests.cs +++ /dev/null @@ -1,152 +0,0 @@ -using TeachingRecordSystem.SupportUi.Pages.Alerts.AddAlert; - -namespace TeachingRecordSystem.SupportUi.Tests.PageTests.Alerts.AddAlert; - -public class ConfirmTests : TestBase -{ - public ConfirmTests(HostFixture hostFixture) - : base(hostFixture) - { - } - - [Fact] - public async Task Get_WithPersonIdForNonExistentPerson_ReturnsNotFound() - { - // Arrange - var personId = Guid.NewGuid(); - - var journeyInstance = await CreateJourneyInstance(personId); - - var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/add?personId={personId}&{journeyInstance.GetUniqueIdQueryParameter()}"); - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - Assert.Equal(StatusCodes.Status404NotFound, (int)response.StatusCode); - } - - [Theory] - [InlineData("G1", null, null)] - [InlineData(null, "These are some test details", null)] - [InlineData(null, null, "2021-01-01")] - public async Task Get_StateHasMissingRequiredData_RedirectsToIndex(string? sanctionCode, string? details, string? startDateString) - { - // Arrange - var person = await TestData.CreatePerson(); - var addAlertState = new AddAlertState(); - if (sanctionCode is not null) - { - var sanctionCodeId = (await TestData.ReferenceDataCache.GetSanctionCodeByValue(sanctionCode)).dfeta_sanctioncodeId; - addAlertState.AlertTypeId = sanctionCodeId; - } - - if (details is not null) - { - addAlertState.Details = details; - } - - if (startDateString is not null) - { - addAlertState.StartDate = DateOnly.Parse(startDateString); - } - - var journeyInstance = await CreateJourneyInstance( - person.ContactId, - addAlertState); - - var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/add/confirm?personId={person.ContactId}&{journeyInstance.GetUniqueIdQueryParameter()}"); - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); - Assert.Equal($"/alerts/add?personId={person.ContactId}&{journeyInstance.GetUniqueIdQueryParameter()}", response.Headers.Location?.OriginalString); - } - - [Fact] - public async Task Get_ValidRequest_RendersExpectedContent() - { - // Arrange - var sanctionCodeValue = "G1"; - var sanctionCode = await TestData.ReferenceDataCache.GetSanctionCodeByValue(sanctionCodeValue); - var sanctionCodeId = sanctionCode.dfeta_sanctioncodeId; - var sanctionCodeName = sanctionCode.dfeta_name; - var details = "These are some test details"; - var link = "http://www.gov.uk"; - var startDate = new DateOnly(2021, 01, 01); - var person = await TestData.CreatePerson(); - - var journeyInstance = await CreateJourneyInstance( - person.ContactId, - new AddAlertState() - { - AlertTypeId = sanctionCodeId, - Details = details, - Link = link, - StartDate = startDate, - }); - - var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/add/confirm?personId={person.ContactId}&{journeyInstance.GetUniqueIdQueryParameter()}"); - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - var doc = await AssertEx.HtmlResponse(response); - Assert.Equal(sanctionCodeName, doc.GetElementByTestId("alert-type")!.TextContent); - var detailsElement = doc.GetElementByTestId("details"); - Assert.NotNull(detailsElement); - Assert.Equal(details, doc.GetElementByTestId("details")!.TextContent); - Assert.Equal(link, doc.GetElementByTestId("link")!.TextContent); - Assert.Equal(startDate.ToString("dd/MM/yyyy"), doc.GetElementByTestId("start-date")!.TextContent); - } - - [Fact] - public async Task Post_ValidRequest_AddsAlertAndCompletesJourney() - { - // Arrange - var sanctionCodeValue = "G1"; - var sanctionCode = await TestData.ReferenceDataCache.GetSanctionCodeByValue(sanctionCodeValue); - var sanctionCodeId = sanctionCode.dfeta_sanctioncodeId; - var sanctionCodeName = sanctionCode.dfeta_name; - var details = "These are some test details"; - var link = "http://www.gov.uk"; - var startDate = new DateOnly(2021, 01, 01); - var person = await TestData.CreatePerson(); - - var journeyInstance = await CreateJourneyInstance( - person.ContactId, - new AddAlertState() - { - AlertTypeId = sanctionCodeId, - Details = details, - Link = link, - StartDate = startDate, - }); - - var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/confirm?personId={person.ContactId}&{journeyInstance.GetUniqueIdQueryParameter()}") - { - Content = new FormUrlEncodedContentBuilder() - }; - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); - var redirectResponse = await response.FollowRedirect(HttpClient); - var redirectDoc = await redirectResponse.GetDocument(); - AssertEx.HtmlDocumentHasFlashSuccess(redirectDoc, "Alert added"); - - journeyInstance = await ReloadJourneyInstance(journeyInstance); - Assert.True(journeyInstance.Completed); - } - - private async Task> CreateJourneyInstance(Guid personId, AddAlertState? state = null) => - await CreateJourneyInstance( - JourneyNames.AddAlert, - state ?? new AddAlertState(), - new KeyValuePair("personId", personId)); -} diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/IndexTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/IndexTests.cs deleted file mode 100644 index f66bd755d..000000000 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/IndexTests.cs +++ /dev/null @@ -1,179 +0,0 @@ -using AngleSharp.Html.Dom; -using TeachingRecordSystem.SupportUi.Pages.Alerts.AddAlert; - -namespace TeachingRecordSystem.SupportUi.Tests.PageTests.Alerts.AddAlert; - -public class IndexTests : TestBase -{ - public IndexTests(HostFixture hostFixture) - : base(hostFixture) - { - } - - [Fact] - public async Task Get_WithPersonIdForNonExistentPerson_ReturnsNotFound() - { - // Arrange - var personId = Guid.NewGuid(); - - var journeyInstance = await CreateJourneyInstance(personId); - - var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/add?personId={personId}&{journeyInstance.GetUniqueIdQueryParameter()}"); - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - Assert.Equal(StatusCodes.Status404NotFound, (int)response.StatusCode); - } - - [Fact] - public async Task Get_WithPersonIdForValidPerson_ReturnsOk() - { - // Arrange - var person = await TestData.CreatePerson(); - - var journeyInstance = await CreateJourneyInstance(person.PersonId); - - var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/add?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - Assert.Equal(StatusCodes.Status200OK, (int)response.StatusCode); - } - - [Fact] - public async Task Get_ValidRequestWithPopulatedDataInJourneyState_PopulatesModelFromJourneyState() - { - // Arrange - var sanctionCode = "G1"; - var sanctionCodeId = (await TestData.ReferenceDataCache.GetSanctionCodeByValue(sanctionCode)).dfeta_sanctioncodeId; - var details = "These are some test details"; - var link = "http://www.gov.uk"; - var startDate = new DateOnly(2021, 01, 01); - var person = await TestData.CreatePerson(); - - var journeyInstance = await CreateJourneyInstance( - person.ContactId, - new AddAlertState() - { - AlertTypeId = sanctionCodeId, - Details = details, - Link = link, - StartDate = startDate, - }); - - var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/add?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - var doc = await AssertEx.HtmlResponse(response); - var alertTypeIdElement = doc.GetElementById("AlertTypeId") as IHtmlSelectElement; - Assert.NotNull(alertTypeIdElement); - Assert.Equal(sanctionCodeId!.Value.ToString(), alertTypeIdElement.Value); - Assert.Equal(details, doc.GetElementById("Details")!.TextContent); - Assert.Equal(link, doc.GetElementById("Link")!.GetAttribute("value")); - Assert.Equal($"{startDate:%d}", doc.GetElementById("StartDate.Day")?.GetAttribute("value")); - Assert.Equal($"{startDate:%M}", doc.GetElementById("StartDate.Month")?.GetAttribute("value")); - Assert.Equal($"{startDate:yyyy}", doc.GetElementById("StartDate.Year")?.GetAttribute("value")); - } - - [Fact] - public async Task Post_EmptyRequiredFields_ReturnsError() - { - // Arrange - var person = await TestData.CreatePerson(); - - var journeyInstance = await CreateJourneyInstance(person.ContactId); - - var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}") - { - Content = new FormUrlEncodedContentBuilder() - }; - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - await AssertEx.HtmlResponseHasError(response, "AlertTypeId", "Add an alert type"); - await AssertEx.HtmlResponseHasError(response, "Details", "Add details"); - await AssertEx.HtmlResponseHasError(response, "StartDate", "Add a start date"); - } - - [Fact] - public async Task Post_InvalidLinkUrl_ReturnsError() - { - // Arrange - var sanctionCode = "G1"; - var sanctionCodeId = (await TestData.ReferenceDataCache.GetSanctionCodeByValue(sanctionCode)).dfeta_sanctioncodeId; - var details = "These are some test details"; - var link = "invalid-url"; - var startDate = new DateOnly(2021, 01, 01); - var person = await TestData.CreatePerson(); - - var journeyInstance = await CreateJourneyInstance(person.ContactId); - - var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}") - { - Content = new FormUrlEncodedContentBuilder() - { - { "AlertTypeId", sanctionCodeId!.Value.ToString() }, - { "Details", details }, - { "Link", link }, - { "StartDate.Day", startDate.Day.ToString() }, - { "StartDate.Month", startDate.Month.ToString() }, - { "StartDate.Year", startDate.Year.ToString() }, - } - }; - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - await AssertEx.HtmlResponseHasError(response, "Link", "Enter a valid URL"); - } - - [Fact] - public async Task Post_ValidData_RedirectsToConfirmPage() - { - // Arrange - var sanctionCode = "G1"; - var sanctionCodeId = (await TestData.ReferenceDataCache.GetSanctionCodeByValue(sanctionCode)).dfeta_sanctioncodeId; - var details = "These are some test details"; - var link = "http://www.gov.uk"; - var startDate = new DateOnly(2021, 01, 01); - var person = await TestData.CreatePerson(); - - var journeyInstance = await CreateJourneyInstance(person.ContactId); - - var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}") - { - Content = new FormUrlEncodedContentBuilder() - { - { "AlertTypeId", sanctionCodeId!.Value.ToString() }, - { "Details", details }, - { "Link", link }, - { "StartDate.Day", startDate.Day.ToString() }, - { "StartDate.Month", startDate.Month.ToString() }, - { "StartDate.Year", startDate.Year.ToString() }, - } - }; - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); - Assert.Equal($"/alerts/add/confirm?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}", response.Headers.Location?.OriginalString); - } - - private async Task> CreateJourneyInstance(Guid personId, AddAlertState? state = null) => - await CreateJourneyInstance( - JourneyNames.AddAlert, - state ?? new AddAlertState(), - new KeyValuePair("personId", personId)); -} diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/Alert/IndexTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/Alert/IndexTests.cs deleted file mode 100644 index 4be41cafc..000000000 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/Alert/IndexTests.cs +++ /dev/null @@ -1,85 +0,0 @@ -using TeachingRecordSystem.SupportUi.Pages.Common; - -namespace TeachingRecordSystem.SupportUi.Tests.PageTests.Alerts.Alert; - -public class IndexTests : TestBase -{ - public IndexTests(HostFixture hostFixture) - : base(hostFixture) - { - } - - [Fact] - public async Task Get_WithAlertIdForNonExistentAlert_ReturnsNotFound() - { - // Arrange - var nonExistentAlertId = Guid.NewGuid().ToString(); - - var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/{nonExistentAlertId}"); - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - Assert.Equal(StatusCodes.Status404NotFound, (int)response.StatusCode); - } - - [Theory] - [InlineData("2021-01-01", "2022-03-05", "Alert details", "http://www.gov.uk", true, true, AlertStatus.Closed)] - [InlineData("2021-01-01", null, null, null, false, true, AlertStatus.Active)] - [InlineData("2021-01-01", null, null, "http://www.gov.uk", false, false, AlertStatus.Inactive)] - [InlineData("2021-01-01", "2022-03-05", "Alert details", null, true, false, AlertStatus.Inactive)] - public async Task Get_ValidRequest_RendersExpectedContent(string startDateString, string? endDateString, string? details, string? detailsLink, bool isSpent, bool isActive, AlertStatus expectedAlertStatus) - { - // Arrange - var sanctionCode = "G1"; - var sanctionCodeName = (await TestData.ReferenceDataCache.GetSanctionCodeByValue(sanctionCode)).dfeta_name; - var startDate = DateOnly.Parse(startDateString); - DateOnly? endDate = endDateString is not null ? DateOnly.Parse(endDateString) : null; - var person = await TestData.CreatePerson(x => x.WithSanction(sanctionCode, startDate: startDate, endDate: endDate, spent: isSpent, details: details, detailsLink: detailsLink, isActive: isActive)); - - var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/{person.Sanctions.Single().SanctionId}"); - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - var doc = await AssertEx.HtmlResponse(response); - - Assert.Equal(sanctionCodeName, doc.GetElementByTestId("title")!.TextContent); - - var alertHeader = doc.GetElementByTestId("alert-header"); - Assert.NotNull(alertHeader); - Assert.Equal(startDate.ToString("dd/MM/yyyy"), alertHeader.GetElementByTestId("start-date")!.TextContent); - Assert.Equal(endDate is not null ? endDate.Value.ToString("dd/MM/yyyy") : "-", alertHeader.GetElementByTestId("end-date")!.TextContent); - Assert.Equal(expectedAlertStatus.ToString(), alertHeader.GetElementByTestId("status")!.TextContent); - if (details is not null) - { - Assert.Equal(details, doc.GetElementByTestId("alert-details")!.TextContent); - } - else - { - Assert.Null(doc.GetElementByTestId("alert-details")); - } - - if (detailsLink is not null) - { - Assert.Equal(detailsLink, doc.GetElementByTestId("full-case-details-link")!.GetAttribute("href")); - } - else - { - Assert.Null(doc.GetElementByTestId("full-case-details-link")); - } - - if (isActive) - { - Assert.NotNull(doc.GetElementByTestId("deactivate-button")); - Assert.Null(doc.GetElementByTestId("reactivate-button")); - } - else - { - Assert.Null(doc.GetElementByTestId("deactivate-button")); - Assert.NotNull(doc.GetElementByTestId("reactivate-button")); - } - } -} diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/CloseAlert/ConfirmTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/CloseAlert/ConfirmTests.cs deleted file mode 100644 index d41969dde..000000000 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/CloseAlert/ConfirmTests.cs +++ /dev/null @@ -1,112 +0,0 @@ -using TeachingRecordSystem.SupportUi.Pages.Alerts.CloseAlert; - -namespace TeachingRecordSystem.SupportUi.Tests.PageTests.Alerts.CloseAlert; - -public class ConfirmTests : TestBase -{ - public ConfirmTests(HostFixture hostFixture) - : base(hostFixture) - { - } - - [Fact] - public async Task Get_WithAlertIdForNonExistentAlert_ReturnsNotFound() - { - // Arrange - var endDate = new DateOnly(2020, 01, 01); - var alertId = Guid.NewGuid(); - - var journeyInstance = await CreateJourneyInstance(alertId, new CloseAlertState() { EndDate = endDate }); - - var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/{alertId}/close/confirm?{journeyInstance.GetUniqueIdQueryParameter()}"); - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - Assert.Equal(StatusCodes.Status404NotFound, (int)response.StatusCode); - } - - [Fact] - public async Task Get_StateHasNoEndDate_RedirectsToIndex() - { - // Arrange - var sanctionCode = "G1"; - var sanctionCodeName = (await TestData.ReferenceDataCache.GetSanctionCodeByValue(sanctionCode)).dfeta_name; - var startDate = new DateOnly(2021, 01, 01); - var endDate = new DateOnly(2020, 01, 01); - var person = await TestData.CreatePerson(x => x.WithSanction(sanctionCode, startDate: startDate)); - var alertId = person.Sanctions.Single().SanctionId; - - var journeyInstance = await CreateJourneyInstance(alertId, new CloseAlertState() { EndDate = null }); - - var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/{alertId}/close/confirm?{journeyInstance.GetUniqueIdQueryParameter()}"); - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); - Assert.Equal($"/alerts/{alertId}/close?{journeyInstance.GetUniqueIdQueryParameter()}", response.Headers.Location?.OriginalString); - } - - [Fact] - public async Task Get_ValidRequest_RendersExpectedContent() - { - // Arrange - var sanctionCode = "G1"; - var sanctionCodeName = (await TestData.ReferenceDataCache.GetSanctionCodeByValue(sanctionCode)).dfeta_name; - var startDate = new DateOnly(2021, 01, 01); - var endDate = new DateOnly(2020, 01, 01); - var person = await TestData.CreatePerson(x => x.WithSanction(sanctionCode, startDate: startDate)); - var alertId = person.Sanctions.Single().SanctionId; - - var journeyInstance = await CreateJourneyInstance(alertId, new CloseAlertState() { EndDate = endDate }); - - var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/{alertId}/close/confirm?{journeyInstance.GetUniqueIdQueryParameter()}"); - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - var doc = await AssertEx.HtmlResponse(response); - Assert.Equal(sanctionCodeName, doc.GetElementByTestId("alert-type")!.TextContent); - Assert.Equal(endDate.ToString("dd/MM/yyyy"), doc.GetElementByTestId("end-date")!.TextContent); - } - - [Fact] - public async Task Post_ValidRequest_ClosesAlertAndCompletesJourney() - { - // Arrange - var sanctionCode = "G1"; - var startDate = new DateOnly(2021, 01, 01); - var endDate = new DateOnly(2023, 08, 02); - var person = await TestData.CreatePerson(x => x.WithSanction(sanctionCode, startDate: startDate)); - var alertId = person.Sanctions.Single().SanctionId; - - var journeyInstance = await CreateJourneyInstance(alertId, new CloseAlertState() { EndDate = endDate }); - - var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/{alertId}/close/confirm?{journeyInstance.GetUniqueIdQueryParameter()}") - { - Content = new FormUrlEncodedContentBuilder() - }; - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); - var redirectResponse = await response.FollowRedirect(HttpClient); - var redirectDoc = await redirectResponse.GetDocument(); - AssertEx.HtmlDocumentHasFlashSuccess(redirectDoc, "Alert closed"); - - journeyInstance = await ReloadJourneyInstance(journeyInstance); - Assert.True(journeyInstance.Completed); - } - - private async Task> CreateJourneyInstance(Guid alertId, CloseAlertState state) => - await CreateJourneyInstance( - JourneyNames.CloseAlert, - state, - new KeyValuePair("alertId", alertId)); -} diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/CloseAlert/IndexTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/CloseAlert/IndexTests.cs deleted file mode 100644 index 7efdfc1d5..000000000 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/CloseAlert/IndexTests.cs +++ /dev/null @@ -1,171 +0,0 @@ -using TeachingRecordSystem.SupportUi.Pages.Alerts.CloseAlert; - -namespace TeachingRecordSystem.SupportUi.Tests.PageTests.Alerts.CloseAlert; - -public class IndexTests : TestBase -{ - public IndexTests(HostFixture hostFixture) - : base(hostFixture) - { - } - - [Fact] - public async Task Get_WithAlertIdForNonExistentAlert_ReturnsNotFound() - { - // Arrange - var alertId = Guid.NewGuid(); - - var journeyInstance = await CreateJourneyInstance(alertId); - - var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/{alertId}/close?{journeyInstance.GetUniqueIdQueryParameter()}"); - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - Assert.Equal(StatusCodes.Status404NotFound, (int)response.StatusCode); - } - - [Fact] - public async Task Get_WithAlertIdForEndedAlert_ReturnsNotFound() - { - // Arrange - var person = await TestData.CreatePerson(x => x.WithSanction("G1", endDate: new DateOnly(2023, 09, 21))); - var alertId = person.Sanctions.Single().SanctionId; - - var journeyInstance = await CreateJourneyInstance(alertId); - - var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/{alertId}/close?{journeyInstance.GetUniqueIdQueryParameter()}"); - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - Assert.Equal(StatusCodes.Status404NotFound, (int)response.StatusCode); - } - - [Fact] - public async Task Get_WithAlertIdForActiveAlert_ReturnsOk() - { - // Arrange - var person = await TestData.CreatePerson(x => x.WithSanction("G1")); - var alertId = person.Sanctions.Single().SanctionId; - - var journeyInstance = await CreateJourneyInstance(alertId); - - var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/{alertId}/close?{journeyInstance.GetUniqueIdQueryParameter()}"); - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - await AssertEx.HtmlResponse(response); - } - - [Fact] - public async Task Get_ValidRequestWithEndDateInJourneyState_PopulatesEndDateFromJourneyState() - { - // Arrange - var startDate = new DateOnly(2021, 01, 01); - var endDate = new DateOnly(2020, 01, 01); - var person = await TestData.CreatePerson(x => x.WithSanction("G1", startDate: startDate)); - var alertId = person.Sanctions.Single().SanctionId; - - var journeyInstance = await CreateJourneyInstance(alertId, new CloseAlertState() { EndDate = endDate }); - - var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/{alertId}/close?{journeyInstance.GetUniqueIdQueryParameter()}"); - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - var doc = await AssertEx.HtmlResponse(response); - Assert.Equal($"{endDate:%d}", doc.GetElementById("EndDate.Day")?.GetAttribute("value")); - Assert.Equal($"{endDate:%M}", doc.GetElementById("EndDate.Month")?.GetAttribute("value")); - Assert.Equal($"{endDate:yyyy}", doc.GetElementById("EndDate.Year")?.GetAttribute("value")); - } - - [Fact] - public async Task Post_EmptyEndDate_ReturnsError() - { - // Arrange - var person = await TestData.CreatePerson(x => x.WithSanction("G1")); - var alertId = person.Sanctions.Single().SanctionId; - - var journeyInstance = await CreateJourneyInstance(alertId); - - var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/{alertId}/close?{journeyInstance.GetUniqueIdQueryParameter()}") - { - Content = new FormUrlEncodedContentBuilder() - }; - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - await AssertEx.HtmlResponseHasError(response, "EndDate", "Add an end date"); - } - - [Fact] - public async Task Post_EndDateBeforeStartDate_ReturnsError() - { - // Arrange - var startDate = new DateOnly(2021, 01, 01); - var endDate = new DateOnly(2020, 01, 01); - var person = await TestData.CreatePerson(x => x.WithSanction("G1", startDate: startDate)); - var alertId = person.Sanctions.Single().SanctionId; - - var journeyInstance = await CreateJourneyInstance(alertId); - - var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/{alertId}/close?{journeyInstance.GetUniqueIdQueryParameter()}") - { - Content = new FormUrlEncodedContentBuilder() - { - { "EndDate.Day", endDate.Day.ToString() }, - { "EndDate.Month", endDate.Month.ToString() }, - { "EndDate.Year", endDate.Year.ToString() }, - } - }; - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - await AssertEx.HtmlResponseHasError(response, "EndDate", "End date must be after the start date"); - } - - [Fact] - public async Task Post_ValidEndDate_RedirectsToConfirmPage() - { - // Arrange - var startDate = new DateOnly(2021, 01, 01); - var endDate = new DateOnly(2022, 08, 03); - var person = await TestData.CreatePerson(x => x.WithSanction("G1", startDate: startDate)); - var alertId = person.Sanctions.Single().SanctionId; - - var journeyInstance = await CreateJourneyInstance(alertId); - - var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/{alertId}/close?{journeyInstance.GetUniqueIdQueryParameter()}") - { - Content = new FormUrlEncodedContentBuilder() - { - { "EndDate.Day", endDate.Day.ToString() }, - { "EndDate.Month", endDate.Month.ToString() }, - { "EndDate.Year", endDate.Year.ToString() }, - } - }; - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); - Assert.Equal($"/alerts/{alertId}/close/confirm?{journeyInstance.GetUniqueIdQueryParameter()}", response.Headers.Location?.OriginalString); - } - - private async Task> CreateJourneyInstance(Guid alertId, CloseAlertState? state = null) => - await CreateJourneyInstance( - JourneyNames.CloseAlert, - state ?? new CloseAlertState(), - new KeyValuePair("alertId", alertId)); -} diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Persons/PersonDetail/AlertsTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Persons/PersonDetail/AlertsTests.cs deleted file mode 100644 index 0e9a827d6..000000000 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Persons/PersonDetail/AlertsTests.cs +++ /dev/null @@ -1,140 +0,0 @@ -namespace TeachingRecordSystem.SupportUi.Tests.PageTests.Persons.PersonDetail; - -public class AlertsTests : TestBase -{ - public AlertsTests(HostFixture hostFixture) - : base(hostFixture) - { - } - - [Fact] - public async Task Get_WithPersonIdForNonExistentPerson_ReturnsNotFound() - { - // Arrange - var nonExistentPersonId = Guid.NewGuid().ToString(); - - var request = new HttpRequestMessage(HttpMethod.Get, $"/persons/{nonExistentPersonId}/alerts"); - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - Assert.Equal(StatusCodes.Status404NotFound, (int)response.StatusCode); - } - - [Fact] - public async Task Get_WithPersonIdForPersonWithNoAlerts_DisplaysNoCurrentAlerts() - { - // Arrange - var person = await TestData.CreatePerson(); - - var request = new HttpRequestMessage(HttpMethod.Get, $"/persons/{person.ContactId}/alerts"); - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - var doc = await AssertEx.HtmlResponse(response); - var noCurrentAlerts = doc.GetElementByTestId("no-current-alerts"); - Assert.NotNull(noCurrentAlerts); - } - - [Fact] - public async Task Get_WithPersonIdForPersonWithOnlyPreviousAlerts_DisplaysExpectedContent() - { - // Arrange - var sanctionCode = "G1"; - var sanctionCodeName = (await TestData.ReferenceDataCache.GetSanctionCodeByValue(sanctionCode)).dfeta_name; - var sanctionStartDate = new DateOnly(2023, 05, 01); - var sanctionEndDate = new DateOnly(2023, 08, 20); - var person = await TestData.CreatePerson(x => x.WithSanction(sanctionCode, startDate: sanctionStartDate, endDate: sanctionEndDate)); - - var request = new HttpRequestMessage(HttpMethod.Get, $"/persons/{person.ContactId}/alerts"); - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - var doc = await AssertEx.HtmlResponse(response); - - var noCurrentAlerts = doc.GetElementByTestId("no-current-alerts"); - Assert.NotNull(noCurrentAlerts); - - var previousAlerts = doc.GetElementByTestId("previous-alerts"); - Assert.NotNull(previousAlerts); - - var previousAlert = previousAlerts.GetElementByTestId($"previous-alert-{person.Sanctions.First().SanctionId}"); - Assert.NotNull(previousAlert); - Assert.Equal(sanctionCodeName, previousAlert.GetElementByTestId($"previous-alert-description-{person.Sanctions.First().SanctionId}")!.TextContent); - Assert.Equal(sanctionStartDate.ToString("dd/MM/yyyy"), previousAlert.GetElementByTestId($"previous-alert-start-date-{person.Sanctions.First().SanctionId}")!.TextContent); - Assert.Equal(sanctionEndDate.ToString("dd/MM/yyyy"), previousAlert.GetElementByTestId($"previous-alert-end-date-{person.Sanctions.First().SanctionId}")!.TextContent); - Assert.Equal("Closed", previousAlert.GetElementByTestId($"previous-alert-status-{person.Sanctions.First().SanctionId}")!.TextContent); - } - - [Fact] - public async Task Get_WithPersonIdForPersonWithOnlyCurrentAlerts_DisplaysExpectedContent() - { - // Arrange - var sanctionCode = "G1"; - var sanctionCodeName = (await TestData.ReferenceDataCache.GetSanctionCodeByValue(sanctionCode)).dfeta_name; - var sanctionStartDate = new DateOnly(2023, 05, 01); - var person = await TestData.CreatePerson(x => x.WithSanction(sanctionCode, startDate: sanctionStartDate)); - - var request = new HttpRequestMessage(HttpMethod.Get, $"/persons/{person.ContactId}/alerts"); - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - var doc = await AssertEx.HtmlResponse(response); - - var currentAlert = doc.GetElementByTestId($"current-alert-{person.Sanctions.First().SanctionId}"); - Assert.NotNull(currentAlert); - Assert.Equal(sanctionStartDate.ToString("dd/MM/yyyy"), currentAlert.GetElementByTestId($"current-alert-start-date-{person.Sanctions.First().SanctionId}")!.TextContent); - var details = currentAlert.GetElementByTestId($"current-alert-details-{person.Sanctions.First().SanctionId}"); - Assert.NotNull(details); - - var previousAlerts = doc.GetElementByTestId("previous-alerts"); - Assert.Null(previousAlerts); - } - - [Fact] - public async Task Get_WithPersonIdForPersonWithCurrentAndPreviousAlerts_DisplaysExpectedContent() - { - // Arrange - var sanction1Code = "G1"; - var sanction1CodeName = (await TestData.ReferenceDataCache.GetSanctionCodeByValue(sanction1Code)).dfeta_name; - var sanction1StartDate = new DateOnly(2023, 05, 01); - - var sanction2Code = "A1"; - var sanction2CodeName = (await TestData.ReferenceDataCache.GetSanctionCodeByValue(sanction2Code)).dfeta_name; - var sanction2StartDate = new DateOnly(2019, 06, 24); - var sanction2EndDate = new DateOnly(2020, 07, 30); - - var person = await TestData.CreatePerson(x => x.WithSanction(sanction1Code, startDate: sanction1StartDate).WithSanction(sanction2Code, startDate: sanction2StartDate, endDate: sanction2EndDate)); - - var request = new HttpRequestMessage(HttpMethod.Get, $"/persons/{person.ContactId}/alerts"); - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - var doc = await AssertEx.HtmlResponse(response); - - var currentAlert = doc.GetElementByTestId($"current-alert-{person.Sanctions.First().SanctionId}"); - Assert.NotNull(currentAlert); - Assert.Equal(sanction1StartDate.ToString("dd/MM/yyyy"), currentAlert.GetElementByTestId($"current-alert-start-date-{person.Sanctions.First().SanctionId}")!.TextContent); - var details = currentAlert.GetElementByTestId($"current-alert-details-{person.Sanctions.First().SanctionId}"); - Assert.NotNull(details); - - var previousAlerts = doc.GetElementByTestId("previous-alerts"); - Assert.NotNull(previousAlerts); - - var previousAlert = previousAlerts.GetElementByTestId($"previous-alert-{person.Sanctions.Last().SanctionId}"); - Assert.NotNull(previousAlert); - Assert.Equal(sanction2CodeName, previousAlert.GetElementByTestId($"previous-alert-description-{person.Sanctions.Last().SanctionId}")!.TextContent); - Assert.Equal(sanction2StartDate.ToString("dd/MM/yyyy"), previousAlert.GetElementByTestId($"previous-alert-start-date-{person.Sanctions.Last().SanctionId}")!.TextContent); - Assert.Equal(sanction2EndDate.ToString("dd/MM/yyyy"), previousAlert.GetElementByTestId($"previous-alert-end-date-{person.Sanctions.Last().SanctionId}")!.TextContent); - Assert.Equal("Closed", previousAlert.GetElementByTestId($"previous-alert-status-{person.Sanctions.Last().SanctionId}")!.TextContent); - } -}