From 62fadf54d09ba8cf0c39175dacbedb25671874c8 Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Tue, 14 Jun 2022 08:50:24 +0100 Subject: [PATCH 01/24] RoFJAA api implementation --- .../Models/Agency/Agency.cs | 7 ++++ .../SFA.DAS.EmployerCommitmentsV2.Web.csproj | 4 +++ .../Services/FjaaAgencyService.cs | 33 +++++++++++++++++++ .../Services/IFjaaAgencyService.cs | 11 +++++++ .../Services/Approvals/ApprovalsApiClient.cs | 6 ++++ .../Services/Approvals/IApprovalsApiClient.cs | 3 +- .../Approvals/Responses/GetAgencyResponse.cs | 7 ++++ 7 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Agency/Agency.cs create mode 100644 src/SFA.DAS.EmployerCommitmentsV2.Web/Services/FjaaAgencyService.cs create mode 100644 src/SFA.DAS.EmployerCommitmentsV2.Web/Services/IFjaaAgencyService.cs create mode 100644 src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/Responses/GetAgencyResponse.cs diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Agency/Agency.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Agency/Agency.cs new file mode 100644 index 000000000..75f9dcac5 --- /dev/null +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Agency/Agency.cs @@ -0,0 +1,7 @@ +namespace SFA.DAS.EmployerCommitmentsV2.Web.Models.Agency +{ + public class Agency + { + public int LegalEntityId { get; set; } + } +} \ No newline at end of file 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 898d848f0..56e4ce688 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/SFA.DAS.EmployerCommitmentsV2.Web.csproj +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/SFA.DAS.EmployerCommitmentsV2.Web.csproj @@ -40,8 +40,12 @@ + + + + diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/FjaaAgencyService.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/FjaaAgencyService.cs new file mode 100644 index 000000000..44744ea10 --- /dev/null +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/FjaaAgencyService.cs @@ -0,0 +1,33 @@ +using System.Threading.Tasks; +using SFA.DAS.EmployerCommitmentsV2.Services.Approvals; +using SFA.DAS.EmployerCommitmentsV2.Services.Approvals.Responses; + +namespace SFA.DAS.EmployerCommitmentsV2.Web.Services +{ + public class FjaaAgencyService : IFjaaAgencyService + { + private readonly IApprovalsApiClient _approvalsApiClient; + + public FjaaAgencyService(IApprovalsApiClient approvalsApiClient) + { + _approvalsApiClient = approvalsApiClient; + } + + public async Task AgencyExists(int legalEntityId) + { + GetAgencyResponse agency = null; + + if (legalEntityId > 0) + { + agency = await _approvalsApiClient.GetAgency(legalEntityId); + + if (agency != null) + { + return true; + } + } + + return false; + } + } +} \ No newline at end of file diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/IFjaaAgencyService.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/IFjaaAgencyService.cs new file mode 100644 index 000000000..30b8570ec --- /dev/null +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/IFjaaAgencyService.cs @@ -0,0 +1,11 @@ +using SFA.DAS.EmployerCommitmentsV2.Web.Models.Agency; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace SFA.DAS.EmployerCommitmentsV2.Web.Services +{ + public interface IFjaaAgencyService + { + Task AgencyExists(int legalEntityId); + } +} diff --git a/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/ApprovalsApiClient.cs b/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/ApprovalsApiClient.cs index a5b346bd3..f39421538 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/ApprovalsApiClient.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/ApprovalsApiClient.cs @@ -23,5 +23,11 @@ public async Task GetProviderCourseDeliveryModels( { return await _client.Get($"Providers/{providerId}/courses/{courseCode}", null, cancellationToken); } + + public async Task GetAgency(int legalEntityId, CancellationToken cancellationToken = default) + { + return await _client.Get($"rofjaa/agency/{legalEntityId}", null, cancellationToken); + } + } } diff --git a/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/IApprovalsApiClient.cs b/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/IApprovalsApiClient.cs index fc5ccd9b1..482fe76bc 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/IApprovalsApiClient.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/IApprovalsApiClient.cs @@ -7,7 +7,8 @@ namespace SFA.DAS.EmployerCommitmentsV2.Services.Approvals public interface IApprovalsApiClient { Task GetPledgeApplication(int pledgeApplicationId, CancellationToken cancellationToken = default); - Task GetProviderCourseDeliveryModels(long providerId, string courseCode, CancellationToken cancellationToken = default); + Task GetAgency(int legalEntityId, CancellationToken cancellationToken = default); + } } diff --git a/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/Responses/GetAgencyResponse.cs b/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/Responses/GetAgencyResponse.cs new file mode 100644 index 000000000..a2c43eb9b --- /dev/null +++ b/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/Responses/GetAgencyResponse.cs @@ -0,0 +1,7 @@ +namespace SFA.DAS.EmployerCommitmentsV2.Services.Approvals.Responses +{ + public class GetAgencyResponse + { + public int LegalEntityId { get; set; } + } +} \ No newline at end of file From d8c3b3af5527fbe8c3201f20f170dfff7297c265 Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Tue, 14 Jun 2022 09:59:37 +0100 Subject: [PATCH 02/24] Query API for FJAA agency --- ...estToSelectDeliveryModelViewModelMapper.cs | 13 +++++- .../Shared/SelectDeliveryModelViewModel.cs | 1 + .../Views/Shared/SelectDeliveryModel.cshtml | 44 ++++++++++++------- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs index 0588fd68b..27a6225d1 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs @@ -4,20 +4,28 @@ using SFA.DAS.EmployerCommitmentsV2.Web.Models.Shared; using System.Linq; using System.Threading.Tasks; +using SFA.DAS.EmployerCommitmentsV2.Web.Services; + namespace SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Cohort { public class ApprenticeRequestToSelectDeliveryModelViewModelMapper : IMapper { private readonly IApprovalsApiClient _approvalsApiClient; + private readonly IFjaaAgencyService _fjaaAgencyService; - public ApprenticeRequestToSelectDeliveryModelViewModelMapper(IApprovalsApiClient approvalsApiClient) - => _approvalsApiClient = approvalsApiClient; + public ApprenticeRequestToSelectDeliveryModelViewModelMapper(IApprovalsApiClient approvalsApiClient, IFjaaAgencyService fjaaAgencyService) + { + _approvalsApiClient = approvalsApiClient; + _fjaaAgencyService = fjaaAgencyService; + } public async Task Map(ApprenticeRequest source) { var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(source.ProviderId, source.CourseCode); + bool agencyExists = await _fjaaAgencyService.AgencyExists((int)source.AccountLegalEntityId); + return new SelectDeliveryModelViewModel { AccountHashedId = source.AccountHashedId, @@ -30,6 +38,7 @@ public async Task Map(ApprenticeRequest source) ReservationId = source.ReservationId, StartMonthYear = source.StartMonthYear, TransferSenderId = source.TransferSenderId, + FjaaAgencyExists = agencyExists }; } } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Shared/SelectDeliveryModelViewModel.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Shared/SelectDeliveryModelViewModel.cs index 99cda29a7..2f69d1335 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Shared/SelectDeliveryModelViewModel.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Shared/SelectDeliveryModelViewModel.cs @@ -20,5 +20,6 @@ public class SelectDeliveryModelViewModel public DeliveryModel? DeliveryModel { get; set; } public DeliveryModel[] DeliveryModels { get; set; } public string TransferSenderId { get; set; } + public bool FjaaAgencyExists { get; set; } } } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Shared/SelectDeliveryModel.cshtml b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Shared/SelectDeliveryModel.cshtml index d72e3c700..365815a1d 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Shared/SelectDeliveryModel.cshtml +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Shared/SelectDeliveryModel.cshtml @@ -18,26 +18,40 @@ Select delivery model @Html.ValidationMessageFor(m => m.DeliveryModel, null, new {@class = "govuk-error-message", id = "error-message-" + Html.IdFor(m => m.DeliveryModel)}) -
-
- - -
- The apprentice will have a single employment contract -
+
+
+ + +
+ The apprentice will have a single employment contract +
+
+
+ + +
+ The apprentice will move between multiple employment contracts
+
+ + @if (Model.FjaaAgencyExists) + {
- -
+ } + +
From f3aed41bf3da5aecf2a5c0fb5ed2091ef5369f8f Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Tue, 14 Jun 2022 10:54:07 +0100 Subject: [PATCH 03/24] Switches for new type + tag on draft page --- .../Extensions/DeliveryModelExtension.cs | 8 ++++++-- .../Models/Cohort/DetailsViewCourseGroupingModel.cs | 1 + .../Views/Cohort/Details.cshtml | 7 ++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Extensions/DeliveryModelExtension.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Extensions/DeliveryModelExtension.cs index e1ba6b14d..06e240f38 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Extensions/DeliveryModelExtension.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Extensions/DeliveryModelExtension.cs @@ -11,14 +11,18 @@ public static string ToDescription(this DeliveryModel deliveryModel) => deliveryModel switch { DeliveryModel.PortableFlexiJob => "Portable flexi-job", + DeliveryModel.FlexiJobAgency => "Flexi-job agency", _ => "Regular" }; - public static string ToIrregularDescription(this DeliveryModel deliveryModel) => - deliveryModel switch + public static string ToIrregularDescription(this DeliveryModel deliveryModel) + { + return deliveryModel switch { DeliveryModel.PortableFlexiJob => "Portable flexi-job", + DeliveryModel.FlexiJobAgency => "Flexi-job agency", _ => null, }; + } } } \ No newline at end of file diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Cohort/DetailsViewCourseGroupingModel.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Cohort/DetailsViewCourseGroupingModel.cs index 5df1dcb7e..505f9bbb5 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Cohort/DetailsViewCourseGroupingModel.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Cohort/DetailsViewCourseGroupingModel.cs @@ -9,6 +9,7 @@ public class DetailsViewCourseGroupingModel public string CourseName { get; set; } public DeliveryModel DeliveryModel { get; set; } public bool IsPortableFlexiJob => DeliveryModel == DeliveryModel.PortableFlexiJob; + public bool IsFlexiJobAgency => DeliveryModel == DeliveryModel.FlexiJobAgency; public string DisplayCourseName => string.IsNullOrWhiteSpace(CourseName) ? "No training course" : CourseName; public int Count => DraftApprenticeships?.Count ?? 0; public FundingBandExcessModel FundingBandExcess { get; set; } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Cohort/Details.cshtml b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Cohort/Details.cshtml index 884312925..211480b99 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Cohort/Details.cshtml +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Cohort/Details.cshtml @@ -73,11 +73,16 @@ @foreach (var course in Model.Courses) { -

@course.Count x @course.DisplayCourseName +

+ @course.Count x @course.DisplayCourseName @if (@course.DeliveryModel == DeliveryModel.PortableFlexiJob) { Portable flexi job } + @if (@course.DeliveryModel == DeliveryModel.FlexiJobAgency) + { + Flexi Job Agency + }

@foreach (var draftApprenticeship in course.DraftApprenticeships) { From 9c1965c61c015ac212d654f30b69a844fbeb5ba5 Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Tue, 14 Jun 2022 14:01:17 +0100 Subject: [PATCH 04/24] Dont display portable option if FJAA exists --- .../Views/Shared/SelectDeliveryModel.cshtml | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Shared/SelectDeliveryModel.cshtml b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Shared/SelectDeliveryModel.cshtml index 365815a1d..e6f36fba3 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Shared/SelectDeliveryModel.cshtml +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Shared/SelectDeliveryModel.cshtml @@ -28,15 +28,19 @@ The apprentice will have a single employment contract
-
- - -
- The apprentice will move between multiple employment contracts + + @if (!Model.FjaaAgencyExists) + { +
+ + +
+ The apprentice will move between multiple employment contracts +
-
+ } @if (Model.FjaaAgencyExists) { @@ -51,7 +55,7 @@
} - + From 869e6dc2f8b6d980125baed52cac115f191ae328 Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Tue, 14 Jun 2022 14:25:16 +0100 Subject: [PATCH 05/24] Surface FJAA Api call on Edit Draft --- .../EditDraftApprenticeshipViewModelMapper.cs | 10 +++++++++- .../Models/Shared/DraftApprenticeshipViewModel.cs | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapper.cs index b8c351576..3d2d14214 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapper.cs @@ -6,6 +6,7 @@ using SFA.DAS.CommitmentsV2.Types; using SFA.DAS.EmployerCommitmentsV2.Web.Models.DraftApprenticeship; using SFA.DAS.Encoding; +using SFA.DAS.EmployerCommitmentsV2.Web.Services; namespace SFA.DAS.EmployerCommitmentsV2.Web.Mappers.DraftApprenticeship { @@ -14,12 +15,16 @@ public class EditDraftApprenticeshipViewModelMapper : IMapper Map(EditDraftApprenticeshipRequest source) @@ -28,6 +33,8 @@ public async Task Map(EditDraftApprenticeshipRequ var draftApprenticeship = await _commitmentsApiClient.GetDraftApprenticeship(source.Request.CohortId, source.Request.DraftApprenticeshipId); + bool agencyExists = await _fjaaAgencyService.AgencyExists((int)source.Cohort.AccountLegalEntityId); + return new EditDraftApprenticeshipViewModel(draftApprenticeship.DateOfBirth, draftApprenticeship.StartDate, draftApprenticeship.EndDate) { DraftApprenticeshipId = draftApprenticeship.Id, @@ -51,6 +58,7 @@ public async Task Map(EditDraftApprenticeshipRequ ProviderName = cohort.ProviderName, LegalEntityName = source.Cohort.LegalEntityName, IsContinuation = draftApprenticeship.IsContinuation, + FjaaAgencyExists = agencyExists, Courses = (cohort.IsFundedByTransfer || cohort.LevyStatus == ApprenticeshipEmployerType.NonLevy) && !draftApprenticeship.IsContinuation ? (await _commitmentsApiClient.GetAllTrainingProgrammeStandards()).TrainingProgrammes : (await _commitmentsApiClient.GetAllTrainingProgrammes()).TrainingProgrammes diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Shared/DraftApprenticeshipViewModel.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Shared/DraftApprenticeshipViewModel.cs index 9ba7ff2b1..09fa14cd0 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Shared/DraftApprenticeshipViewModel.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Shared/DraftApprenticeshipViewModel.cs @@ -114,5 +114,7 @@ public DraftApprenticeshipViewModel() public IEnumerable Courses { get; set; } public bool IsContinuation { get; set; } + + public bool FjaaAgencyExists { get; set; } } } From a05ab6a4e818c32729bcc5f7abfaf2e4a54d31be Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Wed, 15 Jun 2022 13:27:31 +0100 Subject: [PATCH 06/24] Various changes to query API return and display correct options Includes nuget updates necessary for CommitmentsAPI updates --- .../CommitmentsOuterApiBuilder.cs | 2 +- ...SelectDeliveryModelViewModelMapperTests.cs | 9 ++++++- ...SelectDeliveryModelViewModelMapperTests.cs | 9 ++++++- ...DraftApprenticeshipViewModelMapperTests.cs | 10 ++++++- ...estToSelectDeliveryModelViewModelMapper.cs | 27 +++++++++++++------ ...estToSelectDeliveryModelViewModelMapper.cs | 25 ++++++++++++++--- .../EditDraftApprenticeshipViewModelMapper.cs | 3 --- .../Shared/DraftApprenticeshipViewModel.cs | 2 -- .../Shared/SelectDeliveryModelViewModel.cs | 1 - .../SFA.DAS.EmployerCommitmentsV2.Web.csproj | 2 ++ .../ConfirmEditApprenticeship.cshtml | 2 +- .../Views/Shared/SelectDeliveryModel.cshtml | 6 ++--- .../SFA.DAS.EmployerCommitmentsV2.csproj | 16 +++++------ 13 files changed, 81 insertions(+), 33 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Api.FakeServers/CommitmentsOuterApiBuilder.cs b/src/SFA.DAS.EmployerCommitmentsV2.Api.FakeServers/CommitmentsOuterApiBuilder.cs index 85b4cb6cd..f7ce88ef3 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Api.FakeServers/CommitmentsOuterApiBuilder.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Api.FakeServers/CommitmentsOuterApiBuilder.cs @@ -35,7 +35,7 @@ internal CommitmentsOuterApiBuilder WithCourseDeliveryModels() .WithHeader("Content-Type", "application/json") .WithBodyAsJson(new { - DeliveryModels = new[] { "Regular", "PortableFlexiJob" }, + DeliveryModels = new[] { "Regular", "PortableFlexiJob", "FlexiJobAgency" }, })); _server diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs index 7f2267ab0..dfc80a3ed 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs @@ -7,6 +7,7 @@ using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Cohort; using SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort; using SFA.DAS.EmployerCommitmentsV2.Web.Models.Shared; +using SFA.DAS.EmployerCommitmentsV2.Web.Services; using System.Threading; using System.Threading.Tasks; @@ -18,8 +19,10 @@ public class ApprenticeRequestToSelectDeliveryModelViewModelMapperTests private ApprenticeRequestToSelectDeliveryModelViewModelMapper _mapper; private ApprenticeRequest _source; private Mock _approvalsApiClient; + private Mock _fjaaAgencyService; private ProviderCourseDeliveryModels _providerCourseDeliveryModels; private long _providerId; + private int _agencyId; private string _courseCode; private SelectDeliveryModelViewModel _result; @@ -30,6 +33,7 @@ public async Task Arrange() _providerId = autoFixture.Create(); _courseCode = autoFixture.Create(); + _agencyId = autoFixture.Create(); _source = autoFixture.Build() .With(x => x.StartMonthYear, "062020") @@ -45,7 +49,10 @@ public async Task Arrange() _approvalsApiClient = new Mock(); _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); - _mapper = new ApprenticeRequestToSelectDeliveryModelViewModelMapper(_approvalsApiClient.Object); + _fjaaAgencyService = new Mock(); + _fjaaAgencyService.Setup(x => x.AgencyExists(_agencyId)).ReturnsAsync(false); + + _mapper = new ApprenticeRequestToSelectDeliveryModelViewModelMapper(_approvalsApiClient.Object, _fjaaAgencyService.Object); _result = await _mapper.Map(TestHelper.Clone(_source)); } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs index 27a0234a2..47f1953cb 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs @@ -11,6 +11,7 @@ using SFA.DAS.EmployerCommitmentsV2.Services.Approvals.Responses; using System.Threading; using System.Threading.Tasks; +using SFA.DAS.EmployerCommitmentsV2.Web.Services; namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.DraftApprenticeship { @@ -22,10 +23,12 @@ public class AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTe private Mock _commitmentsApiClient; private GetCohortResponse _getCohortResponse; private Mock _approvalsApiClient; + private Mock _fjaaAgencyService; private ProviderCourseDeliveryModels _providerCourseDeliveryModels; private long _providerId; private string _courseCode; private long _cohortId; + private int _agencyId; private SelectDeliveryModelViewModel _result; [SetUp] @@ -36,6 +39,7 @@ public async Task Arrange() _providerId = autoFixture.Create(); _courseCode = autoFixture.Create(); _cohortId = autoFixture.Create(); + _agencyId = autoFixture.Create(); _source = autoFixture.Build() .With(x => x.StartMonthYear, "062020") @@ -62,7 +66,10 @@ public async Task Arrange() _approvalsApiClient = new Mock(); _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); - _mapper = new AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(_commitmentsApiClient.Object, _approvalsApiClient.Object); + _fjaaAgencyService = new Mock(); + _fjaaAgencyService.Setup(x => x.AgencyExists(_agencyId)).ReturnsAsync(false); + + _mapper = new AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(_commitmentsApiClient.Object, _approvalsApiClient.Object, _fjaaAgencyService.Object); _result = await _mapper.Map(TestHelper.Clone(_source)); } 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 02b69b223..ebf418008 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapperTests.cs @@ -10,6 +10,7 @@ using SFA.DAS.CommitmentsV2.Types; using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.DraftApprenticeship; using SFA.DAS.EmployerCommitmentsV2.Web.Models.DraftApprenticeship; +using SFA.DAS.EmployerCommitmentsV2.Web.Services; using SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Extensions; using SFA.DAS.Encoding; @@ -25,8 +26,10 @@ public class EditDraftApprenticeshipViewModelMapperTests private Mock _commitmentsApiClient; private GetDraftApprenticeshipResponse _draftApprenticeshipResponse; private Mock _encodingService; + private Mock _fjaaAgencyService; private string _encodedApprenticeshipId; private string _cohortReference; + private int _agencyId; private GetCohortResponse _cohort; private List _allTrainingProgrammes; private List _standardTrainingProgrammes; @@ -40,6 +43,7 @@ public async Task Arrange() _standardTrainingProgrammes = autoFixture.CreateMany().ToList(); _encodedApprenticeshipId = autoFixture.Create(); _cohortReference = autoFixture.Create(); + _agencyId = autoFixture.Create(); _encodingService = new Mock(); _encodingService @@ -75,9 +79,13 @@ public async Task Arrange() _commitmentsApiClient.Setup(x => x.GetCohort(It.IsAny(), It.IsAny())) .ReturnsAsync(_cohort); + _fjaaAgencyService = new Mock(); + _fjaaAgencyService.Setup(x => x.AgencyExists(_agencyId)).ReturnsAsync(false); + + _source = autoFixture.Create(); _source.Cohort = _cohort; - _mapper = new EditDraftApprenticeshipViewModelMapper(_commitmentsApiClient.Object, _encodingService.Object); + _mapper = new EditDraftApprenticeshipViewModelMapper(_commitmentsApiClient.Object, _encodingService.Object, _fjaaAgencyService.Object); _result = await _mapper.Map(TestHelper.Clone(_source)) as EditDraftApprenticeshipViewModel; } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs index 27a6225d1..6b62721d6 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs @@ -5,7 +5,8 @@ using System.Linq; using System.Threading.Tasks; using SFA.DAS.EmployerCommitmentsV2.Web.Services; - +using SFA.DAS.CommitmentsV2.Types; +using System.Collections.Generic; namespace SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Cohort { @@ -13,19 +14,24 @@ public class ApprenticeRequestToSelectDeliveryModelViewModelMapper : IMapper _deliveryModels; public ApprenticeRequestToSelectDeliveryModelViewModelMapper(IApprovalsApiClient approvalsApiClient, IFjaaAgencyService fjaaAgencyService) - { - _approvalsApiClient = approvalsApiClient; - _fjaaAgencyService = fjaaAgencyService; - } + => (_approvalsApiClient, _fjaaAgencyService) = (approvalsApiClient, fjaaAgencyService); public async Task Map(ApprenticeRequest source) { var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(source.ProviderId, source.CourseCode); + _deliveryModels = response.DeliveryModels.ToList(); + bool agencyExists = await _fjaaAgencyService.AgencyExists((int)source.AccountLegalEntityId); + bool portableAllowed = _deliveryModels.Contains(DeliveryModel.PortableFlexiJob) ? true : false; + + if (agencyExists && portableAllowed == false) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } + if (!agencyExists && portableAllowed == true) { this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + return new SelectDeliveryModelViewModel { AccountHashedId = source.AccountHashedId, @@ -33,13 +39,18 @@ public async Task Map(ApprenticeRequest source) AccountLegalEntityHashedId = source.AccountLegalEntityHashedId, CourseCode = source.CourseCode, DeliveryModel = source.DeliveryModel, - DeliveryModels = response.DeliveryModels.ToArray(), + DeliveryModels = _deliveryModels.ToArray(), ProviderId = source.ProviderId, ReservationId = source.ReservationId, StartMonthYear = source.StartMonthYear, - TransferSenderId = source.TransferSenderId, - FjaaAgencyExists = agencyExists + TransferSenderId = source.TransferSenderId }; } + + protected void RemoveDeliveryModel(int deliveryModelId) + { + _deliveryModels.Remove((DeliveryModel)deliveryModelId); + } + } } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs index a807b2298..988f50d65 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs @@ -1,8 +1,11 @@ using SFA.DAS.CommitmentsV2.Api.Client; using SFA.DAS.CommitmentsV2.Shared.Interfaces; +using SFA.DAS.CommitmentsV2.Types; using SFA.DAS.EmployerCommitmentsV2.Services.Approvals; using SFA.DAS.EmployerCommitmentsV2.Web.Models.DraftApprenticeship; using SFA.DAS.EmployerCommitmentsV2.Web.Models.Shared; +using SFA.DAS.EmployerCommitmentsV2.Web.Services; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -12,9 +15,11 @@ public class AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper : { private readonly ICommitmentsApiClient _commitmentsApiClient; private readonly IApprovalsApiClient _approvalsApiClient; + private readonly IFjaaAgencyService _fjaaAgencyService; + protected List _deliveryModels; - public AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(ICommitmentsApiClient commitmentsApiClient, IApprovalsApiClient approvalsApiClient) - => (_commitmentsApiClient, _approvalsApiClient) = (commitmentsApiClient, approvalsApiClient); + public AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(ICommitmentsApiClient commitmentsApiClient, IApprovalsApiClient approvalsApiClient, IFjaaAgencyService fjaaAgencyService) + => (_commitmentsApiClient, _approvalsApiClient, _fjaaAgencyService) = (commitmentsApiClient, approvalsApiClient, fjaaAgencyService); public async Task Map(AddDraftApprenticeshipRequest source) { @@ -22,6 +27,15 @@ public async Task Map(AddDraftApprenticeshipReques var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode); + _deliveryModels = response.DeliveryModels.ToList(); + + bool agencyExists = await _fjaaAgencyService.AgencyExists((int)source.AccountLegalEntityId); + + bool portableAllowed = _deliveryModels.Contains(DeliveryModel.PortableFlexiJob) ? true : false; + + if (agencyExists && portableAllowed == false) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } + if (!agencyExists && portableAllowed == true) { this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + return new SelectDeliveryModelViewModel { AccountHashedId = source.AccountHashedId, @@ -31,11 +45,16 @@ public async Task Map(AddDraftApprenticeshipReques CohortReference = source.CohortReference, CourseCode = source.CourseCode, DeliveryModel = source.DeliveryModel, - DeliveryModels = response.DeliveryModels.ToArray(), + DeliveryModels = _deliveryModels.ToArray(), ProviderId = source.ProviderId, ReservationId = source.ReservationId, StartMonthYear = source.StartMonthYear, }; } + + protected void RemoveDeliveryModel(int deliveryModelId) + { + _deliveryModels.Remove((DeliveryModel)deliveryModelId); + } } } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapper.cs index 3d2d14214..b5bc6f39a 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapper.cs @@ -33,8 +33,6 @@ public async Task Map(EditDraftApprenticeshipRequ var draftApprenticeship = await _commitmentsApiClient.GetDraftApprenticeship(source.Request.CohortId, source.Request.DraftApprenticeshipId); - bool agencyExists = await _fjaaAgencyService.AgencyExists((int)source.Cohort.AccountLegalEntityId); - return new EditDraftApprenticeshipViewModel(draftApprenticeship.DateOfBirth, draftApprenticeship.StartDate, draftApprenticeship.EndDate) { DraftApprenticeshipId = draftApprenticeship.Id, @@ -58,7 +56,6 @@ public async Task Map(EditDraftApprenticeshipRequ ProviderName = cohort.ProviderName, LegalEntityName = source.Cohort.LegalEntityName, IsContinuation = draftApprenticeship.IsContinuation, - FjaaAgencyExists = agencyExists, Courses = (cohort.IsFundedByTransfer || cohort.LevyStatus == ApprenticeshipEmployerType.NonLevy) && !draftApprenticeship.IsContinuation ? (await _commitmentsApiClient.GetAllTrainingProgrammeStandards()).TrainingProgrammes : (await _commitmentsApiClient.GetAllTrainingProgrammes()).TrainingProgrammes diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Shared/DraftApprenticeshipViewModel.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Shared/DraftApprenticeshipViewModel.cs index 09fa14cd0..9ba7ff2b1 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Shared/DraftApprenticeshipViewModel.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Shared/DraftApprenticeshipViewModel.cs @@ -114,7 +114,5 @@ public DraftApprenticeshipViewModel() public IEnumerable Courses { get; set; } public bool IsContinuation { get; set; } - - public bool FjaaAgencyExists { get; set; } } } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Shared/SelectDeliveryModelViewModel.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Shared/SelectDeliveryModelViewModel.cs index 2f69d1335..99cda29a7 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Shared/SelectDeliveryModelViewModel.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Shared/SelectDeliveryModelViewModel.cs @@ -20,6 +20,5 @@ public class SelectDeliveryModelViewModel public DeliveryModel? DeliveryModel { get; set; } public DeliveryModel[] DeliveryModels { get; set; } public string TransferSenderId { get; set; } - public bool FjaaAgencyExists { 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 56e4ce688..6d3ead994 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/SFA.DAS.EmployerCommitmentsV2.Web.csproj +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/SFA.DAS.EmployerCommitmentsV2.Web.csproj @@ -32,6 +32,7 @@ + @@ -45,6 +46,7 @@ + diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Apprentice/ConfirmEditApprenticeship.cshtml b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Apprentice/ConfirmEditApprenticeship.cshtml index b0d5279d6..dbae865de 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Apprentice/ConfirmEditApprenticeship.cshtml +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Apprentice/ConfirmEditApprenticeship.cshtml @@ -56,7 +56,7 @@
Unique learner number
@Model.OriginalApprenticeship.ULN
- @if (Model.OriginalApprenticeship.DeliveryModel == DeliveryModel.PortableFlexiJob) + @if (Model.OriginalApprenticeship.DeliveryModel == DeliveryModel.PortableFlexiJob || Model.OriginalApprenticeship.DeliveryModel == DeliveryModel.FlexiJobAgency) {
Apprenticeship delivery model
diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Shared/SelectDeliveryModel.cshtml b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Shared/SelectDeliveryModel.cshtml index e6f36fba3..90103bac1 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Shared/SelectDeliveryModel.cshtml +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Shared/SelectDeliveryModel.cshtml @@ -29,7 +29,7 @@
- @if (!Model.FjaaAgencyExists) + @if (Model.DeliveryModels.ToList().Contains(DeliveryModel.PortableFlexiJob)) {
@@ -42,10 +42,10 @@
} - @if (Model.FjaaAgencyExists) + @if (Model.DeliveryModels.ToList().Contains(DeliveryModel.FlexiJobAgency)) {
- + diff --git a/src/SFA.DAS.EmployerCommitmentsV2/SFA.DAS.EmployerCommitmentsV2.csproj b/src/SFA.DAS.EmployerCommitmentsV2/SFA.DAS.EmployerCommitmentsV2.csproj index 7b9b35607..1d317a5ef 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2/SFA.DAS.EmployerCommitmentsV2.csproj +++ b/src/SFA.DAS.EmployerCommitmentsV2/SFA.DAS.EmployerCommitmentsV2.csproj @@ -7,16 +7,16 @@ - - - - - - - + + + + + + + - + \ No newline at end of file From 3498e102c52bb110053e4df7bcf72b2551d3cb9d Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Wed, 15 Jun 2022 15:34:52 +0100 Subject: [PATCH 07/24] Rework logic for options --- ...ticeRequestToSelectDeliveryModelViewModelMapper.cs | 11 ++++++++++- ...shipRequestToSelectDeliveryModelViewModelMapper.cs | 4 +++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs index 6b62721d6..c9347d3bf 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs @@ -29,9 +29,18 @@ public async Task Map(ApprenticeRequest source) bool portableAllowed = _deliveryModels.Contains(DeliveryModel.PortableFlexiJob) ? true : false; - if (agencyExists && portableAllowed == false) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } + //Employer is listed on the RoFJAA & is not involved in Portable flexi-job pilot = Regular & Flexi - Job Agency delivery models available for selection + if (agencyExists && !portableAllowed) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } + + //Employer is listed on the RoFJAA & is also involved in Portable flexi - job pilot = Regular & Flexi - Job Agency delivery models available for selection + if (agencyExists && portableAllowed) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } + + //Employer is not listed on the RoFJAA & is involved in Portable flexi - job pilot = Regular & Portable Flexi - Job delivery models available for selection if (!agencyExists && portableAllowed == true) { this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + //Employer is not listed on the RoFJAA & is not involved in Portable flexi - job pilot = Regular delivery model automatically selected(options not surfaced to the user) + if (!agencyExists && !portableAllowed == true) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + return new SelectDeliveryModelViewModel { AccountHashedId = source.AccountHashedId, diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs index 988f50d65..639316255 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs @@ -33,8 +33,10 @@ public async Task Map(AddDraftApprenticeshipReques bool portableAllowed = _deliveryModels.Contains(DeliveryModel.PortableFlexiJob) ? true : false; - if (agencyExists && portableAllowed == false) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } + if (agencyExists && !portableAllowed) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } + if (agencyExists && portableAllowed) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } if (!agencyExists && portableAllowed == true) { this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + if (!agencyExists && !portableAllowed == true) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } return new SelectDeliveryModelViewModel { From 6aad6438b949efd47ff1981df1f704b4dbdc1e4e Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Wed, 15 Jun 2022 15:40:05 +0100 Subject: [PATCH 08/24] Tidy --- ...ticeRequestToSelectDeliveryModelViewModelMapper.cs | 11 ++--------- ...shipRequestToSelectDeliveryModelViewModelMapper.cs | 4 ++-- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs index c9347d3bf..4eff8fb79 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs @@ -29,17 +29,10 @@ public async Task Map(ApprenticeRequest source) bool portableAllowed = _deliveryModels.Contains(DeliveryModel.PortableFlexiJob) ? true : false; - //Employer is listed on the RoFJAA & is not involved in Portable flexi-job pilot = Regular & Flexi - Job Agency delivery models available for selection if (agencyExists && !portableAllowed) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } - - //Employer is listed on the RoFJAA & is also involved in Portable flexi - job pilot = Regular & Flexi - Job Agency delivery models available for selection if (agencyExists && portableAllowed) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } - - //Employer is not listed on the RoFJAA & is involved in Portable flexi - job pilot = Regular & Portable Flexi - Job delivery models available for selection - if (!agencyExists && portableAllowed == true) { this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } - - //Employer is not listed on the RoFJAA & is not involved in Portable flexi - job pilot = Regular delivery model automatically selected(options not surfaced to the user) - if (!agencyExists && !portableAllowed == true) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + if (!agencyExists && portableAllowed) { this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + if (!agencyExists && !portableAllowed) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } return new SelectDeliveryModelViewModel { diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs index 639316255..18c085131 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs @@ -35,8 +35,8 @@ public async Task Map(AddDraftApprenticeshipReques if (agencyExists && !portableAllowed) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } if (agencyExists && portableAllowed) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } - if (!agencyExists && portableAllowed == true) { this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } - if (!agencyExists && !portableAllowed == true) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + if (!agencyExists && portableAllowed) { this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + if (!agencyExists && !portableAllowed) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } return new SelectDeliveryModelViewModel { From 871a07cec8c8cdefc33aebebd5db28d0edb35608 Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Thu, 16 Jun 2022 09:40:28 +0100 Subject: [PATCH 09/24] Tidy up --- ...questToSelectDeliveryModelViewModelMapperTests.cs | 4 ++-- ...questToSelectDeliveryModelViewModelMapperTests.cs | 2 +- .../EditDraftApprenticeshipViewModelMapperTests.cs | 2 +- ...iceRequestToSelectDeliveryModelViewModelMapper.cs | 12 +++++------- ...hipRequestToSelectDeliveryModelViewModelMapper.cs | 12 +++++------- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs index dfc80a3ed..970312191 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs @@ -45,12 +45,12 @@ public async Task Arrange() .Without(x => x.TransferSenderId).Create(); _providerCourseDeliveryModels = autoFixture.Create(); - + _approvalsApiClient = new Mock(); _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); _fjaaAgencyService = new Mock(); - _fjaaAgencyService.Setup(x => x.AgencyExists(_agencyId)).ReturnsAsync(false); + //_fjaaAgencyService.Setup(x => x.AgencyExists(_agencyId)).ReturnsAsync(true); _mapper = new ApprenticeRequestToSelectDeliveryModelViewModelMapper(_approvalsApiClient.Object, _fjaaAgencyService.Object); _result = await _mapper.Map(TestHelper.Clone(_source)); diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs index 47f1953cb..8ffeb69d5 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs @@ -67,7 +67,7 @@ public async Task Arrange() _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); _fjaaAgencyService = new Mock(); - _fjaaAgencyService.Setup(x => x.AgencyExists(_agencyId)).ReturnsAsync(false); + //_fjaaAgencyService.Setup(x => x.AgencyExists(_agencyId)).ReturnsAsync(true); _mapper = new AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(_commitmentsApiClient.Object, _approvalsApiClient.Object, _fjaaAgencyService.Object); _result = await _mapper.Map(TestHelper.Clone(_source)); 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 ebf418008..9ef40a873 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapperTests.cs @@ -80,7 +80,7 @@ public async Task Arrange() .ReturnsAsync(_cohort); _fjaaAgencyService = new Mock(); - _fjaaAgencyService.Setup(x => x.AgencyExists(_agencyId)).ReturnsAsync(false); + //_fjaaAgencyService.Setup(x => x.AgencyExists(_agencyId)).ReturnsAsync(true); _source = autoFixture.Create(); diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs index 4eff8fb79..109f12e13 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs @@ -22,17 +22,15 @@ public ApprenticeRequestToSelectDeliveryModelViewModelMapper(IApprovalsApiClient public async Task Map(ApprenticeRequest source) { var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(source.ProviderId, source.CourseCode); - _deliveryModels = response.DeliveryModels.ToList(); bool agencyExists = await _fjaaAgencyService.AgencyExists((int)source.AccountLegalEntityId); + bool portable = _deliveryModels.Contains(DeliveryModel.PortableFlexiJob) ? true : false; - bool portableAllowed = _deliveryModels.Contains(DeliveryModel.PortableFlexiJob) ? true : false; - - if (agencyExists && !portableAllowed) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } - if (agencyExists && portableAllowed) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } - if (!agencyExists && portableAllowed) { this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } - if (!agencyExists && !portableAllowed) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + if (agencyExists && !portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } + if (agencyExists && portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } + if (!agencyExists && portable) { this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + if (!agencyExists && !portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } return new SelectDeliveryModelViewModel { diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs index 18c085131..d00233791 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs @@ -26,17 +26,15 @@ public async Task Map(AddDraftApprenticeshipReques var cohort = await _commitmentsApiClient.GetCohort(source.CohortId); var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode); - _deliveryModels = response.DeliveryModels.ToList(); bool agencyExists = await _fjaaAgencyService.AgencyExists((int)source.AccountLegalEntityId); + bool portable = _deliveryModels.Contains(DeliveryModel.PortableFlexiJob) ? true : false; - bool portableAllowed = _deliveryModels.Contains(DeliveryModel.PortableFlexiJob) ? true : false; - - if (agencyExists && !portableAllowed) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } - if (agencyExists && portableAllowed) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } - if (!agencyExists && portableAllowed) { this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } - if (!agencyExists && !portableAllowed) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + if (agencyExists && !portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } + if (agencyExists && portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } + if (!agencyExists && portable) { this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + if (!agencyExists && !portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } return new SelectDeliveryModelViewModel { From 30fe26f6179641c6e780702699d214e37e0e2522 Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Thu, 16 Jun 2022 11:51:41 +0100 Subject: [PATCH 10/24] Toggle options { "Feature": "FJAA", "IsEnabled": true, "Whitelist": null } --- ...SelectDeliveryModelViewModelMapperTests.cs | 6 +++-- ...SelectDeliveryModelViewModelMapperTests.cs | 6 +++-- ...estToSelectDeliveryModelViewModelMapper.cs | 22 ++++++++++------- ...estToSelectDeliveryModelViewModelMapper.cs | 24 ++++++++++++------- .../Features/EmployerFeature.cs | 5 ++-- 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs index 970312191..bb48c7ba7 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs @@ -1,6 +1,7 @@ using AutoFixture; using Moq; using NUnit.Framework; +using SFA.DAS.Authorization.Services; using SFA.DAS.CommitmentsV2.Types; using SFA.DAS.EmployerCommitmentsV2.Services.Approvals; using SFA.DAS.EmployerCommitmentsV2.Services.Approvals.Responses; @@ -20,6 +21,7 @@ public class ApprenticeRequestToSelectDeliveryModelViewModelMapperTests private ApprenticeRequest _source; private Mock _approvalsApiClient; private Mock _fjaaAgencyService; + private Mock _authService; private ProviderCourseDeliveryModels _providerCourseDeliveryModels; private long _providerId; private int _agencyId; @@ -50,9 +52,9 @@ public async Task Arrange() _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); _fjaaAgencyService = new Mock(); - //_fjaaAgencyService.Setup(x => x.AgencyExists(_agencyId)).ReturnsAsync(true); + _authService = new Mock(); - _mapper = new ApprenticeRequestToSelectDeliveryModelViewModelMapper(_approvalsApiClient.Object, _fjaaAgencyService.Object); + _mapper = new ApprenticeRequestToSelectDeliveryModelViewModelMapper(_approvalsApiClient.Object, _fjaaAgencyService.Object, _authService.Object); _result = await _mapper.Map(TestHelper.Clone(_source)); } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs index 8ffeb69d5..2dc99a2a6 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs @@ -12,6 +12,7 @@ using System.Threading; using System.Threading.Tasks; using SFA.DAS.EmployerCommitmentsV2.Web.Services; +using SFA.DAS.Authorization.Services; namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.DraftApprenticeship { @@ -24,6 +25,7 @@ public class AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTe private GetCohortResponse _getCohortResponse; private Mock _approvalsApiClient; private Mock _fjaaAgencyService; + private Mock _authService; private ProviderCourseDeliveryModels _providerCourseDeliveryModels; private long _providerId; private string _courseCode; @@ -67,9 +69,9 @@ public async Task Arrange() _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); _fjaaAgencyService = new Mock(); - //_fjaaAgencyService.Setup(x => x.AgencyExists(_agencyId)).ReturnsAsync(true); + _authService = new Mock(); - _mapper = new AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(_commitmentsApiClient.Object, _approvalsApiClient.Object, _fjaaAgencyService.Object); + _mapper = new AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(_commitmentsApiClient.Object, _approvalsApiClient.Object, _fjaaAgencyService.Object, _authService.Object); _result = await _mapper.Map(TestHelper.Clone(_source)); } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs index 109f12e13..466f6febf 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs @@ -7,6 +7,8 @@ using SFA.DAS.EmployerCommitmentsV2.Web.Services; using SFA.DAS.CommitmentsV2.Types; using System.Collections.Generic; +using SFA.DAS.Authorization.Services; +using SFA.DAS.EmployerCommitmentsV2.Features; namespace SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Cohort { @@ -14,23 +16,27 @@ public class ApprenticeRequestToSelectDeliveryModelViewModelMapper : IMapper _deliveryModels; - public ApprenticeRequestToSelectDeliveryModelViewModelMapper(IApprovalsApiClient approvalsApiClient, IFjaaAgencyService fjaaAgencyService) - => (_approvalsApiClient, _fjaaAgencyService) = (approvalsApiClient, fjaaAgencyService); + public ApprenticeRequestToSelectDeliveryModelViewModelMapper(IApprovalsApiClient approvalsApiClient, IFjaaAgencyService fjaaAgencyService, IAuthorizationService authorizationService) + => (_approvalsApiClient, _fjaaAgencyService, _authorizationService) = (approvalsApiClient, fjaaAgencyService, authorizationService); public async Task Map(ApprenticeRequest source) { var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(source.ProviderId, source.CourseCode); _deliveryModels = response.DeliveryModels.ToList(); - bool agencyExists = await _fjaaAgencyService.AgencyExists((int)source.AccountLegalEntityId); - bool portable = _deliveryModels.Contains(DeliveryModel.PortableFlexiJob) ? true : false; + if (_authorizationService.IsAuthorized(EmployerFeature.FJAA)) + { + bool agencyExists = await _fjaaAgencyService.AgencyExists((int)source.AccountLegalEntityId); + bool portable = _deliveryModels.Contains(DeliveryModel.PortableFlexiJob) ? true : false; - if (agencyExists && !portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } - if (agencyExists && portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } - if (!agencyExists && portable) { this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } - if (!agencyExists && !portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + if (agencyExists && !portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } + if (agencyExists && portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } + if (!agencyExists && portable) { this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + if (!agencyExists && !portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + } return new SelectDeliveryModelViewModel { diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs index d00233791..06a3f2c90 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs @@ -1,6 +1,8 @@ -using SFA.DAS.CommitmentsV2.Api.Client; +using SFA.DAS.Authorization.Services; +using SFA.DAS.CommitmentsV2.Api.Client; using SFA.DAS.CommitmentsV2.Shared.Interfaces; using SFA.DAS.CommitmentsV2.Types; +using SFA.DAS.EmployerCommitmentsV2.Features; using SFA.DAS.EmployerCommitmentsV2.Services.Approvals; using SFA.DAS.EmployerCommitmentsV2.Web.Models.DraftApprenticeship; using SFA.DAS.EmployerCommitmentsV2.Web.Models.Shared; @@ -16,10 +18,11 @@ public class AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper : private readonly ICommitmentsApiClient _commitmentsApiClient; private readonly IApprovalsApiClient _approvalsApiClient; private readonly IFjaaAgencyService _fjaaAgencyService; + private readonly IAuthorizationService _authorizationService; protected List _deliveryModels; - public AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(ICommitmentsApiClient commitmentsApiClient, IApprovalsApiClient approvalsApiClient, IFjaaAgencyService fjaaAgencyService) - => (_commitmentsApiClient, _approvalsApiClient, _fjaaAgencyService) = (commitmentsApiClient, approvalsApiClient, fjaaAgencyService); + public AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(ICommitmentsApiClient commitmentsApiClient, IApprovalsApiClient approvalsApiClient, IFjaaAgencyService fjaaAgencyService, IAuthorizationService authorizationService) + => (_commitmentsApiClient, _approvalsApiClient, _fjaaAgencyService, _authorizationService) = (commitmentsApiClient, approvalsApiClient, fjaaAgencyService, authorizationService); public async Task Map(AddDraftApprenticeshipRequest source) { @@ -28,13 +31,16 @@ public async Task Map(AddDraftApprenticeshipReques var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode); _deliveryModels = response.DeliveryModels.ToList(); - bool agencyExists = await _fjaaAgencyService.AgencyExists((int)source.AccountLegalEntityId); - bool portable = _deliveryModels.Contains(DeliveryModel.PortableFlexiJob) ? true : false; + if (_authorizationService.IsAuthorized(EmployerFeature.FJAA)) + { + bool agencyExists = await _fjaaAgencyService.AgencyExists((int)source.AccountLegalEntityId); + bool portable = _deliveryModels.Contains(DeliveryModel.PortableFlexiJob) ? true : false; - if (agencyExists && !portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } - if (agencyExists && portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } - if (!agencyExists && portable) { this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } - if (!agencyExists && !portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + if (agencyExists && !portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } + if (agencyExists && portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } + if (!agencyExists && portable) { this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + if (!agencyExists && !portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + } return new SelectDeliveryModelViewModel { diff --git a/src/SFA.DAS.EmployerCommitmentsV2/Features/EmployerFeature.cs b/src/SFA.DAS.EmployerCommitmentsV2/Features/EmployerFeature.cs index c585f356e..468499470 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2/Features/EmployerFeature.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2/Features/EmployerFeature.cs @@ -4,7 +4,8 @@ public static class EmployerFeature { private const string Prefix = "EmployerFeature."; - public const string ManageApprenticesV2 = Prefix + "ManageApprenticesV2"; - public const string DeliveryModel = Prefix + "DeliveryModel"; + public const string ManageApprenticesV2 = Prefix + "ManageApprenticesV2"; + public const string DeliveryModel = Prefix + "DeliveryModel"; + public const string FJAA = Prefix + "FJAA"; } } \ No newline at end of file From e49236ee3dc10e6eef1dad476dde681d0d89e57c Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Thu, 16 Jun 2022 12:17:31 +0100 Subject: [PATCH 11/24] Cleanup --- ...equestToSelectDeliveryModelViewModelMapper.cs | 7 +------ ...equestToSelectDeliveryModelViewModelMapper.cs | 7 +------ .../Services/FjaaAgencyService.cs | 16 +++++++++++++++- .../Services/IFjaaAgencyService.cs | 4 +++- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs index 466f6febf..570480822 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs @@ -30,12 +30,7 @@ public async Task Map(ApprenticeRequest source) if (_authorizationService.IsAuthorized(EmployerFeature.FJAA)) { bool agencyExists = await _fjaaAgencyService.AgencyExists((int)source.AccountLegalEntityId); - bool portable = _deliveryModels.Contains(DeliveryModel.PortableFlexiJob) ? true : false; - - if (agencyExists && !portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } - if (agencyExists && portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } - if (!agencyExists && portable) { this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } - if (!agencyExists && !portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + _deliveryModels = await _fjaaAgencyService.AssignDeliveryModels(_deliveryModels, agencyExists); } return new SelectDeliveryModelViewModel diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs index 06a3f2c90..9b03a4b32 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs @@ -34,12 +34,7 @@ public async Task Map(AddDraftApprenticeshipReques if (_authorizationService.IsAuthorized(EmployerFeature.FJAA)) { bool agencyExists = await _fjaaAgencyService.AgencyExists((int)source.AccountLegalEntityId); - bool portable = _deliveryModels.Contains(DeliveryModel.PortableFlexiJob) ? true : false; - - if (agencyExists && !portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } - if (agencyExists && portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); } - if (!agencyExists && portable) { this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } - if (!agencyExists && !portable) { this.RemoveDeliveryModel((int)DeliveryModel.PortableFlexiJob); this.RemoveDeliveryModel((int)DeliveryModel.FlexiJobAgency); } + _deliveryModels = await _fjaaAgencyService.AssignDeliveryModels(_deliveryModels, agencyExists); } return new SelectDeliveryModelViewModel diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/FjaaAgencyService.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/FjaaAgencyService.cs index 44744ea10..65cd088b0 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/FjaaAgencyService.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/FjaaAgencyService.cs @@ -1,4 +1,6 @@ -using System.Threading.Tasks; +using System.Collections.Generic; +using System.Threading.Tasks; +using SFA.DAS.CommitmentsV2.Types; using SFA.DAS.EmployerCommitmentsV2.Services.Approvals; using SFA.DAS.EmployerCommitmentsV2.Services.Approvals.Responses; @@ -29,5 +31,17 @@ public async Task AgencyExists(int legalEntityId) return false; } + + public async Task> AssignDeliveryModels(List models, bool agencyExists) + { + bool portable = models.Contains(DeliveryModel.PortableFlexiJob) ? true : false; + + if (agencyExists && !portable) { models.Remove(DeliveryModel.PortableFlexiJob); } + if (agencyExists && portable) { models.Remove(DeliveryModel.PortableFlexiJob); } + if (!agencyExists && portable) { models.Remove(DeliveryModel.FlexiJobAgency); } + if (!agencyExists && !portable) { models.Remove(DeliveryModel.PortableFlexiJob); models.Remove(DeliveryModel.FlexiJobAgency); } + + return models; + } } } \ No newline at end of file diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/IFjaaAgencyService.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/IFjaaAgencyService.cs index 30b8570ec..7162d2b5f 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/IFjaaAgencyService.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/IFjaaAgencyService.cs @@ -1,4 +1,5 @@ -using SFA.DAS.EmployerCommitmentsV2.Web.Models.Agency; +using SFA.DAS.CommitmentsV2.Types; +using SFA.DAS.EmployerCommitmentsV2.Web.Models.Agency; using System.Collections.Generic; using System.Threading.Tasks; @@ -7,5 +8,6 @@ namespace SFA.DAS.EmployerCommitmentsV2.Web.Services public interface IFjaaAgencyService { Task AgencyExists(int legalEntityId); + Task> AssignDeliveryModels(List models, bool agencyExists); } } From 4740fa26ba2e42a3d384f4c0af97551c482294c6 Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Thu, 16 Jun 2022 12:22:33 +0100 Subject: [PATCH 12/24] Cleanup --- ...ceRequestToSelectDeliveryModelViewModelMapper.cs | 13 +++---------- ...ipRequestToSelectDeliveryModelViewModelMapper.cs | 12 +++--------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs index 570480822..419a2735f 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs @@ -17,7 +17,6 @@ public class ApprenticeRequestToSelectDeliveryModelViewModelMapper : IMapper _deliveryModels; public ApprenticeRequestToSelectDeliveryModelViewModelMapper(IApprovalsApiClient approvalsApiClient, IFjaaAgencyService fjaaAgencyService, IAuthorizationService authorizationService) => (_approvalsApiClient, _fjaaAgencyService, _authorizationService) = (approvalsApiClient, fjaaAgencyService, authorizationService); @@ -25,12 +24,12 @@ public ApprenticeRequestToSelectDeliveryModelViewModelMapper(IApprovalsApiClient public async Task Map(ApprenticeRequest source) { var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(source.ProviderId, source.CourseCode); - _deliveryModels = response.DeliveryModels.ToList(); + var deliveryModels = response.DeliveryModels.ToList(); if (_authorizationService.IsAuthorized(EmployerFeature.FJAA)) { bool agencyExists = await _fjaaAgencyService.AgencyExists((int)source.AccountLegalEntityId); - _deliveryModels = await _fjaaAgencyService.AssignDeliveryModels(_deliveryModels, agencyExists); + deliveryModels = await _fjaaAgencyService.AssignDeliveryModels(deliveryModels, agencyExists); } return new SelectDeliveryModelViewModel @@ -40,18 +39,12 @@ public async Task Map(ApprenticeRequest source) AccountLegalEntityHashedId = source.AccountLegalEntityHashedId, CourseCode = source.CourseCode, DeliveryModel = source.DeliveryModel, - DeliveryModels = _deliveryModels.ToArray(), + DeliveryModels = deliveryModels.ToArray(), ProviderId = source.ProviderId, ReservationId = source.ReservationId, StartMonthYear = source.StartMonthYear, TransferSenderId = source.TransferSenderId }; } - - protected void RemoveDeliveryModel(int deliveryModelId) - { - _deliveryModels.Remove((DeliveryModel)deliveryModelId); - } - } } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs index 9b03a4b32..32868e989 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs @@ -19,7 +19,6 @@ public class AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper : private readonly IApprovalsApiClient _approvalsApiClient; private readonly IFjaaAgencyService _fjaaAgencyService; private readonly IAuthorizationService _authorizationService; - protected List _deliveryModels; public AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(ICommitmentsApiClient commitmentsApiClient, IApprovalsApiClient approvalsApiClient, IFjaaAgencyService fjaaAgencyService, IAuthorizationService authorizationService) => (_commitmentsApiClient, _approvalsApiClient, _fjaaAgencyService, _authorizationService) = (commitmentsApiClient, approvalsApiClient, fjaaAgencyService, authorizationService); @@ -29,12 +28,12 @@ public async Task Map(AddDraftApprenticeshipReques var cohort = await _commitmentsApiClient.GetCohort(source.CohortId); var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode); - _deliveryModels = response.DeliveryModels.ToList(); + var deliveryModels = response.DeliveryModels.ToList(); if (_authorizationService.IsAuthorized(EmployerFeature.FJAA)) { bool agencyExists = await _fjaaAgencyService.AgencyExists((int)source.AccountLegalEntityId); - _deliveryModels = await _fjaaAgencyService.AssignDeliveryModels(_deliveryModels, agencyExists); + deliveryModels = await _fjaaAgencyService.AssignDeliveryModels(deliveryModels, agencyExists); } return new SelectDeliveryModelViewModel @@ -46,16 +45,11 @@ public async Task Map(AddDraftApprenticeshipReques CohortReference = source.CohortReference, CourseCode = source.CourseCode, DeliveryModel = source.DeliveryModel, - DeliveryModels = _deliveryModels.ToArray(), + DeliveryModels = deliveryModels.ToArray(), ProviderId = source.ProviderId, ReservationId = source.ReservationId, StartMonthYear = source.StartMonthYear, }; } - - protected void RemoveDeliveryModel(int deliveryModelId) - { - _deliveryModels.Remove((DeliveryModel)deliveryModelId); - } } } From 352cbc42c045ecb84bc67c3687a047d9fbf5a9d0 Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Thu, 16 Jun 2022 13:40:32 +0100 Subject: [PATCH 13/24] Update FjaaAgencyService.cs --- .../Services/FjaaAgencyService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/FjaaAgencyService.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/FjaaAgencyService.cs index 65cd088b0..ba996a165 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/FjaaAgencyService.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/FjaaAgencyService.cs @@ -32,7 +32,7 @@ public async Task AgencyExists(int legalEntityId) return false; } - public async Task> AssignDeliveryModels(List models, bool agencyExists) + public Task> AssignDeliveryModels(List models, bool agencyExists) { bool portable = models.Contains(DeliveryModel.PortableFlexiJob) ? true : false; @@ -41,7 +41,7 @@ public async Task> AssignDeliveryModels(List if (!agencyExists && portable) { models.Remove(DeliveryModel.FlexiJobAgency); } if (!agencyExists && !portable) { models.Remove(DeliveryModel.PortableFlexiJob); models.Remove(DeliveryModel.FlexiJobAgency); } - return models; + return Task.FromResult(models); } } } \ No newline at end of file From f7122160fa88426cdfb88ec6151afce060a1bdd1 Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Mon, 20 Jun 2022 08:00:59 +0100 Subject: [PATCH 14/24] Removal FJAA services, refactor using updated APIM endpoints Plus fix tests --- ...SelectDeliveryModelViewModelMapperTests.cs | 4 +- ...SelectDeliveryModelViewModelMapperTests.cs | 8 ++-- ...SelectDeliveryModelViewModelMapperTests.cs | 8 ++-- ...DraftApprenticeshipViewModelMapperTests.cs | 7 +-- ...estToSelectDeliveryModelViewModelMapper.cs | 14 +++--- ...estToSelectDeliveryModelViewModelMapper.cs | 19 ++++---- .../EditDraftApprenticeshipViewModelMapper.cs | 6 +-- .../Services/FjaaAgencyService.cs | 47 ------------------- .../Services/IFjaaAgencyService.cs | 13 ----- .../Services/Approvals/ApprovalsApiClient.cs | 10 +--- .../Services/Approvals/IApprovalsApiClient.cs | 4 +- 11 files changed, 33 insertions(+), 107 deletions(-) delete mode 100644 src/SFA.DAS.EmployerCommitmentsV2.Web/Services/FjaaAgencyService.cs delete mode 100644 src/SFA.DAS.EmployerCommitmentsV2.Web/Services/IFjaaAgencyService.cs diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapperTests.cs index b71ffdea3..acaa4acc8 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapperTests.cs @@ -31,6 +31,7 @@ public class EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMap private ProviderCourseDeliveryModels _providerCourseDeliveryModels; private SelectDeliveryModelViewModel _result; private long _cohortId; + private int _legalEntityId; private Fixture _autoFixture; [SetUp] @@ -38,6 +39,7 @@ public async Task Arrange() { _autoFixture = new Fixture(); _cohortId = _autoFixture.Create(); + _legalEntityId = _autoFixture.Create(); _standardTrainingProgrammes = _autoFixture.CreateMany().ToList(); _allTrainingProgrammes = _autoFixture.CreateMany().ToList(); @@ -80,7 +82,7 @@ public async Task Arrange() }); _approvalsApiClient = new Mock(); - _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_getCohortResponse.ProviderId.Value, _source.CourseCode, + _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_getCohortResponse.ProviderId.Value, _source.CourseCode, _legalEntityId, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); _mapper = new EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper(_commitmentsApiClient.Object, _approvalsApiClient.Object); diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs index bb48c7ba7..19e9d439e 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs @@ -20,11 +20,11 @@ public class ApprenticeRequestToSelectDeliveryModelViewModelMapperTests private ApprenticeRequestToSelectDeliveryModelViewModelMapper _mapper; private ApprenticeRequest _source; private Mock _approvalsApiClient; - private Mock _fjaaAgencyService; private Mock _authService; private ProviderCourseDeliveryModels _providerCourseDeliveryModels; private long _providerId; private int _agencyId; + private int _legalEntityId; private string _courseCode; private SelectDeliveryModelViewModel _result; @@ -36,6 +36,7 @@ public async Task Arrange() _providerId = autoFixture.Create(); _courseCode = autoFixture.Create(); _agencyId = autoFixture.Create(); + _legalEntityId = autoFixture.Create(); _source = autoFixture.Build() .With(x => x.StartMonthYear, "062020") @@ -49,12 +50,11 @@ public async Task Arrange() _providerCourseDeliveryModels = autoFixture.Create(); _approvalsApiClient = new Mock(); - _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); + _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, _legalEntityId, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); - _fjaaAgencyService = new Mock(); _authService = new Mock(); - _mapper = new ApprenticeRequestToSelectDeliveryModelViewModelMapper(_approvalsApiClient.Object, _fjaaAgencyService.Object, _authService.Object); + _mapper = new ApprenticeRequestToSelectDeliveryModelViewModelMapper(_approvalsApiClient.Object, _authService.Object); _result = await _mapper.Map(TestHelper.Clone(_source)); } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs index 2dc99a2a6..b3d4d84ba 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs @@ -24,13 +24,13 @@ public class AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTe private Mock _commitmentsApiClient; private GetCohortResponse _getCohortResponse; private Mock _approvalsApiClient; - private Mock _fjaaAgencyService; private Mock _authService; private ProviderCourseDeliveryModels _providerCourseDeliveryModels; private long _providerId; private string _courseCode; private long _cohortId; private int _agencyId; + private int _legalEntityId; private SelectDeliveryModelViewModel _result; [SetUp] @@ -42,6 +42,7 @@ public async Task Arrange() _courseCode = autoFixture.Create(); _cohortId = autoFixture.Create(); _agencyId = autoFixture.Create(); + _legalEntityId = autoFixture.Create(); _source = autoFixture.Build() .With(x => x.StartMonthYear, "062020") @@ -66,12 +67,11 @@ public async Task Arrange() _providerCourseDeliveryModels = autoFixture.Create(); _approvalsApiClient = new Mock(); - _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); + _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, _legalEntityId, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); - _fjaaAgencyService = new Mock(); _authService = new Mock(); - _mapper = new AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(_commitmentsApiClient.Object, _approvalsApiClient.Object, _fjaaAgencyService.Object, _authService.Object); + _mapper = new AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(_commitmentsApiClient.Object, _approvalsApiClient.Object, _authService.Object); _result = await _mapper.Map(TestHelper.Clone(_source)); } 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 9ef40a873..6c8da7649 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapperTests.cs @@ -26,7 +26,6 @@ public class EditDraftApprenticeshipViewModelMapperTests private Mock _commitmentsApiClient; private GetDraftApprenticeshipResponse _draftApprenticeshipResponse; private Mock _encodingService; - private Mock _fjaaAgencyService; private string _encodedApprenticeshipId; private string _cohortReference; private int _agencyId; @@ -79,13 +78,9 @@ public async Task Arrange() _commitmentsApiClient.Setup(x => x.GetCohort(It.IsAny(), It.IsAny())) .ReturnsAsync(_cohort); - _fjaaAgencyService = new Mock(); - //_fjaaAgencyService.Setup(x => x.AgencyExists(_agencyId)).ReturnsAsync(true); - - _source = autoFixture.Create(); _source.Cohort = _cohort; - _mapper = new EditDraftApprenticeshipViewModelMapper(_commitmentsApiClient.Object, _encodingService.Object, _fjaaAgencyService.Object); + _mapper = new EditDraftApprenticeshipViewModelMapper(_commitmentsApiClient.Object, _encodingService.Object); _result = await _mapper.Map(TestHelper.Clone(_source)) as EditDraftApprenticeshipViewModel; } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs index 419a2735f..c71e0f36c 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs @@ -15,23 +15,23 @@ namespace SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Cohort public class ApprenticeRequestToSelectDeliveryModelViewModelMapper : IMapper { private readonly IApprovalsApiClient _approvalsApiClient; - private readonly IFjaaAgencyService _fjaaAgencyService; private readonly IAuthorizationService _authorizationService; - public ApprenticeRequestToSelectDeliveryModelViewModelMapper(IApprovalsApiClient approvalsApiClient, IFjaaAgencyService fjaaAgencyService, IAuthorizationService authorizationService) - => (_approvalsApiClient, _fjaaAgencyService, _authorizationService) = (approvalsApiClient, fjaaAgencyService, authorizationService); + public ApprenticeRequestToSelectDeliveryModelViewModelMapper(IApprovalsApiClient approvalsApiClient, IAuthorizationService authorizationService) + => (_approvalsApiClient, _authorizationService) = (approvalsApiClient, authorizationService); public async Task Map(ApprenticeRequest source) { - var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(source.ProviderId, source.CourseCode); - var deliveryModels = response.DeliveryModels.ToList(); + int legalEntityId = 0; if (_authorizationService.IsAuthorized(EmployerFeature.FJAA)) { - bool agencyExists = await _fjaaAgencyService.AgencyExists((int)source.AccountLegalEntityId); - deliveryModels = await _fjaaAgencyService.AssignDeliveryModels(deliveryModels, agencyExists); + legalEntityId = (int)source.AccountLegalEntityId; } + var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(source.ProviderId, source.CourseCode, legalEntityId); + var deliveryModels = response.DeliveryModels.ToList(); + return new SelectDeliveryModelViewModel { AccountHashedId = source.AccountHashedId, diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs index 32868e989..46cf6ca42 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs @@ -17,25 +17,26 @@ public class AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper : { private readonly ICommitmentsApiClient _commitmentsApiClient; private readonly IApprovalsApiClient _approvalsApiClient; - private readonly IFjaaAgencyService _fjaaAgencyService; private readonly IAuthorizationService _authorizationService; - public AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(ICommitmentsApiClient commitmentsApiClient, IApprovalsApiClient approvalsApiClient, IFjaaAgencyService fjaaAgencyService, IAuthorizationService authorizationService) - => (_commitmentsApiClient, _approvalsApiClient, _fjaaAgencyService, _authorizationService) = (commitmentsApiClient, approvalsApiClient, fjaaAgencyService, authorizationService); + public AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(ICommitmentsApiClient commitmentsApiClient, IApprovalsApiClient approvalsApiClient, IAuthorizationService authorizationService) + => (_commitmentsApiClient, _approvalsApiClient, _authorizationService) = (commitmentsApiClient, approvalsApiClient, authorizationService); public async Task Map(AddDraftApprenticeshipRequest source) { - var cohort = await _commitmentsApiClient.GetCohort(source.CohortId); - - var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode); - var deliveryModels = response.DeliveryModels.ToList(); + int legalEntityId = 0; if (_authorizationService.IsAuthorized(EmployerFeature.FJAA)) { - bool agencyExists = await _fjaaAgencyService.AgencyExists((int)source.AccountLegalEntityId); - deliveryModels = await _fjaaAgencyService.AssignDeliveryModels(deliveryModels, agencyExists); + legalEntityId = (int)source.AccountLegalEntityId; } + var cohort = await _commitmentsApiClient.GetCohort(source.CohortId); + + var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode, legalEntityId); + + var deliveryModels = response.DeliveryModels.ToList(); + return new SelectDeliveryModelViewModel { AccountHashedId = source.AccountHashedId, diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapper.cs index b5bc6f39a..b641c8a44 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapper.cs @@ -15,16 +15,12 @@ public class EditDraftApprenticeshipViewModelMapper : IMapper Map(EditDraftApprenticeshipRequest source) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/FjaaAgencyService.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/FjaaAgencyService.cs deleted file mode 100644 index ba996a165..000000000 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/FjaaAgencyService.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using SFA.DAS.CommitmentsV2.Types; -using SFA.DAS.EmployerCommitmentsV2.Services.Approvals; -using SFA.DAS.EmployerCommitmentsV2.Services.Approvals.Responses; - -namespace SFA.DAS.EmployerCommitmentsV2.Web.Services -{ - public class FjaaAgencyService : IFjaaAgencyService - { - private readonly IApprovalsApiClient _approvalsApiClient; - - public FjaaAgencyService(IApprovalsApiClient approvalsApiClient) - { - _approvalsApiClient = approvalsApiClient; - } - - public async Task AgencyExists(int legalEntityId) - { - GetAgencyResponse agency = null; - - if (legalEntityId > 0) - { - agency = await _approvalsApiClient.GetAgency(legalEntityId); - - if (agency != null) - { - return true; - } - } - - return false; - } - - public Task> AssignDeliveryModels(List models, bool agencyExists) - { - bool portable = models.Contains(DeliveryModel.PortableFlexiJob) ? true : false; - - if (agencyExists && !portable) { models.Remove(DeliveryModel.PortableFlexiJob); } - if (agencyExists && portable) { models.Remove(DeliveryModel.PortableFlexiJob); } - if (!agencyExists && portable) { models.Remove(DeliveryModel.FlexiJobAgency); } - if (!agencyExists && !portable) { models.Remove(DeliveryModel.PortableFlexiJob); models.Remove(DeliveryModel.FlexiJobAgency); } - - return Task.FromResult(models); - } - } -} \ No newline at end of file diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/IFjaaAgencyService.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/IFjaaAgencyService.cs deleted file mode 100644 index 7162d2b5f..000000000 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Services/IFjaaAgencyService.cs +++ /dev/null @@ -1,13 +0,0 @@ -using SFA.DAS.CommitmentsV2.Types; -using SFA.DAS.EmployerCommitmentsV2.Web.Models.Agency; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace SFA.DAS.EmployerCommitmentsV2.Web.Services -{ - public interface IFjaaAgencyService - { - Task AgencyExists(int legalEntityId); - Task> AssignDeliveryModels(List models, bool agencyExists); - } -} diff --git a/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/ApprovalsApiClient.cs b/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/ApprovalsApiClient.cs index f39421538..fd09cbfb4 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/ApprovalsApiClient.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/ApprovalsApiClient.cs @@ -19,15 +19,9 @@ public async Task GetPledgeApplication(int pledgeA return await _client.Get($"PledgeApplications/{pledgeApplicationId}", null, cancellationToken); } - public async Task GetProviderCourseDeliveryModels(long providerId, string courseCode, CancellationToken cancellationToken = default) + public async Task GetProviderCourseDeliveryModels(long providerId, string courseCode, int legalEntityId, CancellationToken cancellationToken = default) { - return await _client.Get($"Providers/{providerId}/courses/{courseCode}", null, cancellationToken); + return await _client.Get($"Providers/{providerId}/courses/{courseCode}?legalEntityId={legalEntityId}", null, cancellationToken); } - - public async Task GetAgency(int legalEntityId, CancellationToken cancellationToken = default) - { - return await _client.Get($"rofjaa/agency/{legalEntityId}", null, cancellationToken); - } - } } diff --git a/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/IApprovalsApiClient.cs b/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/IApprovalsApiClient.cs index 482fe76bc..d2e2f65ed 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/IApprovalsApiClient.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/IApprovalsApiClient.cs @@ -7,8 +7,6 @@ namespace SFA.DAS.EmployerCommitmentsV2.Services.Approvals public interface IApprovalsApiClient { Task GetPledgeApplication(int pledgeApplicationId, CancellationToken cancellationToken = default); - Task GetProviderCourseDeliveryModels(long providerId, string courseCode, CancellationToken cancellationToken = default); - Task GetAgency(int legalEntityId, CancellationToken cancellationToken = default); - + Task GetProviderCourseDeliveryModels(long providerId, string courseCode, int legalEntityId = 0, CancellationToken cancellationToken = default); } } From cc3e08aacfe2b6e95cef1d9737ccc15037cb6418 Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Mon, 20 Jun 2022 08:40:27 +0100 Subject: [PATCH 15/24] Updates --- .../CommitmentsOuterApiBuilder.cs | 2 +- ...lToSelectDeliveryModelViewModelMapperTests.cs | 6 +++++- ...equestToSelectDeliveryModelViewModelMapper.cs | 3 +-- ...wModelToSelectDeliveryModelViewModelMapper.cs | 16 +++++++++++++--- ...equestToSelectDeliveryModelViewModelMapper.cs | 4 +--- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Api.FakeServers/CommitmentsOuterApiBuilder.cs b/src/SFA.DAS.EmployerCommitmentsV2.Api.FakeServers/CommitmentsOuterApiBuilder.cs index f7ce88ef3..0bce052d9 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Api.FakeServers/CommitmentsOuterApiBuilder.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Api.FakeServers/CommitmentsOuterApiBuilder.cs @@ -35,7 +35,7 @@ internal CommitmentsOuterApiBuilder WithCourseDeliveryModels() .WithHeader("Content-Type", "application/json") .WithBodyAsJson(new { - DeliveryModels = new[] { "Regular", "PortableFlexiJob", "FlexiJobAgency" }, + DeliveryModels = new[] { "Regular", "PortableFlexiJob"}, })); _server diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapperTests.cs index acaa4acc8..724e525aa 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapperTests.cs @@ -5,6 +5,7 @@ using AutoFixture; using Moq; using NUnit.Framework; +using SFA.DAS.Authorization.Services; using SFA.DAS.CommitmentsV2.Api.Client; using SFA.DAS.CommitmentsV2.Api.Types.Responses; using SFA.DAS.CommitmentsV2.Shared.Models; @@ -29,6 +30,7 @@ public class EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMap private List _standardTrainingProgrammes; private List _allTrainingProgrammes; private ProviderCourseDeliveryModels _providerCourseDeliveryModels; + private Mock _authorizationService; private SelectDeliveryModelViewModel _result; private long _cohortId; private int _legalEntityId; @@ -85,7 +87,9 @@ public async Task Arrange() _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_getCohortResponse.ProviderId.Value, _source.CourseCode, _legalEntityId, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); - _mapper = new EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper(_commitmentsApiClient.Object, _approvalsApiClient.Object); + _authorizationService = new Mock(); + + _mapper = new EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper(_commitmentsApiClient.Object, _approvalsApiClient.Object, _authorizationService.Object); _result = await _mapper.Map(TestHelper.Clone(_source)); } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs index c71e0f36c..1da916a23 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs @@ -30,7 +30,6 @@ public async Task Map(ApprenticeRequest source) } var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(source.ProviderId, source.CourseCode, legalEntityId); - var deliveryModels = response.DeliveryModels.ToList(); return new SelectDeliveryModelViewModel { @@ -39,7 +38,7 @@ public async Task Map(ApprenticeRequest source) AccountLegalEntityHashedId = source.AccountLegalEntityHashedId, CourseCode = source.CourseCode, DeliveryModel = source.DeliveryModel, - DeliveryModels = deliveryModels.ToArray(), + DeliveryModels = response.DeliveryModels.ToArray(), ProviderId = source.ProviderId, ReservationId = source.ReservationId, StartMonthYear = source.StartMonthYear, diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper.cs index 093bb4d56..a741f0cad 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper.cs @@ -1,7 +1,9 @@ using System.Linq; using System.Threading.Tasks; +using SFA.DAS.Authorization.Services; using SFA.DAS.CommitmentsV2.Api.Client; using SFA.DAS.CommitmentsV2.Shared.Interfaces; +using SFA.DAS.EmployerCommitmentsV2.Features; using SFA.DAS.EmployerCommitmentsV2.Services.Approvals; using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; using SFA.DAS.EmployerCommitmentsV2.Web.Models.Shared; @@ -12,16 +14,24 @@ public class EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMap { private readonly ICommitmentsApiClient _commitmentsApiClient; private readonly IApprovalsApiClient _approvalsApiClient; + private readonly IAuthorizationService _authorizationService; - public EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper(ICommitmentsApiClient commitmentsApiClient, IApprovalsApiClient approvalsApiClient) - => (_commitmentsApiClient, _approvalsApiClient) = (commitmentsApiClient, approvalsApiClient); + public EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper(ICommitmentsApiClient commitmentsApiClient, IApprovalsApiClient approvalsApiClient, IAuthorizationService authorizationService) + => (_commitmentsApiClient, _approvalsApiClient, _authorizationService) = (commitmentsApiClient, approvalsApiClient, authorizationService); public async Task Map(EditApprenticeshipRequestViewModel source) { var apprenticeship = await _commitmentsApiClient.GetApprenticeship(source.ApprenticeshipId); var cohort = await _commitmentsApiClient.GetCohort(apprenticeship.CohortId); - var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode); + int legalEntityId = 0; + + if (_authorizationService.IsAuthorized(EmployerFeature.FJAA)) + { + legalEntityId = (int)cohort.AccountLegalEntityId; + } + + var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode, legalEntityId); return new SelectDeliveryModelViewModel { diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs index 46cf6ca42..320de0eef 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs @@ -35,8 +35,6 @@ public async Task Map(AddDraftApprenticeshipReques var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode, legalEntityId); - var deliveryModels = response.DeliveryModels.ToList(); - return new SelectDeliveryModelViewModel { AccountHashedId = source.AccountHashedId, @@ -46,7 +44,7 @@ public async Task Map(AddDraftApprenticeshipReques CohortReference = source.CohortReference, CourseCode = source.CourseCode, DeliveryModel = source.DeliveryModel, - DeliveryModels = deliveryModels.ToArray(), + DeliveryModels = response.DeliveryModels.ToArray(), ProviderId = source.ProviderId, ReservationId = source.ReservationId, StartMonthYear = source.StartMonthYear, From 2ab05151f9ed57ac0930aa232de50b88eee51819 Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Mon, 20 Jun 2022 12:54:45 +0100 Subject: [PATCH 16/24] Updated to use APIM to yield legalEntityId --- ...tViewModelToSelectDeliveryModelViewModelMapperTests.cs | 8 +++++--- ...iceRequestToSelectDeliveryModelViewModelMapperTests.cs | 6 +++++- ...hipRequestToSelectDeliveryModelViewModelMapperTests.cs | 8 +++++--- ...prenticeRequestToSelectDeliveryModelViewModelMapper.cs | 8 +++++--- ...equestViewModelToSelectDeliveryModelViewModelMapper.cs | 8 +++++--- ...ticeshipRequestToSelectDeliveryModelViewModelMapper.cs | 8 +++++--- .../Services/Approvals/IApprovalsApiClient.cs | 2 +- 7 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapperTests.cs index 724e525aa..f2c0be2da 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapperTests.cs @@ -33,7 +33,8 @@ public class EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMap private Mock _authorizationService; private SelectDeliveryModelViewModel _result; private long _cohortId; - private int _legalEntityId; + private long _accountLegalEntityId; + private string _encodedAccountId; private Fixture _autoFixture; [SetUp] @@ -41,7 +42,8 @@ public async Task Arrange() { _autoFixture = new Fixture(); _cohortId = _autoFixture.Create(); - _legalEntityId = _autoFixture.Create(); + _accountLegalEntityId = _autoFixture.Create(); + _encodedAccountId = _autoFixture.Create(); _standardTrainingProgrammes = _autoFixture.CreateMany().ToList(); _allTrainingProgrammes = _autoFixture.CreateMany().ToList(); @@ -84,7 +86,7 @@ public async Task Arrange() }); _approvalsApiClient = new Mock(); - _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_getCohortResponse.ProviderId.Value, _source.CourseCode, _legalEntityId, + _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_getCohortResponse.ProviderId.Value, _source.CourseCode, _encodedAccountId, _accountLegalEntityId, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); _authorizationService = new Mock(); diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs index 19e9d439e..93756cfd9 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs @@ -26,6 +26,8 @@ public class ApprenticeRequestToSelectDeliveryModelViewModelMapperTests private int _agencyId; private int _legalEntityId; private string _courseCode; + private long _accountLegalEntityId; + private string _encodedAccountId; private SelectDeliveryModelViewModel _result; [SetUp] @@ -37,6 +39,8 @@ public async Task Arrange() _courseCode = autoFixture.Create(); _agencyId = autoFixture.Create(); _legalEntityId = autoFixture.Create(); + _accountLegalEntityId = autoFixture.Create(); + _encodedAccountId = autoFixture.Create(); _source = autoFixture.Build() .With(x => x.StartMonthYear, "062020") @@ -50,7 +54,7 @@ public async Task Arrange() _providerCourseDeliveryModels = autoFixture.Create(); _approvalsApiClient = new Mock(); - _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, _legalEntityId, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); + _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, _encodedAccountId, _accountLegalEntityId, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); _authService = new Mock(); diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs index b3d4d84ba..82d94a5db 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs @@ -30,7 +30,8 @@ public class AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTe private string _courseCode; private long _cohortId; private int _agencyId; - private int _legalEntityId; + private long _accountLegalEntityId; + private string _encodedAccountId; private SelectDeliveryModelViewModel _result; [SetUp] @@ -42,7 +43,8 @@ public async Task Arrange() _courseCode = autoFixture.Create(); _cohortId = autoFixture.Create(); _agencyId = autoFixture.Create(); - _legalEntityId = autoFixture.Create(); + _accountLegalEntityId = autoFixture.Create(); + _encodedAccountId = autoFixture.Create(); _source = autoFixture.Build() .With(x => x.StartMonthYear, "062020") @@ -67,7 +69,7 @@ public async Task Arrange() _providerCourseDeliveryModels = autoFixture.Create(); _approvalsApiClient = new Mock(); - _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, _legalEntityId, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); + _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, _encodedAccountId, _accountLegalEntityId, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); _authService = new Mock(); diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs index 1da916a23..28ac67fe9 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs @@ -22,14 +22,16 @@ public ApprenticeRequestToSelectDeliveryModelViewModelMapper(IApprovalsApiClient public async Task Map(ApprenticeRequest source) { - int legalEntityId = 0; + long accountLegalEntityId = 0; + string encodedAccountId = string.Empty; if (_authorizationService.IsAuthorized(EmployerFeature.FJAA)) { - legalEntityId = (int)source.AccountLegalEntityId; + accountLegalEntityId = source.AccountLegalEntityId; + encodedAccountId = source.AccountHashedId; } - var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(source.ProviderId, source.CourseCode, legalEntityId); + var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(source.ProviderId, source.CourseCode, encodedAccountId, accountLegalEntityId); return new SelectDeliveryModelViewModel { diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper.cs index a741f0cad..58281d5c7 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper.cs @@ -24,14 +24,16 @@ public async Task Map(EditApprenticeshipRequestVie var apprenticeship = await _commitmentsApiClient.GetApprenticeship(source.ApprenticeshipId); var cohort = await _commitmentsApiClient.GetCohort(apprenticeship.CohortId); - int legalEntityId = 0; + long accountLegalEntityId = 0; + string encodedAccountId = string.Empty; if (_authorizationService.IsAuthorized(EmployerFeature.FJAA)) { - legalEntityId = (int)cohort.AccountLegalEntityId; + accountLegalEntityId = cohort.AccountLegalEntityId; + encodedAccountId = source.AccountHashedId; } - var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode, legalEntityId); + var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode, encodedAccountId, accountLegalEntityId); return new SelectDeliveryModelViewModel { diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs index 320de0eef..7bd6ff2e6 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs @@ -24,16 +24,18 @@ public AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(ICommit public async Task Map(AddDraftApprenticeshipRequest source) { - int legalEntityId = 0; + long accountLegalEntityId = 0; + string encodedAccountId = string.Empty; if (_authorizationService.IsAuthorized(EmployerFeature.FJAA)) { - legalEntityId = (int)source.AccountLegalEntityId; + accountLegalEntityId = source.AccountLegalEntityId; + encodedAccountId = source.AccountHashedId; } var cohort = await _commitmentsApiClient.GetCohort(source.CohortId); - var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode, legalEntityId); + var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode, encodedAccountId, accountLegalEntityId); return new SelectDeliveryModelViewModel { diff --git a/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/IApprovalsApiClient.cs b/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/IApprovalsApiClient.cs index d2e2f65ed..707789d6f 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/IApprovalsApiClient.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/IApprovalsApiClient.cs @@ -7,6 +7,6 @@ namespace SFA.DAS.EmployerCommitmentsV2.Services.Approvals public interface IApprovalsApiClient { Task GetPledgeApplication(int pledgeApplicationId, CancellationToken cancellationToken = default); - Task GetProviderCourseDeliveryModels(long providerId, string courseCode, int legalEntityId = 0, CancellationToken cancellationToken = default); + Task GetProviderCourseDeliveryModels(long providerId, string courseCode, string encodedAccountId, long accountLegalEntityId = 0, CancellationToken cancellationToken = default); } } From 188c5e8ebfb54abf65aeed444111546e2be23677 Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Mon, 20 Jun 2022 13:11:19 +0100 Subject: [PATCH 17/24] Update ApprovalsApiClient.cs --- .../Services/Approvals/ApprovalsApiClient.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/ApprovalsApiClient.cs b/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/ApprovalsApiClient.cs index fd09cbfb4..ffbb091b8 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/ApprovalsApiClient.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/ApprovalsApiClient.cs @@ -19,9 +19,9 @@ public async Task GetPledgeApplication(int pledgeA return await _client.Get($"PledgeApplications/{pledgeApplicationId}", null, cancellationToken); } - public async Task GetProviderCourseDeliveryModels(long providerId, string courseCode, int legalEntityId, CancellationToken cancellationToken = default) + public async Task GetProviderCourseDeliveryModels(long providerId, string courseCode, string encodedAccountId, long accountLegalEntityId = 0, CancellationToken cancellationToken = default) { - return await _client.Get($"Providers/{providerId}/courses/{courseCode}?legalEntityId={legalEntityId}", null, cancellationToken); + return await _client.Get($"Providers/{providerId}/courses/{courseCode}?encodedAccountId={encodedAccountId}&accountLegalEntityId={accountLegalEntityId}", null, cancellationToken); } } } From d96a30a9d130a53046bd858af619100489f7e94e Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Tue, 21 Jun 2022 10:58:52 +0100 Subject: [PATCH 18/24] Typo --- .../Views/Cohort/Details.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Cohort/Details.cshtml b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Cohort/Details.cshtml index 211480b99..33a34de99 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Cohort/Details.cshtml +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Cohort/Details.cshtml @@ -81,7 +81,7 @@ } @if (@course.DeliveryModel == DeliveryModel.FlexiJobAgency) { - Flexi Job Agency + Flexi-Job Agency } @foreach (var draftApprenticeship in course.DraftApprenticeships) From e27ec0a9e0c6000758f2c008ad93ebaed13260d5 Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Tue, 21 Jun 2022 14:12:27 +0100 Subject: [PATCH 19/24] Updates to suit APIM endpoint controller params --- ...estViewModelToSelectDeliveryModelViewModelMapperTests.cs | 2 +- ...nticeRequestToSelectDeliveryModelViewModelMapperTests.cs | 2 +- ...eshipRequestToSelectDeliveryModelViewModelMapperTests.cs | 2 +- ...ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs | 4 +--- ...pRequestViewModelToSelectDeliveryModelViewModelMapper.cs | 4 +--- ...enticeshipRequestToSelectDeliveryModelViewModelMapper.cs | 4 +--- .../Services/Approvals/ApprovalsApiClient.cs | 6 ++++-- .../Services/Approvals/IApprovalsApiClient.cs | 2 +- 8 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapperTests.cs index f2c0be2da..60c13e885 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapperTests.cs @@ -86,7 +86,7 @@ public async Task Arrange() }); _approvalsApiClient = new Mock(); - _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_getCohortResponse.ProviderId.Value, _source.CourseCode, _encodedAccountId, _accountLegalEntityId, + _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_getCohortResponse.ProviderId.Value, _source.CourseCode, _accountLegalEntityId, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); _authorizationService = new Mock(); diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs index 93756cfd9..9801ba380 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs @@ -54,7 +54,7 @@ public async Task Arrange() _providerCourseDeliveryModels = autoFixture.Create(); _approvalsApiClient = new Mock(); - _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, _encodedAccountId, _accountLegalEntityId, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); + _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, _accountLegalEntityId, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); _authService = new Mock(); diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs index 82d94a5db..8b43c7417 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs @@ -69,7 +69,7 @@ public async Task Arrange() _providerCourseDeliveryModels = autoFixture.Create(); _approvalsApiClient = new Mock(); - _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, _encodedAccountId, _accountLegalEntityId, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); + _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, _accountLegalEntityId, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); _authService = new Mock(); diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs index 28ac67fe9..aacc09987 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs @@ -23,15 +23,13 @@ public ApprenticeRequestToSelectDeliveryModelViewModelMapper(IApprovalsApiClient public async Task Map(ApprenticeRequest source) { long accountLegalEntityId = 0; - string encodedAccountId = string.Empty; if (_authorizationService.IsAuthorized(EmployerFeature.FJAA)) { accountLegalEntityId = source.AccountLegalEntityId; - encodedAccountId = source.AccountHashedId; } - var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(source.ProviderId, source.CourseCode, encodedAccountId, accountLegalEntityId); + var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(source.ProviderId, source.CourseCode, accountLegalEntityId); return new SelectDeliveryModelViewModel { diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper.cs index 58281d5c7..97fd0edf9 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper.cs @@ -25,15 +25,13 @@ public async Task Map(EditApprenticeshipRequestVie var cohort = await _commitmentsApiClient.GetCohort(apprenticeship.CohortId); long accountLegalEntityId = 0; - string encodedAccountId = string.Empty; if (_authorizationService.IsAuthorized(EmployerFeature.FJAA)) { accountLegalEntityId = cohort.AccountLegalEntityId; - encodedAccountId = source.AccountHashedId; } - var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode, encodedAccountId, accountLegalEntityId); + var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode, accountLegalEntityId); return new SelectDeliveryModelViewModel { diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs index 7bd6ff2e6..1bfb65d64 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs @@ -25,17 +25,15 @@ public AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(ICommit public async Task Map(AddDraftApprenticeshipRequest source) { long accountLegalEntityId = 0; - string encodedAccountId = string.Empty; if (_authorizationService.IsAuthorized(EmployerFeature.FJAA)) { accountLegalEntityId = source.AccountLegalEntityId; - encodedAccountId = source.AccountHashedId; } var cohort = await _commitmentsApiClient.GetCohort(source.CohortId); - var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode, encodedAccountId, accountLegalEntityId); + var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode, accountLegalEntityId); return new SelectDeliveryModelViewModel { diff --git a/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/ApprovalsApiClient.cs b/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/ApprovalsApiClient.cs index ffbb091b8..dfe879eb3 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/ApprovalsApiClient.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/ApprovalsApiClient.cs @@ -3,6 +3,8 @@ using System.Threading; using System.Threading.Tasks; + + namespace SFA.DAS.EmployerCommitmentsV2.Services.Approvals { public class ApprovalsApiClient : IApprovalsApiClient @@ -19,9 +21,9 @@ public async Task GetPledgeApplication(int pledgeA return await _client.Get($"PledgeApplications/{pledgeApplicationId}", null, cancellationToken); } - public async Task GetProviderCourseDeliveryModels(long providerId, string courseCode, string encodedAccountId, long accountLegalEntityId = 0, CancellationToken cancellationToken = default) + public async Task GetProviderCourseDeliveryModels(long providerId, string courseCode, long accountLegalEntityId = 0, CancellationToken cancellationToken = default) { - return await _client.Get($"Providers/{providerId}/courses/{courseCode}?encodedAccountId={encodedAccountId}&accountLegalEntityId={accountLegalEntityId}", null, cancellationToken); + return await _client.Get($"Providers/{providerId}/courses/{courseCode}?accountLegalEntityId={accountLegalEntityId}", null, cancellationToken); } } } diff --git a/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/IApprovalsApiClient.cs b/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/IApprovalsApiClient.cs index 707789d6f..f48d05fb2 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/IApprovalsApiClient.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/IApprovalsApiClient.cs @@ -7,6 +7,6 @@ namespace SFA.DAS.EmployerCommitmentsV2.Services.Approvals public interface IApprovalsApiClient { Task GetPledgeApplication(int pledgeApplicationId, CancellationToken cancellationToken = default); - Task GetProviderCourseDeliveryModels(long providerId, string courseCode, string encodedAccountId, long accountLegalEntityId = 0, CancellationToken cancellationToken = default); + Task GetProviderCourseDeliveryModels(long providerId, string courseCode, long accountLegalEntityId = 0, CancellationToken cancellationToken = default); } } From ab1450d600f79d223fa79d0ed5a32d4315531920 Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Thu, 23 Jun 2022 12:03:04 +0100 Subject: [PATCH 20/24] Delete GetAgencyResponse.cs --- .../Services/Approvals/Responses/GetAgencyResponse.cs | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/Responses/GetAgencyResponse.cs diff --git a/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/Responses/GetAgencyResponse.cs b/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/Responses/GetAgencyResponse.cs deleted file mode 100644 index a2c43eb9b..000000000 --- a/src/SFA.DAS.EmployerCommitmentsV2/Services/Approvals/Responses/GetAgencyResponse.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace SFA.DAS.EmployerCommitmentsV2.Services.Approvals.Responses -{ - public class GetAgencyResponse - { - public int LegalEntityId { get; set; } - } -} \ No newline at end of file From 149aa0f1d64bf3c0b638593728eddaa5607d17dc Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Thu, 23 Jun 2022 13:56:17 +0100 Subject: [PATCH 21/24] Tech review tweaks --- .../Models/Agency/Agency.cs | 7 - .../SFA.DAS.EmployerCommitmentsV2.Web.csproj | 2 - .../ConfirmEditApprenticeship.cshtml | 2 +- .../Views/Cohort/Details.cshtml | 247 +++++++++--------- 4 files changed, 123 insertions(+), 135 deletions(-) delete mode 100644 src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Agency/Agency.cs diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Agency/Agency.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Agency/Agency.cs deleted file mode 100644 index 75f9dcac5..000000000 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Agency/Agency.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace SFA.DAS.EmployerCommitmentsV2.Web.Models.Agency -{ - public class Agency - { - public int LegalEntityId { get; set; } - } -} \ No newline at end of file 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 6d3ead994..ea57edd9f 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/SFA.DAS.EmployerCommitmentsV2.Web.csproj +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/SFA.DAS.EmployerCommitmentsV2.Web.csproj @@ -41,11 +41,9 @@ - - diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Apprentice/ConfirmEditApprenticeship.cshtml b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Apprentice/ConfirmEditApprenticeship.cshtml index dbae865de..757ac0635 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Apprentice/ConfirmEditApprenticeship.cshtml +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Apprentice/ConfirmEditApprenticeship.cshtml @@ -56,7 +56,7 @@
Unique learner number
@Model.OriginalApprenticeship.ULN
- @if (Model.OriginalApprenticeship.DeliveryModel == DeliveryModel.PortableFlexiJob || Model.OriginalApprenticeship.DeliveryModel == DeliveryModel.FlexiJobAgency) + @if (Model.OriginalApprenticeship.DeliveryModel != DeliveryModel.Regular) {
Apprenticeship delivery model
diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Cohort/Details.cshtml b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Cohort/Details.cshtml index 33a34de99..865fb0f6a 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Cohort/Details.cshtml +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Cohort/Details.cshtml @@ -3,6 +3,7 @@ @using SFA.DAS.CommitmentsV2.Types @using SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort @using SFA.DAS.EmployerCommitmentsV2.Web.Models.DraftApprenticeship +@using SFA.DAS.EmployerCommitmentsV2.Web.Extensions @model SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort.DetailsViewModel @{ @@ -75,137 +76,133 @@ {

@course.Count x @course.DisplayCourseName - @if (@course.DeliveryModel == DeliveryModel.PortableFlexiJob) + @if (@course.DeliveryModel != DeliveryModel.Regular) { - Portable flexi job - } - @if (@course.DeliveryModel == DeliveryModel.FlexiJobAgency) - { - Flexi-Job Agency + @course.DeliveryModel.ToDescription() }

- @foreach (var draftApprenticeship in course.DraftApprenticeships) - { - if (draftApprenticeship.HasOverlappingUln && !course.ErrorHasOverlappingUlnDisplayed) - { -
-

Apprenticeship can't have overlapping training dates

-

- You must update training dates to be able to approve -

-
- course.ErrorHasOverlappingUlnDisplayed = true; - } - if (draftApprenticeship.HasOverlappingEmail && !course.ErrorEmailOverlapsDisplayed) - { -
-

@course.EmailOverlaps.DisplayEmailOverlapsMessage

-

- You must enter a unique email address for each apprentice. -

-
- course.ErrorEmailOverlapsDisplayed = true; - } - if (!draftApprenticeship.IsComplete && !course.ErrorIsCompletedDisplayed) - { -
-

Apprentice record incomplete

-

- You must complete the apprentice record to be able to approve -

-
- course.ErrorIsCompletedDisplayed = true; - } - if (draftApprenticeship.ExceedsFundingBandCap && !course.ErrorFundingBandExcessDisplayed) - { -
-

@course.FundingBandExcess.FundingBandCapExcessHeader

-

- @course.FundingBandExcess.FundingBandCapExcessLabel - funding band maximum@course.FundingBandExcess.DisplaySingleFundingBandCap - You'll need to pay the difference directly to the training provider. -

-
- course.ErrorFundingBandExcessDisplayed = true; - } - } - - - - - - - - - - - - - - - @foreach (var draftApprenticeship in course.DraftApprenticeships) { - - - - - - - - - + if (draftApprenticeship.HasOverlappingUln && !course.ErrorHasOverlappingUlnDisplayed) + { +
+

Apprenticeship can't have overlapping training dates

+

+ You must update training dates to be able to approve +

+
+ course.ErrorHasOverlappingUlnDisplayed = true; + } + if (draftApprenticeship.HasOverlappingEmail && !course.ErrorEmailOverlapsDisplayed) + { +
+

@course.EmailOverlaps.DisplayEmailOverlapsMessage

+

+ You must enter a unique email address for each apprentice. +

+
+ course.ErrorEmailOverlapsDisplayed = true; + } + if (!draftApprenticeship.IsComplete && !course.ErrorIsCompletedDisplayed) + { +
+

Apprentice record incomplete

+

+ You must complete the apprentice record to be able to approve +

+
+ course.ErrorIsCompletedDisplayed = true; + } + if (draftApprenticeship.ExceedsFundingBandCap && !course.ErrorFundingBandExcessDisplayed) + { +
+

@course.FundingBandExcess.FundingBandCapExcessHeader

+

+ @course.FundingBandExcess.FundingBandCapExcessLabel + funding band maximum@course.FundingBandExcess.DisplaySingleFundingBandCap + You'll need to pay the difference directly to the training provider. +

+
+ course.ErrorFundingBandExcessDisplayed = true; + } } - -
NameDate of birthTraining datesEmployment end dateTraining price for this employmentTotal training pricePriceAction
- @if (draftApprenticeship.HasOverlappingEmail || !draftApprenticeship.IsComplete) - { - @draftApprenticeship.DisplayName - } - else - { - @draftApprenticeship.DisplayName - } - @draftApprenticeship.DisplayDateOfBirth - @if (draftApprenticeship.HasOverlappingUln) - { - - @draftApprenticeship.DisplayTrainingDates - - } - else - { - @draftApprenticeship.DisplayTrainingDates - } - - @draftApprenticeship.DisplayEmploymentDates - - @draftApprenticeship.DisplayEmploymentPrice - - @if (@draftApprenticeship.ExceedsFundingBandCap) - { - - @draftApprenticeship.DisplayCost - - } - else - { - @draftApprenticeship.DisplayCost - } - - - @(Model.IsReadOnly ? "View" : "Edit") - @draftApprenticeship.DisplayName's details - -

- @if (!Model.IsReadOnly) - { - - Delete @draftApprenticeship.DisplayName's details - - } -
-} + + + + + + + + + + + + + + + + @foreach (var draftApprenticeship in course.DraftApprenticeships) + { + + + + + + + + + + } + +
NameDate of birthTraining datesEmployment end dateTraining price for this employmentTotal training pricePriceAction
+ @if (draftApprenticeship.HasOverlappingEmail || !draftApprenticeship.IsComplete) + { + @draftApprenticeship.DisplayName + } + else + { + @draftApprenticeship.DisplayName + } + @draftApprenticeship.DisplayDateOfBirth + @if (draftApprenticeship.HasOverlappingUln) + { + + @draftApprenticeship.DisplayTrainingDates + + } + else + { + @draftApprenticeship.DisplayTrainingDates + } + + @draftApprenticeship.DisplayEmploymentDates + + @draftApprenticeship.DisplayEmploymentPrice + + @if (@draftApprenticeship.ExceedsFundingBandCap) + { + + @draftApprenticeship.DisplayCost + + } + else + { + @draftApprenticeship.DisplayCost + } + + + @(Model.IsReadOnly ? "View" : "Edit") + @draftApprenticeship.DisplayName's details + +

+ @if (!Model.IsReadOnly) + { + + Delete @draftApprenticeship.DisplayName's details + + } +
+ } From 0efb7966fdd85cdbba5b6d44a28f4fc1b4356fe2 Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Fri, 24 Jun 2022 09:36:22 +0100 Subject: [PATCH 22/24] Removal of feature in favour of new env toggle implemented in APIM --- ...renticeRequestToSelectDeliveryModelViewModelMapper.cs | 9 +-------- ...questViewModelToSelectDeliveryModelViewModelMapper.cs | 9 +-------- ...iceshipRequestToSelectDeliveryModelViewModelMapper.cs | 9 +-------- .../Features/EmployerFeature.cs | 1 - 4 files changed, 3 insertions(+), 25 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs index aacc09987..ad8f3b086 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs @@ -22,14 +22,7 @@ public ApprenticeRequestToSelectDeliveryModelViewModelMapper(IApprovalsApiClient public async Task Map(ApprenticeRequest source) { - long accountLegalEntityId = 0; - - if (_authorizationService.IsAuthorized(EmployerFeature.FJAA)) - { - accountLegalEntityId = source.AccountLegalEntityId; - } - - var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(source.ProviderId, source.CourseCode, accountLegalEntityId); + var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(source.ProviderId, source.CourseCode, source.AccountLegalEntityId); return new SelectDeliveryModelViewModel { diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper.cs index 97fd0edf9..498e76bb1 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper.cs @@ -24,14 +24,7 @@ public async Task Map(EditApprenticeshipRequestVie var apprenticeship = await _commitmentsApiClient.GetApprenticeship(source.ApprenticeshipId); var cohort = await _commitmentsApiClient.GetCohort(apprenticeship.CohortId); - long accountLegalEntityId = 0; - - if (_authorizationService.IsAuthorized(EmployerFeature.FJAA)) - { - accountLegalEntityId = cohort.AccountLegalEntityId; - } - - var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode, accountLegalEntityId); + var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode, cohort.AccountLegalEntityId); return new SelectDeliveryModelViewModel { diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs index 1bfb65d64..c24f80e33 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs @@ -24,16 +24,9 @@ public AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(ICommit public async Task Map(AddDraftApprenticeshipRequest source) { - long accountLegalEntityId = 0; - - if (_authorizationService.IsAuthorized(EmployerFeature.FJAA)) - { - accountLegalEntityId = source.AccountLegalEntityId; - } - var cohort = await _commitmentsApiClient.GetCohort(source.CohortId); - var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode, accountLegalEntityId); + var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(cohort.ProviderId.HasValue ? cohort.ProviderId.Value : 0, source.CourseCode, source.AccountLegalEntityId); return new SelectDeliveryModelViewModel { diff --git a/src/SFA.DAS.EmployerCommitmentsV2/Features/EmployerFeature.cs b/src/SFA.DAS.EmployerCommitmentsV2/Features/EmployerFeature.cs index 468499470..bc0e5430c 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2/Features/EmployerFeature.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2/Features/EmployerFeature.cs @@ -6,6 +6,5 @@ public static class EmployerFeature public const string ManageApprenticesV2 = Prefix + "ManageApprenticesV2"; public const string DeliveryModel = Prefix + "DeliveryModel"; - public const string FJAA = Prefix + "FJAA"; } } \ No newline at end of file From 82cfaff95d1588efc4d97d1295405b68760f19a0 Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Mon, 27 Jun 2022 09:56:41 +0100 Subject: [PATCH 23/24] Fix tests! --- ...ToSelectDeliveryModelViewModelMapperTests.cs | 17 +++++++---------- ...ToSelectDeliveryModelViewModelMapperTests.cs | 11 ++--------- ...ToSelectDeliveryModelViewModelMapperTests.cs | 8 ++------ ...itDraftApprenticeshipViewModelMapperTests.cs | 2 -- ...questToSelectDeliveryModelViewModelMapper.cs | 5 ++--- ...ModelToSelectDeliveryModelViewModelMapper.cs | 5 ++--- ...questToSelectDeliveryModelViewModelMapper.cs | 5 ++--- 7 files changed, 17 insertions(+), 36 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapperTests.cs index 60c13e885..971a322b1 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapperTests.cs @@ -30,11 +30,9 @@ public class EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMap private List _standardTrainingProgrammes; private List _allTrainingProgrammes; private ProviderCourseDeliveryModels _providerCourseDeliveryModels; - private Mock _authorizationService; private SelectDeliveryModelViewModel _result; private long _cohortId; private long _accountLegalEntityId; - private string _encodedAccountId; private Fixture _autoFixture; [SetUp] @@ -43,7 +41,6 @@ public async Task Arrange() _autoFixture = new Fixture(); _cohortId = _autoFixture.Create(); _accountLegalEntityId = _autoFixture.Create(); - _encodedAccountId = _autoFixture.Create(); _standardTrainingProgrammes = _autoFixture.CreateMany().ToList(); _allTrainingProgrammes = _autoFixture.CreateMany().ToList(); @@ -51,19 +48,21 @@ public async Task Arrange() _getApprenticeshipResponse = _autoFixture.Build() .With(x => x.CohortId, _cohortId) + .With(x => x.AccountLegalEntityId, _accountLegalEntityId) .Create(); _getCohortResponse = _autoFixture.Build() .With(x => x.LevyStatus, ApprenticeshipEmployerType.Levy) .With(x => x.WithParty, Party.Employer) + .With(x => x.AccountLegalEntityId, _accountLegalEntityId) .Without(x => x.TransferSenderId) .Create(); _source = _autoFixture.Build() - .With(x=>x.DateOfBirth, new DateModel()) - .With(x=>x.StartDate, new MonthYearModel("")) - .With(x=>x.EndDate, new MonthYearModel("")) - .With(x=>x.EmploymentEndDate, new MonthYearModel("")) + .With(x => x.DateOfBirth, new DateModel()) + .With(x => x.StartDate, new MonthYearModel("")) + .With(x => x.EndDate, new MonthYearModel("")) + .With(x => x.EmploymentEndDate, new MonthYearModel("")) .With(x => x.DeliveryModel, DeliveryModel.PortableFlexiJob) .Create(); @@ -89,9 +88,7 @@ public async Task Arrange() _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_getCohortResponse.ProviderId.Value, _source.CourseCode, _accountLegalEntityId, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); - _authorizationService = new Mock(); - - _mapper = new EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper(_commitmentsApiClient.Object, _approvalsApiClient.Object, _authorizationService.Object); + _mapper = new EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper(_commitmentsApiClient.Object, _approvalsApiClient.Object); _result = await _mapper.Map(TestHelper.Clone(_source)); } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs index 9801ba380..7b79ea2fc 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapperTests.cs @@ -23,11 +23,8 @@ public class ApprenticeRequestToSelectDeliveryModelViewModelMapperTests private Mock _authService; private ProviderCourseDeliveryModels _providerCourseDeliveryModels; private long _providerId; - private int _agencyId; - private int _legalEntityId; private string _courseCode; private long _accountLegalEntityId; - private string _encodedAccountId; private SelectDeliveryModelViewModel _result; [SetUp] @@ -37,16 +34,14 @@ public async Task Arrange() _providerId = autoFixture.Create(); _courseCode = autoFixture.Create(); - _agencyId = autoFixture.Create(); - _legalEntityId = autoFixture.Create(); _accountLegalEntityId = autoFixture.Create(); - _encodedAccountId = autoFixture.Create(); _source = autoFixture.Build() .With(x => x.StartMonthYear, "062020") .With(x => x.AccountId, 12345) .With(x => x.CourseCode, "Course1") .With(x => x.ProviderId, _providerId) + .With(x => x.AccountLegalEntityId, _accountLegalEntityId) .With(x => x.CourseCode, _courseCode) .With(x => x.DeliveryModel, DeliveryModel.PortableFlexiJob) .Without(x => x.TransferSenderId).Create(); @@ -56,9 +51,7 @@ public async Task Arrange() _approvalsApiClient = new Mock(); _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, _accountLegalEntityId, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); - _authService = new Mock(); - - _mapper = new ApprenticeRequestToSelectDeliveryModelViewModelMapper(_approvalsApiClient.Object, _authService.Object); + _mapper = new ApprenticeRequestToSelectDeliveryModelViewModelMapper(_approvalsApiClient.Object); _result = await _mapper.Map(TestHelper.Clone(_source)); } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs index 8b43c7417..221077290 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTests.cs @@ -29,9 +29,7 @@ public class AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapperTe private long _providerId; private string _courseCode; private long _cohortId; - private int _agencyId; private long _accountLegalEntityId; - private string _encodedAccountId; private SelectDeliveryModelViewModel _result; [SetUp] @@ -42,15 +40,14 @@ public async Task Arrange() _providerId = autoFixture.Create(); _courseCode = autoFixture.Create(); _cohortId = autoFixture.Create(); - _agencyId = autoFixture.Create(); _accountLegalEntityId = autoFixture.Create(); - _encodedAccountId = autoFixture.Create(); _source = autoFixture.Build() .With(x => x.StartMonthYear, "062020") .With(x => x.CourseCode, "Course1") .With(x => x.ProviderId, _providerId) .With(x => x.CourseCode, _courseCode) + .With(x => x.AccountLegalEntityId, _accountLegalEntityId) .With(x => x.CohortId, _cohortId) .With(x => x.DeliveryModel, DeliveryModel.PortableFlexiJob) .Create(); @@ -71,9 +68,8 @@ public async Task Arrange() _approvalsApiClient = new Mock(); _approvalsApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, _accountLegalEntityId, It.IsAny())).ReturnsAsync(_providerCourseDeliveryModels); - _authService = new Mock(); + _mapper = new AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(_commitmentsApiClient.Object, _approvalsApiClient.Object); - _mapper = new AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(_commitmentsApiClient.Object, _approvalsApiClient.Object, _authService.Object); _result = await _mapper.Map(TestHelper.Clone(_source)); } 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 6c8da7649..c1ff740c8 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/DraftApprenticeship/EditDraftApprenticeshipViewModelMapperTests.cs @@ -28,7 +28,6 @@ public class EditDraftApprenticeshipViewModelMapperTests private Mock _encodingService; private string _encodedApprenticeshipId; private string _cohortReference; - private int _agencyId; private GetCohortResponse _cohort; private List _allTrainingProgrammes; private List _standardTrainingProgrammes; @@ -42,7 +41,6 @@ public async Task Arrange() _standardTrainingProgrammes = autoFixture.CreateMany().ToList(); _encodedApprenticeshipId = autoFixture.Create(); _cohortReference = autoFixture.Create(); - _agencyId = autoFixture.Create(); _encodingService = new Mock(); _encodingService diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs index ad8f3b086..4f5bfeb29 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/ApprenticeRequestToSelectDeliveryModelViewModelMapper.cs @@ -15,10 +15,9 @@ namespace SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Cohort public class ApprenticeRequestToSelectDeliveryModelViewModelMapper : IMapper { private readonly IApprovalsApiClient _approvalsApiClient; - private readonly IAuthorizationService _authorizationService; - public ApprenticeRequestToSelectDeliveryModelViewModelMapper(IApprovalsApiClient approvalsApiClient, IAuthorizationService authorizationService) - => (_approvalsApiClient, _authorizationService) = (approvalsApiClient, authorizationService); + public ApprenticeRequestToSelectDeliveryModelViewModelMapper(IApprovalsApiClient approvalsApiClient) + => (_approvalsApiClient) = (approvalsApiClient); public async Task Map(ApprenticeRequest source) { diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper.cs index 498e76bb1..f66fbf2c5 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Cohort/EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper.cs @@ -14,10 +14,9 @@ public class EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMap { private readonly ICommitmentsApiClient _commitmentsApiClient; private readonly IApprovalsApiClient _approvalsApiClient; - private readonly IAuthorizationService _authorizationService; - public EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper(ICommitmentsApiClient commitmentsApiClient, IApprovalsApiClient approvalsApiClient, IAuthorizationService authorizationService) - => (_commitmentsApiClient, _approvalsApiClient, _authorizationService) = (commitmentsApiClient, approvalsApiClient, authorizationService); + public EditApprenticeshipRequestViewModelToSelectDeliveryModelViewModelMapper(ICommitmentsApiClient commitmentsApiClient, IApprovalsApiClient approvalsApiClient) + => (_commitmentsApiClient, _approvalsApiClient) = (commitmentsApiClient, approvalsApiClient); public async Task Map(EditApprenticeshipRequestViewModel source) { diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs index c24f80e33..adc56997b 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/DraftApprenticeship/AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper.cs @@ -17,10 +17,9 @@ public class AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper : { private readonly ICommitmentsApiClient _commitmentsApiClient; private readonly IApprovalsApiClient _approvalsApiClient; - private readonly IAuthorizationService _authorizationService; - public AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(ICommitmentsApiClient commitmentsApiClient, IApprovalsApiClient approvalsApiClient, IAuthorizationService authorizationService) - => (_commitmentsApiClient, _approvalsApiClient, _authorizationService) = (commitmentsApiClient, approvalsApiClient, authorizationService); + public AddDraftApprenticeshipRequestToSelectDeliveryModelViewModelMapper(ICommitmentsApiClient commitmentsApiClient, IApprovalsApiClient approvalsApiClient) + => (_commitmentsApiClient, _approvalsApiClient) = (commitmentsApiClient, approvalsApiClient); public async Task Map(AddDraftApprenticeshipRequest source) { From 9c17421915cc25ac1b195f7138d967db0065108c Mon Sep 17 00:00:00 2001 From: Alasdair Reid Date: Mon, 27 Jun 2022 10:03:56 +0100 Subject: [PATCH 24/24] Update DetailsViewModelMapperTests.cs --- .../Cohort/DetailsViewModelMapperTests.cs | 18 ------------------ 1 file changed, 18 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 3f1773375..7a8ccaaf6 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/DetailsViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/DetailsViewModelMapperTests.cs @@ -556,24 +556,6 @@ public async Task EmailOverlapIsMappedCorrectlyToDraftApprenticeshipAndToSummary Assert.AreEqual(apprenticeshipId, course.DraftApprenticeships.First(x => x.HasOverlappingEmail).Id); } - [Test] - public async Task EmailOverlapIsMappedCorrectlyToDraftApprenticeshipsAndToSummaryLineWhenTwoEmailOverlapsExistOnSameCourse() - { - var f = new DetailsViewModelMapperTestsFixture().WithTwoEmailOverlappingOnSameCourse(); - var apprenticeshipId1 = f.EmailOverlapResponse.ApprenticeshipEmailOverlaps.First().Id; - var apprenticeshipId2 = f.EmailOverlapResponse.ApprenticeshipEmailOverlaps.Last().Id; - - var result = await f.Map(); - var course = result.Courses.FirstOrDefault(); - - Assert.NotNull(course); - Assert.NotNull(course.EmailOverlaps); - Assert.AreEqual(2, course.EmailOverlaps.NumberOfEmailOverlaps); - Assert.AreEqual(2, course.DraftApprenticeships.Count(x => x.HasOverlappingEmail)); - Assert.IsTrue(course.DraftApprenticeships.First(x => x.Id == apprenticeshipId1).HasOverlappingEmail); - Assert.IsTrue(course.DraftApprenticeships.First(x => x.Id == apprenticeshipId2).HasOverlappingEmail); - } - [TestCase(true, true)] [TestCase(false, false)] public async Task ShowHasOverlappingUlnIsMappedCorrectlyWhenOverlap(bool hasOverlap, bool hasUlnOverlap)