Skip to content

Commit

Permalink
Merge pull request #114 from SkillsFundingAgency/CV-684-LevyStatus
Browse files Browse the repository at this point in the history
Cv-684 levy status - NoneLevy companies not allowed to select Framework Courses
  • Loading branch information
Najamuddin-Muhammad authored May 1, 2020
2 parents ba716c6 + 30162b3 commit 62ebfb2
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.CommitmentsV2.Shared.Models;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Cohort;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort;
using SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Shared;
Expand All @@ -20,6 +21,7 @@ public class ApprenticeViewModelMapperTests
private ApprenticeViewModelMapper _mapper;
private Mock<ICommitmentsApiClient> _commitmentsApiClient;
private GetProviderResponse _providerResponse;
private AccountLegalEntityResponse _accountLegalEntityResponse;
private ApprenticeRequest _source;
private ApprenticeViewModel _result;
private TrainingProgrammeApiClientMock _trainingProgrammeApiClient;
Expand All @@ -30,14 +32,17 @@ public async Task Arrange()
var autoFixture = new Fixture();

_providerResponse = autoFixture.Create<GetProviderResponse>();
_accountLegalEntityResponse = autoFixture.Build<AccountLegalEntityResponse>().With(x=>x.LevyStatus, ApprenticeshipEmployerType.Levy).Create();
_source = autoFixture.Create<ApprenticeRequest>();
_source.StartMonthYear = "062020";
_source.TransferSenderId = string.Empty;
_source.AccountId = 12345;

_commitmentsApiClient = new Mock<ICommitmentsApiClient>();
_commitmentsApiClient.Setup(x => x.GetProvider(It.IsAny<long>(),
It.IsAny<CancellationToken>()))
_commitmentsApiClient.Setup(x => x.GetProvider(It.IsAny<long>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(_providerResponse);
_commitmentsApiClient.Setup(x => x.GetAccountLegalEntity(_source.AccountLegalEntityId, It.IsAny<CancellationToken>()))
.ReturnsAsync(_accountLegalEntityResponse);

_trainingProgrammeApiClient = new TrainingProgrammeApiClientMock();

Expand Down Expand Up @@ -115,11 +120,21 @@ public void AutoCreatedReservationIsMappedCorrectly()
}

[Test]
public async Task TransferFundedCohortsAllowStandardCoursesOnly()
public async Task TransferFundedCohortsAllowStandardCoursesOnlyWhenEmployerIsLevy()
{
_source.TransferSenderId = "test";
_result = await _mapper.Map(TestHelper.Clone(_source));
Assert.IsFalse(_result.Courses.Any(x => x is Framework));
}

[TestCase("12345")]
[TestCase(null)]
public async Task NonLevyCohortsAllowStandardCoursesOnlyRegardlessOfTransferStatus(string transferSenderId)
{
_source.TransferSenderId = transferSenderId;
_accountLegalEntityResponse.LevyStatus = ApprenticeshipEmployerType.NonLevy;
_result = await _mapper.Map(TestHelper.Clone(_source));
Assert.IsFalse(_result.Courses.Any(x => x is Framework));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AutoFixture;
using Moq;
using NUnit.Framework;
using SFA.DAS.Apprenticeships.Api.Client;
using SFA.DAS.Apprenticeships.Api.Types;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.CommitmentsV2.Shared.Models;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Cohort;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.DraftApprenticeship;
using SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Shared;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Cohort
{
Expand All @@ -21,28 +22,31 @@ public class CreateCohortWithDraftApprenticeshipRequestToAddDraftApprenticeshipV
private AddDraftApprenticeshipViewModelMapper _mapper;
private Mock<ICommitmentsApiClient> _commitmentsApiClient;
private GetProviderResponse _providerResponse;
private AccountLegalEntityResponse _accountLegalEntityResponse;
private ApprenticeRequest _source;
private AddDraftApprenticeshipViewModel _result;
private IReadOnlyList<ITrainingProgramme> _courses;
private Mock<ITrainingProgrammeApiClient> _trainingProgrammeApiClient;
private TrainingProgrammeApiClientMock _trainingProgrammeApiClient;

[SetUp]
public async Task Arrange()
{
var autoFixture = new Fixture();

_providerResponse = autoFixture.Create<GetProviderResponse>();
_source = autoFixture.Create<ApprenticeRequest>();
_source.StartMonthYear = "062020";
_accountLegalEntityResponse = autoFixture.Build<AccountLegalEntityResponse>().With(x => x.LevyStatus, ApprenticeshipEmployerType.Levy).Create();

_source = autoFixture.Build<ApprenticeRequest>()
.With(x=>x.StartMonthYear, "062020")
.With(x=>x.AccountId, 12345)
.Without(x=>x.TransferSenderId).Create();

_commitmentsApiClient = new Mock<ICommitmentsApiClient>();
_commitmentsApiClient.Setup(x => x.GetProvider(It.IsAny<long>(),
It.IsAny<CancellationToken>()))
_commitmentsApiClient.Setup(x => x.GetProvider(It.IsAny<long>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(_providerResponse);
_commitmentsApiClient.Setup(x => x.GetAccountLegalEntity(_source.AccountLegalEntityId, It.IsAny<CancellationToken>()))
.ReturnsAsync(_accountLegalEntityResponse);

_courses = autoFixture.Create<List<Standard>>();
_trainingProgrammeApiClient = new Mock<ITrainingProgrammeApiClient>();
_trainingProgrammeApiClient.Setup(x => x.GetAllTrainingProgrammes()).ReturnsAsync(_courses);
_trainingProgrammeApiClient = new TrainingProgrammeApiClientMock(); ;

_mapper = new AddDraftApprenticeshipViewModelMapper(
_commitmentsApiClient.Object,
Expand Down Expand Up @@ -96,7 +100,25 @@ public void ProviderNameIsMappedCorrectly()
[Test]
public void CoursesAreMappedCorrectly()
{
Assert.AreEqual(_courses, _result.Courses);
Assert.AreEqual(_trainingProgrammeApiClient.All, _result.Courses);
}

[Test]
public async Task TransferFundedCohortsAllowStandardCoursesOnlyWhenEmployerIsLevy()
{
_source.TransferSenderId = "test";
_result = await _mapper.Map(TestHelper.Clone(_source));
Assert.IsFalse(_result.Courses.Any(x => x is Framework));
}

[TestCase("12345")]
[TestCase(null)]
public async Task NonLevyCohortsAllowStandardCoursesOnlyRegardlessOfTransferStatus(string transferSenderId)
{
_source.TransferSenderId = transferSenderId;
_accountLegalEntityResponse.LevyStatus = ApprenticeshipEmployerType.NonLevy;
_result = await _mapper.Map(TestHelper.Clone(_source));
Assert.IsFalse(_result.Courses.Any(x => x is Framework));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ public void ProviderNameIsMappedCorrectly()

[TestCase(123, true)]
[TestCase(null, false)]
public async Task CoursesAreMappedCorrectly(long? transferSenderId, bool fundedByTransfer)
public async Task CoursesAreMappedCorrectlyWithLevy(long? transferSenderId, bool fundedByTransfer)
{
_cohort.LevyStatus = ApprenticeshipEmployerType.Levy;
_cohort.TransferSenderId = transferSenderId;

_result = await _mapper.Map(_source);
Expand All @@ -137,6 +138,18 @@ public async Task CoursesAreMappedCorrectly(long? transferSenderId, bool fundedB
_result.Courses);
}

[TestCase(123)]
[TestCase(null)]
public async Task CoursesAreMappedCorrectlyWithoutLevy(long? transferSenderId)
{
_cohort.LevyStatus = ApprenticeshipEmployerType.NonLevy;
_cohort.TransferSenderId = transferSenderId;

_result = await _mapper.Map(_source);

Assert.AreEqual(_trainingProgrammeApiClient.Standards, _result.Courses);
}

[Test]
public void ThrowsWhenCohortNotWithEditingParty()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ public void ProviderNameIsMappedCorrectly()

[TestCase(123, true)]
[TestCase(null, false)]
public async Task CoursesAreMappedCorrectly(long? transferSenderId, bool fundedByTransfer)
public async Task CoursesAreMappedCorrectlyWhenAccountIsLevy(long? transferSenderId, bool fundedByTransfer)
{
_cohort.LevyStatus = ApprenticeshipEmployerType.Levy;
_cohort.TransferSenderId = transferSenderId;

_result = await _mapper.Map(_source) as EditDraftApprenticeshipViewModel;
Expand All @@ -174,5 +175,17 @@ public async Task CoursesAreMappedCorrectly(long? transferSenderId, bool fundedB
: _trainingProgrammeApiClient.All,
_result.Courses);
}

[TestCase(123)]
[TestCase(null)]
public async Task CoursesAreMappedCorrectlyWhenAccountIsNonLevy(long? transferSenderId)
{
_cohort.LevyStatus = ApprenticeshipEmployerType.NonLevy;
_cohort.TransferSenderId = transferSenderId;

_result = await _mapper.Map(_source) as EditDraftApprenticeshipViewModel;

Assert.AreEqual(_trainingProgrammeApiClient.Standards, _result.Courses);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Types" Version="4.1.1395" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Types" Version="4.1.1432" />
<PackageReference Include="SFA.DAS.Testing" Version="3.0.22" />
<PackageReference Include="SFA.DAS.Testing.AutoFixture" Version="3.0.121" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.CommitmentsV2.Shared.Models;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.DraftApprenticeship;

Expand All @@ -23,7 +24,12 @@ public AddDraftApprenticeshipViewModelMapper(

public async Task<AddDraftApprenticeshipViewModel> Map(ApprenticeRequest source)
{
var courses = await _trainingProgrammeApiClient.GetAllTrainingProgrammes();
var ale = await _commitmentsApiClient.GetAccountLegalEntity(source.AccountLegalEntityId);

var courses = !string.IsNullOrWhiteSpace(source.TransferSenderId) || ale.LevyStatus == ApprenticeshipEmployerType.NonLevy
? await _trainingProgrammeApiClient.GetStandardTrainingProgrammes()
: await _trainingProgrammeApiClient.GetAllTrainingProgrammes();

var provider = await _commitmentsApiClient.GetProvider(source.ProviderId);

var result = new AddDraftApprenticeshipViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.CommitmentsV2.Shared.Models;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort;

namespace SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Cohort
Expand All @@ -21,7 +22,9 @@ public ApprenticeViewModelMapper(ICommitmentsApiClient commitmentsApiClient,

public async Task<ApprenticeViewModel> Map(ApprenticeRequest source)
{
var courses = !string.IsNullOrWhiteSpace(source.TransferSenderId)
var ale = await _commitmentsApiClient.GetAccountLegalEntity(source.AccountLegalEntityId);

var courses = !string.IsNullOrWhiteSpace(source.TransferSenderId) || ale.LevyStatus == ApprenticeshipEmployerType.NonLevy
? await _trainingProgrammeApiClient.GetStandardTrainingProgrammes()
: await _trainingProgrammeApiClient.GetAllTrainingProgrammes();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task<AddDraftApprenticeshipViewModel> Map(AddDraftApprenticeshipReq
StartDate = new MonthYearModel(source.StartMonthYear),
CourseCode = source.CourseCode,
ProviderName = cohort.ProviderName,
Courses = cohort.IsFundedByTransfer
Courses = cohort.IsFundedByTransfer || cohort.LevyStatus == ApprenticeshipEmployerType.NonLevy
? await _trainingProgrammeApiClient.GetStandardTrainingProgrammes()
: await _trainingProgrammeApiClient.GetAllTrainingProgrammes(),
TransferSenderHashedId = cohort.IsFundedByTransfer ? _encodingService.Encode(cohort.TransferSenderId.Value, EncodingType.PublicAccountId) : string.Empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task<IDraftApprenticeshipViewModel> Map(EditDraftApprenticeshipRequ
Reference = draftApprenticeship.Reference,
AccountHashedId = source.Request.AccountHashedId,
ProviderName = cohort.ProviderName,
Courses = cohort.IsFundedByTransfer
Courses = cohort.IsFundedByTransfer || cohort.LevyStatus == ApprenticeshipEmployerType.NonLevy
? await _trainingProgrammeApiClient.GetStandardTrainingProgrammes()
: await _trainingProgrammeApiClient.GetAllTrainingProgrammes()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort
{
public class ApprenticeRequest : AssignRequest, IAuthorizationContextModel
{
public long AccountId { get; set; }
public long AccountLegalEntityId { get; set; }
public bool AutoCreated { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<PackageReference Include="NLog.Schema" Version="4.5.11" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.8.0" />
<PackageReference Include="SFA.DAS.Authorization.Mvc" Version="6.0.59" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Client" Version="4.1.1395" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Shared" Version="4.1.1395" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Client" Version="4.1.1432" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Shared" Version="4.1.1432" />
<PackageReference Include="SFA.DAS.Employer.Shared.UI" Version="2.0.14" />
<PackageReference Include="SFA.DAS.Configuration.AzureTableStorage" Version="3.0.77" />
<PackageReference Include="SFA.DAS.EmployerUrlHelper" Version="3.0.22" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<PackageReference Include="SFA.DAS.Authorization.CommitmentPermissions" Version="6.0.59" />
<PackageReference Include="SFA.DAS.Authorization.EmployerFeatures" Version="6.0.59" />
<PackageReference Include="SFA.DAS.Authorization.EmployerUserRoles" Version="6.0.59" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Client" Version="4.1.1395" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Shared" Version="4.1.1395" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Types" Version="4.1.1395" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Client" Version="4.1.1432" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Shared" Version="4.1.1432" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Types" Version="4.1.1432" />
<PackageReference Include="SFA.DAS.EmployerAccounts.Api.Client" Version="1.6.2086" />
<PackageReference Include="SFA.DAS.EmployerUrlHelper" Version="3.0.22" />
<PackageReference Include="SFA.DAS.Encoding" Version="1.1.61" />
Expand Down

0 comments on commit 62ebfb2

Please sign in to comment.