From 9099e89b46a1dc052e017cee1cb8d1d6334e7be6 Mon Sep 17 00:00:00 2001 From: VasanthaKasirajan3008 <56582101+VasanthaKasirajan3008@users.noreply.github.com> Date: Mon, 16 Nov 2020 10:02:54 +0000 Subject: [PATCH] Con 2567 create cohort request cop (#149) * CON-2567-Added Api call to create cohort request for Cop * CON-2567-package updated * con-2567-updated package * CON-2567 Added Unit Test --- ...tingSendRequestNewTrainingProviderTests.cs | 39 +++++++++++-- .../CreateChangeOfPartyRequestMapperTests.cs | 57 +++++++++++++++++++ ...EmployerCommitmentsV2.Web.UnitTests.csproj | 4 +- .../Controllers/ApprenticeController.cs | 4 +- .../CreateChangeOfPartyRequestMapper.cs | 20 +++++++ .../SFA.DAS.EmployerCommitmentsV2.Web.csproj | 4 +- .../SFA.DAS.EmployerCommitmentsV2.csproj | 6 +- 7 files changed, 120 insertions(+), 14 deletions(-) create mode 100644 src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/CreateChangeOfPartyRequestMapperTests.cs create mode 100644 src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/CreateChangeOfPartyRequestMapper.cs diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingSendRequestNewTrainingProviderTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingSendRequestNewTrainingProviderTests.cs index ce66aad06..5b427abc5 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingSendRequestNewTrainingProviderTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingSendRequestNewTrainingProviderTests.cs @@ -3,11 +3,14 @@ using Moq; using NUnit.Framework; using SFA.DAS.CommitmentsV2.Api.Client; +using SFA.DAS.CommitmentsV2.Api.Types.Requests; using SFA.DAS.CommitmentsV2.Shared.Interfaces; using SFA.DAS.EmployerCommitmentsV2.Web.Controllers; using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; using SFA.DAS.EmployerCommitmentsV2.Web.RouteValues; using SFA.DAS.EmployerUrlHelper; +using System.Threading; +using System.Threading.Tasks; namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests { @@ -22,24 +25,43 @@ public void Arrange() } [Test] - public void VerifyRedirectsToApprenticeDetailsPage() + public async Task VerifyRedirectsToApprenticeDetailsPage() { + //Arrange _fixture.SetConfirm(false); - var result = _fixture.SendRequestNewTrainingProvider(); + //Act + var result = await _fixture.SendRequestNewTrainingProvider(); + //Assert _fixture.VerifyRedirectsToApprenticeDetailsPage(result); } [Test] - public void VerifyRedirectsToSentAction() + public async Task VerifyRedirectsToSentAction() { + //Arrange _fixture.SetConfirm(true); - var result = _fixture.SendRequestNewTrainingProvider(); + //Act + var result = await _fixture.SendRequestNewTrainingProvider(); + //Assert _fixture.VerifyRedirectsToSentAction(result); } + + [Test] + public async Task VerifyCommitmentsApiCreateChangeOfPartyRequestCalled() + { + //Arrange + _fixture.SetConfirm(true); + + //Act + await _fixture.SendRequestNewTrainingProvider(); + + //Assert + _fixture.VerifyCommitmentsApiCreateChangeOfPartyRequestCalled(); + } } public class WhenPostingSendRequestNewTrainingProviderTestsFixture @@ -67,9 +89,9 @@ public WhenPostingSendRequestNewTrainingProviderTestsFixture() _linkGenerator.Object); } - public IActionResult SendRequestNewTrainingProvider() + public async Task SendRequestNewTrainingProvider() { - return _controller.SendRequestNewTrainingProvider(_viewModel); + return await _controller.SendRequestNewTrainingProvider(_viewModel); } public WhenPostingSendRequestNewTrainingProviderTestsFixture SetConfirm(bool confirm) @@ -90,5 +112,10 @@ public void VerifyRedirectsToSentAction(IActionResult result) Assert.AreEqual(RouteNames.ChangeProviderRequestedConfirmation, redirect.RouteName); } + + public void VerifyCommitmentsApiCreateChangeOfPartyRequestCalled() + { + _commitmentsApiClient.Verify(p => p.CreateChangeOfPartyRequest(It.IsAny() ,It.IsAny(), It.IsAny()), Times.Once); + } } } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/CreateChangeOfPartyRequestMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/CreateChangeOfPartyRequestMapperTests.cs new file mode 100644 index 000000000..e7ee18ecc --- /dev/null +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/CreateChangeOfPartyRequestMapperTests.cs @@ -0,0 +1,57 @@ +using AutoFixture; +using NUnit.Framework; +using SFA.DAS.CommitmentsV2.Api.Types.Requests; +using SFA.DAS.CommitmentsV2.Types; +using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice; +using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; +using System.Threading.Tasks; + +namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Apprentice +{ + [TestFixture] + public class CreateChangeOfPartyRequestMapperTests + { + private CreateChangeOfPartyRequestMapper _mapper; + private SendNewTrainingProviderViewModel _source; + private CreateChangeOfPartyRequestRequest _result; + + [SetUp] + public async Task Arrange() + { + //Arrange + var fixture = new Fixture(); + _source = new SendNewTrainingProviderViewModel + { + ProviderId = fixture.Create(), + AccountHashedId = fixture.Create(), + AccountId = fixture.Create(), + Confirm = fixture.Create(), + OldProviderName = fixture.Create(), + NewProviderName = fixture.Create(), + EmployerName = fixture.Create(), + ApprenticeName = fixture.Create(), + ApprenticeshipStatus = ApprenticeshipStatus.Stopped, + ApprenticeshipId = fixture.Create(), + ApprenticeshipHashedId = fixture.Create() + }; + _mapper = new CreateChangeOfPartyRequestMapper(); + + //Act + _result = await _mapper.Map(TestHelper.Clone(_source)); + } + + [Test] + public void ChangeOfPartyRequestTypeIsMappedCorrectly() + { + //Assert + Assert.AreEqual(ChangeOfPartyRequestType.ChangeProvider, _result.ChangeOfPartyRequestType); + } + + [Test] + public void NewPartyIdIsMappedCorrectly() + { + //Assert + Assert.AreEqual(_source.ProviderId, _result.NewPartyId); + } + } +} diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.csproj b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.csproj index dfc15c8bb..e687a7aa9 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.csproj +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.csproj @@ -17,8 +17,8 @@ - - + + diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Controllers/ApprenticeController.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Controllers/ApprenticeController.cs index c916d7381..75cf707b2 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Controllers/ApprenticeController.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Controllers/ApprenticeController.cs @@ -163,10 +163,12 @@ public async Task SendRequestNewTrainingProvider(SendNewTrainingP [Route("{apprenticeshipHashedId}/change-provider/send-request", Name = RouteNames.SendRequestNewTrainingProvider)] [HttpPost] [DasAuthorize(EmployerFeature.ChangeOfProvider)] - public IActionResult SendRequestNewTrainingProvider(SendNewTrainingProviderViewModel request) + public async Task SendRequestNewTrainingProvider(SendNewTrainingProviderViewModel request) { if (request.Confirm.Value) { + var apiRequest = await _modelMapper.Map(request); + await _commitmentsApiClient.CreateChangeOfPartyRequest(request.ApprenticeshipId, apiRequest); return RedirectToRoute(RouteNames.ChangeProviderRequestedConfirmation, new { request.AccountHashedId, request.ApprenticeshipHashedId, request.ProviderId }); } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/CreateChangeOfPartyRequestMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/CreateChangeOfPartyRequestMapper.cs new file mode 100644 index 000000000..ce453a61b --- /dev/null +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/CreateChangeOfPartyRequestMapper.cs @@ -0,0 +1,20 @@ +using SFA.DAS.CommitmentsV2.Api.Types.Requests; +using SFA.DAS.CommitmentsV2.Shared.Interfaces; +using SFA.DAS.CommitmentsV2.Types; +using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; +using System.Threading.Tasks; + +namespace SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice +{ + public class CreateChangeOfPartyRequestMapper : IMapper + { + public Task Map(SendNewTrainingProviderViewModel source) + { + return Task.FromResult(new CreateChangeOfPartyRequestRequest + { + ChangeOfPartyRequestType = ChangeOfPartyRequestType.ChangeProvider, + NewPartyId = source.ProviderId + }); + } + } +} 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 d2d81f7d5..5d6c46ed7 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/SFA.DAS.EmployerCommitmentsV2.Web.csproj +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/SFA.DAS.EmployerCommitmentsV2.Web.csproj @@ -25,8 +25,8 @@ - - + + diff --git a/src/SFA.DAS.EmployerCommitmentsV2/SFA.DAS.EmployerCommitmentsV2.csproj b/src/SFA.DAS.EmployerCommitmentsV2/SFA.DAS.EmployerCommitmentsV2.csproj index abf1119af..59ff95986 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2/SFA.DAS.EmployerCommitmentsV2.csproj +++ b/src/SFA.DAS.EmployerCommitmentsV2/SFA.DAS.EmployerCommitmentsV2.csproj @@ -12,9 +12,9 @@ - - - + + +