-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TRN page for teaching record lookup (#1150)
- Loading branch information
Showing
12 changed files
with
616 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Pages/NotFound.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@page "/not-found" | ||
@model TeachingRecordSystem.AuthorizeAccess.Pages.NotFoundModel | ||
@{ | ||
ViewBag.Title = "[PLACEHOLDER] Not found"; | ||
} | ||
|
||
@section BeforeContent { | ||
<govuk-back-link href="@LinkGenerator.Trn(Model.JourneyInstance!.InstanceId)" /> | ||
} | ||
|
||
<h1>@ViewBag.Title</h1> |
36 changes: 36 additions & 0 deletions
36
TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Pages/NotFound.cshtml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using TeachingRecordSystem.FormFlow; | ||
|
||
namespace TeachingRecordSystem.AuthorizeAccess.Pages; | ||
|
||
[Journey(SignInJourneyState.JourneyName), RequireJourneyInstance] | ||
public class NotFoundModel(SignInJourneyHelper helper) : PageModel | ||
{ | ||
public JourneyInstance<SignInJourneyState>? JourneyInstance { get; set; } | ||
|
||
public void OnGet() | ||
{ | ||
} | ||
|
||
public override void OnPageHandlerExecuting(PageHandlerExecutingContext context) | ||
{ | ||
var state = JourneyInstance!.State; | ||
|
||
if (state.OneLoginAuthenticationTicket is null || !state.IdentityVerified) | ||
{ | ||
// Not authenticated/verified with One Login | ||
context.Result = BadRequest(); | ||
} | ||
else if (!state.NationalInsuranceNumberSpecified || !state.TrnSpecified) | ||
{ | ||
// Not specified NINO or TRN | ||
context.Result = helper.GetNextPage(JourneyInstance).ToActionResult(); | ||
} | ||
else if (state.AuthenticationTicket is not null) | ||
{ | ||
// Already matched to a Teaching Record | ||
context.Result = Redirect(helper.GetSafeRedirectUri(JourneyInstance)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Pages/Trn.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,29 @@ | ||
@page "/trn" | ||
@model TeachingRecordSystem.AuthorizeAccess.Pages.TrnModel | ||
@{ | ||
ViewBag.Title = "What is your teacher reference number (TRN)?"; | ||
} | ||
|
||
@section BeforeContent { | ||
<govuk-back-link href="@LinkGenerator.NationalInsuranceNumber(Model.JourneyInstance!.InstanceId)" /> | ||
} | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds-from-desktop"> | ||
<form action="@LinkGenerator.Trn(Model.JourneyInstance!.InstanceId)" method="post"> | ||
<h1 class="govuk-heading-l">@ViewBag.Title</h1> | ||
|
||
<p class="govuk-body">A TRN is 7 digits long, for example 4567814</p> | ||
<p class="govuk-body">It might include the letters RP and a slash, for example RP99/12345</p> | ||
<p class="govuk-body">It’s previously been known as a QTS, GTC, DfE, DfES and DCSF number</p> | ||
|
||
<govuk-input | ||
asp-for="Trn" | ||
input-class="govuk-!-width-one-quarter govuk-input--extra-letter-spacing" | ||
spellcheck="false" | ||
label-class="govuk-label--s" /> | ||
|
||
<govuk-button type="submit">Continue</govuk-button> | ||
</form> | ||
</div> | ||
</div> |
53 changes: 52 additions & 1 deletion
53
TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Pages/Trn.cshtml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,63 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using TeachingRecordSystem.FormFlow; | ||
|
||
namespace TeachingRecordSystem.AuthorizeAccess.Pages; | ||
|
||
[Journey(SignInJourneyState.JourneyName), RequireJourneyInstance] | ||
public class TrnModel : PageModel | ||
public class TrnModel(SignInJourneyHelper helper, AuthorizeAccessLinkGenerator linkGenerator) : PageModel | ||
{ | ||
public JourneyInstance<SignInJourneyState>? JourneyInstance { get; set; } | ||
|
||
[BindProperty] | ||
[Display(Name = "Teacher reference number (TRN)")] | ||
[Required(ErrorMessage = "Enter your TRN")] | ||
[RegularExpression(@"\A\D*(\d{1}\D*){7}\D*\Z", ErrorMessage = "Your TRN should contain 7 digits")] | ||
public string? Trn { get; set; } | ||
|
||
public void OnGet() | ||
{ | ||
Trn = JourneyInstance!.State.Trn; | ||
} | ||
|
||
public async Task<IActionResult> OnPost() | ||
{ | ||
if (!ModelState.IsValid) | ||
{ | ||
return this.PageWithErrors(); | ||
} | ||
|
||
await JourneyInstance!.UpdateStateAsync(state => | ||
{ | ||
state.TrnSpecified = true; | ||
state.Trn = Trn; | ||
}); | ||
|
||
if (await helper.TryMatchToTeachingRecord(JourneyInstance!)) | ||
{ | ||
return helper.GetNextPage(JourneyInstance).ToActionResult(); | ||
} | ||
else | ||
{ | ||
return Redirect(linkGenerator.NotFound(JourneyInstance.InstanceId)); | ||
} | ||
} | ||
|
||
public override void OnPageHandlerExecuting(PageHandlerExecutingContext context) | ||
{ | ||
var state = JourneyInstance!.State; | ||
|
||
if (state.OneLoginAuthenticationTicket is null || !state.IdentityVerified) | ||
{ | ||
// Not authenticated/verified with One Login | ||
context.Result = BadRequest(); | ||
} | ||
else if (state.AuthenticationTicket is not null) | ||
{ | ||
// Already matched to a Teaching Record | ||
context.Result = Redirect(helper.GetSafeRedirectUri(JourneyInstance)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
...gRecordSystem/tests/TeachingRecordSystem.AuthorizeAccess.Tests/PageTests/NotFoundTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
namespace TeachingRecordSystem.AuthorizeAccess.Tests.PageTests; | ||
|
||
public class NotFoundTests(HostFixture hostFixture) : TestBase(hostFixture) | ||
{ | ||
[Fact] | ||
public async Task Get_NotAuthenticatedWithOneLogin_ReturnsBadRequest() | ||
{ | ||
// Arrange | ||
var state = new SignInJourneyState(redirectUri: "/", authenticationProperties: null); | ||
var journeyInstance = await CreateJourneyInstance(state); | ||
|
||
var request = new HttpRequestMessage(HttpMethod.Get, $"/not-found?{journeyInstance.GetUniqueIdQueryParameter()}"); | ||
|
||
// Act | ||
var response = await HttpClient.SendAsync(request); | ||
|
||
// Assert | ||
Assert.Equal(StatusCodes.Status400BadRequest, (int)response.StatusCode); | ||
} | ||
|
||
[Fact] | ||
public async Task Get_NotVerifiedWithOneLogin_ReturnsBadRequest() | ||
{ | ||
// Arrange | ||
var state = new SignInJourneyState(redirectUri: "/", authenticationProperties: null); | ||
var journeyInstance = await CreateJourneyInstance(state); | ||
|
||
var ticket = CreateOneLoginAuthenticationTicket(createCoreIdentityVc: false); | ||
await GetSignInJourneyHelper().OnSignedInWithOneLogin(journeyInstance, ticket); | ||
|
||
var request = new HttpRequestMessage(HttpMethod.Get, $"/not-found?{journeyInstance.GetUniqueIdQueryParameter()}"); | ||
|
||
// Act | ||
var response = await HttpClient.SendAsync(request); | ||
|
||
// Assert | ||
Assert.Equal(StatusCodes.Status400BadRequest, (int)response.StatusCode); | ||
} | ||
|
||
[Fact] | ||
public async Task Get_AlreadyAuthenticated_RedirectsToStateRedirectUri() | ||
{ | ||
// Arrange | ||
var redirectUri = "/"; | ||
var state = new SignInJourneyState(redirectUri, authenticationProperties: null); | ||
var journeyInstance = await CreateJourneyInstance(state); | ||
|
||
var person = await TestData.CreatePerson(b => b.WithTrn()); | ||
var oneLoginUser = await TestData.CreateOneLoginUser(person.PersonId); | ||
|
||
var ticket = CreateOneLoginAuthenticationTicket(oneLoginUser); | ||
await GetSignInJourneyHelper().OnSignedInWithOneLogin(journeyInstance, ticket); | ||
|
||
var request = new HttpRequestMessage(HttpMethod.Get, $"/not-found?{journeyInstance.GetUniqueIdQueryParameter()}"); | ||
|
||
// Act | ||
var response = await HttpClient.SendAsync(request); | ||
|
||
// Assert | ||
Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); | ||
Assert.Equal($"{redirectUri}?{journeyInstance.GetUniqueIdQueryParameter()}", response.Headers.Location?.OriginalString); | ||
} | ||
|
||
[Fact] | ||
public async Task Get_NationalInsuranceNumberNotSpecified_RedirectsToStartOfMatchingQuestions() | ||
{ | ||
// Arrange | ||
var state = new SignInJourneyState(redirectUri: "/", authenticationProperties: null); | ||
var journeyInstance = await CreateJourneyInstance(state); | ||
|
||
var ticket = CreateOneLoginAuthenticationTicket(); | ||
await GetSignInJourneyHelper().OnSignedInWithOneLogin(journeyInstance, ticket); | ||
|
||
await journeyInstance.UpdateStateAsync(state => | ||
{ | ||
state.NationalInsuranceNumberSpecified = false; | ||
}); | ||
|
||
var request = new HttpRequestMessage(HttpMethod.Get, $"/not-found?{journeyInstance.GetUniqueIdQueryParameter()}"); | ||
|
||
// Act | ||
var response = await HttpClient.SendAsync(request); | ||
|
||
// Assert | ||
Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); | ||
Assert.Equal($"/national-insurance-number?{journeyInstance.GetUniqueIdQueryParameter()}", response.Headers.Location?.OriginalString); | ||
} | ||
|
||
[Fact] | ||
public async Task Get_TrnNotSpecified_RedirectsToStartOfMatchingQuestions() | ||
{ | ||
// Arrange | ||
var state = new SignInJourneyState(redirectUri: "/", authenticationProperties: null); | ||
var journeyInstance = await CreateJourneyInstance(state); | ||
|
||
var ticket = CreateOneLoginAuthenticationTicket(); | ||
await GetSignInJourneyHelper().OnSignedInWithOneLogin(journeyInstance, ticket); | ||
|
||
await journeyInstance.UpdateStateAsync(state => | ||
{ | ||
state.NationalInsuranceNumberSpecified = true; | ||
state.TrnSpecified = false; | ||
}); | ||
|
||
var request = new HttpRequestMessage(HttpMethod.Get, $"/not-found?{journeyInstance.GetUniqueIdQueryParameter()}"); | ||
|
||
// Act | ||
var response = await HttpClient.SendAsync(request); | ||
|
||
// Assert | ||
Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); | ||
Assert.Equal($"/national-insurance-number?{journeyInstance.GetUniqueIdQueryParameter()}", response.Headers.Location?.OriginalString); | ||
} | ||
|
||
[Fact] | ||
public async Task Get_ValidRequest_RendersExpectedContent() | ||
{ | ||
// Arrange | ||
var state = new SignInJourneyState(redirectUri: "/", authenticationProperties: null); | ||
var journeyInstance = await CreateJourneyInstance(state); | ||
|
||
var ticket = CreateOneLoginAuthenticationTicket(); | ||
await GetSignInJourneyHelper().OnSignedInWithOneLogin(journeyInstance, ticket); | ||
|
||
await journeyInstance.UpdateStateAsync(async state => | ||
{ | ||
state.NationalInsuranceNumberSpecified = true; | ||
state.Trn = await TestData.GenerateTrn(); | ||
state.TrnSpecified = true; | ||
}); | ||
|
||
var request = new HttpRequestMessage(HttpMethod.Get, $"/not-found?{journeyInstance.GetUniqueIdQueryParameter()}"); | ||
|
||
// Act | ||
var response = await HttpClient.SendAsync(request); | ||
|
||
// Assert | ||
Assert.Equal(StatusCodes.Status200OK, (int)response.StatusCode); | ||
|
||
var doc = await response.GetDocument(); | ||
} | ||
} |
Oops, something went wrong.