Skip to content

Commit

Permalink
Add check to see if user requesting a TRN is intending to do an NPQ
Browse files Browse the repository at this point in the history
  • Loading branch information
hortha committed Aug 16, 2024
1 parent 6d90564 commit 4a0d056
Show file tree
Hide file tree
Showing 11 changed files with 412 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public string SignOut(JourneyInstanceId journeyInstanceId) =>
public string RequestTrn(JourneyInstanceId journeyInstanceId) =>
GetRequiredPathByPage("/RequestTrn/Index", journeyInstanceId: journeyInstanceId);

public string RequestTrnNpqCheck(JourneyInstanceId journeyInstanceId) =>
GetRequiredPathByPage("/RequestTrn/NpqCheck", journeyInstanceId: journeyInstanceId);

public string RequestTrnNotEligible(JourneyInstanceId journeyInstanceId) =>
GetRequiredPathByPage("/RequestTrn/NotEligible", journeyInstanceId: journeyInstanceId);

public string RequestTrnEmail(JourneyInstanceId journeyInstanceId, bool? fromCheckAnswers = null) =>
GetRequiredPathByPage("/RequestTrn/Email", routeValues: new { fromCheckAnswers }, journeyInstanceId: journeyInstanceId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}

@section BeforeContent {
<govuk-back-link href="@(Model.FromCheckAnswers == true ? LinkGenerator.RequestTrnCheckAnswers(Model.JourneyInstance!.InstanceId) : LinkGenerator.RequestTrn(Model.JourneyInstance!.InstanceId))" />
<govuk-back-link href="@(Model.FromCheckAnswers == true ? LinkGenerator.RequestTrnCheckAnswers(Model.JourneyInstance!.InstanceId) : LinkGenerator.RequestTrnNpqCheck(Model.JourneyInstance!.InstanceId))" />
}

<div class="govuk-grid-row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
</div>
</div>

<govuk-button-link href="@LinkGenerator.RequestTrnEmail(Model.JourneyInstance!.InstanceId)" is-start-button="true">Start now</govuk-button-link>
<govuk-button-link href="@LinkGenerator.RequestTrnNpqCheck(Model.JourneyInstance!.InstanceId)" is-start-button="true">Start now</govuk-button-link>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@page "/request-trn/not-eligible"
@model TeachingRecordSystem.AuthorizeAccess.Pages.RequestTrn.NotEligibleModel
@{
ViewBag.Title = "You cannot use this service to get a TRN";
}

@section BeforeContent {
<govuk-back-link href="@LinkGenerator.RequestTrnNpqCheck(Model.JourneyInstance!.InstanceId)" />
}

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<h1 class="govuk-heading-l">@ViewBag.Title</h1>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.RazorPages;
using TeachingRecordSystem.UiCommon.FormFlow;

namespace TeachingRecordSystem.AuthorizeAccess.Pages.RequestTrn;

[Journey(RequestTrnJourneyState.JourneyName), RequireJourneyInstance]
public class NotEligibleModel(AuthorizeAccessLinkGenerator linkGenerator) : PageModel
{
public JourneyInstance<RequestTrnJourneyState>? JourneyInstance { get; set; }

public override void OnPageHandlerExecuting(PageHandlerExecutingContext context)
{
var state = JourneyInstance!.State;
if (state.HasPendingTrnRequest)
{
context.Result = Redirect(linkGenerator.RequestTrnSubmitted(JourneyInstance!.InstanceId));
}
else if (state.IsPlanningToTakeAnNpq is null)
{
context.Result = Redirect(linkGenerator.RequestTrnNpqCheck(JourneyInstance!.InstanceId));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@page "/request-trn/npq-check"
@model TeachingRecordSystem.AuthorizeAccess.Pages.RequestTrn.NpqCheckModel
@{
ViewBag.Title = Html.DisplayNameFor(m => m.IsPlanningToTakeAnNpq);
}

@section BeforeContent {
<govuk-back-link href="@LinkGenerator.RequestTrn(Model.JourneyInstance!.InstanceId)" />
}

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<form action="@LinkGenerator.RequestTrnNpqCheck(Model.JourneyInstance!.InstanceId)" method="post">
<govuk-radios asp-for="IsPlanningToTakeAnNpq">
<govuk-radios-fieldset>
<govuk-radios-fieldset-legend is-page-heading="true" class="govuk-fieldset__legend--l" />
<govuk-radios-item value="@true">Yes</govuk-radios-item>
<govuk-radios-item value="@false">No</govuk-radios-item>
</govuk-radios-fieldset>
</govuk-radios>

<govuk-button type="submit">Continue</govuk-button>
</form>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.RazorPages;
using TeachingRecordSystem.UiCommon.FormFlow;

namespace TeachingRecordSystem.AuthorizeAccess.Pages.RequestTrn;

[Journey(RequestTrnJourneyState.JourneyName), RequireJourneyInstance]
public class NpqCheckModel(AuthorizeAccessLinkGenerator linkGenerator) : PageModel
{
public JourneyInstance<RequestTrnJourneyState>? JourneyInstance { get; set; }

[BindProperty]
[Display(Name = "Do you plan on taking a national professional qualification (NPQ)?")]
[Required(ErrorMessage = "Tell us whether you plan on taking a national professional qualification (NPQ)")]
public bool? IsPlanningToTakeAnNpq { get; set; }

public async Task<IActionResult> OnPost()
{
if (!ModelState.IsValid)
{
return this.PageWithErrors();
}

await JourneyInstance!.UpdateStateAsync(state => state.IsPlanningToTakeAnNpq = IsPlanningToTakeAnNpq);

return IsPlanningToTakeAnNpq == true ?
Redirect(linkGenerator.RequestTrnEmail(JourneyInstance!.InstanceId)) :
Redirect(linkGenerator.RequestTrnNotEligible(JourneyInstance.InstanceId));
}

public override void OnPageHandlerExecuting(PageHandlerExecutingContext context)
{
var state = JourneyInstance!.State;
if (state.HasPendingTrnRequest)
{
context.Result = Redirect(linkGenerator.RequestTrnSubmitted(JourneyInstance!.InstanceId));
return;
}

IsPlanningToTakeAnNpq ??= JourneyInstance!.State.IsPlanningToTakeAnNpq;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class RequestTrnJourneyState()
public static JourneyDescriptor JourneyDescriptor { get; } =
new JourneyDescriptor(JourneyName, typeof(RequestTrnJourneyState), requestDataKeys: [], appendUniqueKey: true);

public bool? IsPlanningToTakeAnNpq { get; set; }
public string? Email { get; set; }
public string? Name { get; set; }
public bool? HasPreviousName { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,88 +5,104 @@ namespace TeachingRecordSystem.AuthorizeAccess.EndToEndTests;
public class RequestTrnTests(HostFixture hostFixture) : TestBase(hostFixture)
{
[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task RequestTrn(bool hasNationalInsuranceNumber)
[InlineData(true, true)]
[InlineData(true, false)]
[InlineData(false, false)]
public async Task RequestTrn(bool isPlanningToTakeAnNpq, bool hasNationalInsuranceNumber)
{
await using var context = await HostFixture.CreateBrowserContext();
var page = await context.NewPageAsync();

await page.GotoAsync("/request-trn");
await page.ClickButton("Start now");
await page.WaitForUrlPathAsync("/request-trn/email");
await page.WaitForUrlPathAsync("/request-trn/npq-check");

var email = Faker.Internet.Email();
await page.FillAsync("input[name=Email]", email);
await page.ClickButton("Continue");

await page.WaitForUrlPathAsync("/request-trn/name");
if (isPlanningToTakeAnNpq)
{
await page.CheckAsync("text=Yes");
await page.ClickButton("Continue");

var name = Faker.Name.FullName();
var previousName = Faker.Name.FullName();
await page.FillAsync("input[name=Name]", name);
await page.ClickButton("Continue");
await page.WaitForUrlPathAsync("/request-trn/email");

await page.WaitForUrlPathAsync("/request-trn/previous-name");
var email = Faker.Internet.Email();
await page.FillAsync("input[name=Email]", email);
await page.ClickButton("Continue");

await page.CheckAsync("text=Yes");
await page.FillAsync("input[name=PreviousName]", previousName);
await page.ClickButton("Continue");
await page.WaitForUrlPathAsync("/request-trn/name");

await page.WaitForUrlPathAsync("/request-trn/date-of-birth");
var name = Faker.Name.FullName();
var previousName = Faker.Name.FullName();
await page.FillAsync("input[name=Name]", name);
await page.ClickButton("Continue");

var dateOfBirth = new DateOnly(1980, 10, 12);
await page.FillDateInput(dateOfBirth);
await page.ClickButton("Continue");
await page.WaitForUrlPathAsync("/request-trn/previous-name");

await page.WaitForUrlPathAsync("/request-trn/identity");
await page.CheckAsync("text=Yes");
await page.FillAsync("input[name=PreviousName]", previousName);
await page.ClickButton("Continue");

await page
.GetByLabel("Upload file")
.SetInputFilesAsync(
new FilePayload()
{
Name = "evidence.jpg",
MimeType = "image/jpeg",
Buffer = TestData.JpegImage
});
await page.ClickButton("Continue");
await page.WaitForUrlPathAsync("/request-trn/date-of-birth");

await page.WaitForUrlPathAsync("/request-trn/national-insurance-number");
var dateOfBirth = new DateOnly(1980, 10, 12);
await page.FillDateInput(dateOfBirth);
await page.ClickButton("Continue");

var nationalInsuranceNumber = Faker.Identification.UkNationalInsuranceNumber();
if (hasNationalInsuranceNumber)
{
await page.CheckAsync("text=Yes");
await page.FillAsync("input[name=NationalInsuranceNumber]", nationalInsuranceNumber);
await page.WaitForUrlPathAsync("/request-trn/identity");

await page
.GetByLabel("Upload file")
.SetInputFilesAsync(
new FilePayload()
{
Name = "evidence.jpg",
MimeType = "image/jpeg",
Buffer = TestData.JpegImage
});
await page.ClickButton("Continue");

await page.WaitForUrlPathAsync("/request-trn/check-answers");
await page.WaitForUrlPathAsync("/request-trn/national-insurance-number");

var nationalInsuranceNumber = Faker.Identification.UkNationalInsuranceNumber();
if (hasNationalInsuranceNumber)
{
await page.CheckAsync("text=Yes");
await page.FillAsync("input[name=NationalInsuranceNumber]", nationalInsuranceNumber);
await page.ClickButton("Continue");

await page.WaitForUrlPathAsync("/request-trn/check-answers");
}
else
{
await page.CheckAsync("text=No");
await page.ClickButton("Continue");
await page.WaitForUrlPathAsync("/request-trn/address");

var addressLine1 = Faker.Address.StreetAddress();
var addressLine2 = Faker.Address.SecondaryAddress();
var townOrCity = Faker.Address.City();
var postalCode = Faker.Address.ZipCode();
var country = Faker.Address.Country();

await page.FillAsync("input[name=AddressLine1]", addressLine1);
await page.FillAsync("input[name=AddressLine2]", addressLine2);
await page.FillAsync("input[name=TownOrCity]", townOrCity);
await page.FillAsync("input[name=PostalCode]", postalCode);
await page.FillAsync("input[name=Country]", country);
await page.ClickButton("Continue");

await page.WaitForUrlPathAsync("/request-trn/check-answers");
}

await page.ClickButton("Submit request");

await page.WaitForUrlPathAsync("/request-trn/submitted");
}
else
{
await page.CheckAsync("text=No");
await page.ClickButton("Continue");
await page.WaitForUrlPathAsync("/request-trn/address");

var addressLine1 = Faker.Address.StreetAddress();
var addressLine2 = Faker.Address.SecondaryAddress();
var townOrCity = Faker.Address.City();
var postalCode = Faker.Address.ZipCode();
var country = Faker.Address.Country();

await page.FillAsync("input[name=AddressLine1]", addressLine1);
await page.FillAsync("input[name=AddressLine2]", addressLine2);
await page.FillAsync("input[name=TownOrCity]", townOrCity);
await page.FillAsync("input[name=PostalCode]", postalCode);
await page.FillAsync("input[name=Country]", country);
await page.ClickButton("Continue");

await page.WaitForUrlPathAsync("/request-trn/check-answers");
await page.WaitForUrlPathAsync("/request-trn/not-eligible");
}

await page.ClickButton("Submit request");

await page.WaitForUrlPathAsync("/request-trn/submitted");
}
}
Loading

0 comments on commit 4a0d056

Please sign in to comment.