From 3f8d968421d581061942ab34a532313ad2e69256 Mon Sep 17 00:00:00 2001 From: Paul Graham Date: Wed, 1 Apr 2020 12:21:02 +0100 Subject: [PATCH 1/7] Changed course mapping so NonLevy accounts can only select standard coursea --- .../Cohort/DetailsViewModelMapperTests.cs | 2 +- ...itDraftApprenticeshipViewModelMapperTests.cs | 17 ++++++++++++++++- ...S.EmployerCommitmentsV2.Web.UnitTests.csproj | 2 +- .../EditDraftApprenticeshipViewModelMapper.cs | 2 +- .../SFA.DAS.EmployerCommitmentsV2.Web.csproj | 4 ++-- .../SFA.DAS.EmployerCommitmentsV2.csproj | 6 +++--- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/DetailsViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/DetailsViewModelMapperTests.cs index bdc80e5a5..503bb54ca 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/DetailsViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/DetailsViewModelMapperTests.cs @@ -493,7 +493,7 @@ public DetailsViewModelMapperTestsFixture() .ReturnsAsync(Cohort); CommitmentsApiClient.Setup(x => x.GetDraftApprenticeships(It.IsAny(), It.IsAny())) .ReturnsAsync(DraftApprenticeshipsResponse); - CommitmentsApiClient.Setup(x => x.GetLegalEntity(It.IsAny(), It.IsAny())) + CommitmentsApiClient.Setup(x => x.GetAccountLegalEntity(It.IsAny(), It.IsAny())) .ReturnsAsync(AccountLegalEntityResponse); AccountApiClient = new Mock(); 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..030a443fc 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,19 @@ 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 bce6180f7..64adfd1cd 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/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/SFA.DAS.EmployerCommitmentsV2.Web.csproj b/src/SFA.DAS.EmployerCommitmentsV2.Web/SFA.DAS.EmployerCommitmentsV2.Web.csproj index b252c73f8..55f1818e5 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 492399aa3..1db390bef 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2/SFA.DAS.EmployerCommitmentsV2.csproj +++ b/src/SFA.DAS.EmployerCommitmentsV2/SFA.DAS.EmployerCommitmentsV2.csproj @@ -12,9 +12,9 @@ - - - + + + From f8f14257914616faae0c95b560c711fd7cc670df Mon Sep 17 00:00:00 2001 From: Paul Graham Date: Wed, 1 Apr 2020 13:04:21 +0100 Subject: [PATCH 2/7] mapping for the AddDraftApprenticeshipMapper for NonLevy accounts --- .../AddDraftApprenticeshipViewModelMapperTests.cs | 15 ++++++++++++++- .../AddDraftApprenticeshipViewModelMapper.cs | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) 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/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, From bfa8b6885e995f5b413998fc5c38eb7177d153a7 Mon Sep 17 00:00:00 2001 From: Paul Graham Date: Wed, 1 Apr 2020 15:48:49 +0100 Subject: [PATCH 3/7] added in NonLevy check on standard course when the conhort and apprentriceship is getting created at the same time --- .../Cohort/ApprenticeViewModelMapperTests.cs | 21 ++++++++++++++++--- ...DraftApprenticeshipViewModelMapperTests.cs | 2 -- ...EmployerCommitmentsV2.Web.UnitTests.csproj | 2 +- .../Cohort/ApprenticeViewModelMapper.cs | 5 ++++- .../Models/Cohort/ApprenticeRequest.cs | 1 + .../SFA.DAS.EmployerCommitmentsV2.Web.csproj | 4 ++-- .../SFA.DAS.EmployerCommitmentsV2.csproj | 6 +++--- 7 files changed, 29 insertions(+), 12 deletions(-) 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..1f4e8b18f 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 AccountResponse _accountResponse; private ApprenticeRequest _source; private ApprenticeViewModel _result; private TrainingProgrammeApiClientMock _trainingProgrammeApiClient; @@ -30,14 +32,17 @@ public async Task Arrange() var autoFixture = new Fixture(); _providerResponse = autoFixture.Create(); + _accountResponse = 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.GetAccount(_source.AccountId, It.IsAny())) + .ReturnsAsync(_accountResponse); _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; + _accountResponse.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/EditDraftApprenticeshipViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapperTests.cs index 030a443fc..e1cbff147 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapperTests.cs @@ -187,7 +187,5 @@ public async Task CoursesAreMappedCorrectlyWhenAccountIsNonLevy(long? transferSe 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 64adfd1cd..448cb355e 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/ApprenticeViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeViewModelMapper.cs index 80a01ba90..9a999bd85 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 account = await _commitmentsApiClient.GetAccount(source.AccountId); + + var courses = !string.IsNullOrWhiteSpace(source.TransferSenderId) || account.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 55f1818e5..1bcfdfd14 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 1db390bef..c6146ebb9 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2/SFA.DAS.EmployerCommitmentsV2.csproj +++ b/src/SFA.DAS.EmployerCommitmentsV2/SFA.DAS.EmployerCommitmentsV2.csproj @@ -12,9 +12,9 @@ - - - + + + From c75442d4b497fe82fdbe6437996f2c6ce1590f4d Mon Sep 17 00:00:00 2001 From: Paul Graham Date: Thu, 2 Apr 2020 08:27:35 +0100 Subject: [PATCH 4/7] added NonLevy flag to cohort create apprentice --- ...DraftApprenticeshipViewModelMapperTests.cs | 46 ++++++++++++++----- .../AddDraftApprenticeshipViewModelMapper.cs | 8 +++- 2 files changed, 41 insertions(+), 13 deletions(-) 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..b0e962467 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 AccountResponse _accountResponse; 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"; + _accountResponse = 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.GetAccount(_source.AccountId, It.IsAny())) + .ReturnsAsync(_accountResponse); - _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; + _accountResponse.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/Mappers/Cohort/AddDraftApprenticeshipViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/AddDraftApprenticeshipViewModelMapper.cs index 5f551ffb3..60fe5b677 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 account = await _commitmentsApiClient.GetAccount(source.AccountId); + + var courses = !string.IsNullOrWhiteSpace(source.TransferSenderId) || account.LevyStatus == ApprenticeshipEmployerType.NonLevy + ? await _trainingProgrammeApiClient.GetStandardTrainingProgrammes() + : await _trainingProgrammeApiClient.GetAllTrainingProgrammes(); + var provider = await _commitmentsApiClient.GetProvider(source.ProviderId); var result = new AddDraftApprenticeshipViewModel From 031190ffa970edf115657f675f4dbaa410ecd2b9 Mon Sep 17 00:00:00 2001 From: Paul Graham Date: Tue, 7 Apr 2020 10:45:05 +0100 Subject: [PATCH 5/7] replac e GetAccount with GetAccountLegalEntity --- .../Mappers/Cohort/ApprenticeViewModelMapperTests.cs | 10 +++++----- ...uestToAddDraftApprenticeshipViewModelMapperTests.cs | 10 +++++----- .../SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.csproj | 2 +- .../Cohort/AddDraftApprenticeshipViewModelMapper.cs | 4 ++-- .../Mappers/Cohort/ApprenticeViewModelMapper.cs | 4 ++-- .../SFA.DAS.EmployerCommitmentsV2.Web.csproj | 4 ++-- .../SFA.DAS.EmployerCommitmentsV2.csproj | 6 +++--- 7 files changed, 20 insertions(+), 20 deletions(-) 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 1f4e8b18f..e7e4323bc 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeViewModelMapperTests.cs @@ -21,7 +21,7 @@ public class ApprenticeViewModelMapperTests private ApprenticeViewModelMapper _mapper; private Mock _commitmentsApiClient; private GetProviderResponse _providerResponse; - private AccountResponse _accountResponse; + private AccountLegalEntityResponse _accountLegalEntityResponse; private ApprenticeRequest _source; private ApprenticeViewModel _result; private TrainingProgrammeApiClientMock _trainingProgrammeApiClient; @@ -32,7 +32,7 @@ public async Task Arrange() var autoFixture = new Fixture(); _providerResponse = autoFixture.Create(); - _accountResponse = autoFixture.Build().With(x=>x.LevyStatus, ApprenticeshipEmployerType.Levy).Create(); + _accountLegalEntityResponse = autoFixture.Build().With(x=>x.LevyStatus, ApprenticeshipEmployerType.Levy).Create(); _source = autoFixture.Create(); _source.StartMonthYear = "062020"; _source.TransferSenderId = string.Empty; @@ -41,8 +41,8 @@ public async Task Arrange() _commitmentsApiClient = new Mock(); _commitmentsApiClient.Setup(x => x.GetProvider(It.IsAny(), It.IsAny())) .ReturnsAsync(_providerResponse); - _commitmentsApiClient.Setup(x => x.GetAccount(_source.AccountId, It.IsAny())) - .ReturnsAsync(_accountResponse); + _commitmentsApiClient.Setup(x => x.GetAccountLegalEntity(_source.AccountLegalEntityId, It.IsAny())) + .ReturnsAsync(_accountLegalEntityResponse); _trainingProgrammeApiClient = new TrainingProgrammeApiClientMock(); @@ -132,7 +132,7 @@ public async Task TransferFundedCohortsAllowStandardCoursesOnlyWhenEmployerIsLev public async Task NonLevyCohortsAllowStandardCoursesOnlyRegardlessOfTransferStatus(string transferSenderId) { _source.TransferSenderId = transferSenderId; - _accountResponse.LevyStatus = ApprenticeshipEmployerType.NonLevy; + _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 b0e962467..781f9b2bb 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/CreateCohortWithDraftApprenticeshipRequestToAddDraftApprenticeshipViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/CreateCohortWithDraftApprenticeshipRequestToAddDraftApprenticeshipViewModelMapperTests.cs @@ -22,7 +22,7 @@ public class CreateCohortWithDraftApprenticeshipRequestToAddDraftApprenticeshipV private AddDraftApprenticeshipViewModelMapper _mapper; private Mock _commitmentsApiClient; private GetProviderResponse _providerResponse; - private AccountResponse _accountResponse; + private AccountLegalEntityResponse _accountLegalEntityResponse; private ApprenticeRequest _source; private AddDraftApprenticeshipViewModel _result; private TrainingProgrammeApiClientMock _trainingProgrammeApiClient; @@ -33,7 +33,7 @@ public async Task Arrange() var autoFixture = new Fixture(); _providerResponse = autoFixture.Create(); - _accountResponse = autoFixture.Build().With(x => x.LevyStatus, ApprenticeshipEmployerType.Levy).Create(); + _accountLegalEntityResponse = autoFixture.Build().With(x => x.LevyStatus, ApprenticeshipEmployerType.Levy).Create(); _source = autoFixture.Build() .With(x=>x.StartMonthYear, "062020") @@ -43,8 +43,8 @@ public async Task Arrange() _commitmentsApiClient = new Mock(); _commitmentsApiClient.Setup(x => x.GetProvider(It.IsAny(), It.IsAny())) .ReturnsAsync(_providerResponse); - _commitmentsApiClient.Setup(x => x.GetAccount(_source.AccountId, It.IsAny())) - .ReturnsAsync(_accountResponse); + _commitmentsApiClient.Setup(x => x.GetAccountLegalEntity(_source.AccountLegalEntityId, It.IsAny())) + .ReturnsAsync(_accountLegalEntityResponse); _trainingProgrammeApiClient = new TrainingProgrammeApiClientMock(); ; @@ -116,7 +116,7 @@ public async Task TransferFundedCohortsAllowStandardCoursesOnlyWhenEmployerIsLev public async Task NonLevyCohortsAllowStandardCoursesOnlyRegardlessOfTransferStatus(string transferSenderId) { _source.TransferSenderId = transferSenderId; - _accountResponse.LevyStatus = ApprenticeshipEmployerType.NonLevy; + _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/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.csproj b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.csproj index 448cb355e..d90fc6bcf 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 60fe5b677..95227c0da 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/AddDraftApprenticeshipViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/AddDraftApprenticeshipViewModelMapper.cs @@ -24,9 +24,9 @@ public AddDraftApprenticeshipViewModelMapper( public async Task Map(ApprenticeRequest source) { - var account = await _commitmentsApiClient.GetAccount(source.AccountId); + var ale = await _commitmentsApiClient.GetAccountLegalEntity(source.AccountLegalEntityId); - var courses = !string.IsNullOrWhiteSpace(source.TransferSenderId) || account.LevyStatus == ApprenticeshipEmployerType.NonLevy + 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/Cohort/ApprenticeViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeViewModelMapper.cs index 9a999bd85..e8ed30e15 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeViewModelMapper.cs @@ -22,9 +22,9 @@ public ApprenticeViewModelMapper(ICommitmentsApiClient commitmentsApiClient, public async Task Map(ApprenticeRequest source) { - var account = await _commitmentsApiClient.GetAccount(source.AccountId); + var ale = await _commitmentsApiClient.GetAccountLegalEntity(source.AccountLegalEntityId); - var courses = !string.IsNullOrWhiteSpace(source.TransferSenderId) || account.LevyStatus == ApprenticeshipEmployerType.NonLevy + var courses = !string.IsNullOrWhiteSpace(source.TransferSenderId) || ale.LevyStatus == ApprenticeshipEmployerType.NonLevy ? await _trainingProgrammeApiClient.GetStandardTrainingProgrammes() : await _trainingProgrammeApiClient.GetAllTrainingProgrammes(); 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 1bcfdfd14..7c91ff914 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 c6146ebb9..73943fa86 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2/SFA.DAS.EmployerCommitmentsV2.csproj +++ b/src/SFA.DAS.EmployerCommitmentsV2/SFA.DAS.EmployerCommitmentsV2.csproj @@ -12,9 +12,9 @@ - - - + + + From a4b8fce38b0ee290049be1981ea00570867011d0 Mon Sep 17 00:00:00 2001 From: Shahzad Date: Tue, 14 Apr 2020 09:01:20 +0100 Subject: [PATCH 6/7] CV-684 Package update --- .../SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.csproj | 2 +- .../SFA.DAS.EmployerCommitmentsV2.Web.csproj | 4 ++-- .../SFA.DAS.EmployerCommitmentsV2.csproj | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) 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 d90fc6bcf..131104424 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/SFA.DAS.EmployerCommitmentsV2.Web.csproj b/src/SFA.DAS.EmployerCommitmentsV2.Web/SFA.DAS.EmployerCommitmentsV2.Web.csproj index 7c91ff914..da9f5ccfa 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 73943fa86..43c54eddb 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2/SFA.DAS.EmployerCommitmentsV2.csproj +++ b/src/SFA.DAS.EmployerCommitmentsV2/SFA.DAS.EmployerCommitmentsV2.csproj @@ -12,9 +12,9 @@ - - - + + + From 30162b39eef2e4661057315d44f86d76416d8967 Mon Sep 17 00:00:00 2001 From: Paul Graham Date: Wed, 29 Apr 2020 17:51:56 +0100 Subject: [PATCH 7/7] fixed merge issue --- .../SFA.DAS.EmployerCommitmentsV2.Web.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a7f0d9526..422004cc3 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/SFA.DAS.EmployerCommitmentsV2.Web.csproj +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/SFA.DAS.EmployerCommitmentsV2.Web.csproj @@ -26,7 +26,7 @@ - +