-
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.
- Loading branch information
Showing
3 changed files
with
30 additions
and
3 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
10 changes: 8 additions & 2 deletions
10
...cordSystem/src/TeachingRecordSystem.AuthorizeAccess/Pages/RequestTrn/EmailInUse.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,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)); | ||
} | ||
} | ||
} | ||
|
22 changes: 22 additions & 0 deletions
22
.../tests/TeachingRecordSystem.AuthorizeAccess.Tests/PageTests/RequestTrn/EmailInUseTests.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,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); | ||
} | ||
} |