Skip to content

Commit

Permalink
Merge pull request #384 from DFE-Digital/validaiton-update-education-…
Browse files Browse the repository at this point in the history
…phase

Adjust validation to allow null preferred education phase
  • Loading branch information
ethax-ross authored Nov 27, 2020
2 parents bbfb7c4 + 2a32aba commit d357d68
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public TeacherTrainingAdviserSignUpValidator(IStore store)
RuleFor(request => request.DateOfBirth).NotNull();
RuleFor(request => request.AcceptedPolicyId).NotNull();
RuleFor(request => request.CountryId).NotNull();
RuleFor(request => request.PreferredEducationPhaseId).NotNull();

RuleFor(request => request.PreferredEducationPhaseId)
.NotNull()
.Unless(request => request.SubjectTaughtId != null);

RuleFor(request => request.AddressLine1).NotEmpty().Unless(request => request.CountryId != TypeEntity.UnitedKingdomCountryId)
.WithMessage("Must be set candidate in the UK.");
Expand Down Expand Up @@ -112,11 +115,6 @@ public TeacherTrainingAdviserSignUpValidator(IStore store)
.When(request => request.Candidate.PreferredEducationPhaseId == (int)Candidate.PreferredEducationPhase.Secondary)
.WithMessage("Must be set when preferred education phase is secondary.");

RuleFor(request => request.PreferredEducationPhaseId)
.Must(phase => phase == (int)Candidate.PreferredEducationPhase.Secondary)
.When(request => request.Candidate.IsReturningToTeaching())
.WithMessage("Must be secondary when past teaching positions are present.");

RuleFor(request => request)
.Must(request => HasOrIsPlanningOnRetakingEnglishAndMaths(request) && HasOrIsPlanningOnRetakingScience(request))
.When(request => request.PreferredEducationPhaseId == (int)Candidate.PreferredEducationPhase.Primary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,31 @@ public void Validate_CountryIdIsNull_HasError()
}

[Fact]
public void Validate_PreferredEducationPhaseIdIsNull_HasError()
{
_validator.ShouldHaveValidationErrorFor(request => request.PreferredEducationPhaseId, null as int?);
public void Validate_PreferredEducationPhaseIdIsNull_NotReturningToTeaching_HasError()
{
var request = new TeacherTrainingAdviserSignUp
{
PreferredEducationPhaseId = null,
SubjectTaughtId = null,
};

var result = _validator.TestValidate(request);

result.ShouldHaveValidationErrorFor("PreferredEducationPhaseId");
}

[Fact]
public void Validate_PreferredEducationPhaseIdIsNull_ReturningToTeaching_HasNoError()
{
var request = new TeacherTrainingAdviserSignUp
{
PreferredEducationPhaseId = null,
SubjectTaughtId = Guid.NewGuid(),
};

var result = _validator.TestValidate(request);

result.ShouldNotHaveValidationErrorFor("PreferredEducationPhaseId");
}

[Fact]
Expand Down Expand Up @@ -623,20 +645,6 @@ public void Validate_PreferredEducationPhaseIsSecondaryAndPreferredTeachingSubje
result.ShouldNotHaveValidationErrorFor("PreferredTeachingSubjectId");
}

[Fact]
public void Validate_HasPastTeachingPositionsAndPreferredEducationPhaseIsPrimary_HasError()
{
var request = new TeacherTrainingAdviserSignUp
{
SubjectTaughtId = Guid.NewGuid(),
PreferredEducationPhaseId = (int)Candidate.PreferredEducationPhase.Primary,
};

var result = _validator.TestValidate(request);

result.ShouldHaveValidationErrorFor("PreferredEducationPhaseId").WithErrorMessage("Must be secondary when past teaching positions are present.");
}

[Fact]
public void Validate_HasPastTeachingPositionsAndPreferredEducationPhaseIsSecondary_HasNoError()
{
Expand Down

0 comments on commit d357d68

Please sign in to comment.