diff --git a/GetIntoTeachingApi/Models/Validators/TeacherTrainingAdviserSignUpValidator.cs b/GetIntoTeachingApi/Models/Validators/TeacherTrainingAdviserSignUpValidator.cs index 24b3a7696..ea4fb7e00 100644 --- a/GetIntoTeachingApi/Models/Validators/TeacherTrainingAdviserSignUpValidator.cs +++ b/GetIntoTeachingApi/Models/Validators/TeacherTrainingAdviserSignUpValidator.cs @@ -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."); @@ -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) diff --git a/GetIntoTeachingApiTests/Models/Validators/TeacherTrainingAdviserSignUpValidatorTests.cs b/GetIntoTeachingApiTests/Models/Validators/TeacherTrainingAdviserSignUpValidatorTests.cs index 3c888e0b1..9a3532d36 100644 --- a/GetIntoTeachingApiTests/Models/Validators/TeacherTrainingAdviserSignUpValidatorTests.cs +++ b/GetIntoTeachingApiTests/Models/Validators/TeacherTrainingAdviserSignUpValidatorTests.cs @@ -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] @@ -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() {