Skip to content

Commit

Permalink
Add support for Primary education phase
Browse files Browse the repository at this point in the history
New (optional) StageTaughtId parameter
+ updated tests
  • Loading branch information
martyn-w committed Dec 4, 2023
1 parent 5e3fe16 commit 5876af5
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class CandidatePastTeachingPosition : BaseModel, IHasCandidateId
{
public enum EducationPhase
{
Primary = 222750000,
Secondary = 222750001,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
});
}
}
}

Expand Down Expand Up @@ -360,10 +378,5 @@ private bool ContainsQualification()
{
return UkDegreeGradeId != null || DegreeStatusId != null || DegreeSubject != null || DegreeTypeId != null;
}

private bool ContainsPastTeachingPosition()
{
return SubjectTaughtId != null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(), () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}

Expand Down

0 comments on commit 5876af5

Please sign in to comment.