Skip to content

Commit

Permalink
Merge pull request #511 from DFE-Digital/ofsted-date-null-handling
Browse files Browse the repository at this point in the history
Updated Ofsted logic to handle nulls
  • Loading branch information
dneed-nimble authored Sep 20, 2024
2 parents 4d340ff + 7e6f2b6 commit d22709b
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased][unreleased]

### Changed

- Ofsted logic can now handle null dates

## [Release-6][release-6] (production-2024-09-17.3129)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Globalization;
using DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Extensions;
using DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Models.Gias;
using DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Models.Mis;
using System.Globalization;

namespace DfE.FindInformationAcademiesTrusts.Data.AcademiesDb.Factories;

Expand Down Expand Up @@ -39,49 +39,53 @@ public Academy CreateFrom(GiasGroupLink gl, GiasEstablishment giasEstablishment,
private static OfstedRating GetCurrentOfstedRating(MisEstablishment? misEstablishmentCurrentOfsted,
MisFurtherEducationEstablishment? misFurtherEducationEstablishment)
{
if (misEstablishmentCurrentOfsted is not null && misEstablishmentCurrentOfsted.OverallEffectiveness is not null)
if (misEstablishmentCurrentOfsted is not null
&& misEstablishmentCurrentOfsted.OverallEffectiveness is not null
&& !string.IsNullOrEmpty(misEstablishmentCurrentOfsted.InspectionEndDate))
{
return new OfstedRating(
(OfstedRatingScore)misEstablishmentCurrentOfsted.OverallEffectiveness.Value,
DateTime.ParseExact(misEstablishmentCurrentOfsted.InspectionEndDate!, "dd/MM/yyyy",
CultureInfo.InvariantCulture)
DateTime.ParseExact(misEstablishmentCurrentOfsted.InspectionEndDate!, "dd/MM/yyyy", CultureInfo.InvariantCulture)
);
}

if (misFurtherEducationEstablishment is not null && misFurtherEducationEstablishment.OverallEffectiveness is not null)
if (misFurtherEducationEstablishment is not null
&& misFurtherEducationEstablishment.OverallEffectiveness is not null
&& !string.IsNullOrEmpty(misFurtherEducationEstablishment.LastDayOfInspection))
{
return new OfstedRating(
(OfstedRatingScore)misFurtherEducationEstablishment.OverallEffectiveness.Value,
DateTime.ParseExact(misFurtherEducationEstablishment.LastDayOfInspection!, "dd/MM/yyyy",
CultureInfo.InvariantCulture)
);
(OfstedRatingScore)misFurtherEducationEstablishment.OverallEffectiveness.Value,
DateTime.ParseExact(misFurtherEducationEstablishment.LastDayOfInspection!, "dd/MM/yyyy", CultureInfo.InvariantCulture)
);
}

return OfstedRating.None;
}

private static OfstedRating GetPreviousOfstedRating(MisEstablishment? misEstablishmentPreviousOfsted,
MisFurtherEducationEstablishment? misFurtherEducationEstablishment)
MisFurtherEducationEstablishment? misFurtherEducationEstablishment)
{
if (misEstablishmentPreviousOfsted is not null && misEstablishmentPreviousOfsted.PreviousFullInspectionOverallEffectiveness is not null)
if (misEstablishmentPreviousOfsted is not null
&& !string.IsNullOrEmpty(misEstablishmentPreviousOfsted.PreviousFullInspectionOverallEffectiveness)
&& !string.IsNullOrEmpty(misEstablishmentPreviousOfsted.PreviousInspectionEndDate))
{
return new OfstedRating(
(OfstedRatingScore)int.Parse(misEstablishmentPreviousOfsted
.PreviousFullInspectionOverallEffectiveness!),
DateTime.ParseExact(misEstablishmentPreviousOfsted.PreviousInspectionEndDate!, "dd/MM/yyyy",
CultureInfo.InvariantCulture)
(OfstedRatingScore)int.Parse(misEstablishmentPreviousOfsted.PreviousFullInspectionOverallEffectiveness!),
DateTime.ParseExact(misEstablishmentPreviousOfsted.PreviousInspectionEndDate!, "dd/MM/yyyy", CultureInfo.InvariantCulture)
);
}

if (misFurtherEducationEstablishment is not null && misFurtherEducationEstablishment.PreviousOverallEffectiveness is not null)
if (misFurtherEducationEstablishment is not null
&& misFurtherEducationEstablishment.PreviousOverallEffectiveness is not null
&& !string.IsNullOrEmpty(misFurtherEducationEstablishment.PreviousLastDayOfInspection))
{
return new OfstedRating(
(OfstedRatingScore)misFurtherEducationEstablishment.PreviousOverallEffectiveness.Value,
DateTime.ParseExact(misFurtherEducationEstablishment.PreviousLastDayOfInspection!, "dd/MM/yyyy",
CultureInfo.InvariantCulture)
);
(OfstedRatingScore)misFurtherEducationEstablishment.PreviousOverallEffectiveness.Value,
DateTime.ParseExact(misFurtherEducationEstablishment.PreviousLastDayOfInspection!, "dd/MM/yyyy", CultureInfo.InvariantCulture)
);
}

return OfstedRating.None;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,56 @@ public void
result.PreviousOfstedRating.Should().NotBeNull();
result.PreviousOfstedRating.InspectionEndDate.Should().Be(new DateTime(year, month, day));
}
[Fact]
public void CreateAcademyFrom_should_set_current_ofsted_inspection_date_to_null_if_InspectionEndDate_is_null_or_empty()
{
var misEstablishmentWithNullDate = new MisEstablishment
{
UrnAtTimeOfLatestFullInspection = _giasEstablishment.Urn,
InspectionEndDate = null,
OverallEffectiveness = 1
};

var misEstablishmentWithEmptyDate = new MisEstablishment
{
UrnAtTimeOfLatestFullInspection = _giasEstablishment.Urn,
InspectionEndDate = "",
OverallEffectiveness = 1
};

// Test when InspectionEndDate is null
var resultWithNullDate = _sut.CreateFrom(_giasGroupLink, _giasEstablishment, misEstablishmentWithNullDate);
resultWithNullDate.CurrentOfstedRating.InspectionEndDate.Should().BeNull(); // The date should be null

// Test when InspectionEndDate is empty
var resultWithEmptyDate = _sut.CreateFrom(_giasGroupLink, _giasEstablishment, misEstablishmentWithEmptyDate);
resultWithEmptyDate.CurrentOfstedRating.InspectionEndDate.Should().BeNull(); // The date should be null
}

[Fact]
public void CreateAcademyFrom_should_set_previous_ofsted_inspection_date_to_null_if_PreviousInspectionEndDate_is_null_or_empty()
{
var misEstablishmentWithNullDate = new MisEstablishment
{
UrnAtTimeOfPreviousFullInspection = _giasEstablishment.Urn,
PreviousInspectionEndDate = null,
PreviousFullInspectionOverallEffectiveness = "1"
};

var misEstablishmentWithEmptyDate = new MisEstablishment
{
UrnAtTimeOfPreviousFullInspection = _giasEstablishment.Urn,
PreviousInspectionEndDate = "",
PreviousFullInspectionOverallEffectiveness = "1"
};

// Test when PreviousInspectionEndDate is null
var resultWithNullDate = _sut.CreateFrom(_giasGroupLink, _giasEstablishment, misEstablishmentWithNullDate);
resultWithNullDate.PreviousOfstedRating.InspectionEndDate.Should().BeNull(); // The date should be null

// Test when PreviousInspectionEndDate is empty
var resultWithEmptyDate = _sut.CreateFrom(_giasGroupLink, _giasEstablishment, misEstablishmentWithEmptyDate);
resultWithEmptyDate.PreviousOfstedRating.InspectionEndDate.Should().BeNull(); // The date should be null
}

}

0 comments on commit d22709b

Please sign in to comment.