diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/LinkGeneratorExtensions.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/LinkGeneratorExtensions.cs index 45c0eb45c6..ca34bbbcb2 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/LinkGeneratorExtensions.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/LinkGeneratorExtensions.cs @@ -10,7 +10,7 @@ public static string GetRequiredPathByPage(this LinkGenerator linkGenerator, str if (journeyInstanceId?.UniqueKey is string journeyInstanceUniqueKey) { - url = QueryHelpers.AddQueryString(url, WebCommon.FormFlow.Constants.UniqueKeyQueryParameterName, journeyInstanceUniqueKey); + url = QueryHelpers.AddQueryString(url, Constants.UniqueKeyQueryParameterName, journeyInstanceUniqueKey); } return url; diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/AddAlertLinkGenerator.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/AddAlertLinkGenerator.cs index e8108cb418..552509a59a 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/AddAlertLinkGenerator.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/AddAlertLinkGenerator.cs @@ -5,32 +5,32 @@ public class AddAlertLinkGenerator(LinkGenerator linkGenerator) public string Index(Guid personId, JourneyInstanceId? journeyInstanceId) => linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Index", routeValues: new { personId }, journeyInstanceId: journeyInstanceId); - public string Type(Guid personId, JourneyInstanceId journeyInstanceId, bool? fromCheckAnswers = null) => - linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Type", routeValues: new { personId, fromCheckAnswers }, journeyInstanceId: journeyInstanceId); + public string Type(Guid personId, JourneyInstanceId journeyInstanceId, string? returnUrl = null) => + linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Type", routeValues: new { personId, returnUrl }, journeyInstanceId: journeyInstanceId); public string TypeCancel(Guid personId, JourneyInstanceId journeyInstanceId) => linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Type", "cancel", routeValues: new { personId }, journeyInstanceId: journeyInstanceId); - public string Details(Guid personId, JourneyInstanceId journeyInstanceId, bool? fromCheckAnswers = null) => - linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Details", routeValues: new { personId, fromCheckAnswers }, journeyInstanceId: journeyInstanceId); + public string Details(Guid personId, JourneyInstanceId journeyInstanceId, string? returnUrl = null) => + linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Details", routeValues: new { personId, returnUrl }, journeyInstanceId: journeyInstanceId); public string DetailsCancel(Guid personId, JourneyInstanceId journeyInstanceId) => linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Details", "cancel", routeValues: new { personId }, journeyInstanceId: journeyInstanceId); - public string Link(Guid personId, JourneyInstanceId journeyInstanceId, bool? fromCheckAnswers = null) => - linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Link", routeValues: new { personId, fromCheckAnswers }, journeyInstanceId: journeyInstanceId); + public string Link(Guid personId, JourneyInstanceId journeyInstanceId, string? returnUrl = null) => + linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Link", routeValues: new { personId, returnUrl }, journeyInstanceId: journeyInstanceId); public string LinkCancel(Guid personId, JourneyInstanceId journeyInstanceId) => linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Link", "cancel", routeValues: new { personId }, journeyInstanceId: journeyInstanceId); - public string StartDate(Guid personId, JourneyInstanceId journeyInstanceId, bool? fromCheckAnswers = null) => - linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/StartDate", routeValues: new { personId, fromCheckAnswers }, journeyInstanceId: journeyInstanceId); + public string StartDate(Guid personId, JourneyInstanceId journeyInstanceId, string? returnUrl = null) => + linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/StartDate", routeValues: new { personId, returnUrl }, journeyInstanceId: journeyInstanceId); public string StartDateCancel(Guid personId, JourneyInstanceId journeyInstanceId) => linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/StartDate", "cancel", routeValues: new { personId }, journeyInstanceId: journeyInstanceId); - public string Reason(Guid personId, JourneyInstanceId journeyInstanceId, bool? fromCheckAnswers = null) => - linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Reason", routeValues: new { personId, fromCheckAnswers }, journeyInstanceId: journeyInstanceId); + public string Reason(Guid personId, JourneyInstanceId journeyInstanceId, string? returnUrl = null) => + linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Reason", routeValues: new { personId, returnUrl }, journeyInstanceId: journeyInstanceId); public string ReasonCancel(Guid personId, JourneyInstanceId journeyInstanceId) => linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Reason", "cancel", routeValues: new { personId }, journeyInstanceId: journeyInstanceId); diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/AddAlertState.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/AddAlertState.cs index b502c453e0..1d89c086c1 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/AddAlertState.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/AddAlertState.cs @@ -1,10 +1,7 @@ -using System.Diagnostics.CodeAnalysis; -using System.Text.Json.Serialization; using TeachingRecordSystem.SupportUi.Pages.Shared.Evidence; - namespace TeachingRecordSystem.SupportUi.Pages.Alerts.AddAlert; -public class AddAlertState : IRegisterJourney +public class AddAlertState : IRegisterJourney, IJourneyWithSteps { public static JourneyDescriptor Journey => new( JourneyNames.AddAlert, @@ -12,6 +9,8 @@ public class AddAlertState : IRegisterJourney requestDataKeys: ["personId"], appendUniqueKey: true); + public required JourneySteps Steps { get; init; } + public Guid? AlertTypeId { get; set; } public string? AlertTypeName { get; set; } @@ -32,14 +31,14 @@ public class AddAlertState : IRegisterJourney public EvidenceUploadModel Evidence { get; set; } = new(); - [JsonIgnore] - [MemberNotNullWhen(true, nameof(AlertTypeId), nameof(Details), nameof(StartDate))] - public bool IsComplete => - AlertTypeId.HasValue && - AddLink.HasValue && - StartDate.HasValue && - AddReason.HasValue && - HasAdditionalReasonDetail is bool hasDetail && - (!hasDetail || AddReasonDetail is not null) && - Evidence.IsComplete; +} +public class AddAlertStateJourneyStateFactory(SupportUiLinkGenerator linkGenerator) : IJourneyStateFactory +{ + public Task CreateAsync(CreateJourneyStateContext context) + { + var personId = context.HttpContext.GetCurrentPersonFeature().PersonId; + var firstStep = new JourneyStep(linkGenerator.Alerts.AddAlert.Index(personId, context.InstanceId)); + var state = new AddAlertState { Steps = JourneySteps.Create(firstStep) }; + return Task.FromResult(state); + } } diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/CheckAnswers.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/CheckAnswers.cshtml index b56e4a7a4f..41ca01b4e0 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/CheckAnswers.cshtml +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/CheckAnswers.cshtml @@ -1,11 +1,13 @@ -@page "/alerts/add/check-answers/{handler?}" +@page "/alerts/add/check-answers" @model TeachingRecordSystem.SupportUi.Pages.Alerts.AddAlert.CheckAnswersModel @{ ViewBag.Title = "Check details before adding alert"; + + var returnUrl = Request.GetEncodedPathAndQuery(); } @section BeforeContent { - Back + Back }
@@ -19,14 +21,14 @@ Alert type @Model.AlertTypeName - Change + Change Details @Html.ConvertNewlinesToLineBreaks(Model.Details) - Change + Change @@ -42,14 +44,14 @@ } - Change + Change Start date @Model.StartDate.ToString(UiDefaults.DateOnlyDisplayFormat) - Change + Change @@ -61,7 +63,7 @@ Reason @Model.AddReason.GetDisplayName() - Change + Change @@ -77,7 +79,7 @@ } - Change + Change @@ -87,7 +89,7 @@ - Change + Change diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/CheckAnswers.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/CheckAnswers.cshtml.cs index 724746b550..6593eb74e2 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/CheckAnswers.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/CheckAnswers.cshtml.cs @@ -19,9 +19,6 @@ public class CheckAnswersModel( [FromQuery] public Guid PersonId { get; set; } - [FromQuery] - public bool FromCheckAnswers { get; set; } - public string? PersonName { get; set; } public Guid AlertTypeId { get; set; } @@ -45,16 +42,10 @@ public class CheckAnswersModel( public override void OnPageHandlerExecuting(PageHandlerExecutingContext context) { - if (!JourneyInstance!.State.IsComplete) - { - context.Result = Redirect(linkGenerator.Alerts.AddAlert.Reason(PersonId, JourneyInstance.InstanceId)); - return; - } - var personInfo = context.HttpContext.GetCurrentPersonFeature(); PersonName = personInfo.Name; - AlertTypeId = JourneyInstance.State.AlertTypeId!.Value; + AlertTypeId = JourneyInstance!.State.AlertTypeId!.Value; AlertTypeName = JourneyInstance.State.AlertTypeName; Details = JourneyInstance.State.Details; Link = JourneyInstance.State.Link; diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Details.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Details.cshtml index 6abc50aba4..478cc41e2f 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Details.cshtml +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Details.cshtml @@ -1,16 +1,16 @@ -@page "/alerts/add/details/{handler?}" +@page "/alerts/add/details" @model TeachingRecordSystem.SupportUi.Pages.Alerts.AddAlert.DetailsModel @{ ViewBag.Title = "Enter details about this alert (optional)"; } @section BeforeContent { - + }
-
+ Add an alert - @Model.PersonName

@ViewBag.Title

@Model.AlertTypeName

diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Details.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Details.cshtml.cs index 1bdc470cfc..fb6f686982 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Details.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Details.cshtml.cs @@ -14,9 +14,6 @@ public class DetailsModel(SupportUiLinkGenerator linkGenerator, EvidenceUploadMa [FromQuery] public Guid PersonId { get; set; } - [FromQuery] - public bool FromCheckAnswers { get; set; } - public string? PersonName { get; set; } public string? AlertTypeName { get; set; } @@ -37,14 +34,11 @@ public async Task OnPostAsync() return this.PageWithErrors(); } - await JourneyInstance!.UpdateStateAsync(state => - { - state.Details = Details; - }); + var nextStep = linkGenerator.Alerts.AddAlert.Link(PersonId, JourneyInstance!.InstanceId); - return Redirect(FromCheckAnswers - ? linkGenerator.Alerts.AddAlert.CheckAnswers(PersonId, JourneyInstance.InstanceId) - : linkGenerator.Alerts.AddAlert.Link(PersonId, JourneyInstance.InstanceId)); + return await JourneyInstance.UpdateStateAndRedirectToNextStepAsync( + state => state.Details = Details, + nextStep); } public async Task OnPostCancelAsync() @@ -56,15 +50,9 @@ public async Task OnPostCancelAsync() public override void OnPageHandlerExecuting(PageHandlerExecutingContext context) { - if (JourneyInstance!.State.AlertTypeId is null) - { - context.Result = Redirect(linkGenerator.Alerts.AddAlert.Type(PersonId, JourneyInstance.InstanceId)); - return; - } - var personInfo = context.HttpContext.GetCurrentPersonFeature(); PersonName = personInfo.Name; - AlertTypeName = JourneyInstance.State.AlertTypeName; + AlertTypeName = JourneyInstance!.State.AlertTypeName; } } diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Index.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Index.cshtml.cs index 446b10f0f6..5a88f4b3a9 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Index.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Index.cshtml.cs @@ -11,5 +11,6 @@ public class IndexModel(SupportUiLinkGenerator linkGenerator) : PageModel [FromQuery] public Guid PersonId { get; set; } - public IActionResult OnGet() => Redirect(linkGenerator.Alerts.AddAlert.Type(PersonId, JourneyInstance!.InstanceId)); + public Task OnGetAsync() => + JourneyInstance!.UpdateStateAndRedirectToNextStepAsync(_ => { }, linkGenerator.Alerts.AddAlert.Type(PersonId, JourneyInstance!.InstanceId)); } diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Link.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Link.cshtml index 2da6014ab3..207f64519a 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Link.cshtml +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Link.cshtml @@ -1,16 +1,16 @@ -@page "/alerts/add/link/{handler?}" +@page "/alerts/add/link" @model TeachingRecordSystem.SupportUi.Pages.Alerts.AddAlert.LinkModel @{ ViewBag.Title = Html.DisplayNameFor(m => m.AddLink); } @section BeforeContent { - + }
- + Add an alert - @Model.PersonName diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Link.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Link.cshtml.cs index 41738dd1a4..024da9c6bf 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Link.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Link.cshtml.cs @@ -14,9 +14,6 @@ public class LinkModel(SupportUiLinkGenerator linkGenerator, EvidenceUploadManag [FromQuery] public Guid PersonId { get; set; } - [FromQuery] - public bool FromCheckAnswers { get; set; } - public string? PersonName { get; set; } [BindProperty] @@ -44,15 +41,15 @@ public async Task OnPostAsync() return this.PageWithErrors(); } - await JourneyInstance!.UpdateStateAsync(state => - { - state.AddLink = AddLink; - state.Link = AddLink == true ? Link : null; - }); + var nextStep = linkGenerator.Alerts.AddAlert.StartDate(PersonId, JourneyInstance!.InstanceId); - return Redirect(FromCheckAnswers - ? linkGenerator.Alerts.AddAlert.CheckAnswers(PersonId, JourneyInstance.InstanceId) - : linkGenerator.Alerts.AddAlert.StartDate(PersonId, JourneyInstance.InstanceId)); + return await JourneyInstance.UpdateStateAndRedirectToNextStepAsync( + state => + { + state.AddLink = AddLink; + state.Link = AddLink == true ? Link : null; + }, + nextStep); } public async Task OnPostCancelAsync() diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Reason.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Reason.cshtml index 1878b9bc0e..5f7066df46 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Reason.cshtml +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Reason.cshtml @@ -1,16 +1,16 @@ -@page "/alerts/add/reason/{handler?}" +@page "/alerts/add/reason" @model TeachingRecordSystem.SupportUi.Pages.Alerts.AddAlert.ReasonModel @{ ViewBag.Title = "Why are you adding this alert?"; } @section BeforeContent { - Back + Back }
- + Add an alert - @Model.PersonName

@ViewBag.Title

diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Reason.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Reason.cshtml.cs index e82b5e6558..91e0279ea5 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Reason.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Reason.cshtml.cs @@ -14,9 +14,6 @@ public class ReasonModel(SupportUiLinkGenerator linkGenerator, EvidenceUploadMan [FromQuery] public Guid PersonId { get; set; } - [FromQuery] - public bool FromCheckAnswers { get; set; } - public string? PersonName { get; set; } [BindProperty] @@ -69,15 +66,17 @@ public async Task OnPostAsync() return this.PageWithErrors(); } - await JourneyInstance!.UpdateStateAsync(state => - { - state.AddReason = AddReason; - state.HasAdditionalReasonDetail = HasAdditionalReasonDetail; - state.AddReasonDetail = AddReasonDetail; - state.Evidence = Evidence; - }); - - return Redirect(linkGenerator.Alerts.AddAlert.CheckAnswers(PersonId, JourneyInstance.InstanceId)); + var nextStep = linkGenerator.Alerts.AddAlert.CheckAnswers(PersonId, JourneyInstance!.InstanceId); + + return await JourneyInstance!.UpdateStateAndRedirectToNextStepAsync( + state => + { + state.AddReason = AddReason; + state.HasAdditionalReasonDetail = HasAdditionalReasonDetail; + state.AddReasonDetail = AddReasonDetail; + state.Evidence = Evidence; + }, + nextStep); } public async Task OnPostCancelAsync() diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/StartDate.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/StartDate.cshtml index b05aa25c90..08fa9e95a2 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/StartDate.cshtml +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/StartDate.cshtml @@ -1,16 +1,16 @@ -@page "/alerts/add/start-date/{handler?}" +@page "/alerts/add/start-date" @model TeachingRecordSystem.SupportUi.Pages.Alerts.AddAlert.StartDateModel @{ ViewBag.Title = "Enter the alert start date"; } @section BeforeContent { - Back + Back }
- + Add an alert - @Model.PersonName diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/StartDate.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/StartDate.cshtml.cs index 0086a01f81..2370d5b517 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/StartDate.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/StartDate.cshtml.cs @@ -14,9 +14,6 @@ public class StartDateModel(SupportUiLinkGenerator linkGenerator, EvidenceUpload [FromQuery] public Guid PersonId { get; set; } - [FromQuery] - public bool FromCheckAnswers { get; set; } - public string? PersonName { get; set; } [BindProperty] @@ -40,14 +37,11 @@ public async Task OnPostAsync() return this.PageWithErrors(); } - await JourneyInstance!.UpdateStateAsync(state => - { - state.StartDate = StartDate!.Value; - }); + var nextStep = linkGenerator.Alerts.AddAlert.Reason(PersonId, JourneyInstance!.InstanceId); - return Redirect(FromCheckAnswers - ? linkGenerator.Alerts.AddAlert.CheckAnswers(PersonId, JourneyInstance.InstanceId) - : linkGenerator.Alerts.AddAlert.Reason(PersonId, JourneyInstance.InstanceId)); + return await JourneyInstance.UpdateStateAndRedirectToNextStepAsync( + state => state.StartDate = StartDate!.Value, + nextStep); } public async Task OnPostCancelAsync() @@ -59,12 +53,6 @@ public async Task OnPostCancelAsync() public override void OnPageHandlerExecuting(PageHandlerExecutingContext context) { - if (JourneyInstance!.State.AddLink is null) - { - context.Result = Redirect(linkGenerator.Alerts.AddAlert.Link(PersonId, JourneyInstance.InstanceId)); - return; - } - var personInfo = context.HttpContext.GetCurrentPersonFeature(); PersonName = personInfo.Name; diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Type.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Type.cshtml index f06bf14f89..347d904c5c 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Type.cshtml +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Type.cshtml @@ -1,16 +1,16 @@ -@page "/alerts/add/type/{handler?}" +@page "/alerts/add/type" @model TeachingRecordSystem.SupportUi.Pages.Alerts.AddAlert.TypeModel @{ ViewBag.Title = Html.DisplayNameFor(m => m.AlertTypeId); } @section BeforeContent { - Back + Back }
- + Add an alert - @Model.PersonName diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Type.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Type.cshtml.cs index 1a98e7cffb..345e5e3410 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Type.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Type.cshtml.cs @@ -21,9 +21,6 @@ public class TypeModel( [FromQuery] public Guid PersonId { get; set; } - [FromQuery] - public bool FromCheckAnswers { get; set; } - public string? PersonName { get; set; } [BindProperty] @@ -47,17 +44,15 @@ public async Task OnPostAsync() } var selectedType = AlertTypes!.Single(t => t.AlertTypeId == AlertTypeId); + var nextStep = linkGenerator.Alerts.AddAlert.Details(PersonId, JourneyInstance!.InstanceId); - await JourneyInstance!.UpdateStateAsync( + return await JourneyInstance.UpdateStateAndRedirectToNextStepAsync( state => { state.AlertTypeId = AlertTypeId; state.AlertTypeName = selectedType.Name; - }); - - return Redirect(FromCheckAnswers - ? linkGenerator.Alerts.AddAlert.CheckAnswers(PersonId, JourneyInstance.InstanceId) - : linkGenerator.Alerts.AddAlert.Details(PersonId, JourneyInstance.InstanceId)); + }, + nextStep); } public async Task OnPostCancelAsync() diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/_ViewImports.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/_ViewImports.cshtml index c567cb5c77..ce0bd28770 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/_ViewImports.cshtml +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/_ViewImports.cshtml @@ -1,4 +1,5 @@ @using GovUk.Frontend.AspNetCore +@using Microsoft.AspNetCore.Http.Extensions @using Microsoft.AspNetCore.Http.Features @using TeachingRecordSystem.Core.Models @using TeachingRecordSystem.WebCommon diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/TrsLinkGenerator.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/TrsLinkGenerator.cs deleted file mode 100644 index 947a9a994b..0000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/TrsLinkGenerator.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Microsoft.AspNetCore.WebUtilities; -using TeachingRecordSystem.SupportUi.Infrastructure.ModelBinding; - -namespace TeachingRecordSystem.SupportUi; - -public partial class TrsLinkGenerator(LinkGenerator linkGenerator) -{ - protected const string DateOnlyFormat = DateOnlyModelBinder.Format; - - public string Index() => GetRequiredPathByPage("/Index"); - - public string SignOut() => GetRequiredPathByPage("/SignOut"); - - public string SignedOut() => GetRequiredPathByPage("/SignedOut"); - - private string GetRequiredPathByPage(string page, string? handler = null, object? routeValues = null, JourneyInstanceId? journeyInstanceId = null) - { - var url = linkGenerator.GetPathByPage(page, handler, values: routeValues) ?? throw new InvalidOperationException("Page was not found."); - - if (journeyInstanceId?.UniqueKey is string journeyInstanceUniqueKey) - { - url = QueryHelpers.AddQueryString(url, Constants.UniqueKeyQueryParameterName, journeyInstanceUniqueKey); - } - - return url; - } -} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.WebCommon/FormFlow/JourneySteps.cs b/TeachingRecordSystem/src/TeachingRecordSystem.WebCommon/FormFlow/JourneySteps.cs index 6fa858dda0..7274516d5c 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.WebCommon/FormFlow/JourneySteps.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.WebCommon/FormFlow/JourneySteps.cs @@ -15,10 +15,15 @@ public JourneyStep(string stepUrl) : } [JsonConverter(typeof(JourneyStepsJsonConverter))] -public class JourneySteps(IReadOnlyCollection steps) +public class JourneySteps(IEnumerable steps) { private readonly List _steps = steps.ToList(); + public JourneySteps(params IEnumerable stepUrls) + : this(stepUrls.Select(url => new JourneyStep(url))) + { + } + public string LastStepUrl => _steps.Last().StepUrl; public IReadOnlyCollection Steps => _steps.AsReadOnly(); diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/JourneyInstanceExtensions.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/FormFlowExtensions.cs similarity index 52% rename from TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/JourneyInstanceExtensions.cs rename to TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/FormFlowExtensions.cs index a0677d5794..d120242f51 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/JourneyInstanceExtensions.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/FormFlowExtensions.cs @@ -1,9 +1,14 @@ namespace TeachingRecordSystem.SupportUi.Tests; -public static class JourneyInstanceExtensions +public static class FormFlowExtensions { public static string GetUniqueIdQueryParameter(this JourneyInstance journeyInstance) => journeyInstance.InstanceId.UniqueKey is string uniqueKey ? $"{Constants.UniqueKeyQueryParameterName}={Uri.EscapeDataString(uniqueKey)}" : string.Empty; + + public static string GetUniqueIdQueryParameter(this JourneyInstanceId instanceId) => + instanceId.UniqueKey is string uniqueKey ? + $"{Constants.UniqueKeyQueryParameterName}={Uri.EscapeDataString(uniqueKey)}" : + string.Empty; } diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/AddAlertTestBase.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/AddAlertTestBase.cs index 08662613b2..420f80d3a0 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/AddAlertTestBase.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/AddAlertTestBase.cs @@ -5,83 +5,95 @@ namespace TeachingRecordSystem.SupportUi.Tests.PageTests.Alerts.AddAlert; public abstract class AddAlertTestBase(HostFixture hostFixture) : TestBase(hostFixture) { - protected Task> CreateEmptyJourneyInstanceAsync(Guid personId) => - CreateJourneyInstanceAsync(personId, new()); - - protected async Task> CreateJourneyInstanceForAllStepsCompletedAsync(Guid personId, bool populateOptional = true) + protected Task> CreateJourneyInstanceForNoStepsCompletedAsync(Guid personId) { - var alertType = await GetKnownAlertTypeAsync(); - - return await CreateJourneyInstanceAsync(personId, new AddAlertState - { - AlertTypeId = alertType.AlertTypeId, - AlertTypeName = alertType.Name, - Details = "Alert Details", - AddLink = populateOptional, - Link = populateOptional ? "https://www.example.com" : null, - StartDate = Clock.Today.AddDays(-30), - AddReason = AddAlertReasonOption.AnotherReason, - HasAdditionalReasonDetail = populateOptional ? true : false, - AddReasonDetail = populateOptional ? "More details" : null, - Evidence = new() - { - UploadEvidence = populateOptional ? true : false, - UploadedEvidenceFile = populateOptional ? new() - { - FileId = Guid.NewGuid(), - FileName = "evidence.jpeg", - FileSizeDescription = "5MB" - } : null - } - }); + return CreateJourneyInstanceForCompletedStepAsync(JourneyStepNames.Index, personId, alertType: null); } - protected async Task> CreateJourneyInstanceForCompletedStepAsync(string step, Guid personId, bool populateOptional = true) + protected Task> CreateJourneyInstanceForIncompleteStepAsync( + string stepName, + Guid personId, + bool populateOptional = true) { - var alertType = await GetKnownAlertTypeAsync(); + var previousStep = stepName switch + { + JourneyStepNames.Index or JourneyStepNames.AlertType => JourneyStepNames.Index, + JourneyStepNames.Details => JourneyStepNames.AlertType, + JourneyStepNames.Link => JourneyStepNames.Details, + JourneyStepNames.StartDate => JourneyStepNames.Link, + JourneyStepNames.Reason => JourneyStepNames.StartDate, + JourneyStepNames.CheckAnswers => JourneyStepNames.Reason, + _ => throw new ArgumentException($"Unknown {nameof(stepName)}: '{stepName}'", nameof(stepName)) + }; - return await CreateJourneyInstanceForCompletedStepAsync(step, personId, alertType, populateOptional); + return CreateJourneyInstanceForCompletedStepAsync(previousStep, personId, populateOptional: populateOptional); } - protected async Task> CreateJourneyInstanceForCompletedStepAsync(string step, Guid personId, Guid alertTypeId, bool populateOptional = true) + protected async Task> CreateJourneyInstanceForCompletedStepAsync( + string stepName, + Guid personId, + AlertType? alertType = null, + bool populateOptional = true) { - var alertType = await TestData.ReferenceDataCache.GetAlertTypeByIdAsync(alertTypeId); - - return await CreateJourneyInstanceForCompletedStepAsync(step, personId, alertType, populateOptional); - } + alertType ??= await GetKnownAlertTypeAsync(); - protected Task> CreateJourneyInstanceForCompletedStepAsync(string step, Guid personId, AlertType alertType, bool populateOptional = true) - { - return - (step switch + return await + (stepName switch { - JourneySteps.New or JourneySteps.Index => - CreateEmptyJourneyInstanceAsync(personId), - JourneySteps.AlertType => - CreateJourneyInstanceAsync(personId, new AddAlertState + JourneyStepNames.Index => + CreateJourneyInstanceAsync(personId, instanceId => new AddAlertState() + { + Steps = new JourneySteps( + GetStepUrl(JourneyStepNames.Index, personId, instanceId), + GetStepUrl(JourneyStepNames.AlertType, personId, instanceId)) + }), + JourneyStepNames.AlertType => + CreateJourneyInstanceAsync(personId, instanceId => new AddAlertState { + Steps = new JourneySteps( + GetStepUrl(JourneyStepNames.Index, personId, instanceId), + GetStepUrl(JourneyStepNames.AlertType, personId, instanceId), + GetStepUrl(JourneyStepNames.Details, personId, instanceId)), AlertTypeId = alertType.AlertTypeId, AlertTypeName = alertType.Name }), - JourneySteps.Details => - CreateJourneyInstanceAsync(personId, new AddAlertState + JourneyStepNames.Details => + CreateJourneyInstanceAsync(personId, instanceId => new AddAlertState { + Steps = new JourneySteps( + GetStepUrl(JourneyStepNames.Index, personId, instanceId), + GetStepUrl(JourneyStepNames.AlertType, personId, instanceId), + GetStepUrl(JourneyStepNames.Details, personId, instanceId), + GetStepUrl(JourneyStepNames.Link, personId, instanceId)), AlertTypeId = alertType.AlertTypeId, AlertTypeName = alertType.Name, Details = "Alert Details" }), - JourneySteps.Link => - CreateJourneyInstanceAsync(personId, new AddAlertState + JourneyStepNames.Link => + CreateJourneyInstanceAsync(personId, instanceId => new AddAlertState { + Steps = new JourneySteps( + GetStepUrl(JourneyStepNames.Index, personId, instanceId), + GetStepUrl(JourneyStepNames.AlertType, personId, instanceId), + GetStepUrl(JourneyStepNames.Details, personId, instanceId), + GetStepUrl(JourneyStepNames.Link, personId, instanceId), + GetStepUrl(JourneyStepNames.StartDate, personId, instanceId)), AlertTypeId = alertType.AlertTypeId, AlertTypeName = alertType.Name, Details = "Alert Details", AddLink = populateOptional, Link = populateOptional ? "https://www.example.com" : null }), - JourneySteps.StartDate => - CreateJourneyInstanceAsync(personId, new AddAlertState + JourneyStepNames.StartDate => + CreateJourneyInstanceAsync(personId, instanceId => new AddAlertState { + Steps = new JourneySteps( + GetStepUrl(JourneyStepNames.Index, personId, instanceId), + GetStepUrl(JourneyStepNames.AlertType, personId, instanceId), + GetStepUrl(JourneyStepNames.Details, personId, instanceId), + GetStepUrl(JourneyStepNames.Link, personId, instanceId), + GetStepUrl(JourneyStepNames.StartDate, personId, instanceId), + GetStepUrl(JourneyStepNames.Reason, personId, instanceId)), AlertTypeId = alertType.AlertTypeId, AlertTypeName = alertType.Name, Details = "Alert Details", @@ -89,24 +101,98 @@ protected Task> CreateJourneyInstanceForCompleted Link = populateOptional ? "https://www.example.com" : null, StartDate = Clock.Today.AddDays(-30) }), - JourneySteps.Reason or JourneySteps.CheckAnswers => - CreateJourneyInstanceForAllStepsCompletedAsync(personId, populateOptional: true), - _ => throw new ArgumentException($"Unknown {nameof(step)}: '{step}'.", nameof(step)) + JourneyStepNames.Reason => + CreateJourneyInstanceAsync(personId, instanceId => new AddAlertState + { + Steps = new JourneySteps( + GetStepUrl(JourneyStepNames.Index, personId, instanceId), + GetStepUrl(JourneyStepNames.AlertType, personId, instanceId), + GetStepUrl(JourneyStepNames.Details, personId, instanceId), + GetStepUrl(JourneyStepNames.Link, personId, instanceId), + GetStepUrl(JourneyStepNames.StartDate, personId, instanceId), + GetStepUrl(JourneyStepNames.Reason, personId, instanceId), + GetStepUrl(JourneyStepNames.CheckAnswers, personId, instanceId)), + AlertTypeId = alertType.AlertTypeId, + AlertTypeName = alertType.Name, + Details = "Alert Details", + AddLink = populateOptional, + Link = populateOptional ? "https://www.example.com" : null, + StartDate = Clock.Today.AddDays(-30), + AddReason = AddAlertReasonOption.AnotherReason, + HasAdditionalReasonDetail = populateOptional, + AddReasonDetail = populateOptional ? "More details" : null, + Evidence = new() + { + UploadEvidence = populateOptional, + UploadedEvidenceFile = populateOptional ? new() + { + FileId = Guid.NewGuid(), + FileName = "evidence.jpeg", + FileSizeDescription = "5MB" + } : null + } + }), + JourneyStepNames.CheckAnswers => + CreateJourneyInstanceAsync(personId, instanceId => new AddAlertState + { + Steps = new JourneySteps( + GetStepUrl(JourneyStepNames.Index, personId, instanceId), + GetStepUrl(JourneyStepNames.AlertType, personId, instanceId), + GetStepUrl(JourneyStepNames.Details, personId, instanceId), + GetStepUrl(JourneyStepNames.Link, personId, instanceId), + GetStepUrl(JourneyStepNames.StartDate, personId, instanceId), + GetStepUrl(JourneyStepNames.Reason, personId, instanceId), + GetStepUrl(JourneyStepNames.CheckAnswers, personId, instanceId)), + AlertTypeId = alertType.AlertTypeId, + AlertTypeName = alertType.Name, + Details = "Alert Details", + AddLink = populateOptional, + Link = populateOptional ? "https://www.example.com" : null, + StartDate = Clock.Today.AddDays(-30), + AddReason = AddAlertReasonOption.AnotherReason, + HasAdditionalReasonDetail = populateOptional, + AddReasonDetail = populateOptional ? "More details" : null, + Evidence = new() + { + UploadEvidence = populateOptional, + UploadedEvidenceFile = populateOptional ? new() + { + FileId = Guid.NewGuid(), + FileName = "evidence.jpeg", + FileSizeDescription = "5MB" + } : null + } + }), + _ => throw new ArgumentException($"Unknown {nameof(stepName)}: '{stepName}'.", nameof(stepName)) }); } protected Task GetKnownAlertTypeAsync(bool isDbsAlertType = false) => - isDbsAlertType ? TestData.ReferenceDataCache.GetAlertTypeByDqtSanctionCodeAsync("") : TestData.ReferenceDataCache.GetAlertTypeByDqtSanctionCodeAsync("T4"); + isDbsAlertType ? + TestData.ReferenceDataCache.GetAlertTypeByIdAsync(AlertType.DbsAlertTypeId) : + TestData.ReferenceDataCache.GetAlertTypeByIdAsync(AlertType.ProhibitionBySoSMisconduct); + + protected static string GetStepUrl(string stepName, Guid personId, JourneyInstanceId instanceId) => + stepName switch + { + JourneyStepNames.Index => $"/alerts/add?personId={personId}&{instanceId.GetUniqueIdQueryParameter()}", + JourneyStepNames.AlertType => $"/alerts/add/type?personId={personId}&{instanceId.GetUniqueIdQueryParameter()}", + JourneyStepNames.Details => $"/alerts/add/details?personId={personId}&{instanceId.GetUniqueIdQueryParameter()}", + JourneyStepNames.Link => $"/alerts/add/link?personId={personId}&{instanceId.GetUniqueIdQueryParameter()}", + JourneyStepNames.StartDate => $"/alerts/add/start-date?personId={personId}&{instanceId.GetUniqueIdQueryParameter()}", + JourneyStepNames.Reason => $"/alerts/add/reason?personId={personId}&{instanceId.GetUniqueIdQueryParameter()}", + JourneyStepNames.CheckAnswers => $"/alerts/add/check-answers?personId={personId}&{instanceId.GetUniqueIdQueryParameter()}", + _ => throw new ArgumentException($"Unknown {nameof(stepName)}: '{stepName}'.", nameof(stepName)) + }; - private Task> CreateJourneyInstanceAsync(Guid personId, AddAlertState state) => + private Task> CreateJourneyInstanceAsync(Guid personId, Func createState) => CreateJourneyInstance( JourneyNames.AddAlert, - state ?? new AddAlertState(), + createState, new KeyValuePair("personId", personId)); - public static class JourneySteps + protected static class JourneyStepNames { - public const string New = nameof(New); public const string Index = nameof(Index); public const string AlertType = nameof(AlertType); public const string Details = nameof(Details); diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/CheckAnswersTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/CheckAnswersTests.cs index db4b613ee5..494a81570d 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/CheckAnswersTests.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/CheckAnswersTests.cs @@ -4,7 +4,7 @@ namespace TeachingRecordSystem.SupportUi.Tests.PageTests.Alerts.AddAlert; public class CheckAnswersTests(HostFixture hostFixture) : AddAlertTestBase(hostFixture), IAsyncLifetime { - private const string PreviousStep = JourneySteps.Reason; + private const string PreviousStep = JourneyStepNames.Reason; async ValueTask IAsyncLifetime.InitializeAsync() => SetCurrentUser(await TestData.CreateUserAsync(role: UserRoles.AlertsManagerTraDbs)); @@ -45,11 +45,11 @@ public async Task Get_WithPersonIdForNonExistentPerson_ReturnsNotFound() } [Fact] - public async Task Get_MissingDataInJourneyState_RedirectsToReasonPage() + public async Task Get_MissingDataInJourneyState_RedirectsToTypePage() { // Arrange var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateEmptyJourneyInstanceAsync(person.PersonId); + var journeyInstance = await CreateJourneyInstanceForIncompleteStepAsync(PreviousStep, person.PersonId); var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/add/check-answers?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); @@ -58,7 +58,7 @@ public async Task Get_MissingDataInJourneyState_RedirectsToReasonPage() // Assert Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); - Assert.StartsWith($"/alerts/add/reason?personId={person.PersonId}", response.Headers.Location?.OriginalString); + Assert.Equal(GetStepUrl(PreviousStep, person.PersonId, journeyInstance.InstanceId), response.Headers.Location?.OriginalString); } [Theory] @@ -68,7 +68,7 @@ public async Task Get_WithPersonIdForValidPerson_ReturnsOk(bool populateOptional { // Arrange var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateJourneyInstanceForAllStepsCompletedAsync(person.PersonId, populateOptional); + var journeyInstance = await CreateJourneyInstanceForCompletedStepAsync(PreviousStep, person.PersonId, populateOptional: populateOptional); var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/add/check-answers?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); @@ -128,7 +128,7 @@ public async Task Post_Confirm_CreatesAlertCreatesEventCompletesJourneyAndRedire { // Arrange var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateJourneyInstanceForAllStepsCompletedAsync(person.PersonId, populateOptional); + var journeyInstance = await CreateJourneyInstanceForCompletedStepAsync(PreviousStep, person.PersonId, populateOptional: populateOptional); EventObserver.Clear(); @@ -182,9 +182,9 @@ public async Task Post_Cancel_DeletesJourneyAndRedirects() { // Arrange var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateJourneyInstanceForAllStepsCompletedAsync(person.PersonId, populateOptional: true); + var journeyInstance = await CreateJourneyInstanceForCompletedStepAsync(PreviousStep, person.PersonId); - var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/check-answers/cancel?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); + var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/check-answers?handler=cancel&personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); // Act var response = await HttpClient.SendAsync(request); @@ -209,7 +209,7 @@ await WithDbContextAsync(async dbContext => await dbContext.SaveChangesAsync(); }); - var journeyInstance = await CreateJourneyInstanceForAllStepsCompletedAsync(person.PersonId, populateOptional: true); + var journeyInstance = await CreateJourneyInstanceForCompletedStepAsync(PreviousStep, person.PersonId); var request = new HttpRequestMessage(httpMethod, $"/alerts/add/check-answers?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/DetailsTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/DetailsTests.cs index 0dcf45fe7f..fad9cec836 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/DetailsTests.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/DetailsTests.cs @@ -4,8 +4,8 @@ namespace TeachingRecordSystem.SupportUi.Tests.PageTests.Alerts.AddAlert; public class DetailsTests(HostFixture hostFixture) : AddAlertTestBase(hostFixture), IAsyncLifetime { - private const string PreviousStep = JourneySteps.AlertType; - private const string ThisStep = JourneySteps.Details; + private const string PreviousStep = JourneyStepNames.AlertType; + private const string ThisStep = JourneyStepNames.Details; async ValueTask IAsyncLifetime.InitializeAsync() => SetCurrentUser(await TestData.CreateUserAsync(role: UserRoles.AlertsManagerTraDbs)); @@ -51,7 +51,7 @@ public async Task Get_MissingDataInJourneyState_Redirects() { // Arrange var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateEmptyJourneyInstanceAsync(person.PersonId); + var journeyInstance = await CreateJourneyInstanceForIncompleteStepAsync(PreviousStep, person.PersonId); var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/add/details?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); @@ -60,7 +60,7 @@ public async Task Get_MissingDataInJourneyState_Redirects() // Assert Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); - Assert.StartsWith($"/alerts/add/type?personId={person.PersonId}", response.Headers.Location?.OriginalString); + Assert.Equal(GetStepUrl(PreviousStep, person.PersonId, journeyInstance.InstanceId), response.Headers.Location?.OriginalString); } [Fact] @@ -136,7 +136,7 @@ public async Task Post_WithMissingDataInJourneyState_Redirects() { // Arrange var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateEmptyJourneyInstanceAsync(person.PersonId); + var journeyInstance = await CreateJourneyInstanceForNoStepsCompletedAsync(person.PersonId); var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/details?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); @@ -223,7 +223,7 @@ public async Task Post_Cancel_DeletesJourneyAndRedirects() var person = await TestData.CreatePersonAsync(); var journeyInstance = await CreateJourneyInstanceForCompletedStepAsync(PreviousStep, person.PersonId); - var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/details/cancel?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); + var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/details?handler=cancel&personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); // Act var response = await HttpClient.SendAsync(request); diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/LinkTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/LinkTests.cs index 03316b71bd..daf2baa940 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/LinkTests.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/LinkTests.cs @@ -2,8 +2,8 @@ namespace TeachingRecordSystem.SupportUi.Tests.PageTests.Alerts.AddAlert; public class LinkTests(HostFixture hostFixture) : AddAlertTestBase(hostFixture), IAsyncLifetime { - private const string PreviousStep = JourneySteps.Details; - private const string ThisStep = JourneySteps.Link; + private const string PreviousStep = JourneyStepNames.Details; + private const string ThisStep = JourneyStepNames.Link; async ValueTask IAsyncLifetime.InitializeAsync() => SetCurrentUser(await TestData.CreateUserAsync(role: UserRoles.AlertsManagerTraDbs)); @@ -45,11 +45,11 @@ public async Task Get_WithPersonIdForNonExistentPerson_ReturnsNotFound() } [Fact] - public async Task Get_MissingDetailsInJourneyState_ReturnsOk() + public async Task Get_MissingDetailsInJourneyState_Redirects() { // Arrange var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateEmptyJourneyInstanceAsync(person.PersonId); + var journeyInstance = await CreateJourneyInstanceForIncompleteStepAsync(PreviousStep, person.PersonId); var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/add/link?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); @@ -57,7 +57,8 @@ public async Task Get_MissingDetailsInJourneyState_ReturnsOk() var response = await HttpClient.SendAsync(request); // Assert - Assert.Equal(StatusCodes.Status200OK, (int)response.StatusCode); + Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); + Assert.Equal(GetStepUrl(PreviousStep, person.PersonId, journeyInstance.InstanceId), response.Headers.Location?.OriginalString); } [Fact] @@ -129,11 +130,11 @@ public async Task Post_WithPersonIdForNonExistentPerson_ReturnsNotFound() } [Fact] - public async Task Post_WithMissingDetailsDataInJourneyState_RedirectsToStartDatePage() + public async Task Post_WithMissingDetailsDataInJourneyState_Redirects() { // Arrange var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateJourneyInstanceForCompletedStepAsync(PreviousStep, person.PersonId); + var journeyInstance = await CreateJourneyInstanceForCompletedStepAsync(JourneyStepNames.AlertType, person.PersonId); var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/link?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}") { @@ -144,10 +145,10 @@ public async Task Post_WithMissingDetailsDataInJourneyState_RedirectsToStartDate // Assert Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); - Assert.StartsWith($"/alerts/add/start-date?personId={person.PersonId}", response.Headers.Location?.OriginalString); + Assert.Equal(GetStepUrl(PreviousStep, person.PersonId, journeyInstance.InstanceId), response.Headers.Location?.OriginalString); journeyInstance = await ReloadJourneyInstance(journeyInstance); - Assert.False(journeyInstance.State.AddLink); + Assert.Null(journeyInstance.State.AddLink); Assert.Null(journeyInstance.State.Link); } @@ -207,7 +208,7 @@ public async Task Post_WithLink_UpdatesStateAndRedirectsToStartDatePage() // Assert Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); - Assert.StartsWith($"/alerts/add/start-date?personId={person.PersonId}", response.Headers.Location?.OriginalString); + Assert.Equal(GetStepUrl(JourneyStepNames.StartDate, person.PersonId, journeyInstance.InstanceId), response.Headers.Location?.OriginalString); journeyInstance = await ReloadJourneyInstance(journeyInstance); Assert.True(journeyInstance.State.AddLink); @@ -231,7 +232,7 @@ public async Task Post_WithNoLink_UpdatesStateAndRedirectsToStartDatePage() // Assert Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); - Assert.StartsWith($"/alerts/add/start-date?personId={person.PersonId}", response.Headers.Location?.OriginalString); + Assert.Equal(GetStepUrl(JourneyStepNames.StartDate, person.PersonId, journeyInstance.InstanceId), response.Headers.Location?.OriginalString); journeyInstance = await ReloadJourneyInstance(journeyInstance); Assert.False(journeyInstance.State.AddLink); @@ -245,7 +246,7 @@ public async Task Post_Cancel_DeletesJourneyAndRedirects() var person = await TestData.CreatePersonAsync(); var journeyInstance = await CreateJourneyInstanceForCompletedStepAsync(PreviousStep, person.PersonId); - var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/link/cancel?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); + var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/link?handler=cancel&personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); // Act var response = await HttpClient.SendAsync(request); diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/ReasonTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/ReasonTests.cs index d96066c3dd..6b1cbced7b 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/ReasonTests.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/ReasonTests.cs @@ -4,8 +4,8 @@ namespace TeachingRecordSystem.SupportUi.Tests.PageTests.Alerts.AddAlert; public class ReasonTests(HostFixture hostFixture) : AddAlertTestBase(hostFixture), IAsyncLifetime { - private const string PreviousStep = JourneySteps.StartDate; - private const string ThisStep = JourneySteps.Reason; + private const string PreviousStep = JourneyStepNames.StartDate; + private const string ThisStep = JourneyStepNames.Reason; async ValueTask IAsyncLifetime.InitializeAsync() => SetCurrentUser(await TestData.CreateUserAsync(role: UserRoles.AlertsManagerTraDbs)); @@ -51,7 +51,7 @@ public async Task Get_MissingDataInJourneyState_RedirectsToStartDatePage() { // Arrange var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateEmptyJourneyInstanceAsync(person.PersonId); + var journeyInstance = await CreateJourneyInstanceForCompletedStepAsync(JourneyStepNames.Link, person.PersonId); var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/add/reason?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); @@ -60,7 +60,7 @@ public async Task Get_MissingDataInJourneyState_RedirectsToStartDatePage() // Assert Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); - Assert.StartsWith($"/alerts/add/start-date?personId={person.PersonId}", response.Headers.Location?.OriginalString); + Assert.Equal(GetStepUrl(PreviousStep, person.PersonId, journeyInstance.InstanceId), response.Headers.Location?.OriginalString); } [Fact] @@ -146,11 +146,11 @@ public async Task Post_WithPersonIdForNonExistentPerson_ReturnsNotFound() } [Fact] - public async Task Post_WithMissingDataInJourneyState_RedirectsToStartDatePage() + public async Task Post_WithMissingDataInJourneyState_Redirects() { // Arrange var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateEmptyJourneyInstanceAsync(person.PersonId); + var journeyInstance = await CreateJourneyInstanceForIncompleteStepAsync(PreviousStep, person.PersonId); var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/reason?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); @@ -159,7 +159,7 @@ public async Task Post_WithMissingDataInJourneyState_RedirectsToStartDatePage() // Assert Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); - Assert.StartsWith($"/alerts/add/start-date?personId={person.PersonId}", response.Headers.Location?.OriginalString); + Assert.Equal(GetStepUrl(PreviousStep, person.PersonId, journeyInstance.InstanceId), response.Headers.Location?.OriginalString); } [Fact] @@ -341,7 +341,7 @@ public async Task Post_ValidInputWithoutEvidenceFile_UpdatesStateAndRedirectsToC // Assert Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); - Assert.StartsWith($"/alerts/add/check-answers?personId={person.PersonId}", response.Headers.Location?.OriginalString); + Assert.Equal(GetStepUrl(JourneyStepNames.CheckAnswers, person.PersonId, journeyInstance.InstanceId), response.Headers.Location?.OriginalString); journeyInstance = await ReloadJourneyInstance(journeyInstance); Assert.Equal(reason, journeyInstance.State.AddReason); @@ -375,7 +375,7 @@ public async Task Post_ValidInputWithEvidenceFile_UpdatesStateAndRedirectsToChec // Assert Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); - Assert.StartsWith($"/alerts/add/check-answers?personId={person.PersonId}", response.Headers.Location?.OriginalString); + Assert.Equal(GetStepUrl(JourneyStepNames.CheckAnswers, person.PersonId, journeyInstance.InstanceId), response.Headers.Location?.OriginalString); journeyInstance = await ReloadJourneyInstance(journeyInstance); Assert.Equal(reason, journeyInstance.State.AddReason); @@ -392,7 +392,7 @@ public async Task Post_Cancel_DeletesJourneyAndRedirects() var person = await TestData.CreatePersonAsync(); var journeyInstance = await CreateJourneyInstanceForCompletedStepAsync(PreviousStep, person.PersonId); - var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/reason/cancel?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); + var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/reason?handler=cancel&personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); // Act var response = await HttpClient.SendAsync(request); diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/StartDateTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/StartDateTests.cs index 6b0d7e02f9..919e9289d6 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/StartDateTests.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/StartDateTests.cs @@ -2,8 +2,8 @@ namespace TeachingRecordSystem.SupportUi.Tests.PageTests.Alerts.AddAlert; public class StartDateTests(HostFixture hostFixture) : AddAlertTestBase(hostFixture), IAsyncLifetime { - private const string PreviousStep = JourneySteps.Link; - private const string ThisStep = JourneySteps.StartDate; + private const string PreviousStep = JourneyStepNames.Link; + private const string ThisStep = JourneyStepNames.StartDate; async ValueTask IAsyncLifetime.InitializeAsync() => SetCurrentUser(await TestData.CreateUserAsync(role: UserRoles.AlertsManagerTraDbs)); @@ -45,11 +45,11 @@ public async Task Get_WithPersonIdForNonExistentPerson_ReturnsNotFound() } [Fact] - public async Task Get_MissingDataInJourneyState_RedirectsToLinkPage() + public async Task Get_MissingDataInJourneyState_RedirectsToStartPage() { // Arrange var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateEmptyJourneyInstanceAsync(person.PersonId); + var journeyInstance = await CreateJourneyInstanceForCompletedStepAsync(JourneyStepNames.Details, person.PersonId); var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/add/start-date?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); @@ -58,7 +58,7 @@ public async Task Get_MissingDataInJourneyState_RedirectsToLinkPage() // Assert Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); - Assert.StartsWith($"/alerts/add/link?personId={person.PersonId}", response.Headers.Location?.OriginalString); + Assert.Equal(GetStepUrl(PreviousStep, person.PersonId, journeyInstance.InstanceId), response.Headers.Location?.OriginalString); } [Fact] @@ -132,11 +132,11 @@ public async Task Post_WithPersonIdForNonExistentPerson_ReturnsNotFound() } [Fact] - public async Task Post_WithMissingDataInJourneyState_RedirectsToLinkPage() + public async Task Post_WithMissingDataInJourneyState_Redirects() { // Arrange var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateEmptyJourneyInstanceAsync(person.PersonId); + var journeyInstance = await CreateJourneyInstanceForIncompleteStepAsync(PreviousStep, person.PersonId); var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/start-date?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); @@ -145,7 +145,7 @@ public async Task Post_WithMissingDataInJourneyState_RedirectsToLinkPage() // Assert Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); - Assert.StartsWith($"/alerts/add/link?personId={person.PersonId}", response.Headers.Location?.OriginalString); + Assert.Equal(GetStepUrl(PreviousStep, person.PersonId, journeyInstance.InstanceId), response.Headers.Location?.OriginalString); } [Fact] @@ -202,7 +202,7 @@ public async Task Post_WithValidInput_UpdatesStateAndRedirectsToReasonPage() // Assert Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); - Assert.StartsWith($"/alerts/add/reason?personId={person.PersonId}", response.Headers.Location?.OriginalString); + Assert.Equal(GetStepUrl(JourneyStepNames.Reason, person.PersonId, journeyInstance.InstanceId), response.Headers.Location?.OriginalString); journeyInstance = await ReloadJourneyInstance(journeyInstance); Assert.Equal(startDate, journeyInstance.State.StartDate); @@ -215,7 +215,7 @@ public async Task Post_Cancel_DeletesJourneyAndRedirects() var person = await TestData.CreatePersonAsync(); var journeyInstance = await CreateJourneyInstanceForCompletedStepAsync(PreviousStep, person.PersonId); - var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/start-date/cancel?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); + var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/start-date?handler=cancel&personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); // Act var response = await HttpClient.SendAsync(request); diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/TypeTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/TypeTests.cs index cf661af00d..b5b05fd5e8 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/TypeTests.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Alerts/AddAlert/TypeTests.cs @@ -4,8 +4,8 @@ namespace TeachingRecordSystem.SupportUi.Tests.PageTests.Alerts.AddAlert; public class TypeTests(HostFixture hostFixture) : AddAlertTestBase(hostFixture), IAsyncLifetime { - private const string PreviousStep = JourneySteps.Index; - private const string ThisStep = JourneySteps.AlertType; + private const string PreviousStep = JourneyStepNames.Index; + private const string ThisStep = JourneyStepNames.AlertType; async ValueTask IAsyncLifetime.InitializeAsync() => SetCurrentUser(await TestData.CreateUserAsync(role: UserRoles.AlertsManagerTraDbs)); @@ -19,7 +19,7 @@ public async Task Get_UserDoesNotHavePermission_ReturnsForbidden(string? role) SetCurrentUser(await TestData.CreateUserAsync(role: role)); var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateEmptyJourneyInstanceAsync(person.PersonId); + var journeyInstance = await CreateJourneyInstanceForNoStepsCompletedAsync(person.PersonId); var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/add/type?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); @@ -35,7 +35,7 @@ public async Task Get_WithPersonIdForNonExistentPerson_ReturnsNotFound() { // Arrange var personId = Guid.NewGuid(); - var journeyInstance = await CreateEmptyJourneyInstanceAsync(personId); + var journeyInstance = await CreateJourneyInstanceForNoStepsCompletedAsync(personId); var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/add/type?personId={personId}&{journeyInstance.GetUniqueIdQueryParameter()}"); @@ -51,7 +51,7 @@ public async Task Get_WithPersonIdForValidPerson_ReturnsOk() { // Arrange var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateEmptyJourneyInstanceAsync(person.PersonId); + var journeyInstance = await CreateJourneyInstanceForNoStepsCompletedAsync(person.PersonId); var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/add/type?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); @@ -69,7 +69,7 @@ public async Task Get_UserHasDbsAlertReadWriteRole_ShowsDbsAlertType() SetCurrentUser(await TestData.CreateUserAsync(role: UserRoles.AlertsManagerTraDbs)); var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateEmptyJourneyInstanceAsync(person.PersonId); + var journeyInstance = await CreateJourneyInstanceForNoStepsCompletedAsync(person.PersonId); var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/add/type?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); @@ -89,7 +89,7 @@ public async Task Get_UserDoesNotHaveDbsAlertReadWriteRole_DoesNotShowDbsAlertTy SetCurrentUser(await TestData.CreateUserAsync(role: UserRoles.AlertsManagerTra)); var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateEmptyJourneyInstanceAsync(person.PersonId); + var journeyInstance = await CreateJourneyInstanceForNoStepsCompletedAsync(person.PersonId); var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/add/type?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); @@ -109,7 +109,7 @@ public async Task Get_UserHasAlertsReadWriteRole_ShowsAllNonDbsRoles() SetCurrentUser(await TestData.CreateUserAsync(role: UserRoles.AlertsManagerTra)); var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateEmptyJourneyInstanceAsync(person.PersonId); + var journeyInstance = await CreateJourneyInstanceForNoStepsCompletedAsync(person.PersonId); var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/add/type?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); @@ -150,7 +150,7 @@ public async Task Post_UserDoesNotHavePermission_ReturnsForbidden(string? role) SetCurrentUser(await TestData.CreateUserAsync(role: role)); var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateEmptyJourneyInstanceAsync(person.PersonId); + var journeyInstance = await CreateJourneyInstanceForNoStepsCompletedAsync(person.PersonId); var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/type?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); @@ -166,7 +166,7 @@ public async Task Post_WithPersonIdForNonExistentPerson_ReturnsNotFound() { // Arrange var personId = Guid.NewGuid(); - var journeyInstance = await CreateEmptyJourneyInstanceAsync(personId); + var journeyInstance = await CreateJourneyInstanceForNoStepsCompletedAsync(personId); var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/type?personId={personId}&{journeyInstance.GetUniqueIdQueryParameter()}"); @@ -182,7 +182,7 @@ public async Task Post_WhenAlertTypeHasNotBeenSelected_ReturnsError() { // Arrange var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateEmptyJourneyInstanceAsync(person.PersonId); + var journeyInstance = await CreateJourneyInstanceForNoStepsCompletedAsync(person.PersonId); var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/type?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); @@ -198,7 +198,7 @@ public async Task Post_ValidInput_UpdatesStateAndRedirectsToDetailsPage() { // Arrange var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateEmptyJourneyInstanceAsync(person.PersonId); + var journeyInstance = await CreateJourneyInstanceForNoStepsCompletedAsync(person.PersonId); var alertType = await GetKnownAlertTypeAsync(); var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/type?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}") @@ -222,9 +222,9 @@ public async Task Post_Cancel_DeletesJourneyAndRedirects() { // Arrange var person = await TestData.CreatePersonAsync(); - var journeyInstance = await CreateEmptyJourneyInstanceAsync(person.PersonId); + var journeyInstance = await CreateJourneyInstanceForNoStepsCompletedAsync(person.PersonId); - var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/type/cancel?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); + var request = new HttpRequestMessage(HttpMethod.Post, $"/alerts/add/type?handler=cancel&personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}"); // Act var response = await HttpClient.SendAsync(request); @@ -248,7 +248,7 @@ await WithDbContextAsync(async dbContext => person.Person.Status = PersonStatus.Deactivated; await dbContext.SaveChangesAsync(); }); - var journeyInstance = await CreateEmptyJourneyInstanceAsync(person.PersonId); + var journeyInstance = await CreateJourneyInstanceForNoStepsCompletedAsync(person.PersonId); var request = new HttpRequestMessage(httpMethod, $"/alerts/add/type?personId={person.PersonId}&{journeyInstance.GetUniqueIdQueryParameter()}");