Skip to content

Commit

Permalink
Merge pull request #721 from SkillsFundingAgency/MF-509-Hide_ILR_Mism…
Browse files Browse the repository at this point in the history
…atch_For_Employers

MF-509 hide ilr mismatch for employers
  • Loading branch information
SijiOdun authored Apr 27, 2020
2 parents 3f30e71 + 8ee266a commit 514fb42
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ protected static List<Apprenticeship> GetTestApprenticeshipsWithAlerts(Apprentic
CourseName = "Course",
StartDate = DateTime.UtcNow,
EndDate = DateTime.UtcNow.AddMonths(12),
ProviderRef = searchParameters.ProviderId.ToString(),
EmployerRef = searchParameters.EmployerAccountId.ToString(),
Cohort = new Cohort {AccountLegalEntity = CreateAccountLegalEntity("Employer")},
ApprenticeshipUpdate = new List<ApprenticeshipUpdate>(),
DataLockStatus = new List<DataLockStatus>()
Expand All @@ -76,8 +74,6 @@ protected static List<Apprenticeship> GetTestApprenticeshipsWithAlerts(Apprentic
CourseName = "Course",
StartDate = DateTime.UtcNow,
EndDate = DateTime.UtcNow.AddMonths(12),
ProviderRef = searchParameters.ProviderId.ToString(),
EmployerRef = searchParameters.EmployerAccountId.ToString(),
Cohort = new Cohort {AccountLegalEntity = CreateAccountLegalEntity("Employer")},
ApprenticeshipUpdate = new List<ApprenticeshipUpdate>(),
DataLockStatus = new List<DataLockStatus>()
Expand All @@ -89,8 +85,6 @@ protected static List<Apprenticeship> GetTestApprenticeshipsWithAlerts(Apprentic
Uln = "Uln",
CourseName = "Course",
StartDate = DateTime.UtcNow,
ProviderRef = searchParameters.ProviderId.ToString(),
EmployerRef = searchParameters.EmployerAccountId.ToString(),
Cohort = new Cohort {AccountLegalEntity = CreateAccountLegalEntity("Employer")},
ApprenticeshipUpdate = new List<ApprenticeshipUpdate>(),
DataLockStatus = new List<DataLockStatus>()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeships.Search.Services.Parameters;
using SFA.DAS.CommitmentsV2.Domain.Interfaces;
using SFA.DAS.CommitmentsV2.Extensions;
using SFA.DAS.CommitmentsV2.Models;
using SFA.DAS.CommitmentsV2.Types;

namespace SFA.DAS.CommitmentsV2.UnitTests.Extensions.QueryableApprenticeshipsExtensions
{
public class WhenGettingEmployerApprenticeshipsWithOrWithoutAlerts
{
private IQueryable<Apprenticeship> _apprenticeships;
private readonly ApprenticeshipSearchParameters _parameters = new ApprenticeshipSearchParameters { EmployerAccountId = 1 };

[SetUp]
public void Arrange()
{
_apprenticeships = GetTestData();
}

[Test]
public void ThenWillReturnApprenticeshipsWithAlerts()
{
//Act
var result = _apprenticeships.WithAlerts(true, _parameters).ToList();

//Assert
Assert.AreEqual(2, result.Count);
Assert.AreEqual(1, result[0].Id);
Assert.AreEqual(3, result[1].Id);
}

[Test]
public void ThenWillReturnApprenticeshipsWithoutAlerts()
{
//Act
var result = _apprenticeships.WithAlerts(false, _parameters).ToList();

//Assert
Assert.AreEqual(6, result.Count);

Assert.AreEqual(2, result[0].Id);
Assert.AreEqual(4, result[1].Id);
Assert.AreEqual(5, result[2].Id);
Assert.AreEqual(6, result[3].Id);
Assert.AreEqual(7, result[4].Id);
Assert.AreEqual(9, result[5].Id);
}

private static IQueryable<Apprenticeship> GetTestData()
{
var apprenticeships = new List<Apprenticeship>
{
new Apprenticeship
{
Id = 1,
DataLockStatus = new List<DataLockStatus>
{
new DataLockStatus
{
IsResolved = false,
Status = Status.Fail,
EventStatus = EventStatus.New,
TriageStatus = TriageStatus.Change
}
}
},
new Apprenticeship {Id = 2},
new Apprenticeship
{
Id = 3,
ApprenticeshipUpdate = new List<ApprenticeshipUpdate>
{
new ApprenticeshipUpdate
{
Status = ApprenticeshipUpdateStatus.Pending,
Originator = Originator.Provider
}
}
},
new Apprenticeship
{
Id = 4,
DataLockStatus = new List<DataLockStatus>
{
new DataLockStatus
{
IsResolved = true,
Status = Status.Fail,
EventStatus = EventStatus.New
}
}
},
new Apprenticeship
{
Id = 5,
DataLockStatus = new List<DataLockStatus>
{
new DataLockStatus
{
IsResolved = false,
Status = Status.Pass,
EventStatus = EventStatus.New
}
}
},
new Apprenticeship
{
Id = 6,
DataLockStatus = new List<DataLockStatus>
{
new DataLockStatus
{
IsResolved = false,
Status = Status.Fail,
EventStatus = EventStatus.Removed
}
}
},
new Apprenticeship
{
Id = 7,
ApprenticeshipUpdate = new List<ApprenticeshipUpdate>
{
new ApprenticeshipUpdate
{
Status = ApprenticeshipUpdateStatus.Deleted,
Originator = Originator.Provider
}
}
},
new Apprenticeship
{
Id = 8,
ApprenticeshipUpdate = new List<ApprenticeshipUpdate>
{
new ApprenticeshipUpdate
{
Status = ApprenticeshipUpdateStatus.Pending,
Originator = Originator.Unknown
}
}
},
new Apprenticeship
{
Id = 9,
DataLockStatus = new List<DataLockStatus>
{
new DataLockStatus
{
ErrorCode = DataLockErrorCode.Dlock03,
TriageStatus = TriageStatus.Unknown,
IsResolved = false

}
}
}
}.AsQueryable();
return apprenticeships;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeships.Search.Services.Parameters;
using SFA.DAS.CommitmentsV2.Domain.Interfaces;
using SFA.DAS.CommitmentsV2.Extensions;
using SFA.DAS.CommitmentsV2.Models;
using SFA.DAS.CommitmentsV2.Types;

namespace SFA.DAS.CommitmentsV2.UnitTests.Extensions.QueryableApprenticeshipsExtensions
{
public class WhenGettingApprenticeshipsWithOrWithoutAlerts
public class WhenGettingProviderApprenticeshipsWithOrWithoutAlerts
{
private IQueryable<Apprenticeship> _apprenticeships;
private readonly ApprenticeshipSearchParameters _parameters = new ApprenticeshipSearchParameters { ProviderId = 1 };

[SetUp]
public void Arrange()
Expand All @@ -21,7 +24,7 @@ public void Arrange()
public void ThenWillReturnApprenticeshipsWithAlerts()
{
//Act
var result = _apprenticeships.WithAlerts(true).ToList();
var result = _apprenticeships.WithAlerts(true, _parameters).ToList();

//Assert
Assert.AreEqual(2, result.Count);
Expand All @@ -33,7 +36,7 @@ public void ThenWillReturnApprenticeshipsWithAlerts()
public void ThenWillReturnApprenticeshipsWithoutAlerts()
{
//Act
var result = _apprenticeships.WithAlerts(false).ToList();
var result = _apprenticeships.WithAlerts(false, _parameters).ToList();

//Assert
Assert.AreEqual(5, result.Count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private IQueryable<Apprenticeship> GetApprenticeshipsQuery(ApprenticeshipSearchP
private IQueryable<Apprenticeship> GetApprenticeshipsWithFiltersQuery(ApprenticeshipSearchParameters searchParameters, bool withAlerts)
{
return GetApprenticeshipsQuery(searchParameters)
.WithAlerts(withAlerts)
.WithAlerts(withAlerts, searchParameters)
.Filter(searchParameters.Filters);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task<ApprenticeshipSearchResult> Find(OrderedApprenticeshipSearchPa

apprenticeshipsQuery = apprenticeshipsQuery.Filter(searchParameters.Filters);

var totalApprenticeshipsWithAlertsFound = await apprenticeshipsQuery.WithAlerts(true).CountAsync(searchParameters.CancellationToken);
var totalApprenticeshipsWithAlertsFound = await apprenticeshipsQuery.WithAlerts(true, searchParameters).CountAsync(searchParameters.CancellationToken);

apprenticeshipsQuery = apprenticeshipsQuery
.OrderBy(GetOrderByField(searchParameters.FieldName))
Expand All @@ -36,7 +36,9 @@ public async Task<ApprenticeshipSearchResult> Find(OrderedApprenticeshipSearchPa
.Include(apprenticeship => apprenticeship.DataLockStatus)
.Include(apprenticeship => apprenticeship.PriceHistory)
.Include(apprenticeship => apprenticeship.Cohort)
.ThenInclude(cohort => cohort.AccountLegalEntity);
.ThenInclude(cohort => cohort.AccountLegalEntity)
.Include(apprenticeship => apprenticeship.Cohort)
.ThenInclude(cohort => cohort.Provider);

var totalApprenticeshipsFound = await apprenticeshipsQuery.CountAsync(searchParameters.CancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task<ApprenticeshipSearchResult> Find(ReverseOrderedApprenticeshipS

apprenticeshipsQuery = apprenticeshipsQuery.Filter(searchParameters.Filters);

var totalApprenticeshipsWithAlertsFound = await apprenticeshipsQuery.WithAlerts(true).CountAsync(searchParameters.CancellationToken);
var totalApprenticeshipsWithAlertsFound = await apprenticeshipsQuery.WithAlerts(true, searchParameters).CountAsync(searchParameters.CancellationToken);

apprenticeshipsQuery = apprenticeshipsQuery
.OrderByDescending(GetOrderByField(searchParameters.FieldName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static bool HasCourseDataLock(Apprenticeship source)

private static bool HasPriceDataLock(Apprenticeship source)
{
return source.DataLockStatus.Any(x =>
return source.IsProviderSearch && source.DataLockStatus.Any(x =>
x.IsPriceOnly() &&
x.TriageStatus == TriageStatus.Unknown &&
!x.IsResolved);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SFA.DAS.CommitmentsV2.Domain.Extensions;
using SFA.DAS.CommitmentsV2.Domain.Interfaces;
using SFA.DAS.CommitmentsV2.Models;
using SFA.DAS.CommitmentsV2.Types;
Expand Down Expand Up @@ -105,7 +106,14 @@ public static IQueryable<Apprenticeship> Filter(this IQueryable<Apprenticeship>
return apprenticeships;
}

public static IQueryable<Apprenticeship> WithAlerts(this IQueryable<Apprenticeship> apprenticeships, bool hasAlerts)
public static IQueryable<Apprenticeship> WithAlerts(
this IQueryable<Apprenticeship> apprenticeships, bool hasAlerts,
IEmployerProviderIdentifier identifier)
{
return identifier.ProviderId.HasValue ? WithAlertsProvider(apprenticeships, hasAlerts) : WithAlertsEmployer(apprenticeships, hasAlerts);
}

private static IQueryable<Apprenticeship> WithAlertsProvider(this IQueryable<Apprenticeship> apprenticeships, bool hasAlerts)
{
if (hasAlerts)
{
Expand All @@ -122,6 +130,27 @@ public static IQueryable<Apprenticeship> WithAlerts(this IQueryable<Apprenticesh
(apprenticeship.ApprenticeshipUpdate == null ||
apprenticeship.ApprenticeshipUpdate.All(c => c.Status != ApprenticeshipUpdateStatus.Pending)));
}
private static IQueryable<Apprenticeship> WithAlertsEmployer(this IQueryable<Apprenticeship> apprenticeships, bool hasAlerts)
{
if (hasAlerts)
{
return apprenticeships.Where(apprenticeship => apprenticeship.DataLockStatus.Any(c => !c.IsResolved
&& c.Status == Status.Fail
&& c.EventStatus != EventStatus.Removed
&& c.TriageStatus != TriageStatus.Unknown) ||
apprenticeship.ApprenticeshipUpdate != null &&
apprenticeship.ApprenticeshipUpdate.Any(
c => c.Status == ApprenticeshipUpdateStatus.Pending
&& (c.Originator == Originator.Employer
|| c.Originator == Originator.Provider)));
}
return apprenticeships.Where(apprenticeship =>
!apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail && c.EventStatus != EventStatus.Removed
&& c.TriageStatus != TriageStatus.Unknown) &&

(apprenticeship.ApprenticeshipUpdate == null ||
apprenticeship.ApprenticeshipUpdate.All(c => c.Status != ApprenticeshipUpdateStatus.Pending)));
}

public static IQueryable<Apprenticeship> WithProviderOrEmployerId(
this IQueryable<Apprenticeship> apprenticeships, IEmployerProviderIdentifier identifier)
Expand Down

0 comments on commit 514fb42

Please sign in to comment.