Skip to content

Commit

Permalink
add email check
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKevJoy committed Aug 1, 2024
1 parent eda31c4 commit 683d223
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public async Task<IActionResult> OnPost()
return Redirect(linkGenerator.RequestTrnEmailInUse(JourneyInstance!.InstanceId));
}


return FromCheckAnswers == true ?
Redirect(linkGenerator.RequestTrnCheckAnswers(JourneyInstance!.InstanceId)) :
Redirect(linkGenerator.RequestTrnName(JourneyInstance.InstanceId));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
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 EmailInUseModel : PageModel
public class EmailInUseModel(AuthorizeAccessLinkGenerator linkGenerator) : PageModel
{
public JourneyInstance<RequestTrnJourneyState>? JourneyInstance { get; set; }

public void OnGet()
public override void OnPageHandlerExecuting(PageHandlerExecutingContext context)
{
var state = JourneyInstance!.State;
if (state.Email is null)
{
context.Result = Redirect(linkGenerator.RequestTrnEmail(JourneyInstance.InstanceId));
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace TeachingRecordSystem.AuthorizeAccess.Tests.PageTests.RequestTrn;

public class EmailInUseTests(HostFixture hostFixture) : TestBase(hostFixture)
{
[Fact]
public async Task Get_WithoutEmailAddress_RedirectsToEmail()
{
// Arrange
var state = CreateNewState();
state.HasPendingTrnRequest = true;
var journeyInstance = await CreateJourneyInstance(state);

var request = new HttpRequestMessage(HttpMethod.Get, $"/request-trn/emailinuse?{journeyInstance.GetUniqueIdQueryParameter()}");

// Act
var response = await HttpClient.SendAsync(request);

// Assert
Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode);
Assert.Equal($"/request-trn/email?{journeyInstance.GetUniqueIdQueryParameter()}", response.Headers.Location?.OriginalString);
}
}

0 comments on commit 683d223

Please sign in to comment.