Skip to content

Commit

Permalink
Merge branch 'main' into fix/contentful-table-renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielClarkeEducation authored Jul 4, 2024
2 parents 754c83b + 05800e1 commit 08e4060
Show file tree
Hide file tree
Showing 59 changed files with 1,183 additions and 881 deletions.
427 changes: 221 additions & 206 deletions content/Dfe.EarlyYearsQualification.ContentUpload/Program.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ namespace Dfe.EarlyYearsQualification.Content.Constants;

public static class QuestionPages
{

//// Radio Button Pages

/// <summary>
Expand All @@ -21,7 +20,7 @@ public static class QuestionPages
/// Entry ID for the "When was the qualification started" question page.
/// </summary>
public const string WhenWasTheQualificationStarted = "2o331MBr0R6nsZNBem4yvk";

//// Dropdown Pages

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public class AccessibilityStatementPage
public string Heading { get; init; } = string.Empty;

public Document? Body { get; init; }

public NavigationLink? BackButton { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public class AdvicePage
public string Heading { get; init; } = string.Empty;

public Document? Body { get; init; }

public NavigationLink? BackButton { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public class CookiesPage
public Document? SuccessBannerContent { get; init; }

public string ErrorText { get; init; } = string.Empty;

public NavigationLink? BackButton { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public class DateQuestionPage
public string MonthLabel { get; init; } = string.Empty;

public string YearLabel { get; init; } = string.Empty;

public NavigationLink? BackButton { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public class DetailsPage
public string FurtherInfoHeading { get; init; } = string.Empty;

public Document? FurtherInfoText { get; init; }

public NavigationLink? BackButton { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public class DropdownQuestionPage
public string NotInListText { get; init; } = string.Empty;

public string DefaultText { get; init; } = string.Empty;
public NavigationLink? BackButton { get; set; }

public NavigationLink? BackButton { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Dfe.EarlyYearsQualification.Content.Entities;

public class QualificationListPage
{
public string Header { get; set; } = string.Empty;
public NavigationLink? BackButton { get; set; }
public string Header { get; init; } = string.Empty;

public NavigationLink? BackButton { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public class RadioQuestionPage
public string AdditionalInformationHeader { get; init; } = string.Empty;

public Document? AdditionalInformationBody { get; init; }

public NavigationLink? BackButton { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,24 @@ public class ContentfulContentFilterService(
: IContentFilterService
{
private const int Day = 28;
private static readonly DateTimeFormatInfo CurrentFormatInfo = CultureInfo.CurrentCulture.DateTimeFormat;

private readonly ReadOnlyDictionary<int, string>
_months = new(
new Dictionary<int, string>
{
{ 1, CurrentFormatInfo.AbbreviatedMonthNames[0] },
{ 2, CurrentFormatInfo.AbbreviatedMonthNames[1] },
{ 3, CurrentFormatInfo.AbbreviatedMonthNames[2] },
{ 4, CurrentFormatInfo.AbbreviatedMonthNames[3] },
{ 5, CurrentFormatInfo.AbbreviatedMonthNames[4] },
{ 6, CurrentFormatInfo.AbbreviatedMonthNames[5] },
{ 7, CurrentFormatInfo.AbbreviatedMonthNames[6] },
{ 8, CurrentFormatInfo.AbbreviatedMonthNames[7] },
{ 9, CurrentFormatInfo.AbbreviatedMonthNames[8] },
{ 10, CurrentFormatInfo.AbbreviatedMonthNames[9] },
{ 11, CurrentFormatInfo.AbbreviatedMonthNames[10] },
{ 12, CurrentFormatInfo.AbbreviatedMonthNames[11] }
});

private static readonly ReadOnlyDictionary<string, int>
Months = new(
new Dictionary<string, int>(StringComparer.InvariantCultureIgnoreCase)
{
{ "Jan", 1 },
{ "Feb", 2 },
{ "Mar", 3 },
{ "Apr", 4 },
{ "May", 5 },
{ "Jun", 6 },
{ "Jul", 7 },
{ "Aug", 8 },
{ "Sep", 9 },
{ "Oct", 10 },
{ "Nov", 11 },
{ "Dec", 12 }
});

// Used by the unit tests to inject a mock builder that returns the query params
public QueryBuilder<Qualification> QueryBuilder { get; init; } = QueryBuilder<Qualification>.New;
Expand Down Expand Up @@ -94,6 +93,8 @@ private List<Qualification> FilterQualificationsByDate(int startDateMonth, int s
}
else if (qualificationStartDate is null
&& qualificationEndDate is not null
// ReSharper disable once MergeSequentialChecks
// ...reveals the intention more clearly this way
&& enteredStartDate <= qualificationEndDate)
{
// if qualification start date is null, check entered start date is <= ToWhichYear & add to results
Expand Down Expand Up @@ -124,12 +125,49 @@ private List<Qualification> FilterQualificationsByDate(int startDateMonth, int s

private DateOnly? ConvertToDateTime(string qualificationDate)
{
var splitQualificationDate = qualificationDate.Split('-');
if (splitQualificationDate.Length != 2) return null;
var (isValid, month, yearMod2000) = ValidateQualificationDate(qualificationDate);

if (!isValid)
{
return null;
}

var month = _months.FirstOrDefault(x => x.Value == splitQualificationDate[0]).Key;
var year = Convert.ToInt32(splitQualificationDate[1]) + 2000;
var year = yearMod2000 + 2000;

return new DateOnly(year, month, Day);
}

private (bool isValid, int month, int yearMod2000) ValidateQualificationDate(string qualificationDate)
{
var splitQualificationDate = qualificationDate.Split('-');
if (splitQualificationDate.Length != 2)
{
logger.LogError("Qualification date {QualificationDate} has unexpected format", qualificationDate);
return (false, 0, 0);
}

var abbreviatedMonth = splitQualificationDate[0];
var yearFilter = splitQualificationDate[1];

var yearIsValid = int.TryParse(yearFilter,
NumberStyles.Integer,
NumberFormatInfo.InvariantInfo,
out var yearPart);

if (!yearIsValid)
{
logger.LogError("Qualification date {QualificationDate} contains unexpected year value", qualificationDate);
return (false, 0, 0);
}

if (!Months.TryGetValue(abbreviatedMonth, out var month))
{
logger.LogError("Qualification date {QualificationDate} contains unexpected month value",
qualificationDate);

return (false, 0, 0);
}

return (true, month, yearPart);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private readonly Dictionary<object, string> _contentTypes
{ typeof(Qualification), ContentTypes.Qualification },
{ typeof(DetailsPage), ContentTypes.DetailsPage },
{ typeof(AdvicePage), ContentTypes.AdvicePage },
{ typeof(RadioQuestionPage), ContentTypes.RadioQuestionPage},
{ typeof(RadioQuestionPage), ContentTypes.RadioQuestionPage },
{ typeof(AccessibilityStatementPage), ContentTypes.AccessibilityStatementPage },
{ typeof(NavigationLinks), ContentTypes.NavigationLinks },
{ typeof(CookiesPage), ContentTypes.CookiesPage },
Expand All @@ -29,12 +29,14 @@ private readonly Dictionary<object, string> _contentTypes
{ typeof(DateQuestionPage), ContentTypes.DateQuestionPage },
{ typeof(DropdownQuestionPage), ContentTypes.DropdownQuestionPage },
{ typeof(QualificationListPage), ContentTypes.QualificationListPage },
{ typeof(ConfirmQualificationPage), ContentTypes.ConfirmQualificationPage},
{ typeof(ConfirmQualificationPage), ContentTypes.ConfirmQualificationPage }
};

public async Task<StartPage?> GetStartPage()
{
var startPageEntries = await GetEntriesByType<StartPage>();

// ReSharper disable once InvertIf
if (startPageEntries is null || !startPageEntries.Any())
{
logger.LogWarning("No start page entry returned");
Expand All @@ -60,6 +62,8 @@ private readonly Dictionary<object, string> _contentTypes
public async Task<AccessibilityStatementPage?> GetAccessibilityStatementPage()
{
var accessibilityStatementEntities = await GetEntriesByType<AccessibilityStatementPage>();

// ReSharper disable once InvertIf
if (accessibilityStatementEntities is null || !accessibilityStatementEntities.Any())
{
logger.LogWarning("No accessibility statement page entry returned");
Expand Down Expand Up @@ -116,6 +120,8 @@ public async Task<List<NavigationLink>> GetNavigationLinks()
public async Task<AdvicePage?> GetAdvicePage(string entryId)
{
var advicePage = await GetEntryById<AdvicePage>(entryId);

// ReSharper disable once InvertIf
if (advicePage is null)
{
logger.LogWarning("Advice page with {EntryID} could not be found", entryId);
Expand Down Expand Up @@ -143,6 +149,8 @@ public async Task<List<NavigationLink>> GetNavigationLinks()
public async Task<PhaseBanner?> GetPhaseBannerContent()
{
var phaseBannerEntities = await GetEntriesByType<PhaseBanner>();

// ReSharper disable once InvertIf
if (phaseBannerEntities is null || !phaseBannerEntities.Any())
{
logger.LogWarning("No phase banner entry returned");
Expand All @@ -155,6 +163,8 @@ public async Task<List<NavigationLink>> GetNavigationLinks()
public async Task<CookiesBanner?> GetCookiesBannerContent()
{
var cookiesBannerEntry = await GetEntriesByType<CookiesBanner>();

// ReSharper disable once InvertIf
if (cookiesBannerEntry is null || !cookiesBannerEntry.Any())
{
logger.LogWarning("No cookies banner entry returned");
Expand All @@ -173,6 +183,8 @@ public async Task<List<Qualification>> GetQualifications()
public async Task<ConfirmQualificationPage?> GetConfirmQualificationPage()
{
var confirmQualificationEntities = await GetEntriesByType<ConfirmQualificationPage>();

// ReSharper disable once InvertIf
if (confirmQualificationEntities is null || !confirmQualificationEntities.Any())
{
logger.LogWarning("No confirm qualification page entry returned");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,32 @@ public class MockContentfulFilterService : IContentFilterService
{
public Task<List<Qualification>> GetFilteredQualifications(int? level, int? startDateMonth, int? startDateYear)
{
var qualifications = new List<Qualification>
{
CreateQualification("EYQ-100", "CACHE", 2, null, "Aug-19"),
CreateQualification("EYQ-101", "NCFE", 2, "Sep-14", "Aug-19"),
CreateQualification("EYQ-102", "Pearson", 3, "Sep-14", "Aug-19"),
CreateQualification("EYQ-103", "NCFE", 3, "Sep-14", "Aug-19"),
CreateQualification("EYQ-104", "City & Guilds", 4, "Sep-14", "Aug-19"),
CreateQualification("EYQ-105", "Montessori Centre International", 4, "Sep-14", "Aug-19"),
CreateQualification("EYQ-106", "Various Awarding Organisations", 5, "Sep-14", "Aug-19"),
CreateQualification("EYQ-107", "Edexcel (now Pearson Education Ltd)", 5, "Sep-14", "Aug-19"),
CreateQualification("EYQ-108", "Kent Sussex Montessori Centre", 6, "Sep-14", "Aug-19"),
CreateQualification("EYQ-109", "NNEB National Nursery Examination Board", 6, "Sep-14", "Aug-19"),
CreateQualification("EYQ-110", "Various Awarding Organisations", 7, "Sep-14", "Aug-19"),
CreateQualification("EYQ-111", "City & Guilds", 7, "Sep-14", "Aug-19"),
CreateQualification("EYQ-112", "Pearson", 8, "Sep-14", "Aug-19"),
CreateQualification("EYQ-113", "CACHE", 8, "Sep-14", "Aug-19")
};
var qualifications =
new List<Qualification>
{
CreateQualification("EYQ-100", "CACHE", 2, null, "Aug-19"),
CreateQualification("EYQ-101", "NCFE", 2, "Sep-14", "Aug-19"),
CreateQualification("EYQ-102", "Pearson", 3, "Sep-14", "Aug-19"),
CreateQualification("EYQ-103", "NCFE", 3, "Sep-14", "Aug-19"),
CreateQualification("EYQ-104", "City & Guilds", 4, "Sep-14", "Aug-19"),
CreateQualification("EYQ-105", "Montessori Centre International", 4, "Sep-14", "Aug-19"),
CreateQualification("EYQ-106", "Various Awarding Organisations", 5, "Sep-14", "Aug-19"),
CreateQualification("EYQ-107", "Edexcel (now Pearson Education Ltd)", 5, "Sep-14", "Aug-19"),
CreateQualification("EYQ-108", "Kent Sussex Montessori Centre", 6, "Sep-14", "Aug-19"),
CreateQualification("EYQ-109", "NNEB National Nursery Examination Board", 6, "Sep-14", "Aug-19"),
CreateQualification("EYQ-110", "Various Awarding Organisations", 7, "Sep-14", "Aug-19"),
CreateQualification("EYQ-111", "City & Guilds", 7, "Sep-14", "Aug-19"),
CreateQualification("EYQ-112", "Pearson", 8, "Sep-14", "Aug-19"),
CreateQualification("EYQ-113", "CACHE", 8, "Sep-14", "Aug-19")
};

return Task.FromResult(qualifications.Where(x => x.QualificationLevel == level).ToList());
}

private static Qualification CreateQualification(string qualificationId, string awardingOrganisation, int level, string? startDate, string endDate)
private static Qualification CreateQualification(string qualificationId, string awardingOrganisation, int level,
string? startDate, string endDate)
{
return new Qualification(
qualificationId,
return new Qualification(qualificationId,
$"{qualificationId}-test",
awardingOrganisation,
level,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,37 +218,37 @@ public Task<List<Qualification>> GetQualifications()
public async Task<ConfirmQualificationPage?> GetConfirmQualificationPage()
{
return await Task.FromResult(new ConfirmQualificationPage
{
QualificationLabel = "Test qualification label",
BackButton = new NavigationLink
{
DisplayText = "Test back button",
OpenInNewTab = false,
Href = "/qualifications"
},
ErrorText = "Test error text",
ButtonText = "Test button text",
LevelLabel = "Test level label",
DateAddedLabel = "Test date added label",
Heading = "Test heading",
Options =
[
new Option
{
Label = "yes",
Value = "yes"
},
new Option
{
Label = "no",
Value = "no"
}
],
RadioHeading = "Test radio heading",
AwardingOrganisationLabel = "Test awarding organisation label",
ErrorBannerHeading = "Test error banner heading",
ErrorBannerLink = "Test error banner link"
});
{
QualificationLabel = "Test qualification label",
BackButton = new NavigationLink
{
DisplayText = "Test back button",
OpenInNewTab = false,
Href = "/qualifications"
},
ErrorText = "Test error text",
ButtonText = "Test button text",
LevelLabel = "Test level label",
DateAddedLabel = "Test date added label",
Heading = "Test heading",
Options =
[
new Option
{
Label = "yes",
Value = "yes"
},
new Option
{
Label = "no",
Value = "no"
}
],
RadioHeading = "Test radio heading",
AwardingOrganisationLabel = "Test awarding organisation label",
ErrorBannerHeading = "Test error banner heading",
ErrorBannerLink = "Test error banner link"
});
}

public async Task<StartPage?> GetStartPage()
Expand Down
Loading

0 comments on commit 08e4060

Please sign in to comment.