diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/PersonDetail/Induction.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/PersonDetail/Induction.cshtml.cs index d972fdecc..2bc6d57ab 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/PersonDetail/Induction.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/PersonDetail/Induction.cshtml.cs @@ -8,9 +8,9 @@ namespace TeachingRecordSystem.SupportUi.Pages.Persons.PersonDetail; public class InductionModel(TrsDbContext dbContext, ICrmQueryDispatcher crmQueryDispatcher, IClock clock) : PageModel { - private static readonly string NoQualifiedTeacherStatusWarning = "This teacher doesn\u2019t have QTS and, therefore, is ineligible for induction."; - private static readonly string InductionManagedByCpdWarning = "To change a teacher\u2019s induction status to passed, failed, or in progress, use the Record inductions as an appropriate body service."; - private bool StatusManagedByCPD; + private static readonly string NoQualifiedTeacherStatusWarning = "This teacher has not been awarded QTS and is therefore ineligible for induction."; + private static readonly string InductionIsManagedByCpdWarning = "To change a teacher\u2019s induction status to passed, failed, or in progress, use the Record inductions as an appropriate body service."; + private bool StatusIsManagedByCPD; private bool TeacherHoldsQualifiedTeacherStatus; [FromRoute] @@ -44,9 +44,9 @@ public string? StatusWarningMessage { get { - if (StatusManagedByCPD) + if (StatusIsManagedByCPD) { - return InductionManagedByCpdWarning; + return InductionIsManagedByCpdWarning; } else if (TeacherHoldsQualifiedTeacherStatus) { @@ -70,15 +70,24 @@ public async Task OnGetAsync() var result = await crmQueryDispatcher.ExecuteQueryAsync(query); - TeacherHoldsQualifiedTeacherStatus = result?.Contact.dfeta_QTSDate is null; - Status = person!.InductionStatus; StartDate = person!.InductionStartDate; CompletionDate = person!.InductionCompletedDate; ExemptionReasons = person!.InductionExemptionReasons; + StatusIsManagedByCPD = StatusManagedByCPDRule(person!.CpdInductionStatus, person.CpdInductionCompletedDate); + TeacherHoldsQualifiedTeacherStatus = TeacherHoldsQualifiedTeacherStatusRule(result?.Contact.dfeta_QTSDate); + } + + private bool TeacherHoldsQualifiedTeacherStatusRule(DateTime? qtsDate) + { + return qtsDate is null; + } + + private bool StatusManagedByCPDRule(InductionStatus? status, DateOnly? inductionCompletedDate) + { var sevenYearsAgo = clock.Today.AddYears(-7); - StatusManagedByCPD = person!.CpdInductionStatus is not null - && person.CpdInductionCompletedDate is not null - && person.CpdInductionCompletedDate < sevenYearsAgo; + return status is not null + && inductionCompletedDate is not null + && inductionCompletedDate < sevenYearsAgo; } } diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Persons/PersonDetail/InductionTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Persons/PersonDetail/InductionTests.cs index 80807410f..e0f32607c 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Persons/PersonDetail/InductionTests.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Persons/PersonDetail/InductionTests.cs @@ -1,4 +1,5 @@ using TeachingRecordSystem.Core.DataStore.Postgres.Models; +using TeachingRecordSystem.Core.Dqt; namespace TeachingRecordSystem.SupportUi.Tests.PageTests.Persons.PersonDetail; @@ -24,7 +25,7 @@ public async Task Get_WithPersonIdForPersonWithNoQTS_DisplaysExpectedContent() { // Arrange var person = await TestData.CreatePersonAsync(); - var expectedWarning = "This teacher doesn’t have QTS "; + var expectedWarning = "This teacher has not been awarded QTS "; var request = new HttpRequestMessage(HttpMethod.Get, $"/persons/{person.ContactId}/induction"); @@ -40,7 +41,10 @@ public async Task Get_WithPersonIdForPersonWithNoQTS_DisplaysExpectedContent() public async Task Get_WithPersonIdForPersonWithInductionStatusNone_DisplaysExpectedContent() { // Arrange - var person = await TestData.CreatePersonAsync(builder => builder.WithInductionStatus(InductionStatus.None)); + var person = await TestData.CreatePersonAsync(builder => + builder + .WithInductionStatus(InductionStatus.None) + .WithQtlsDate(Clock.Today)); var request = new HttpRequestMessage(HttpMethod.Get, $"/persons/{person.ContactId}/induction"); @@ -237,8 +241,9 @@ public async Task Get_WithPersonIdForPersonWithInductionStatusNotManagedByCPD_No //Arrange var underSevenYearsAgo = Clock.Today.AddYears(-6); - var person = await TestData.CreatePersonAsync(); - + var person = await TestData.CreatePersonAsync( + builder => builder.WithQtlsDate(Clock.Today)); + await WithDbContext(async dbContext => { dbContext.Attach(person.Person); @@ -252,7 +257,8 @@ await WithDbContext(async dbContext => out _); await dbContext.SaveChangesAsync(); }); - + + var request = new HttpRequestMessage(HttpMethod.Get, $"/persons/{person.ContactId}/induction"); // Act