-
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.
Prevent resubmitting trn request for same email
- Loading branch information
Showing
16 changed files
with
247 additions
and
8 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
16 changes: 16 additions & 0 deletions
16
...gRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Pages/RequestTrn/EmailInUse.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,16 @@ | ||
@page "/request-trn/emailinuse" | ||
@model TeachingRecordSystem.AuthorizeAccess.Pages.RequestTrn.EmailInUseModel | ||
@{ | ||
} | ||
|
||
@section BeforeContent { | ||
<govuk-back-link href="@(LinkGenerator.RequestTrnCheckAnswers(Model.JourneyInstance!.InstanceId))" /> | ||
} | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds-from-desktop"> | ||
<p class="govuk-body"> | ||
You've already submitted a request for a TRN | ||
</p> | ||
</div> | ||
</div> |
15 changes: 15 additions & 0 deletions
15
...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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using TeachingRecordSystem.UiCommon.FormFlow; | ||
|
||
namespace TeachingRecordSystem.AuthorizeAccess.Pages.RequestTrn; | ||
|
||
[Journey(RequestTrnJourneyState.JourneyName), RequireJourneyInstance] | ||
public class EmailInUseModel : PageModel | ||
{ | ||
public JourneyInstance<RequestTrnJourneyState>? JourneyInstance { get; set; } | ||
|
||
public void OnGet() | ||
{ | ||
} | ||
} | ||
|
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
3 changes: 3 additions & 0 deletions
3
...ecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/GetOpenTasksForEmailAddressQuery.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,3 @@ | ||
namespace TeachingRecordSystem.Core.Dqt.Queries; | ||
|
||
public record GetOpenTasksForEmailAddressQuery(string EmailAddress) : ICrmQuery<CrmTask[]>; |
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
28 changes: 28 additions & 0 deletions
28
...tem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/GetOpenTasksForEmailAddressHandler.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,28 @@ | ||
using Microsoft.PowerPlatform.Dataverse.Client; | ||
using Microsoft.Xrm.Sdk.Messages; | ||
using Microsoft.Xrm.Sdk.Query; | ||
using TeachingRecordSystem.Core.Dqt.Queries; | ||
|
||
namespace TeachingRecordSystem.Core.Dqt.QueryHandlers; | ||
public class GetOpenTasksForEmailAddressHandler : ICrmQueryHandler<GetOpenTasksForEmailAddressQuery, CrmTask[]> | ||
{ | ||
public async Task<CrmTask[]> Execute(GetOpenTasksForEmailAddressQuery query, IOrganizationServiceAsync organizationService) | ||
{ | ||
var queryExpression = new QueryExpression() | ||
{ | ||
EntityName = CrmTask.EntityLogicalName, | ||
ColumnSet = new ColumnSet( | ||
CrmTask.Fields.dfeta_EmailAddress, CrmTask.Fields.StateCode) | ||
}; | ||
queryExpression.Criteria.AddCondition(CrmTask.Fields.dfeta_EmailAddress, ConditionOperator.Equal, query.EmailAddress); | ||
queryExpression.Criteria.AddCondition(CrmTask.Fields.StateCode, ConditionOperator.Equal, (int)TaskState.Open); | ||
|
||
var request = new RetrieveMultipleRequest() | ||
{ | ||
Query = queryExpression | ||
}; | ||
|
||
var response = await organizationService.RetrieveMultipleAsync(queryExpression); | ||
return response.Entities.Select(e => e.ToEntity<CrmTask>()).ToArray(); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -116,7 +116,6 @@ public async Task Post_InvalidFormatEmailAddress_ReturnsError() | |
await AssertEx.HtmlResponseHasError(response, "Email", "Enter an email address in the correct format, like [email protected]"); | ||
} | ||
|
||
|
||
[Fact] | ||
public async Task Post_ValidRequestWithValidData_RedirectsToNamePage() | ||
{ | ||
|
@@ -140,4 +139,34 @@ public async Task Post_ValidRequestWithValidData_RedirectsToNamePage() | |
Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); | ||
Assert.Equal($"/request-trn/name?{journeyInstance.GetUniqueIdQueryParameter()}", response.Headers.Location?.OriginalString); | ||
} | ||
|
||
[Fact] | ||
public async Task Post_RequestForEmailWithOpenTasks_RedirectsToEmailInUse() | ||
{ | ||
// Arrange | ||
var email = Faker.Internet.Email(); | ||
var state = CreateNewState(); | ||
var journeyInstance = await CreateJourneyInstance(state); | ||
var person = await TestData.CreatePerson(); | ||
await TestData.CreateCrmTask(x => | ||
{ | ||
x.WithPersonId(person.ContactId); | ||
x.WithEmailAddress(email); | ||
}); | ||
|
||
var request = new HttpRequestMessage(HttpMethod.Post, $"/request-trn/email?{journeyInstance.GetUniqueIdQueryParameter()}") | ||
{ | ||
Content = new FormUrlEncodedContent(new Dictionary<string, string> | ||
{ | ||
{ "Email", email } | ||
}) | ||
}; | ||
|
||
// Act | ||
var response = await HttpClient.SendAsync(request); | ||
|
||
// Assert | ||
Assert.Equal(StatusCodes.Status302Found, (int)response.StatusCode); | ||
Assert.Equal($"/request-trn/emailinuse?{journeyInstance.GetUniqueIdQueryParameter()}", response.Headers.Location?.OriginalString); | ||
} | ||
} |
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
93 changes: 93 additions & 0 deletions
93
...gRecordSystem.Core.Dqt.CrmIntegrationTests/QueryTests/GetOpenTasksForEmailAddressTests.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,93 @@ | ||
namespace TeachingRecordSystem.Core.Dqt.CrmIntegrationTests.QueryTests; | ||
|
||
public class GetOpenTasksForEmailAddressTests : IAsyncLifetime | ||
{ | ||
private readonly CrmClientFixture.TestDataScope _dataScope; | ||
private readonly CrmQueryDispatcher _crmQueryDispatcher; | ||
|
||
public GetOpenTasksForEmailAddressTests(CrmClientFixture crmClientFixture) | ||
{ | ||
_dataScope = crmClientFixture.CreateTestDataScope(); | ||
_crmQueryDispatcher = crmClientFixture.CreateQueryDispatcher(); | ||
} | ||
|
||
public Task InitializeAsync() => Task.CompletedTask; | ||
|
||
public async Task DisposeAsync() => await _dataScope.DisposeAsync(); | ||
|
||
[Fact] | ||
public async Task WhenCalled_WithEmailWithNoOpenTasks_ReturnsEmpty() | ||
{ | ||
// Arrange | ||
var emailWithNoOpenTasks = Faker.Internet.Email(); | ||
|
||
// Act | ||
var result = await _crmQueryDispatcher.ExecuteQuery(new GetOpenTasksForEmailAddressQuery(emailWithNoOpenTasks)); | ||
|
||
// Assert | ||
Assert.Empty(result); | ||
} | ||
|
||
[Fact] | ||
public async Task WhenCalled_WithEmailWithOpenTasks_ReturnsTasks() | ||
{ | ||
// Arrange | ||
var person = await _dataScope.TestData.CreatePerson(); | ||
var emailWithOpenTasks = Faker.Internet.Email(); | ||
await _dataScope.TestData.CreateCrmTask(x => | ||
{ | ||
x.WithPersonId(person.ContactId); | ||
x.WithEmailAddress(emailWithOpenTasks); | ||
}); | ||
|
||
// Act | ||
var result = await _crmQueryDispatcher.ExecuteQuery(new GetOpenTasksForEmailAddressQuery(emailWithOpenTasks)); | ||
|
||
// Assert | ||
Assert.NotEmpty(result); | ||
Assert.Collection(result, item1 => | ||
{ | ||
Assert.Equal(emailWithOpenTasks, item1.dfeta_EmailAddress); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public async Task WhenCalled_WithEmailWithCompletedTasks_ReturnsEmpty() | ||
{ | ||
// Arrange | ||
var person = await _dataScope.TestData.CreatePerson(); | ||
var emailWithOpenTasks = Faker.Internet.Email(); | ||
await _dataScope.TestData.CreateCrmTask(x => | ||
{ | ||
x.WithPersonId(person.ContactId); | ||
x.WithEmailAddress(emailWithOpenTasks); | ||
x.WithCompletedStatus(); | ||
}); | ||
|
||
// Act | ||
var result = await _crmQueryDispatcher.ExecuteQuery(new GetOpenTasksForEmailAddressQuery(emailWithOpenTasks)); | ||
|
||
// Assert | ||
Assert.Empty(result); | ||
} | ||
|
||
[Fact] | ||
public async Task WhenCalled_WithEmailWithCancelledTasks_ReturnsEmpty() | ||
{ | ||
// Arrange | ||
var person = await _dataScope.TestData.CreatePerson(); | ||
var emailWithOpenTasks = Faker.Internet.Email(); | ||
await _dataScope.TestData.CreateCrmTask(x => | ||
{ | ||
x.WithPersonId(person.ContactId); | ||
x.WithEmailAddress(emailWithOpenTasks); | ||
x.WithCanceledStatus(); | ||
}); | ||
|
||
// Act | ||
var result = await _crmQueryDispatcher.ExecuteQuery(new GetOpenTasksForEmailAddressQuery(emailWithOpenTasks)); | ||
|
||
// Assert | ||
Assert.Empty(result); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -333,6 +333,7 @@ | |
"regardingobjectid", | ||
"scheduledend", | ||
"statecode", | ||
"subject" | ||
"subject", | ||
"dfeta_EmailAddress" | ||
] | ||
} |
Oops, something went wrong.