Skip to content

Commit

Permalink
Updated Journey to skip qts/itt questions if trnmatchpolicy is strict (
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKevJoy authored Sep 21, 2023
1 parent 3d714a0 commit 33fc760
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ protected override bool IsFinished() =>
Steps.NiNumber => AuthenticationState is { HasNationalInsuranceNumber: true, ContactDetailsVerified: true },
Steps.HasTrn => (AuthenticationState is ({ NationalInsuranceNumberSet: true } or { HasNationalInsuranceNumberSet: true, HasNationalInsuranceNumber: false }) and { ContactDetailsVerified: true }),
Steps.Trn => AuthenticationState is { HasTrn: true, ContactDetailsVerified: true },
Steps.HasQts => AuthenticationState is ({ StatedTrn: { } } or { HasTrnSet: true, HasTrn: false }) and { ContactDetailsVerified: true },
Steps.IttProvider => AuthenticationState is { AwardedQts: true, ContactDetailsVerified: true },
Steps.HasQts => AuthenticationState is ({ StatedTrn: { }, OAuthState: { TrnMatchPolicy: Models.TrnMatchPolicy.Default } } or { OAuthState: { TrnMatchPolicy: Models.TrnMatchPolicy.Default }, HasTrnSet: true, HasTrn: false }) and { ContactDetailsVerified: true },
Steps.IttProvider => AuthenticationState is { OAuthState: { TrnMatchPolicy: Models.TrnMatchPolicy.Default }, AwardedQts: true, ContactDetailsVerified: true },
SignInJourney.Steps.TrnInUse => AuthenticationState.TrnLookup == AuthenticationState.TrnLookupState.ExistingTrnFound,
SignInJourney.Steps.TrnInUseResendTrnOwnerEmailConfirmation => AuthenticationState.TrnLookup == AuthenticationState.TrnLookupState.ExistingTrnFound,
SignInJourney.Steps.TrnInUseChooseEmail => AuthenticationState.TrnLookup == AuthenticationState.TrnLookupState.EmailOfExistingAccountForTrnVerified,
Expand All @@ -125,6 +125,7 @@ protected override bool IsFinished() =>
(Steps.HasNiNumber, { HasNationalInsuranceNumber: false }) => shouldCheckAnswers ? CoreSignInJourney.Steps.CheckAnswers : Steps.HasTrn,
(Steps.NiNumber, _) => shouldCheckAnswers ? CoreSignInJourney.Steps.CheckAnswers : Steps.HasTrn,
(Steps.HasTrn, { HasTrn: true }) => Steps.Trn,
(Steps.HasTrn, { HasTrn: false, OAuthState.TrnMatchPolicy: Models.TrnMatchPolicy.Strict }) => CoreSignInJourney.Steps.CheckAnswers,
(Steps.HasTrn, { HasTrn: false }) => shouldCheckAnswers ? CoreSignInJourney.Steps.CheckAnswers : Steps.HasQts,
(Steps.Trn, _) => shouldCheckAnswers ? CoreSignInJourney.Steps.CheckAnswers : Steps.HasQts,
(Steps.HasQts, { AwardedQts: true }) => Steps.IttProvider,
Expand Down Expand Up @@ -202,8 +203,8 @@ protected override bool AreAllQuestionsAnswered() =>
AuthenticationState.DateOfBirthSet &&
AuthenticationState.HasNationalInsuranceNumberSet &&
(AuthenticationState.NationalInsuranceNumberSet || AuthenticationState.HasNationalInsuranceNumber == false) &&
AuthenticationState.AwardedQtsSet &&
(AuthenticationState.HasIttProviderSet || AuthenticationState.AwardedQts == false);
((AuthenticationState.AwardedQtsSet &&
(AuthenticationState.HasIttProviderSet || AuthenticationState.AwardedQts == false) || (AuthenticationState.AwardedQtsSet == false && AuthenticationState?.OAuthState?.TrnMatchPolicy == Models.TrnMatchPolicy.Strict)));

public new static class Steps
{
Expand Down
6 changes: 6 additions & 0 deletions dotnet-authserver/src/TeacherIdentity.TestClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public static void Main(string[] args)
ctx.ProtocolMessage.SetParameter("trn_requirement", trnRequirement);
}

var trnMatchPolicy = ctx.HttpContext.Request.Query["trn_match_policy"].ToString();
if (!string.IsNullOrEmpty(trnMatchPolicy))
{
ctx.ProtocolMessage.SetParameter("trn_match_policy", trnMatchPolicy);
}

var trnToken = ctx.HttpContext.Request.Query["trn_token"].ToString();
if (!string.IsNullOrEmpty(trnToken))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public static async Task StartOAuthJourney(
this IPage page,
string? additionalScope = null,
TrnRequirementType? trnRequirement = null,
string? trnToken = null)
string? trnToken = null,
TrnMatchPolicy trnMatchPolicy = TrnMatchPolicy.Default)
{
var allScopes = new List<string>()
{
Expand All @@ -65,6 +66,8 @@ public static async Task StartOAuthJourney(
url.SetQueryParam("trn_token", trnToken);
}

url.SetQueryParam("trn_match_policy", trnMatchPolicy.ToString());

await page.GotoAsync(url);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,94 @@ public async Task NewUser_WithoutTrnLookup_CanRegister()
});
}

[Fact]
public async Task NewUser_WithTrnLookup_TrnNotFound_CanRegister_StrictTrnMatchPolicy()
{
var email = Faker.Internet.Email();
var mobileNumber = _hostFixture.TestData.GenerateUniqueMobileNumber();
var firstName = Faker.Name.First();
var lastName = Faker.Name.Last();
var dateOfBirth = DateOnly.FromDateTime(Faker.Identification.DateOfBirth());
var nino = Faker.Identification.UkNationalInsuranceNumber();
var ittProvider = Faker.Company.Name();
var trn = _hostFixture.TestData.GenerateTrn();

ConfigureDqtApiFindTeachersRequest(result: null);

_hostFixture.DqtApiClient
.Setup(mock => mock.GetIttProviders(It.IsAny<CancellationToken>()))
.ReturnsAsync(new GetIttProvidersResponse()
{
IttProviders = new[]
{
new IttProvider()
{
ProviderName = "Provider 1",
Ukprn = "123"
},
new IttProvider()
{
ProviderName = ittProvider,
Ukprn = "234"
}
}
});

await using var context = await _hostFixture.CreateBrowserContext();
var page = await context.NewPageAsync();

await page.StartOAuthJourney(CustomScopes.DqtRead, TrnRequirementType.Optional, trnMatchPolicy: TrnMatchPolicy.Strict);

await page.RegisterFromLandingPage();

await page.SubmitRegisterEmailPage(email);

await page.SubmitRegisterEmailConfirmationPage();

await page.SubmitRegisterPhonePage(mobileNumber);

await page.SubmitRegisterPhoneConfirmationPage();

await page.SubmitRegisterNamePage(firstName, lastName);

await page.SubmitRegisterPreferredNamePage();

await page.SubmitDateOfBirthPage(dateOfBirth);

await page.SubmitRegisterHasNinoPage(hasNino: true);

await page.SubmitRegisterNiNumberPage(nino);

await page.SubmitCheckAnswersPage();

await page.SubmitCompletePageForNewUser();

await page.AssertSignedInOnTestClient(email, trn: null, firstName, lastName);

Guid createdUserId = default;

_hostFixture.EventObserver.AssertEventsSaved(
e =>
{
var userRegisteredEvent = Assert.IsType<UserRegisteredEvent>(e);
Assert.Equal(_hostFixture.TestClientId, userRegisteredEvent.ClientId);
Assert.Equal(email, userRegisteredEvent.User.EmailAddress);
Assert.Equal(mobileNumber, userRegisteredEvent.User.MobileNumber);
Assert.Equal(firstName, userRegisteredEvent.User.FirstName);
Assert.Equal(lastName, userRegisteredEvent.User.LastName);
Assert.Equal(dateOfBirth, userRegisteredEvent.User.DateOfBirth);

createdUserId = userRegisteredEvent.User.UserId;
},
e =>
{
var userSignedInEvent = Assert.IsType<UserSignedInEvent>(e);
Assert.Equal(createdUserId, userSignedInEvent.User.UserId);
});
}



[Fact]
public async Task NewUser_WithTrnLookup_TrnNotFound_CanRegister()
{
Expand Down

0 comments on commit 33fc760

Please sign in to comment.