Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APPMAN-1019 LTM transfers #536

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,17 @@ public async Task When_Calling_GetSelectDirectTransferConnections_Then_The_Data_

actual.Should().BeSameAs(response);
}

[Test, AutoData]
public async Task When_Calling_GetSelectLevyTransferConnections_Then_The_Data_Is_Returned(long accountId, GetSelectLevyTransferConnectionResponse response)
{
var outerApiClient = new Mock<IOuterApiClient>();
var expectedUrl = $"{accountId}/unapproved/add/select-funding/select-accepted-levy-connection";
outerApiClient.Setup(x => x.Get<GetSelectLevyTransferConnectionResponse>(expectedUrl)).ReturnsAsync(response);
var approvalsApiClient = new ApprovalsApiClient(outerApiClient.Object);

var actual = await approvalsApiClient.GetSelectLevyTransferConnection(accountId);

actual.Should().BeSameAs(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using FluentAssertions;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.EmployerCommitmentsV2.Web.Controllers;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort;
using SFA.DAS.Testing.AutoFixture;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.CohortControllerTests;

[TestFixture]
public class WhenGettingSelectAcceptedLevyConnections
{
[Test, MoqAutoData]
public async Task WithSelectAcceptedLevyTransfersThenReturnsView(
BaseSelectProviderRequest request,
SelectAcceptedLevyTransferConnectionViewModel viewModel,
[Frozen] Mock<IModelMapper> mockMapper,
[Greedy] CohortController controller)
{
mockMapper
.Setup(mapper => mapper.Map<SelectAcceptedLevyTransferConnectionViewModel>(request))
.ReturnsAsync(viewModel);

var result = await controller.SelectAcceptedLevyTransferConnection(request) as ViewResult;

result.Should().NotBeNull();
result.Model.Should().Be(viewModel);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using FluentAssertions;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.EmployerCommitmentsV2.Web.Controllers;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort;
using SFA.DAS.Testing.AutoFixture;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.CohortControllerTests;

[TestFixture]
public class WhenGettingSelectDirectConnections
{
[Test, MoqAutoData]
public async Task WithSelectDirectTransfersThenReturnsView(
BaseSelectProviderRequest request,
SelectTransferConnectionViewModel viewModel,
[Frozen] Mock<IModelMapper> mockMapper,
[Greedy] CohortController controller)
{
mockMapper
.Setup(mapper => mapper.Map<SelectTransferConnectionViewModel>(request))
.ReturnsAsync(viewModel);

var result = await controller.SelectDirectTransferConnection(request) as ViewResult;

result.Should().NotBeNull();
result.Model.Should().Be(viewModel);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using FluentAssertions;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.EmployerCommitmentsV2.Contracts;
using SFA.DAS.EmployerCommitmentsV2.Interfaces;
using SFA.DAS.EmployerCommitmentsV2.Web.Controllers;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort;
using SFA.DAS.EmployerUrlHelper;
using SFA.DAS.Encoding;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.CohortControllerTests;

[TestFixture]
public class WhenPostingSelectFunding
{
private CohortController _controller;
private SelectFundingViewModel _model;

[SetUp]
public void Arrange()
{
var autoFixture = new Fixture();
_model = autoFixture.Create<SelectFundingViewModel>();

_controller = new CohortController(Mock.Of<ICommitmentsApiClient>(),
Mock.Of<ILogger<CohortController>>(),
Mock.Of<ILinkGenerator>(),
Mock.Of<IModelMapper>(),
Mock.Of<IEncodingService>(),
Mock.Of<IApprovalsApiClient>(),
Mock.Of<ICacheStorageService>());
}

[TearDown]
public void TearDown() => _controller?.Dispose();

[TestCase(FundingType.AdditionalReservations)]
[TestCase(FundingType.UnallocatedReservations)]
[TestCase(FundingType.CurrentLevy)]
public async Task And_This_Funding_Option_Is_Selected_Then_User_Is_Redirected_To_SelectProvider_Page(FundingType fundingType)
{
_model.FundingType = fundingType;
//Act
var result = await _controller.SetFundingType(_model);

//Assert
var redirectToActionResult = result as RedirectToActionResult;
redirectToActionResult.ActionName.Should().Be("SelectProvider");
}

[Test]
public async Task And_DirectTransfers_Is_Selected_Then_User_Is_Redirected_To_SelectDirectTransferConnection_Page()
{
_model.FundingType = FundingType.DirectTransfers;
//Act
var result = await _controller.SetFundingType(_model);

//Assert
var redirectToActionResult = result as RedirectToActionResult;
redirectToActionResult.ActionName.Should().Be("SelectDirectTransferConnection");
}

[Test]
public async Task And_LtmTransfers_Is_Selected_Then_User_Is_Redirected_To_SelectLtmTransfers_Page()
{
_model.FundingType = FundingType.LtmTransfers;
//Act
var result = await _controller.SetFundingType(_model);

//Assert
var redirectToActionResult = result as RedirectToActionResult;
redirectToActionResult.ActionName.Should().Be("SelectAcceptedLevyTransferConnection");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using FluentAssertions;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.EmployerCommitmentsV2.Contracts;
using SFA.DAS.EmployerCommitmentsV2.Interfaces;
using SFA.DAS.EmployerCommitmentsV2.Web.Controllers;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort;
using SFA.DAS.EmployerUrlHelper;
using SFA.DAS.Encoding;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.CohortControllerTests;

[TestFixture]
public class WhenPostingSelectLevyConnection
{
private CohortController _controller;
private SelectAcceptedLevyTransferConnectionViewModel _model;

[SetUp]
public void Arrange()
{
var autoFixture = new Fixture();
_model = autoFixture.Create<SelectAcceptedLevyTransferConnectionViewModel>();

foreach (var app in _model.Applications)
{
app.ApplicationAndSenderHashedId = app.ApplicationHashedId + "|" + app.SendingEmployerPublicHashedId;
}

_model.ApplicationAndSenderHashedId = _model.Applications.First().ApplicationAndSenderHashedId;

_controller = new CohortController(Mock.Of<ICommitmentsApiClient>(),
Mock.Of<ILogger<CohortController>>(),
Mock.Of<ILinkGenerator>(),
Mock.Of<IModelMapper>(),
Mock.Of<IEncodingService>(),
Mock.Of<IApprovalsApiClient>(),
Mock.Of<ICacheStorageService>());
}

[TearDown]
public void TearDown() => _controller?.Dispose();

[Test]
public async Task Then_User_Is_Redirected_To_SelectProvider_Page()
{
//Act
var result = _controller.SelectAcceptedLevyTransferConnection(_model);

//Assert
var redirectToActionResult = result as RedirectToActionResult;
redirectToActionResult.ActionName.Should().Be("SelectProvider");
}

[Test]
public async Task Then_Verify_RouteValues()
{
//Act
var result = _controller.SelectAcceptedLevyTransferConnection(_model);
var ids = _model.ApplicationAndSenderHashedId.Split("|");

//Assert
var redirectToActionResult = result as RedirectToActionResult;
redirectToActionResult.RouteValues["AccountHashedId"].Should().Be(_model.AccountHashedId);
redirectToActionResult.RouteValues["EncodedPledgeApplicationId"].Should().Be(ids[0]);
redirectToActionResult.RouteValues["TransferSenderId"].Should().Be(ids[1]);
redirectToActionResult.RouteValues["AccountLegalEntityHashedId"].Should().Be(_model.AccountLegalEntityHashedId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,10 @@ public void HasAdditionalReservationFundsAvailableIsMappedCorrectly()
{
_result.HasAdditionalReservationFundsAvailable.Should().Be(_fundingOptionsResponse.HasAdditionalReservationFundsAvailable);
}

[Test]
public void HasLtmTransfersAvailableIsMappedCorrectly()
{
_result.HasLtmTransfersAvailable.Should().Be(_fundingOptionsResponse.HasLtmTransfersAvailable);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using FluentAssertions;
using SFA.DAS.EmployerCommitmentsV2.Contracts;
using SFA.DAS.EmployerCommitmentsV2.Services.Approvals.Responses;
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Cohort;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort;
using SFA.DAS.Encoding;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Cohort;

[TestFixture]
public class WhenMappingBaseSelectProviderRequestToLevyConnectionViewModelTests
{
private Mock<IApprovalsApiClient> _approvalsApiClient;
private Mock<IEncodingService> _encodingService;
private BaseSelectProviderRequestToSelectAcceptedLevyTransferConnectionViewModelMapper _mapper;
private BaseSelectProviderRequest _request;
private GetSelectLevyTransferConnectionResponse _response;

[SetUp]
public void Arrange()
{
var autoFixture = new Fixture();
_approvalsApiClient = new Mock<IApprovalsApiClient>();
_encodingService = new Mock<IEncodingService>();
_request = autoFixture.Create<BaseSelectProviderRequest>();
_response = autoFixture.Create<GetSelectLevyTransferConnectionResponse>();

_approvalsApiClient.Setup(x => x.GetSelectLevyTransferConnection(_request.AccountId, CancellationToken.None))
.ReturnsAsync(_response);
_encodingService.Setup(x => x.Encode(It.IsAny<long>(), EncodingType.PledgeApplicationId)).Returns((long input, EncodingType _) => input.ToString() + "AppId");
_encodingService.Setup(x => x.Encode(It.IsAny<long>(), EncodingType.PledgeId)).Returns((long input, EncodingType _) => input.ToString() + "PledgeId");
_encodingService.Setup(x => x.Encode(It.IsAny<long>(), EncodingType.PublicAccountId)).Returns((long input, EncodingType _) => input.ToString() + "PublicId");

_mapper = new BaseSelectProviderRequestToSelectAcceptedLevyTransferConnectionViewModelMapper(_approvalsApiClient.Object, _encodingService.Object);
}

[Test]
public async Task Then_AccountId_Is_Mapped()
{
//Act
var result = await _mapper.Map(_request);

//Assert
_approvalsApiClient.Verify(x => x.GetSelectLevyTransferConnection(_request.AccountId, CancellationToken.None));
}

[Test]
public async Task Then_AccountHashedId_Is_Mapped()
{
//Act
var result = await _mapper.Map(_request);

//Assert
result.AccountHashedId.Should().Be(_request.AccountHashedId);
}

[Test]
public async Task Then_List_Of_Applications_Is_Mapped()
{
//Act
var result = await _mapper.Map(_request);

//Assert
result.Applications.Should().BeEquivalentTo(_response.Applications.Select(x => new LevyTransferDisplayConnection()
{
Id = x.Id,
ApplicationHashedId = x.Id + "AppId",
SendingEmployerPublicHashedId = x.SenderEmployerAccountId + "PublicId",
OpportunityHashedId = x.OpportunityId + "PledgeId",
ApplicationAndSenderHashedId = x.Id + "AppId" + "|" + x.SenderEmployerAccountId + "PublicId",
DisplayName = (x.IsNamePublic ? x.SenderEmployerAccountName : "Opportunity") + $" ({x.OpportunityId + "PledgeId"}) - £{x.TotalAmount.ToString("N")}"
}));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort;
using SFA.DAS.EmployerCommitmentsV2.Web.Validators;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Validators;

public class SelectAcceptedLevyTransferConnectionViewModelValidatorTests : ValidatorTestBase<SelectAcceptedLevyTransferConnectionViewModel, SelectAcceptedLevyTransferConnectionViewModelValidator>
{
[Test]
[InlineAutoData("5143541", true)]
[InlineAutoData(" ", false)]
[InlineAutoData("", false)]
[InlineAutoData(null, false)]
public void WhenValidatingSelectAcceptedLevyTransferConnection_ValidateTheAccountHashedId(string accountHashedId, bool expectedValid, SelectAcceptedLevyTransferConnectionViewModel viewModel)
{
//Arrange
viewModel.AccountHashedId = accountHashedId;

//Assert
AssertValidationResult(x => x.AccountHashedId, viewModel, expectedValid);
}

[Test]
[InlineAutoData(" ", false, "Select a transfer")]
[InlineAutoData("", false, "Select a transfer")]
public void WhenValidatingSelectTransferConnection_ValidateTransferConnectionCode(string selectedCode, bool expectedValid, string errorMessage, SelectAcceptedLevyTransferConnectionViewModel viewModel)
{
//Arrange
viewModel.ApplicationAndSenderHashedId = selectedCode;

//Assert
AssertValidationResult(x => x.ApplicationAndSenderHashedId, viewModel, expectedValid, errorMessage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,12 @@ public async Task<ActionResult> SetFundingType(SelectFundingViewModel selectedFu
FundingType = selectedFunding.FundingType
};

if (selectedFunding.FundingType == FundingType.DirectTransfers)
return selectedFunding.FundingType switch
{
return RedirectToAction("SelectDirectTransferConnection", redirectRequest);
}
return RedirectToAction("SelectProvider", redirectRequest);
FundingType.DirectTransfers => RedirectToAction("SelectDirectTransferConnection", redirectRequest),
FundingType.LtmTransfers => RedirectToAction("SelectAcceptedLevyTransferConnection", redirectRequest),
_ => RedirectToAction("SelectProvider", redirectRequest)
};
}

[HttpGet]
Expand All @@ -594,6 +595,31 @@ public ActionResult SelectDirectTransferConnection(SelectTransferConnectionViewM
});
}

[HttpGet]
[Route("add/select-funding/select-accepted-levy-connection")]
public async Task<IActionResult> SelectAcceptedLevyTransferConnection(BaseSelectProviderRequest request)
{
var viewModel = await _modelMapper.Map<SelectAcceptedLevyTransferConnectionViewModel>(request);

return View(viewModel);
}

[HttpPost]
[Route("add/select-funding/select-accepted-levy-connection")]
public ActionResult SelectAcceptedLevyTransferConnection(SelectAcceptedLevyTransferConnectionViewModel selectedLevyTransferConnection)
{
var ids = selectedLevyTransferConnection.ApplicationAndSenderHashedId.Split('|');

return RedirectToAction("SelectProvider", new BaseSelectProviderRequest
{
AccountHashedId = selectedLevyTransferConnection.AccountHashedId,
EncodedPledgeApplicationId = ids[0],
TransferSenderId = ids[1],
AccountLegalEntityHashedId = selectedLevyTransferConnection.AccountLegalEntityHashedId,
});
}


[HttpGet]
[Route("AgreementNotSigned")]
public async Task<ActionResult> AgreementNotSigned(LegalEntitySignedAgreementViewModel viewModel)
Expand Down
Loading
Loading