From 5876af5daaa78c1ac66f93b0982ab155c3c47d53 Mon Sep 17 00:00:00 2001 From: Martyn Whitwell Date: Mon, 4 Dec 2023 17:01:17 +0000 Subject: [PATCH] Add support for Primary education phase New (optional) StageTaughtId parameter + updated tests --- .../Crm/CandidatePastTeachingPosition.cs | 1 + .../TeacherTrainingAdviserSignUp.cs | 37 +++++++--- .../TeacherTrainingAdviserSignUpValidator.cs | 17 ++++- ...cherTrainingAdviserSignUpValidatorTests.cs | 74 ++++++++++++++++++- 4 files changed, 112 insertions(+), 17 deletions(-) diff --git a/GetIntoTeachingApi/Models/Crm/CandidatePastTeachingPosition.cs b/GetIntoTeachingApi/Models/Crm/CandidatePastTeachingPosition.cs index 9a5941ec5..585fd2296 100644 --- a/GetIntoTeachingApi/Models/Crm/CandidatePastTeachingPosition.cs +++ b/GetIntoTeachingApi/Models/Crm/CandidatePastTeachingPosition.cs @@ -12,6 +12,7 @@ public class CandidatePastTeachingPosition : BaseModel, IHasCandidateId { public enum EducationPhase { + Primary = 222750000, Secondary = 222750001, } diff --git a/GetIntoTeachingApi/Models/TeacherTrainingAdviser/TeacherTrainingAdviserSignUp.cs b/GetIntoTeachingApi/Models/TeacherTrainingAdviser/TeacherTrainingAdviserSignUp.cs index b9a7174fa..a08e67149 100644 --- a/GetIntoTeachingApi/Models/TeacherTrainingAdviser/TeacherTrainingAdviserSignUp.cs +++ b/GetIntoTeachingApi/Models/TeacherTrainingAdviser/TeacherTrainingAdviserSignUp.cs @@ -56,6 +56,7 @@ public enum ResubscribableAdviserStatus public int? DegreeStatusId { get; set; } public int? DegreeTypeId { get; set; } public int? InitialTeacherTrainingYearId { get; set; } + public int? StageTaughtId { get; set; } public int? PreferredEducationPhaseId { get; set; } public int? HasGcseMathsAndEnglishId { get; set; } public int? HasGcseScienceId { get; set; } @@ -115,7 +116,7 @@ private static bool CanSubscribe(Candidate candidate) private static void DefaultPreferredEducationPhase(Candidate candidate) { - if (candidate.IsReturningToTeaching()) + if (candidate.IsReturningToTeaching() && candidate.PreferredEducationPhaseId == null) { candidate.PreferredEducationPhaseId = (int)Candidate.PreferredEducationPhase.Secondary; } @@ -323,14 +324,31 @@ private void AddQualification(Candidate candidate) private void AddPastTeachingPosition(Candidate candidate) { - if (ContainsPastTeachingPosition()) + // NB: StageTaughtId is a new parameter and might not be set by older clients. + // NB: If the StageTaughtId==primary, SubjectTaughtId will be null + if (candidate.IsReturningToTeaching()) { - candidate.PastTeachingPositions.Add(new CandidatePastTeachingPosition() + if (StageTaughtId == (int)CandidatePastTeachingPosition.EducationPhase.Primary || + SubjectTaughtId == TeachingSubject.PrimaryTeachingSubjectId) { - Id = PastTeachingPositionId, - SubjectTaughtId = SubjectTaughtId, - EducationPhaseId = (int)CandidatePastTeachingPosition.EducationPhase.Secondary, - }); + candidate.PastTeachingPositions.Add(new CandidatePastTeachingPosition() + { + Id = PastTeachingPositionId, + SubjectTaughtId = TeachingSubject.PrimaryTeachingSubjectId, + EducationPhaseId = (int)CandidatePastTeachingPosition.EducationPhase.Primary, + }); + } + else if ((StageTaughtId == null || + StageTaughtId == (int)CandidatePastTeachingPosition.EducationPhase.Secondary) && + SubjectTaughtId != null) + { + candidate.PastTeachingPositions.Add(new CandidatePastTeachingPosition() + { + Id = PastTeachingPositionId, + SubjectTaughtId = SubjectTaughtId, + EducationPhaseId = (int)CandidatePastTeachingPosition.EducationPhase.Secondary, + }); + } } } @@ -360,10 +378,5 @@ private bool ContainsQualification() { return UkDegreeGradeId != null || DegreeStatusId != null || DegreeSubject != null || DegreeTypeId != null; } - - private bool ContainsPastTeachingPosition() - { - return SubjectTaughtId != null; - } } } diff --git a/GetIntoTeachingApi/Models/TeacherTrainingAdviser/Validators/TeacherTrainingAdviserSignUpValidator.cs b/GetIntoTeachingApi/Models/TeacherTrainingAdviser/Validators/TeacherTrainingAdviserSignUpValidator.cs index e57efad59..25e5c2a5e 100644 --- a/GetIntoTeachingApi/Models/TeacherTrainingAdviser/Validators/TeacherTrainingAdviserSignUpValidator.cs +++ b/GetIntoTeachingApi/Models/TeacherTrainingAdviser/Validators/TeacherTrainingAdviserSignUpValidator.cs @@ -41,10 +41,21 @@ public TeacherTrainingAdviserSignUpValidator(IStore store, IDateTimeProvider dat When(request => request.Candidate.IsReturningToTeaching(), () => { - RuleFor(request => request.SubjectTaughtId).NotNull() - .WithMessage("Must be set for candidates returning to teacher training."); RuleFor(request => request.PreferredTeachingSubjectId).NotNull() - .WithMessage("Must be set for candidates returning to teacher training."); + .When(request => request.Candidate.PreferredEducationPhaseId == (int)Candidate.PreferredEducationPhase.Secondary) + .WithMessage("For candidates returning to teacher training, must be set when preferred education phase is secondary."); + + RuleFor(request => request.PreferredTeachingSubjectId).NotNull() + .When(request => request.Candidate.PreferredEducationPhaseId == null) + .WithMessage("For candidates returning to teacher training, must be set when preferred education phase defaults to secondary."); + + RuleFor(request => request.SubjectTaughtId).NotNull() + .When(request => request.StageTaughtId == null) + .WithMessage("For candidates returning to teacher training, must be set when stage taught defaults to secondary."); + + RuleFor(request => request.SubjectTaughtId).NotNull() + .When(request => request.StageTaughtId == (int) CandidatePastTeachingPosition.EducationPhase.Secondary) + .WithMessage("For candidates returning to teacher training, must be set when stage taught is secondary."); }); When(request => request.Candidate.IsInterestedInTeaching(), () => diff --git a/GetIntoTeachingApiTests/Models/TeacherTrainingAdviser/Validators/TeacherTrainingAdviserSignUpValidatorTests.cs b/GetIntoTeachingApiTests/Models/TeacherTrainingAdviser/Validators/TeacherTrainingAdviserSignUpValidatorTests.cs index 6da6c23a9..3b096f015 100644 --- a/GetIntoTeachingApiTests/Models/TeacherTrainingAdviser/Validators/TeacherTrainingAdviserSignUpValidatorTests.cs +++ b/GetIntoTeachingApiTests/Models/TeacherTrainingAdviser/Validators/TeacherTrainingAdviserSignUpValidatorTests.cs @@ -154,10 +154,80 @@ public void Validate_WhenRequiredAttributesAreNull_HasErrors() var result = _validator.TestValidate(_request); result.ShouldHaveValidationErrorFor(request => request.SubjectTaughtId) - .WithErrorMessage("Must be set for candidates returning to teacher training."); + .WithErrorMessage("For candidates returning to teacher training, must be set when stage taught defaults to secondary."); result.ShouldHaveValidationErrorFor(request => request.PreferredTeachingSubjectId) - .WithErrorMessage("Must be set for candidates returning to teacher training."); + .WithErrorMessage("For candidates returning to teacher training, must be set when preferred education phase is secondary."); + } + + [Fact] + public void Validate_WhenPreferredEducationPhaseNullRequiredAttributesAreNull_HasErrors() + { + _request.PreferredEducationPhaseId = null; + _request.PreferredTeachingSubjectId = null; + + var result = _validator.TestValidate(_request); + + result.ShouldHaveValidationErrorFor(request => request.PreferredTeachingSubjectId) + .WithErrorMessage("For candidates returning to teacher training, must be set when preferred education phase is secondary."); + } + + [Fact] + public void Validate_WhenPreferredEducationPhasePrimaryRequiredAttributesAreNull_HasErrors() + { + _request.PreferredEducationPhaseId = (int)Candidate.PreferredEducationPhase.Primary; + _request.PreferredTeachingSubjectId = null; + + var result = _validator.TestValidate(_request); + + result.ShouldNotHaveValidationErrorFor(request => request.PreferredTeachingSubjectId); + } + + [Fact] + public void Validate_WhenPreferredEducationPhaseSecondaryRequiredAttributesAreNull_HasErrors() + { + _request.PreferredEducationPhaseId = (int)Candidate.PreferredEducationPhase.Secondary; + _request.PreferredTeachingSubjectId = null; + + var result = _validator.TestValidate(_request); + + result.ShouldHaveValidationErrorFor(request => request.PreferredTeachingSubjectId) + .WithErrorMessage("For candidates returning to teacher training, must be set when preferred education phase is secondary."); + } + + [Fact] + public void Validate_WhenStageTaughtNullRequiredAttributesAreNull_HasErrors() + { + _request.StageTaughtId = null; + _request.SubjectTaughtId = null; + + var result = _validator.TestValidate(_request); + + result.ShouldHaveValidationErrorFor(request => request.SubjectTaughtId) + .WithErrorMessage("For candidates returning to teacher training, must be set when stage taught defaults to secondary."); + } + + [Fact] + public void Validate_WhenStageTaughtPrimaryRequiredAttributesAreNull_HasErrors() + { + _request.StageTaughtId = (int)CandidatePastTeachingPosition.EducationPhase.Primary; + _request.SubjectTaughtId = null; + + var result = _validator.TestValidate(_request); + + result.ShouldNotHaveValidationErrorFor(request => request.SubjectTaughtId); + } + + [Fact] + public void Validate_WhenStageTaughtSecondaryRequiredAttributesAreNull_HasErrors() + { + _request.StageTaughtId = (int)CandidatePastTeachingPosition.EducationPhase.Secondary; + _request.SubjectTaughtId = null; + + var result = _validator.TestValidate(_request); + + result.ShouldHaveValidationErrorFor(request => request.SubjectTaughtId) + .WithErrorMessage("For candidates returning to teacher training, must be set when stage taught is secondary."); } }