Skip to content

Commit

Permalink
Merge branch 'FAI-2070_DisplayNhsJobsOnSearchAlerts' into FAI-2185-Fa…
Browse files Browse the repository at this point in the history
…aJobEmailError
  • Loading branch information
dashton82 authored Dec 18, 2024
2 parents 1ed3ce6 + d581979 commit 26fb41e
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentAssertions;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers;
using NUnit.Framework;
using SFA.DAS.FindApprenticeshipJobs.Application.Commands.SavedSearch.SendNotification;
using SFA.DAS.FindApprenticeshipJobs.Domain.EmailTemplates;
Expand Down Expand Up @@ -163,8 +164,9 @@ public void GetSavedSearchVacanciesSnippet_Should_Return_Correct_Snippet()
},
Distance = 10,
TrainingCourse = "Software Engineering",
Wage = "�30,000",
ClosingDate = "2022-12-31"
Wage = "£30,000",
ClosingDate = "2022-12-31",
VacancySource = "FAA"
}
};

Expand All @@ -176,7 +178,7 @@ ABC Company
* Distance: 10 miles
* Training course: Software Engineering
* Annual wage: �30,000
* Wage: £30,000 a year
2022-12-31
Expand Down Expand Up @@ -214,7 +216,7 @@ public void GetSavedSearchVacanciesSnippet_Should_Return_Correct_Snippet_With_No
},
Distance = 10,
TrainingCourse = "Software Engineering",
Wage = "30,000",
Wage = "£30,000",
ClosingDate = "2022-12-31"
}
};
Expand All @@ -226,7 +228,7 @@ ABC Company
123 Main St, 12345
* Training course: Software Engineering
* Annual wage: �30,000
* Wage: £30,000 a year
2022-12-31
Expand All @@ -240,7 +242,121 @@ ABC Company
// Assert
snippet.Should().Be(expectedSnippet);
}


[TestCase("Competitive", "", "Competitive")]
[TestCase("", "month", "£30,000 a year")]
[TestCase("", "hour", "£30,000 a year")]
public void GetSavedSearchVacanciesSnippet_Should_Return_Snippet_With_Correct_Wage_Text_For_Faa_VacancySource_And_Different_WageTypes(
string wagetype, string wageUnit, string expectedWageText)
{
// Arrange
var environmentHelper = new EmailEnvironmentHelper("test")
{
VacancyDetailsUrl = "https://example.com/vacancy/{vacancy-reference}"
};

var vacancies = new List<PostSendSavedSearchNotificationCommand.Vacancy>
{
new()
{
Title = "Software Developer",
VacancyReference = "12345",
EmployerName = "ABC Company",
Address = new PostSendSavedSearchNotificationCommand.Address
{
AddressLine1 = "123 Main St",
Postcode = "12345"
},
Distance = 10,
TrainingCourse = "Software Engineering",
Wage = "£30,000",
ClosingDate = "2022-12-31",
VacancySource = "FAA",
WageUnit = wageUnit,
WageType = wagetype
}
};

string expectedSnippet = $"""
#[Software Developer](https://example.com/vacancy/12345)
ABC Company
123 Main St, 12345
* Distance: 10 miles
* Training course: Software Engineering
* Wage: {expectedWageText}
2022-12-31
---
""";

// Act
var snippet = EmailTemplateBuilder.GetSavedSearchVacanciesSnippet(environmentHelper, vacancies, true);

// Assert
snippet.Should().Be(expectedSnippet);
}

[TestCase("Competitive", "", "Depends on experience")]
[TestCase("", "month", "£30,000 a month")]
[TestCase("", "hour", "£30,000 an hour")]
public void GetSavedSearchVacanciesSnippet_Should_Return_Snippet_With_Correct_Wage_Text_For_Nhs_VacancySource_And_Different_WageTypes(
string wagetype, string wageUnit, string expectedWageText)
{
// Arrange
var environmentHelper = new EmailEnvironmentHelper("test")
{
VacancyDetailsNhsUrl = "https://example.com/vacancy/nhs/{vacancy-reference}"
};

var vacancies = new List<PostSendSavedSearchNotificationCommand.Vacancy>
{
new()
{
Title = "Mental Health Nurse",
VacancyReference = "12345",
EmployerName = "NHS Jobs",
Address = new PostSendSavedSearchNotificationCommand.Address
{
AddressLine1 = "123 Main St",
Postcode = "12345"
},
Distance = 10,
TrainingCourse = "",
Wage = "£30,000",
ClosingDate = "2022-12-31",
VacancySource = "NHS",
WageUnit = wageUnit,
WageType = wagetype
}
};

string expectedSnippet = $"""
#[Mental Health Nurse](https://example.com/vacancy/nhs/12345)
NHS Jobs
123 Main St, 12345
* Distance: 10 miles
* Training course: See more details on NHS Jobs
* Wage: {expectedWageText}
2022-12-31
---
""";

// Act
var snippet = EmailTemplateBuilder.GetSavedSearchVacanciesSnippet(environmentHelper, vacancies, true);

// Assert
snippet.Should().Be(expectedSnippet);
}

private static object[] _titleTestCases =
[
new object?[] { "Foo", new Dictionary<int, string> {{1, "Route 1"},{2,"Route 2"}}, new Dictionary<int, string> {{1, "Level 1"}, {2, "Level 2"}}, null, true, "Foo in all of England" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,17 @@ public class Vacancy

public string? Wage { get; set; }

public string? WageUnit { get; set; }

public string? WageType { get; set; }

public string? ClosingDate { get; set; }

public string? TrainingCourse { get; set; }

public double? Distance { get; set; }

public string? VacancySource { get; set; }
}

public class Address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ public class ApprenticeshipVacancy
public string? EmployerName { get; set; }
public Address Address { get; set; } = null!;
public string? Wage { get; set; }
public string? WageUnit { get; set; }
public string? WageType { get; set; }
public string? ClosingDate { get; set; }
public string? TrainingCourse { get; set; }
public decimal? Distance { get; set; }
public string? VacancySource { get; set; }

public static implicit operator ApprenticeshipVacancy(GetVacanciesListItem source)
{
Expand All @@ -44,9 +47,12 @@ public static implicit operator ApprenticeshipVacancy(GetVacanciesListItem sourc
Title = source.Title,
EmployerName = source.EmployerName,
Wage = source.WageText,
WageUnit = source.WageUnit,
WageType = source.WageType,
Address = source.VacancyAddress,
TrainingCourse = $"{source.CourseTitle} (level {source.CourseLevel})",
Distance = source.Distance.HasValue ? Math.Round(source.Distance.Value, 1) : null,
VacancySource = source.VacancySource,
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class EmailEnvironmentHelper(string environmentName)

public string VacancyDetailsUrl { get; set; } =
$"{GetBaseUrl(environmentName)}apprenticeship/{{vacancy-reference}}";
public string VacancyDetailsNhsUrl { get; set; } =
$"{GetBaseUrl(environmentName)}apprenticeship/nhs/{{vacancy-reference}}";

private static string GetBaseUrl(string environmentName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,24 @@ public static string GetSavedSearchVacanciesSnippet(

foreach (var vacancy in vacancies)
{
string? trainingCourseText;
string? wageText;

sb.AppendLine();
sb.AppendLine($"#[{vacancy.Title}]({environmentHelper.VacancyDetailsUrl.Replace("{vacancy-reference}", vacancy.VacancyReference)})");
if (vacancy.VacancySource == "NHS")
{
sb.AppendLine($"#[{vacancy.Title}]({environmentHelper.VacancyDetailsNhsUrl.Replace("{vacancy-reference}", vacancy.VacancyReference)})");
trainingCourseText = "See more details on NHS Jobs";
wageText = (vacancy.WageType == "Competitive") ?
"Depends on experience" :
vacancy.Wage + ((vacancy.WageUnit == "hour") ? " an " : " a ") + vacancy.WageUnit;
}
else
{
sb.AppendLine($"#[{vacancy.Title}]({environmentHelper.VacancyDetailsUrl.Replace("{vacancy-reference}", vacancy.VacancyReference)})");
trainingCourseText = vacancy.TrainingCourse;
wageText = (vacancy.WageType == "Competitive") ? vacancy.WageType : vacancy.Wage + " a year";
}
sb.AppendLine(vacancy.EmployerName);
sb.AppendLine(!string.IsNullOrEmpty(vacancy.Address.AddressLine4) ? $"{vacancy.Address.AddressLine4}, {vacancy.Address.Postcode}" :
!string.IsNullOrEmpty(vacancy.Address.AddressLine3) ? $"{vacancy.Address.AddressLine3}, {vacancy.Address.Postcode}" :
Expand All @@ -80,9 +96,9 @@ public static string GetSavedSearchVacanciesSnippet(
{
sb.AppendLine($"* Distance: {vacancy.Distance} miles");
}
sb.AppendLine($"* Training course: {vacancy.TrainingCourse}");
sb.AppendLine($"* Annual wage: {vacancy.Wage}");

sb.AppendLine($"* Training course: {trainingCourseText}");
sb.AppendLine($"* Wage: {wageText}");

sb.AppendLine();
sb.AppendLine($"{vacancy.ClosingDate}");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;

namespace SFA.DAS.FindApprenticeshipJobs.InnerApi.Responses
{
Expand Down Expand Up @@ -31,6 +31,12 @@ public class GetVacanciesListItem
[JsonPropertyName("wageText")]
public string WageText { get; set; }

[JsonPropertyName("wageUnit")]
public string WageUnit { get; set; }

[JsonPropertyName("wageType")]
public string WageType { get; set; }

[JsonPropertyName("address")]
public VacancyAddress VacancyAddress { get; set; }

Expand All @@ -42,6 +48,9 @@ public class GetVacanciesListItem

[JsonPropertyName("standardLevel")]
public string CourseLevel { get; set; }

[JsonPropertyName("vacancySource")]
public string VacancySource { get; set; }
}

public class VacancyAddress
Expand Down

0 comments on commit 26fb41e

Please sign in to comment.