Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FAI-1325 vacancies api NHS details link correction #1845

Merged
merged 7 commits into from
Jan 9, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public void Then_The_Fields_Are_Mapped(GetVacancyQueryResult source, int ukprn)
.Excluding(c => c.ClosingDate)
.Excluding(item => item.Ukprn)
.Excluding(item => item.VacancyReference)
.Excluding(item => item.VacancySource)
);
actual.FullDescription.Should().Be(source.Vacancy.LongDescription);
actual.Qualifications.Should().BeEquivalentTo(source.Vacancy.Qualifications.Select(c=>(GetVacancyQualification)c).ToList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public static implicit operator GetVacancyResponse(GetVacancyQueryResult source)
EmployerName = source.Vacancy.IsEmployerAnonymous ? source.Vacancy.AnonymousEmployerName : source.Vacancy.EmployerName,
HoursPerWeek = source.Vacancy.HoursPerWeek,
IsDisabilityConfident = source.Vacancy.IsDisabilityConfident,
IsNationalVacancy = source.Vacancy.VacancyLocationType.Equals("National", StringComparison.CurrentCultureIgnoreCase),
IsNationalVacancy = source.Vacancy.VacancyLocationType?.Equals("National", StringComparison.CurrentCultureIgnoreCase) ?? false,
NumberOfPositions = source.Vacancy.NumberOfPositions,
PostedDate = source.Vacancy.PostedDate,
ProviderName = source.Vacancy.ProviderName,
StartDate = source.Vacancy.StartDate,
Title = source.Vacancy.Title,
Ukprn = int.Parse(source.Vacancy.Ukprn),
VacancyReference = source.Vacancy.VacancyReference.Replace("VAC",""),
VacancyReference = source.Vacancy.VacancySource.Equals("NHS", StringComparison.CurrentCultureIgnoreCase) ? source.Vacancy.VacancyReference : source.Vacancy.VacancyReference.Replace("VAC",""),
VacancyUrl = source.Vacancy.VacancyUrl,
Course = source.Vacancy,
Wage = source.Vacancy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,50 @@ public async Task Then_The_Route_And_CourseTitle_Are_Taken_From_Standards_Servic
{
vacancy.VacancyUrl.Should().Be($"{findAnApprenticeshipBaseUrl}/apprenticeship/reference/{vacancy.VacancyReference}");
}
}


[Test, MoqAutoData]
public async Task Then_The_VacancyUrl_Is_Correct_For_Each_Vacancy_Source(
int standardLarsCode,
string findAnApprenticeshipBaseUrl,
GetVacanciesQuery query,
GetVacanciesListItem vacancyRaa,
GetVacanciesListItem vacancyNhs,
GetStandardsListItem courseResponse,
[Frozen] Mock<IFindApprenticeshipApiClient<FindApprenticeshipApiConfiguration>> apiClient,
[Frozen] Mock<ICourseService> courseService,
[Frozen] Mock<IOptions<VacanciesConfiguration>> vacanciesConfiguration,
GetVacanciesQueryHandler handler)
{
vacanciesConfiguration.Object.Value.FindAnApprenticeshipBaseUrl = findAnApprenticeshipBaseUrl;
courseResponse.LarsCode = standardLarsCode;
vacancyRaa.VacancySource = "RAA";
vacancyNhs.VacancySource = "NHS";
var apiResponse = new GetVacanciesResponse
{
ApprenticeshipVacancies = new List<GetVacanciesListItem> { vacancyRaa, vacancyNhs },
TotalFound = 2,
Total = 2
};
foreach (var vacanciesItem in apiResponse.ApprenticeshipVacancies)
{
vacanciesItem.StandardLarsCode = standardLarsCode;
}
query.AccountLegalEntityPublicHashedId = "";
var expectedGetRequest = new GetVacanciesRequest(query.PageNumber, query.PageSize,
query.AccountLegalEntityPublicHashedId, query.Ukprn, query.AccountPublicHashedId, query.StandardLarsCode,
query.NationWideOnly, query.Lat, query.Lon, query.DistanceInMiles, query.Routes, query.PostedInLastNumberOfDays, query.AdditionalDataSources, query.Sort);
apiClient.Setup(x =>
x.Get<GetVacanciesResponse>(It.Is<GetVacanciesRequest>(c =>
c.GetUrl.Equals(expectedGetRequest.GetUrl)))).ReturnsAsync(apiResponse);
courseService.Setup(x => x.GetActiveStandards<GetStandardsListResponse>(nameof(GetStandardsListResponse))).ReturnsAsync(new GetStandardsListResponse
{ Standards = new List<GetStandardsListItem> { courseResponse } });

var actual = await handler.Handle(query, CancellationToken.None);

actual.Vacancies.First(x => x.Id.Equals(vacancyRaa.Id)).VacancyUrl.Should().Be($"{findAnApprenticeshipBaseUrl}/apprenticeship/reference/{vacancyRaa.VacancyReference}");
actual.Vacancies.First(x => x.Id.Equals(vacancyNhs.Id)).VacancyUrl.Should().Be($"{findAnApprenticeshipBaseUrl}/apprenticeship/reference/{vacancyNhs.VacancyReference}");
}

[Test, MoqAutoData]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -20,6 +21,7 @@ public class WhenHandlingGetVacancy
{
[Test, MoqAutoData]
public async Task Then_The_Api_Is_Called_With_The_Request_And_Vacancy_And_Course_Returned(
Guid vacancyReference,
GetVacancyQuery query,
GetVacancyApiResponse apiApiResponse,
GetStandardsListItem courseResponse,
Expand All @@ -31,7 +33,7 @@ public async Task Then_The_Api_Is_Called_With_The_Request_And_Vacancy_And_Course
GetVacancyQueryHandler handler)
{
vacanciesConfiguration.Object.Value.FindAnApprenticeshipBaseUrl = findAnApprenticeshipBaseUrl;
courseResponse.LarsCode = apiApiResponse.StandardLarsCode.Value;
courseResponse.LarsCode = apiApiResponse.StandardLarsCode!.Value;
standardsService.Setup(x => x.GetActiveStandards<GetStandardsListResponse>(nameof(GetStandardsListResponse))).ReturnsAsync(new GetStandardsListResponse
{ Standards = new List<GetStandardsListItem> { courseResponse } });

Expand All @@ -49,6 +51,40 @@ public async Task Then_The_Api_Is_Called_With_The_Request_And_Vacancy_And_Course
actual.Vacancy.CourseTitle.Should().Be(courseResponse.Title);
actual.Vacancy.Route.Should().Be(courseResponse.Route);
}
[Test, MoqAutoData]
public async Task Then_The_Vacancy_Url_Is_Correct_For_Nhs_Vacancy(
Guid vacancyReference,
GetVacancyQuery query,
GetVacancyApiResponse vacancyApiResponse,
GetStandardsListItem courseResponse,
string findAnApprenticeshipBaseUrl,
List<string> categories,
[Frozen] Mock<ICourseService> standardsService,
[Frozen] Mock<IFindApprenticeshipApiClient<FindApprenticeshipApiConfiguration>> apiClient,
[Frozen] Mock<IOptions<VacanciesConfiguration>> vacanciesConfiguration,
GetVacancyQueryHandler handler)
{
vacanciesConfiguration.Object.Value.FindAnApprenticeshipBaseUrl = findAnApprenticeshipBaseUrl;
courseResponse.LarsCode = vacancyApiResponse.StandardLarsCode!.Value;
vacancyApiResponse.VacancySource = "NhS";
vacancyApiResponse.VacancyReference = vacancyReference.ToString();
standardsService.Setup(x => x.GetActiveStandards<GetStandardsListResponse>(nameof(GetStandardsListResponse))).ReturnsAsync(new GetStandardsListResponse
{ Standards = new List<GetStandardsListItem> { courseResponse } });

var expectedGetRequest = new GetVacancyRequest(query.VacancyReference);
apiClient.Setup(x =>
x.Get<GetVacancyApiResponse>(It.Is<GetVacancyRequest>(c =>
c.GetUrl.Equals(expectedGetRequest.GetUrl)))).ReturnsAsync(vacancyApiResponse);

var actual = await handler.Handle(query, CancellationToken.None);

actual.Vacancy.Should().BeEquivalentTo(vacancyApiResponse);
actual.Vacancy.VacancyUrl.Should()
.Be($"{findAnApprenticeshipBaseUrl}/apprenticeship/reference/{vacancyApiResponse.VacancyReference.Replace("VAC","", StringComparison.CurrentCultureIgnoreCase)}");
actual.Vacancy.CourseLevel.Should().Be(courseResponse.Level);
actual.Vacancy.CourseTitle.Should().Be(courseResponse.Title);
actual.Vacancy.Route.Should().Be(courseResponse.Route);
}

[Test, MoqAutoData]
public async Task Then_The_Api_Is_Called_With_The_Request_And_Vacancy_And_Course_Not_looked_Up_If_Standard_Is_Null(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public async Task<GetVacanciesQueryResult> Handle(GetVacanciesQuery request, Can
vacanciesItem.CourseLevel = standard.Level;
}

vacanciesItem.VacancyUrl = $"{_vacanciesConfiguration.FindAnApprenticeshipBaseUrl}/apprenticeship/reference/{vacanciesItem.VacancyReference}";
vacanciesItem.VacancyUrl = $"{_vacanciesConfiguration.FindAnApprenticeshipBaseUrl}/apprenticeship/reference/{vacanciesItem.VacancyReference.Replace("VAC","")}";

// increase the count of vacancy appearing in search results counter metrics.
_metrics.IncreaseVacancySearchResultViews(vacanciesItem.Id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -43,7 +44,7 @@ public async Task<GetVacancyQueryResult> Handle(GetVacancyQuery request, Cancell
};
}

vacancyResponseTask.Result.VacancyUrl = vacancyResponseTask.Result.VacancyUrl = $"{_vacanciesConfiguration.FindAnApprenticeshipBaseUrl}/apprenticeship/reference/{vacancyResponseTask.Result.VacancyReference}";
vacancyResponseTask.Result.VacancyUrl = $"{_vacanciesConfiguration.FindAnApprenticeshipBaseUrl}/apprenticeship/reference/{vacancyResponseTask.Result.VacancyReference.Replace("VAC","")}";

if (vacancyResponseTask.Result.StandardLarsCode != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public class GetVacanciesListItem
[JsonPropertyName("distance")]
public decimal? Distance { get; set; }

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

[JsonIgnore]
public string CourseTitle { get ; set ; }
[JsonIgnore]
Expand Down