diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeViewModelMapperTests.cs index f827ff459..e7e4323bc 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeViewModelMapperTests.cs @@ -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; @@ -20,6 +21,7 @@ public class ApprenticeViewModelMapperTests private ApprenticeViewModelMapper _mapper; private Mock _commitmentsApiClient; private GetProviderResponse _providerResponse; + private AccountLegalEntityResponse _accountLegalEntityResponse; private ApprenticeRequest _source; private ApprenticeViewModel _result; private TrainingProgrammeApiClientMock _trainingProgrammeApiClient; @@ -30,14 +32,17 @@ public async Task Arrange() var autoFixture = new Fixture(); _providerResponse = autoFixture.Create(); + _accountLegalEntityResponse = autoFixture.Build().With(x=>x.LevyStatus, ApprenticeshipEmployerType.Levy).Create(); _source = autoFixture.Create(); _source.StartMonthYear = "062020"; _source.TransferSenderId = string.Empty; + _source.AccountId = 12345; _commitmentsApiClient = new Mock(); - _commitmentsApiClient.Setup(x => x.GetProvider(It.IsAny(), - It.IsAny())) + _commitmentsApiClient.Setup(x => x.GetProvider(It.IsAny(), It.IsAny())) .ReturnsAsync(_providerResponse); + _commitmentsApiClient.Setup(x => x.GetAccountLegalEntity(_source.AccountLegalEntityId, It.IsAny())) + .ReturnsAsync(_accountLegalEntityResponse); _trainingProgrammeApiClient = new TrainingProgrammeApiClientMock(); @@ -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)); + } } } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/CreateCohortWithDraftApprenticeshipRequestToAddDraftApprenticeshipViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/CreateCohortWithDraftApprenticeshipRequestToAddDraftApprenticeshipViewModelMapperTests.cs index aa8610c82..781f9b2bb 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/CreateCohortWithDraftApprenticeshipRequestToAddDraftApprenticeshipViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/CreateCohortWithDraftApprenticeshipRequestToAddDraftApprenticeshipViewModelMapperTests.cs @@ -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 { @@ -21,10 +22,10 @@ public class CreateCohortWithDraftApprenticeshipRequestToAddDraftApprenticeshipV private AddDraftApprenticeshipViewModelMapper _mapper; private Mock _commitmentsApiClient; private GetProviderResponse _providerResponse; + private AccountLegalEntityResponse _accountLegalEntityResponse; private ApprenticeRequest _source; private AddDraftApprenticeshipViewModel _result; - private IReadOnlyList _courses; - private Mock _trainingProgrammeApiClient; + private TrainingProgrammeApiClientMock _trainingProgrammeApiClient; [SetUp] public async Task Arrange() @@ -32,17 +33,20 @@ public async Task Arrange() var autoFixture = new Fixture(); _providerResponse = autoFixture.Create(); - _source = autoFixture.Create(); - _source.StartMonthYear = "062020"; + _accountLegalEntityResponse = autoFixture.Build().With(x => x.LevyStatus, ApprenticeshipEmployerType.Levy).Create(); + + _source = autoFixture.Build() + .With(x=>x.StartMonthYear, "062020") + .With(x=>x.AccountId, 12345) + .Without(x=>x.TransferSenderId).Create(); _commitmentsApiClient = new Mock(); - _commitmentsApiClient.Setup(x => x.GetProvider(It.IsAny(), - It.IsAny())) + _commitmentsApiClient.Setup(x => x.GetProvider(It.IsAny(), It.IsAny())) .ReturnsAsync(_providerResponse); + _commitmentsApiClient.Setup(x => x.GetAccountLegalEntity(_source.AccountLegalEntityId, It.IsAny())) + .ReturnsAsync(_accountLegalEntityResponse); - _courses = autoFixture.Create>(); - _trainingProgrammeApiClient = new Mock(); - _trainingProgrammeApiClient.Setup(x => x.GetAllTrainingProgrammes()).ReturnsAsync(_courses); + _trainingProgrammeApiClient = new TrainingProgrammeApiClientMock(); ; _mapper = new AddDraftApprenticeshipViewModelMapper( _commitmentsApiClient.Object, @@ -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)); } } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipViewModelMapperTests.cs index 57eee105e..0bd5947a8 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipViewModelMapperTests.cs @@ -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); @@ -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() { diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapperTests.cs index ef2679e41..e1cbff147 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapperTests.cs @@ -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; @@ -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); + } } } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.csproj b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.csproj index 9dc19df03..58c0b259f 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.csproj +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.csproj @@ -17,7 +17,7 @@ - + diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/AddDraftApprenticeshipViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/AddDraftApprenticeshipViewModelMapper.cs index 5f551ffb3..95227c0da 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/AddDraftApprenticeshipViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/AddDraftApprenticeshipViewModelMapper.cs @@ -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; @@ -23,7 +24,12 @@ public AddDraftApprenticeshipViewModelMapper( public async Task 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 diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeViewModelMapper.cs index 80a01ba90..e8ed30e15 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeViewModelMapper.cs @@ -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 @@ -21,7 +22,9 @@ public ApprenticeViewModelMapper(ICommitmentsApiClient commitmentsApiClient, public async Task 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(); diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipViewModelMapper.cs index b685d5876..f01a9eb6b 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipViewModelMapper.cs @@ -43,7 +43,7 @@ public async Task 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, diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapper.cs index fa891909d..58f51cff1 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapper.cs @@ -46,7 +46,7 @@ public async Task 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() }; diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Cohort/ApprenticeRequest.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Cohort/ApprenticeRequest.cs index 535bfd4ae..3f19ddbf4 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Cohort/ApprenticeRequest.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Cohort/ApprenticeRequest.cs @@ -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; } } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/SFA.DAS.EmployerCommitmentsV2.Web.csproj b/src/SFA.DAS.EmployerCommitmentsV2.Web/SFA.DAS.EmployerCommitmentsV2.Web.csproj index 55334ac86..422004cc3 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/SFA.DAS.EmployerCommitmentsV2.Web.csproj +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/SFA.DAS.EmployerCommitmentsV2.Web.csproj @@ -24,8 +24,8 @@ - - + + diff --git a/src/SFA.DAS.EmployerCommitmentsV2/SFA.DAS.EmployerCommitmentsV2.csproj b/src/SFA.DAS.EmployerCommitmentsV2/SFA.DAS.EmployerCommitmentsV2.csproj index 669ed8870..4115e83e1 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2/SFA.DAS.EmployerCommitmentsV2.csproj +++ b/src/SFA.DAS.EmployerCommitmentsV2/SFA.DAS.EmployerCommitmentsV2.csproj @@ -12,9 +12,9 @@ - - - + + +