Skip to content

Commit

Permalink
Merge pull request #322 from SkillsFundingAgency/PA-372-show-delivery…
Browse files Browse the repository at this point in the history
…-model-when-multiple-exist

PA-372 Added support to show DeliveryModel link if there are multiple
  • Loading branch information
SreekanthBadigenchula authored Jul 25, 2022
2 parents c1cb712 + 5fae534 commit 3663ebf
Show file tree
Hide file tree
Showing 15 changed files with 194 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice;
using SFA.DAS.Encoding;
using static SFA.DAS.CommitmentsV2.Api.Types.Responses.GetPriceEpisodesResponse;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Apprentice
Expand Down Expand Up @@ -380,6 +381,26 @@ public async Task IsEndDateLockedForUpdate_Is_Mapped(ApprenticeshipStatus status
Assert.AreEqual(expectedIsEndDateLockedForUpdate, viewModel.IsEndDateLockedForUpdate);
}

[Test]
public async Task ProviderId_IsMapped()
{
//Act
await _fixture.Map();

//Assert
_fixture.VerifyProviderIdIsMapped();
}

[Test]
public async Task AccountLegalEntityId_IsMapped()
{
//Act
await _fixture.Map();

//Assert
_fixture.VerifyAccountLegalEntityIdIsMapped();
}

}

public class EditApprenticeshipRequestToViewModelMapperTestsFixture
Expand All @@ -389,6 +410,7 @@ public class EditApprenticeshipRequestToViewModelMapperTestsFixture
private Mock<ICommitmentsApiClient> _mockCommitmentsApiClient;
private Mock<IAcademicYearDateProvider> _mockAcademicYearDateProvider;
private Mock<ICurrentDateTime> _mockCurrentDateTimeProvider;
private Mock<IEncodingService> _mockEncodingService;

private GetPriceEpisodesResponse _priceEpisodesResponse;
private GetCohortResponse _cohortResponse;
Expand Down Expand Up @@ -655,7 +677,22 @@ public EditApprenticeshipRequestToViewModelMapperTestsFixture()

_mockCurrentDateTimeProvider = new Mock<ICurrentDateTime>();

_mapper = new EditApprenticeshipRequestToViewModelMapper(_mockCommitmentsApiClient.Object, _mockAcademicYearDateProvider.Object, _mockCurrentDateTimeProvider.Object);
_mockEncodingService = new Mock<IEncodingService>();
_mockEncodingService.Setup(x => x.Encode(It.IsAny<long>(), EncodingType.PublicAccountLegalEntityId))
.Returns("ALEID");

_mapper = new EditApprenticeshipRequestToViewModelMapper(_mockCommitmentsApiClient.Object, _mockAcademicYearDateProvider.Object, _mockCurrentDateTimeProvider.Object, _mockEncodingService.Object);
}

internal void VerifyProviderIdIsMapped()
{
Assert.AreEqual(ApprenticeshipResponse.ProviderId, _viewModel.ProviderId);
}

internal void VerifyAccountLegalEntityIdIsMapped()
{
Assert.AreEqual("ALEID", _viewModel.AccountLegalEntityHashedId);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class EditDraftApprenticeshipViewModelMapperTests
private Mock<IEncodingService> _encodingService;
private string _encodedApprenticeshipId;
private string _cohortReference;
private string _aleHashedId;
private GetCohortResponse _cohort;
private List<TrainingProgramme> _allTrainingProgrammes;
private List<TrainingProgramme> _standardTrainingProgrammes;
Expand All @@ -41,6 +42,7 @@ public async Task Arrange()
_standardTrainingProgrammes = autoFixture.CreateMany<TrainingProgramme>().ToList();
_encodedApprenticeshipId = autoFixture.Create<string>();
_cohortReference = autoFixture.Create<string>();
_aleHashedId = autoFixture.Create<string>();

_encodingService = new Mock<IEncodingService>();
_encodingService
Expand All @@ -49,6 +51,9 @@ public async Task Arrange()
_encodingService
.Setup(x => x.Encode(It.IsAny<long>(), It.Is<EncodingType>(e => e == EncodingType.CohortReference)))
.Returns(_cohortReference);
_encodingService
.Setup(x => x.Encode(It.IsAny<long>(), EncodingType.PublicAccountLegalEntityId))
.Returns(_aleHashedId);

_draftApprenticeshipResponse = autoFixture.Create<GetDraftApprenticeshipResponse>();
_draftApprenticeshipResponse.IsContinuation = false;
Expand Down Expand Up @@ -203,6 +208,12 @@ public void ProviderNameIsMappedCorrectly()
Assert.AreEqual(_cohort.ProviderName, _result.ProviderName);
}

[Test]
public void ProviderIdsMappedCorrectly()
{
Assert.AreEqual(_cohort.ProviderId, _result.ProviderId);
}

[Test]
public void LegalEntityNameIsMappedCorrectly()
{
Expand Down Expand Up @@ -255,5 +266,17 @@ public async Task ThenIsContinuationIsMappedCorrectly(bool isContinuation)
_result = await _mapper.Map(_source) as EditDraftApprenticeshipViewModel;
Assert.AreEqual(_draftApprenticeshipResponse.IsContinuation, _result.IsContinuation);
}

[Test]
public void AccountLegalEntityIdIsMappedCorrectly()
{
Assert.AreEqual(_source.Cohort.AccountLegalEntityId, _result.AccountLegalEntityId);
}

[Test]
public void AccountLegalEntityHashedIdIsMappedCorrectly()
{
Assert.AreEqual(_aleHashedId, _result.AccountLegalEntityHashedId);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using AutoFixture;
using Moq;
using NUnit.Framework;
using SFA.DAS.EmployerCommitmentsV2.Web.Services;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerCommitmentsV2.Services.Approvals;
using SFA.DAS.EmployerCommitmentsV2.Services.Approvals.Responses;
using SFA.DAS.Encoding;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Service
{
[TestFixture]
public class DeliveryModelServiceTests
{
private DeliveryModelService _mapper;
private Mock<IApprovalsApiClient> _outerApiClient;
private Mock<IEncodingService> _encodingService;
private ProviderCourseDeliveryModels _response;
private long _providerId;
private string _courseCode;

[SetUp]
public void Arrange()
{
var fixture = new Fixture();
_providerId = fixture.Create<long>();
_courseCode = fixture.Create<string>();
_response = fixture.Create<ProviderCourseDeliveryModels>();

_outerApiClient = new Mock<IApprovalsApiClient>();
_outerApiClient.Setup(x => x.GetProviderCourseDeliveryModels(_providerId, _courseCode, 1234, It.IsAny<CancellationToken>())).ReturnsAsync(_response);
_encodingService = new Mock<IEncodingService>();
_encodingService.Setup(x => x.Decode(It.IsAny<string>(), EncodingType.PublicAccountLegalEntityId))
.Returns(1234);

_mapper = new DeliveryModelService(_outerApiClient.Object, _encodingService.Object);
}

[Test]
public async Task ThenReturnsTrueWhenMultipleDeliveryModelsExist()
{
var result = await _mapper.HasMultipleDeliveryModels(_providerId, _courseCode, "ALEID");
Assert.IsTrue(result);
}

[Test]
public async Task ThenReturnsFalseWhenMultipleDeliveryModelsDoNotExist()
{
_response.DeliveryModels = new List<DeliveryModel> { DeliveryModel.Regular };
var result = await _mapper.HasMultipleDeliveryModels(_providerId, _courseCode, "ALEID");
Assert.IsFalse(result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using SFA.DAS.Encoding;

namespace SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice
{
Expand All @@ -15,12 +16,14 @@ public class EditApprenticeshipRequestToViewModelMapper : IMapper<EditApprentice
private readonly ICommitmentsApiClient _commitmentsApiClient;
private readonly IAcademicYearDateProvider _academicYearDateProvider;
private readonly ICurrentDateTime _currentDateTime;
private readonly IEncodingService _encodingService;

public EditApprenticeshipRequestToViewModelMapper(ICommitmentsApiClient commitmentsApiClient, IAcademicYearDateProvider academicYearDateProvider, ICurrentDateTime currentDateTime)
public EditApprenticeshipRequestToViewModelMapper(ICommitmentsApiClient commitmentsApiClient, IAcademicYearDateProvider academicYearDateProvider, ICurrentDateTime currentDateTime, IEncodingService encodingService)
{
_commitmentsApiClient = commitmentsApiClient;
_academicYearDateProvider = academicYearDateProvider;
_currentDateTime = currentDateTime;
_encodingService = encodingService;
}
public async Task<EditApprenticeshipRequestViewModel> Map(EditApprenticeshipRequest source)
{
Expand Down Expand Up @@ -69,7 +72,9 @@ public async Task<EditApprenticeshipRequestViewModel> Map(EditApprenticeshipRequ
AccountHashedId = source.AccountHashedId,
EmailAddressConfirmedByApprentice = apprenticeship.EmailAddressConfirmedByApprentice,
EmailShouldBePresent = apprenticeship.EmailShouldBePresent,
EmploymentPrice = apprenticeship.EmploymentPrice
EmploymentPrice = apprenticeship.EmploymentPrice,
ProviderId = apprenticeship.ProviderId,
AccountLegalEntityHashedId = _encodingService.Encode(apprenticeship.AccountLegalEntityId, EncodingType.PublicAccountLegalEntityId)
};

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ public async Task<IDraftApprenticeshipViewModel> Map(EditDraftApprenticeshipRequ
EmploymentEndYear = draftApprenticeship.EmploymentEndDate.HasValue ? draftApprenticeship.EmploymentEndDate.Value.Year : (int?)null,
Reference = draftApprenticeship.Reference,
AccountHashedId = source.Request.AccountHashedId,
ProviderId = source.Cohort.ProviderId.Value,
ProviderName = cohort.ProviderName,
LegalEntityName = source.Cohort.LegalEntityName,
IsContinuation = draftApprenticeship.IsContinuation,
Courses = (cohort.IsFundedByTransfer || cohort.LevyStatus == ApprenticeshipEmployerType.NonLevy) && !draftApprenticeship.IsContinuation
? (await _commitmentsApiClient.GetAllTrainingProgrammeStandards()).TrainingProgrammes
: (await _commitmentsApiClient.GetAllTrainingProgrammes()).TrainingProgrammes
: (await _commitmentsApiClient.GetAllTrainingProgrammes()).TrainingProgrammes,
AccountLegalEntityId = cohort.AccountLegalEntityId,
AccountLegalEntityHashedId = _encodingService.Encode(cohort.AccountLegalEntityId, EncodingType.PublicAccountLegalEntityId)
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,7 @@ public EditApprenticeshipRequestViewModel(DateTime? dateOfBirth, DateTime? start
[SuppressArgumentException(nameof(EmploymentEndDate), "The employment end date is not valid")]
public int? EmploymentEndYear { get => EmploymentEndDate.Year; set => EmploymentEndDate.Year = value; }

public long ProviderId { get; set; }
public string AccountLegalEntityHashedId { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ public class ApprenticeViewModel : DraftApprenticeshipViewModel, IAuthorizationC
{
public long AccountId { get; set; }
public string AccountHashedId { get; set; }

public long AccountLegalEntityId { get; set; }
public string AccountLegalEntityHashedId { get; set; }
public string LegalEntityName { get; set; }
public string TransferSenderId { get; set; }
public long? DecodedTransferSenderId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ public class AddDraftApprenticeshipViewModel : DraftApprenticeshipViewModel, IAu
public long AccountId { get; set; }
public string AccountHashedId { get; set; }

public long AccountLegalEntityId { get; set; }
public string AccountLegalEntityHashedId { get; set; }
public string LegalEntityName { get; set; }
public string TransferSenderHashedId { get; set; }
public bool AutoCreatedReservation { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using SFA.DAS.Authorization.ModelBinding;
using SFA.DAS.CommitmentsV2.Shared.Models;
using SFA.DAS.EmployerCommitmentsV2.Web.Attributes;
using SFA.DAS.CommitmentsV2.Types;

namespace SFA.DAS.EmployerCommitmentsV2.Web.Models.Shared
{
public class DraftApprenticeshipViewModel
public class DraftApprenticeshipViewModel : IAuthorizationContextModel
{
public DraftApprenticeshipViewModel(DateTime? dateOfBirth, DateTime? startDate, DateTime? endDate, DateTime? employmentEndDate = null) : base()
{
Expand Down Expand Up @@ -114,5 +115,7 @@ public DraftApprenticeshipViewModel()
public IEnumerable<TrainingProgramme> Courses { get; set; }

public bool IsContinuation { get; set; }
public long AccountLegalEntityId { get; set; }
public string AccountLegalEntityHashedId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Linq;
using System.Threading.Tasks;
using SFA.DAS.EmployerCommitmentsV2.Services.Approvals;
using SFA.DAS.Encoding;

namespace SFA.DAS.EmployerCommitmentsV2.Web.Services
{
public class DeliveryModelService : IDeliveryModelService
{
private readonly IEncodingService _encodingService;
private readonly IApprovalsApiClient _approvalsApiClient;

public DeliveryModelService(IApprovalsApiClient approvalsApiClient, IEncodingService encodingService)
{
_encodingService = encodingService;
_approvalsApiClient = approvalsApiClient;
}

public async Task<bool> HasMultipleDeliveryModels(long providerId, string courseCode, string accountLegalEntity)
{
var aleId = _encodingService.Decode(accountLegalEntity, EncodingType.PublicAccountLegalEntityId);

var response = await _approvalsApiClient.GetProviderCourseDeliveryModels(providerId, courseCode, aleId);
return (response?.DeliveryModels.Count() > 1);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Threading.Tasks;

namespace SFA.DAS.EmployerCommitmentsV2.Web.Services
{
public interface IDeliveryModelService
{
Task<bool> HasMultipleDeliveryModels(long providerId, string courseCode, string accountLegalEntity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
@using SFA.DAS.EmployerCommitmentsV2.Web.Extensions
@using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice
@using SFA.DAS.CommitmentsV2.Api.Client
@using SFA.DAS.EmployerCommitmentsV2.Web.Services
@inject SFA.DAS.Authorization.Services.IAuthorizationService AuthorizationService
@inject ICommitmentsApiClient CommitmentsApiClient
@inject IDeliveryModelService DeliveryModelService


@model SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice.EditApprenticeshipRequestViewModel

Expand All @@ -13,8 +16,9 @@
ViewBag.Section = "apprentices";
ViewBag.PageId = "edit-apprentices-detail";
ViewBag.GaData.Vpv = "/accounts/apprentices/manage/edit-apprentice-details";
var multipleDeliveryModels = await DeliveryModelService.HasMultipleDeliveryModels(Model.ProviderId, Model.CourseCode, Model.AccountLegalEntityHashedId);

Model.Cost = (int?) Model.Cost;
Model.Cost = (int?)Model.Cost;
Model.CourseCode = ViewData.ModelState[nameof(Model.CourseCode)]?.AttemptedValue ?? Model.CourseCode;
Model.DeliveryModel = ViewData.ModelState[nameof(Model.DeliveryModel)]?.AttemptedValue.ToEnum<DeliveryModel>() ?? Model.DeliveryModel;
}
Expand All @@ -32,6 +36,8 @@
@Html.HiddenFor(x => x.Version)
@Html.HiddenFor(x => x.Option)
@Html.HiddenFor(x => x.EmailShouldBePresent)
@Html.HiddenFor(x => x.ProviderId)
@Html.HiddenFor(x => x.AccountLegalEntityHashedId)

@if (Model.IsContinuation)
{
Expand Down Expand Up @@ -152,7 +158,7 @@
<dd class="das-definition-list__definition" id="uln">@Model.ULN</dd>
@Html.HiddenFor(x => x.ULN)
</dl>

@if (Model.IsLockedForUpdate || Model.IsUpdateLockedForStartDateAndCourse || Model.IsContinuation)
{
<hr class="govuk-section-break govuk-section-break--visible govuk-!-margin-top-6 govuk-!-margin-bottom-6" />
Expand All @@ -168,12 +174,12 @@
<dl class="das-definition-list">
<dt asp-for="DeliveryModel" class="das-definition-list__title">Apprenticeship delivery model</dt>
<dd class="das-definition-list__definition" id="trainingName">@Model.DeliveryModel.ToDescription()</dd>
</dl>
</dl>
}
@Html.HiddenFor(x => x.DeliveryModel)
}
else
{
{
@if (AuthorizationService.IsAuthorized(SFA.DAS.EmployerCommitmentsV2.Features.EmployerFeature.DeliveryModel))
{
if (!string.IsNullOrWhiteSpace(Model.CourseCode))
Expand All @@ -193,7 +199,7 @@
</div>
<input type="hidden" asp-for="CourseCode" class="govuk-radios__input" value="@Model.CourseCode">

if (Model.DeliveryModel != DeliveryModel.Regular)
if (multipleDeliveryModels)
{
<div class="govuk-form-group">
<p class="govuk-!-font-weight-bold govuk-!-margin-bottom-0">Delivery model</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

<form id="addApprenticeship" novalidate method="post">
@Html.AntiForgeryToken()
@Html.HiddenFor(x => x.ProviderId)
@Html.HiddenFor(x => x.AccountLegalEntityHashedId)
@Html.HiddenFor(x => x.TransferSenderId)
@Html.HiddenFor(x => x.Origin)
@Html.HiddenFor(x => x.EncodedPledgeApplicationId)
Expand Down
Loading

0 comments on commit 3663ebf

Please sign in to comment.