Skip to content

Commit

Permalink
Qulaified teacher status test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
CathLass committed Dec 9, 2024
1 parent b09d180 commit f025a1c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -44,9 +44,9 @@ public string? StatusWarningMessage
{
get
{
if (StatusManagedByCPD)
if (StatusIsManagedByCPD)
{
return InductionManagedByCpdWarning;
return InductionIsManagedByCpdWarning;
}
else if (TeacherHoldsQualifiedTeacherStatus)
{
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using TeachingRecordSystem.Core.DataStore.Postgres.Models;
using TeachingRecordSystem.Core.Dqt;

namespace TeachingRecordSystem.SupportUi.Tests.PageTests.Persons.PersonDetail;

Expand All @@ -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");

Expand All @@ -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");

Expand Down Expand Up @@ -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);
Expand All @@ -252,7 +257,8 @@ await WithDbContext(async dbContext =>
out _);
await dbContext.SaveChangesAsync();
});



var request = new HttpRequestMessage(HttpMethod.Get, $"/persons/{person.ContactId}/induction");

// Act
Expand Down

0 comments on commit f025a1c

Please sign in to comment.