diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenCallingChangeProviderRequestedConfirmationPageTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenCallingChangeProviderRequestedConfirmationPageTests.cs index 29b5f6ede..8e63163f5 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenCallingChangeProviderRequestedConfirmationPageTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenCallingChangeProviderRequestedConfirmationPageTests.cs @@ -3,6 +3,7 @@ using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; +using SFA.DAS.Authorization.Services; using SFA.DAS.CommitmentsV2.Api.Client; using SFA.DAS.CommitmentsV2.Shared.Interfaces; using SFA.DAS.EmployerCommitmentsV2.Web.Controllers; @@ -55,7 +56,8 @@ public WhenCallingChangeProviderRequestedConfirmationPageTestsFixture() Mock.Of>(), Mock.Of(), Mock.Of(), - Mock.Of>()); + Mock.Of>(), + Mock.Of()); } public async Task ChangeProviderRequested() diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenCallingGetEnterNewTrainingProviderTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenCallingGetEnterNewTrainingProviderTests.cs index 5799bad48..e652985fe 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenCallingGetEnterNewTrainingProviderTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenCallingGetEnterNewTrainingProviderTests.cs @@ -3,14 +3,12 @@ using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; +using SFA.DAS.Authorization.Services; using SFA.DAS.CommitmentsV2.Api.Client; using SFA.DAS.CommitmentsV2.Shared.Interfaces; using SFA.DAS.EmployerCommitmentsV2.Web.Controllers; using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; using SFA.DAS.EmployerUrlHelper; -using System; -using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests @@ -57,7 +55,8 @@ public WhenCallingGetEnterNewTrainingProviderTestsFixture() Mock.Of>(), Mock.Of(), Mock.Of(), - Mock.Of>()); + Mock.Of>(), + Mock.Of()); } public async Task EnterNewTrainingProvider() diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenCallingGetSendRequestNewTrainingProviderTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenCallingGetSendRequestNewTrainingProviderTests.cs index c88c29728..74284e8b8 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenCallingGetSendRequestNewTrainingProviderTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenCallingGetSendRequestNewTrainingProviderTests.cs @@ -1,15 +1,14 @@ using AutoFixture; -using AutoFixture.NUnit3; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; +using SFA.DAS.Authorization.Services; using SFA.DAS.CommitmentsV2.Api.Client; using SFA.DAS.CommitmentsV2.Shared.Interfaces; using SFA.DAS.EmployerCommitmentsV2.Web.Controllers; using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; using SFA.DAS.EmployerUrlHelper; -using SFA.DAS.Testing.AutoFixture; using System.Threading.Tasks; namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests @@ -56,7 +55,8 @@ public WhenCallingGetSendRequestNewTrainingProviderTestsFixture() Mock.Of>(), Mock.Of(), Mock.Of(), - Mock.Of>()); + Mock.Of>(), + Mock.Of()); } public async Task SendRequestNewTrainingProvider() diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenCallingGetWhoWillEnterTheDetailsTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenCallingGetWhoWillEnterTheDetailsTests.cs new file mode 100644 index 000000000..5cc16b1a3 --- /dev/null +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenCallingGetWhoWillEnterTheDetailsTests.cs @@ -0,0 +1,76 @@ +using AutoFixture; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using Moq; +using NUnit.Framework; +using SFA.DAS.Authorization.Services; +using SFA.DAS.CommitmentsV2.Api.Client; +using SFA.DAS.CommitmentsV2.Shared.Interfaces; +using SFA.DAS.EmployerCommitmentsV2.Web.Controllers; +using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; +using SFA.DAS.EmployerUrlHelper; +using System.Threading.Tasks; + +namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests +{ + public class WhenCallingGetWhoWillEnterTheDetailsTests + { + WhenCallingGetWhoWillEnterTheDetailsTestsFixture _fixture; + + [SetUp] + public void Arrange() + { + _fixture = new WhenCallingGetWhoWillEnterTheDetailsTestsFixture(); + } + + [Test] + public async Task ThenTheCorrectViewIsReturned() + { + var result = await _fixture.WhoWillEnterTheDetails(); + + _fixture.VerifyViewModel(result as ViewResult); + } + } + + public class WhenCallingGetWhoWillEnterTheDetailsTestsFixture + { + private readonly WhoWillEnterTheDetailsRequest _request; + private readonly WhoWillEnterTheDetailsViewModel _viewModel; + + private readonly Mock _mockMapper; + + private readonly ApprenticeController _controller; + + public WhenCallingGetWhoWillEnterTheDetailsTestsFixture() + { + var autoFixture = new Fixture(); + + _request = autoFixture.Create(); + _viewModel = autoFixture.Create(); + + _mockMapper = new Mock(); + _mockMapper.Setup(m => m.Map(_request)) + .ReturnsAsync(_viewModel); + + _controller = new ApprenticeController(_mockMapper.Object, + Mock.Of>(), + Mock.Of(), + Mock.Of(), + Mock.Of>(), + Mock.Of()); + } + + public async Task WhoWillEnterTheDetails() + { + return await _controller.WhoWillEnterTheDetails(_request); + } + + public void VerifyViewModel(ViewResult viewResult) + { + var viewModel = viewResult.Model as WhoWillEnterTheDetailsViewModel; + + Assert.IsInstanceOf(viewModel); + Assert.AreEqual(_viewModel, viewModel); + } + } +} diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenCallingTheViewChangesPageTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenCallingTheViewChangesPageTests.cs index 2856b3b1a..eeee2a016 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenCallingTheViewChangesPageTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenCallingTheViewChangesPageTests.cs @@ -3,14 +3,12 @@ using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; +using SFA.DAS.Authorization.Services; using SFA.DAS.CommitmentsV2.Api.Client; using SFA.DAS.CommitmentsV2.Shared.Interfaces; using SFA.DAS.EmployerCommitmentsV2.Web.Controllers; using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; using SFA.DAS.EmployerUrlHelper; -using System; -using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests @@ -57,7 +55,8 @@ public WhenCallingTheViewChangesPageTestsFixture() Mock.Of>(), Mock.Of(), Mock.Of(), - Mock.Of>()); + Mock.Of>(), + Mock.Of()); } public async Task ViewChanges() diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingChangeStatus.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingChangeStatus.cs index 07b8ed52f..824d58aaa 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingChangeStatus.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingChangeStatus.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; +using SFA.DAS.Authorization.Services; using SFA.DAS.CommitmentsV2.Api.Client; using SFA.DAS.CommitmentsV2.Shared.Interfaces; using SFA.DAS.EmployerCommitmentsV2.Web.Controllers; @@ -21,7 +22,12 @@ public void Arrange() _mockCommitmentsApiClient = new Mock(); _mockLinkGenerator = new Mock(); - _controller = new ApprenticeController(_mockModelMapper.Object, _mockCookieStorageService.Object, _mockCommitmentsApiClient.Object, _mockLinkGenerator.Object, Mock.Of>()); + _controller = new ApprenticeController(_mockModelMapper.Object, + _mockCookieStorageService.Object, + _mockCommitmentsApiClient.Object, + _mockLinkGenerator.Object, + Mock.Of>(), + Mock.Of()); } [Test, MoqAutoData] diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingEnterNewTrainingProvider.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingEnterNewTrainingProvider.cs index 8cb66d759..4308d1401 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingEnterNewTrainingProvider.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingEnterNewTrainingProvider.cs @@ -3,15 +3,14 @@ using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; +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.Web.Controllers; using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; using SFA.DAS.EmployerCommitmentsV2.Web.RouteValues; using SFA.DAS.EmployerUrlHelper; -using System; -using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests @@ -27,18 +26,28 @@ public void Arrange() } [Test] - public async Task ThenRedirectToSendRequestPage() + public async Task AndTheFeatureToggleIsEnable_ThenRedirectToWhoWillEnterTheDetailsPage() { - var result = await _fixture.EnterNewTrainingProvider(); + var result = await _fixture.EnterNewTrainingProvider(true); - _fixture.VerifyRedirectsToSendNewTrainingProviderRequest(result); - } + _fixture.VerifyRedirectsToWhoWillEnterTheDetailsPage(result); + } + + [Test] + + public async Task AndTheFeatureToggleIsDisabled_ThenRedirectToSendRequestPage() + { + var result = await _fixture.EnterNewTrainingProvider(false); + + _fixture.VerifyRedirectsToSendNewTrainingProviderRequestPage(result); + } } public class WhenPostingEnterNewTrainingProviderFixture { private readonly Mock _mockMapper; - private readonly Mock _mockLinkGenerator; + private readonly Mock _mockAuthorizationService; + private readonly EnterNewTrainingProviderViewModel _viewModel; private readonly ApprenticeController _controller; @@ -50,27 +59,41 @@ public WhenPostingEnterNewTrainingProviderFixture() _viewModel = autoFixture.Create(); _mockMapper = new Mock(); + _mockMapper.Setup(m => m.Map(_viewModel)) + .ReturnsAsync(new WhoWillEnterTheDetailsRequest { AccountHashedId = _viewModel.AccountHashedId, ApprenticeshipHashedId = _viewModel.ApprenticeshipHashedId, ProviderId = _viewModel.Ukprn }); _mockMapper.Setup(m => m.Map(_viewModel)) - .ReturnsAsync(new SendNewTrainingProviderRequest { AccountHashedId = _viewModel.AccountHashedId, ApprenticeshipHashedId = _viewModel.ApprenticeshipHashedId, ProviderId = _viewModel.Ukprn }); + .ReturnsAsync(new SendNewTrainingProviderRequest { AccountHashedId = _viewModel.AccountHashedId, ApprenticeshipHashedId = _viewModel.ApprenticeshipHashedId, ProviderId = _viewModel.Ukprn }); - _mockLinkGenerator = new Mock(); - _mockLinkGenerator.Setup(x => x.CommitmentsLink(It.IsAny())).Returns(s => s); + _mockAuthorizationService = new Mock(); - _controller = new ApprenticeController(_mockMapper.Object, Mock.Of>(), Mock.Of(), _mockLinkGenerator.Object, Mock.Of>()); - + _controller = new ApprenticeController(_mockMapper.Object, + Mock.Of>(), + Mock.Of(), + Mock.Of(), + Mock.Of>(), + _mockAuthorizationService.Object); } - public async Task EnterNewTrainingProvider() + public async Task EnterNewTrainingProvider(bool changeProviderFeatureToggleEnabled) { + _mockAuthorizationService.Setup(a => a.IsAuthorized(EmployerFeature.ChangeOfProvider)) + .Returns(changeProviderFeatureToggleEnabled); + return await _controller.EnterNewTrainingProvider(_viewModel); } - public void VerifyRedirectsToSendNewTrainingProviderRequest(IActionResult result) + public void VerifyRedirectsToWhoWillEnterTheDetailsPage(IActionResult result) { var redirect = (RedirectToRouteResult)result; - Assert.AreEqual(RouteNames.SendRequestNewTrainingProvider, redirect.RouteName); + Assert.AreEqual(RouteNames.WhoWillEnterTheDetails, redirect.RouteName); } + public void VerifyRedirectsToSendNewTrainingProviderRequestPage(IActionResult result) + { + var redirect = (RedirectToRouteResult)result; + + Assert.AreEqual(RouteNames.SendRequestNewTrainingProvider, redirect.RouteName); + } } } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingPauseRequestConfirmation.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingPauseRequestConfirmation.cs index d4e7148e7..22cad73d8 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingPauseRequestConfirmation.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingPauseRequestConfirmation.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; +using SFA.DAS.Authorization.Services; using SFA.DAS.CommitmentsV2.Api.Client; using SFA.DAS.CommitmentsV2.Api.Types.Requests; using SFA.DAS.CommitmentsV2.Shared.Interfaces; @@ -25,7 +26,12 @@ public void Arrange() _mockCommitmentsApiClient = new Mock(); _mockLinkGenerator = new Mock(); - _controller = new ApprenticeController(_mockModelMapper.Object, _mockCookieStorageService.Object, _mockCommitmentsApiClient.Object, _mockLinkGenerator.Object, Mock.Of>()); + _controller = new ApprenticeController(_mockModelMapper.Object, + _mockCookieStorageService.Object, + _mockCommitmentsApiClient.Object, + _mockLinkGenerator.Object, + Mock.Of>(), + Mock.Of()); } [Test, MoqAutoData] diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingResumeRequestConfirmation.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingResumeRequestConfirmation.cs index 378332884..47eac597f 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingResumeRequestConfirmation.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingResumeRequestConfirmation.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; +using SFA.DAS.Authorization.Services; using SFA.DAS.CommitmentsV2.Api.Client; using SFA.DAS.CommitmentsV2.Api.Types.Requests; using SFA.DAS.CommitmentsV2.Shared.Interfaces; @@ -25,7 +26,12 @@ public void Arrange() _mockCommitmentsApiClient = new Mock(); _mockLinkGenerator = new Mock(); - _controller = new ApprenticeController(_mockModelMapper.Object, _mockCookieStorageService.Object, _mockCommitmentsApiClient.Object, _mockLinkGenerator.Object, Mock.Of>()); + _controller = new ApprenticeController(_mockModelMapper.Object, + _mockCookieStorageService.Object, + _mockCommitmentsApiClient.Object, + _mockLinkGenerator.Object, + Mock.Of>(), + Mock.Of()); } [Test, MoqAutoData] 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 a6c25d466..fa1bd0e35 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingSendRequestNewTrainingProviderTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingSendRequestNewTrainingProviderTests.cs @@ -3,6 +3,7 @@ using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; +using SFA.DAS.Authorization.Services; using SFA.DAS.CommitmentsV2.Api.Client; using SFA.DAS.CommitmentsV2.Api.Types.Requests; using SFA.DAS.CommitmentsV2.Shared.Interfaces; @@ -79,7 +80,6 @@ public async Task And_NewProviderIsTheSameAsCurrentProvider_Then_RedirectToError public class WhenPostingSendRequestNewTrainingProviderTestsFixture { - private readonly Mock _modelMapper; private readonly Mock _commitmentsApiClient; private readonly Mock _linkGenerator; private ApprenticeController _controller; @@ -91,8 +91,6 @@ public WhenPostingSendRequestNewTrainingProviderTestsFixture() _viewModel = autoFixture.Create(); _commitmentsApiClient = new Mock(); - _modelMapper = new Mock(); - _linkGenerator = new Mock(); _linkGenerator.Setup(x => x.CommitmentsLink(It.IsAny())).Returns(s => s); @@ -100,7 +98,8 @@ public WhenPostingSendRequestNewTrainingProviderTestsFixture() Mock.Of>(), _commitmentsApiClient.Object, _linkGenerator.Object, - Mock.Of>()); + Mock.Of>(), + Mock.Of()); } public async Task SendRequestNewTrainingProvider() diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingWhoWillEnterTheDetails.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingWhoWillEnterTheDetails.cs new file mode 100644 index 000000000..d634287b8 --- /dev/null +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenPostingWhoWillEnterTheDetails.cs @@ -0,0 +1,89 @@ +using AutoFixture; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using Moq; +using NUnit.Framework; +using SFA.DAS.Authorization.Services; +using SFA.DAS.CommitmentsV2.Api.Client; +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; + +namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests +{ + public class WhenPostingWhoWillEnterTheDetails + { + private Fixture _autoFixture; + private WhenPostingWhoWillEnterTheDetailsTestFixture _fixture; + + [SetUp] + public void Arrange() + { + _autoFixture = new Fixture(); + + _fixture = new WhenPostingWhoWillEnterTheDetailsTestFixture(); + } + + [Test] + public void AndEmployerIsSelected_ThenRedirectToWhatIsTheNewStartDateRoute() + { + var viewModel = _autoFixture.Build() + .With(vm => vm.EmployerWillAdd, true) + .Create(); + + var result = _fixture.WhoWillEnterTheDetails(viewModel); + + _fixture.VerifyRedirectsToWhatIsTheNewStartDateRoute(result); + } + + [Test] + public void AndProviderIsSelected_ThenRedirectToSendNewTrainingProviderRequest() + { + var viewModel = _autoFixture.Build() + .With(vm => vm.EmployerWillAdd, false) + .Create(); + + var result = _fixture.WhoWillEnterTheDetails(viewModel); + + _fixture.VerifyRedirectsToSendRequestNewTrainingProviderRoute(result); + } + } + + public class WhenPostingWhoWillEnterTheDetailsTestFixture + { + + private readonly ApprenticeController _controller; + + public WhenPostingWhoWillEnterTheDetailsTestFixture() + { + + _controller = new ApprenticeController(Mock.Of(), + Mock.Of>(), + Mock.Of(), + Mock.Of(), + Mock.Of>(), + Mock.Of()); + } + + public IActionResult WhoWillEnterTheDetails(WhoWillEnterTheDetailsViewModel viewModel) + { + return _controller.WhoWillEnterTheDetails(viewModel); + } + + public void VerifyRedirectsToWhatIsTheNewStartDateRoute(IActionResult result) + { + var redirectResult = (RedirectToRouteResult)result; + + Assert.AreEqual(RouteNames.WhatIsTheNewStartDate, redirectResult.RouteName); + } + + public void VerifyRedirectsToSendRequestNewTrainingProviderRoute(IActionResult result) + { + var redirectResult = (RedirectToRouteResult)result; + + Assert.AreEqual(RouteNames.SendRequestNewTrainingProvider, redirectResult.RouteName); + } + } +} diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenRequestingChangeStatusPage.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenRequestingChangeStatusPage.cs index c9a3c1c37..57ac96529 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenRequestingChangeStatusPage.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenRequestingChangeStatusPage.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; +using SFA.DAS.Authorization.Services; using SFA.DAS.CommitmentsV2.Api.Client; using SFA.DAS.CommitmentsV2.Shared.Interfaces; using SFA.DAS.CommitmentsV2.Types; @@ -22,7 +23,12 @@ public void Arrange() _mockCommitmentsApiClient = new Mock(); _mockLinkGenerator = new Mock(); - _controller = new ApprenticeController(_mockModelMapper.Object, _mockCookieStorageService.Object, _mockCommitmentsApiClient.Object, _mockLinkGenerator.Object, Mock.Of>()); + _controller = new ApprenticeController(_mockModelMapper.Object, + _mockCookieStorageService.Object, + _mockCommitmentsApiClient.Object, + _mockLinkGenerator.Object, + Mock.Of>(), + Mock.Of()); } [Test] diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenRequestingPauseApprenticeshipConfirmationPage.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenRequestingPauseApprenticeshipConfirmationPage.cs index c34247354..9ba27cde5 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenRequestingPauseApprenticeshipConfirmationPage.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenRequestingPauseApprenticeshipConfirmationPage.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; +using SFA.DAS.Authorization.Services; using SFA.DAS.CommitmentsV2.Api.Client; using SFA.DAS.CommitmentsV2.Shared.Interfaces; using SFA.DAS.EmployerCommitmentsV2.Web.Controllers; @@ -22,7 +23,12 @@ public void Arrange() _mockCommitmentsApiClient = new Mock(); _mockLinkGenerator = new Mock(); - _controller = new ApprenticeController(_mockModelMapper.Object, _mockCookieStorageService.Object, _mockCommitmentsApiClient.Object, _mockLinkGenerator.Object, Mock.Of>()); + _controller = new ApprenticeController(_mockModelMapper.Object, + _mockCookieStorageService.Object, + _mockCommitmentsApiClient.Object, + _mockLinkGenerator.Object, + Mock.Of>(), + Mock.Of()); } [Test] diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenRequestingResumeApprenticeshipConfirmationPage.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenRequestingResumeApprenticeshipConfirmationPage.cs index f48e81b30..bf3ebcbe6 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenRequestingResumeApprenticeshipConfirmationPage.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Controllers/ApprenticeControllerTests/WhenRequestingResumeApprenticeshipConfirmationPage.cs @@ -9,6 +9,7 @@ using SFA.DAS.EmployerUrlHelper; using System.Threading.Tasks; using Microsoft.Extensions.Logging; +using SFA.DAS.Authorization.Services; namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests { @@ -22,7 +23,12 @@ public void Arrange() _mockCommitmentsApiClient = new Mock(); _mockLinkGenerator = new Mock(); - _controller = new ApprenticeController(_mockModelMapper.Object, _mockCookieStorageService.Object, _mockCommitmentsApiClient.Object, _mockLinkGenerator.Object, Mock.Of>()); + _controller = new ApprenticeController(_mockModelMapper.Object, + _mockCookieStorageService.Object, + _mockCommitmentsApiClient.Object, + _mockLinkGenerator.Object, + Mock.Of>(), + Mock.Of()); } [Test] diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/ChangeProviderInformViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/ChangeProviderInformViewModelMapperTests.cs index 71710252c..fd1670475 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/ChangeProviderInformViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/ChangeProviderInformViewModelMapperTests.cs @@ -32,7 +32,6 @@ public void Arrange() .With(a => a.Status, ApprenticeshipStatus.Stopped) .Create(); - _mockCommitmentsApiClient = new Mock(); _mockCommitmentsApiClient.Setup(a => a.GetApprenticeship(It.IsAny(), It.IsAny())) .ReturnsAsync(_apprenticeshipResponse); @@ -41,7 +40,6 @@ public void Arrange() _mockEncodingService.Setup(d => d.Decode(It.IsAny(), EncodingType.ApprenticeshipId)) .Returns(ApprenticeshipId); - _mapper = new ChangeProviderInformViewModelMapper(_mockCommitmentsApiClient.Object, _mockEncodingService.Object); } diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/SendNewTrainingProviderRequestMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/SendNewTrainingProviderRequestMapperTests.cs index 64a63091a..e0420cbf3 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/SendNewTrainingProviderRequestMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/SendNewTrainingProviderRequestMapperTests.cs @@ -2,9 +2,6 @@ using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice; using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; using SFA.DAS.Testing.AutoFixture; -using System; -using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Apprentice diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/WhoWillEnterTheDetailsViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/WhoWillEnterTheDetailsViewModelMapperTests.cs new file mode 100644 index 000000000..e7e67822b --- /dev/null +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/WhoWillEnterTheDetailsViewModelMapperTests.cs @@ -0,0 +1,82 @@ +using Moq; +using NUnit.Framework; +using SFA.DAS.CommitmentsV2.Api.Client; +using SFA.DAS.CommitmentsV2.Api.Types.Responses; +using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice; +using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; +using SFA.DAS.Testing.AutoFixture; +using System.Threading; +using System.Threading.Tasks; + +namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Apprentice +{ + public class WhoWillEnterTheDetailsViewModelMapperTests + { + private Mock _mockCommitmentsApiClient; + + private GetProviderResponse _getProviderResponse; + + private WhoWillEnterTheDetailsViewModelMapper _mapper; + + [SetUp] + public void Arrange() + { + _getProviderResponse = MockGetProvider(); + + _mockCommitmentsApiClient = new Mock(); + _mockCommitmentsApiClient.Setup(m => m.GetProvider(It.IsAny(), It.IsAny())) + .ReturnsAsync(_getProviderResponse); + + _mapper = new WhoWillEnterTheDetailsViewModelMapper(_mockCommitmentsApiClient.Object); + } + + [Test, MoqAutoData] + public async Task ApprenticeshipHashedId_IsMapped(WhoWillEnterTheDetailsRequest request) + { + var result = await _mapper.Map(request); + + Assert.AreEqual(request.ApprenticeshipHashedId, result.ApprenticeshipHashedId); + } + + [Test, MoqAutoData] + public async Task AccountHashedId_IsMapped(WhoWillEnterTheDetailsRequest request) + { + var result = await _mapper.Map(request); + + Assert.AreEqual(request.AccountHashedId, result.AccountHashedId); + } + + [Test, MoqAutoData] + public async Task ProviderId_IsMapped(WhoWillEnterTheDetailsRequest request) + { + var result = await _mapper.Map(request); + + Assert.AreEqual(request.ProviderId, result.ProviderId); + } + + [Test, MoqAutoData] + public async Task WhenRequestingTheWhoWillEnterTheDetailsPage_ThenTheGetProviderRequestIsCalled(WhoWillEnterTheDetailsRequest request) + { + var result = await _mapper.Map(request); + + _mockCommitmentsApiClient.Verify(m => m.GetProvider(request.ProviderId, It.IsAny()), Times.Once()); + } + + [Test, MoqAutoData] + public async Task WhenRequestingTheWhoWillEnterTheDetailsPage_ThenTheProviderNameIsReturnedAndMapped(WhoWillEnterTheDetailsRequest request) + { + var result = await _mapper.Map(request); + + Assert.AreEqual(result.ProviderName, _getProviderResponse.Name); + } + + private GetProviderResponse MockGetProvider() + { + return new GetProviderResponse + { + Name = "Test Provider", + ProviderId = 12345678 + }; + } + } +} diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Validators/WhoWillEnterTheDetailsViewModelValidatorTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Validators/WhoWillEnterTheDetailsViewModelValidatorTests.cs new file mode 100644 index 000000000..dd33719f2 --- /dev/null +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Validators/WhoWillEnterTheDetailsViewModelValidatorTests.cs @@ -0,0 +1,48 @@ +using AutoFixture; +using NUnit.Framework; +using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; +using SFA.DAS.EmployerCommitmentsV2.Web.Validators; +using SFA.DAS.Testing.AutoFixture; +using System.Linq; + +namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Validators +{ + public class WhoWillEnterTheDetailsViewModelValidatorTests + { + private const string errorMessage = "Select who will enter the new course dates and price"; + + private WhoWillEnterTheDetailsViewModelValidator _validator; + private Fixture _autoFixture; + + [SetUp] + public void Arrange() + { + _autoFixture = new Fixture(); + _validator = new WhoWillEnterTheDetailsViewModelValidator(); + } + + [Test] + public void WhenValidatingWhoWillEnterTheDetails_AndSelectionIsNotMade_ThenValidatorReturnsInvalid() + { + var viewModel = _autoFixture.Create(); + viewModel.EmployerWillAdd = null; + + var result = _validator.Validate(viewModel); + + Assert.False(result.IsValid); + Assert.AreEqual(errorMessage, result.Errors.First().ErrorMessage); + } + + [TestCase(true)] + [TestCase(false)] + public void WhenValidatingWhoWillEnterTheDetails_AndSelectionIsMade_ThenValidatorReturnsValid(bool employerResponsibility) + { + var viewModel = _autoFixture.Build() + .With(vm => vm.EmployerWillAdd, employerResponsibility).Create(); + + var result = _validator.Validate(viewModel); + + Assert.True(result.IsValid); + } + } +} diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Controllers/ApprenticeController.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Controllers/ApprenticeController.cs index 2754c1ada..421e90f08 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Controllers/ApprenticeController.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Controllers/ApprenticeController.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.Logging; using SFA.DAS.Authorization.EmployerUserRoles.Options; using SFA.DAS.Authorization.Mvc.Attributes; +using SFA.DAS.Authorization.Services; using SFA.DAS.CommitmentsV2.Api.Client; using SFA.DAS.CommitmentsV2.Api.Types.Requests; using SFA.DAS.CommitmentsV2.Shared.Interfaces; @@ -30,14 +31,16 @@ public class ApprenticeController : Controller private readonly ICommitmentsApiClient _commitmentsApiClient; private readonly ILinkGenerator _linkGenerator; private readonly ILogger _logger; + private readonly IAuthorizationService _authorizationService; - public ApprenticeController(IModelMapper modelMapper, ICookieStorageService cookieStorage, ICommitmentsApiClient commitmentsApiClient, ILinkGenerator linkGenerator, ILogger logger) + public ApprenticeController(IModelMapper modelMapper, ICookieStorageService cookieStorage, ICommitmentsApiClient commitmentsApiClient, ILinkGenerator linkGenerator, ILogger logger, IAuthorizationService authorizationService) { _modelMapper = modelMapper; _cookieStorage = cookieStorage; _commitmentsApiClient = commitmentsApiClient; _linkGenerator = linkGenerator; _logger = logger; + _authorizationService = authorizationService; } [Route("", Name = RouteNames.ApprenticesIndex)] @@ -119,7 +122,6 @@ public IActionResult ChangeStatus(ChangeStatusRequestViewModel viewModel) } [Route("{apprenticeshipHashedId}/change-provider", Name = RouteNames.ChangeProviderInform)] - [DasAuthorize(EmployerFeature.ChangeOfProvider)] public async Task ChangeProviderInform(ChangeProviderInformRequest request) { var viewModel = await _modelMapper.Map(request); @@ -135,10 +137,8 @@ public IActionResult ApprenticeNotStoppedError() return View(); } - [HttpGet] [Route("{apprenticeshipHashedId}/change-provider/select-provider", Name = RouteNames.EnterNewTrainingProvider)] - [DasAuthorize(EmployerFeature.ChangeOfProvider)] public async Task EnterNewTrainingProvider(EnterNewTrainingProviderRequest request) { var viewModel = await _modelMapper.Map(request); @@ -148,25 +148,64 @@ public async Task EnterNewTrainingProvider(EnterNewTrainingProvid [HttpPost] [Route("{apprenticeshipHashedId}/change-provider/select-provider", Name = RouteNames.EnterNewTrainingProvider)] - [DasAuthorize(EmployerFeature.ChangeOfProvider)] public async Task EnterNewTrainingProvider(EnterNewTrainingProviderViewModel viewModel) { + if (_authorizationService.IsAuthorized(EmployerFeature.ChangeOfProvider)) + { + var whoWillEnterTheDetailsRequest = await _modelMapper.Map(viewModel); + + return RedirectToRoute(RouteNames.WhoWillEnterTheDetails, new { whoWillEnterTheDetailsRequest.AccountHashedId, whoWillEnterTheDetailsRequest.ApprenticeshipHashedId, whoWillEnterTheDetailsRequest.ProviderId }); + } + var request = await _modelMapper.Map(viewModel); return RedirectToRoute(RouteNames.SendRequestNewTrainingProvider, new { request.AccountHashedId, request.ApprenticeshipHashedId, request.ProviderId }); } - [Route("{apprenticeshipHashedId}/change-provider/send-request", Name = RouteNames.SendRequestNewTrainingProvider)] + [HttpGet] + [Route("{apprenticeshipHashedId}/change-provider/who-enter-details", Name = RouteNames.WhoWillEnterTheDetails)] [DasAuthorize(EmployerFeature.ChangeOfProvider)] + public async Task WhoWillEnterTheDetails(WhoWillEnterTheDetailsRequest request) + { + var viewModel = await _modelMapper.Map(request); + + return View(viewModel); + } + + [HttpPost] + [Route("{apprenticeshipHashedId}/change-provider/who-enter-details", Name = RouteNames.WhoWillEnterTheDetails)] + [DasAuthorize(EmployerFeature.ChangeOfProvider)] + public IActionResult WhoWillEnterTheDetails(WhoWillEnterTheDetailsViewModel viewModel) + { + if (viewModel.EmployerWillAdd == true) + { + return RedirectToRoute(RouteNames.WhatIsTheNewStartDate, new { viewModel.AccountHashedId, viewModel.ApprenticeshipHashedId, viewModel.ProviderId }); + } + else + { + return RedirectToRoute(RouteNames.SendRequestNewTrainingProvider, new { viewModel.AccountHashedId, viewModel.ApprenticeshipHashedId, viewModel.ProviderId }); + } + } + + // Placeholder for CON-2519 + [HttpGet] + [Route("{apprenticeshipHashedId}/change-provider/start-date", Name = RouteNames.WhatIsTheNewStartDate)] + [DasAuthorize(EmployerFeature.ChangeOfProvider)] + public IActionResult WhatIsTheNewStartDate() + { + return View(); + } + + [HttpGet] + [Route("{apprenticeshipHashedId}/change-provider/send-request", Name = RouteNames.SendRequestNewTrainingProvider)] public async Task SendRequestNewTrainingProvider(SendNewTrainingProviderRequest request) { var viewModel = await _modelMapper.Map(request); return View(viewModel); } - [Route("{apprenticeshipHashedId}/change-provider/send-request", Name = RouteNames.SendRequestNewTrainingProvider)] [HttpPost] - [DasAuthorize(EmployerFeature.ChangeOfProvider)] + [Route("{apprenticeshipHashedId}/change-provider/send-request", Name = RouteNames.SendRequestNewTrainingProvider)] public async Task SendRequestNewTrainingProvider(SendNewTrainingProviderViewModel request) { if (request.Confirm.Value) @@ -187,8 +226,8 @@ public async Task SendRequestNewTrainingProvider(SendNewTrainingP return Redirect(_linkGenerator.ApprenticeDetails(request.AccountHashedId, request.ApprenticeshipHashedId)); } + [HttpGet] [Route("{apprenticeshipHashedId}/change-provider/change-provider-requested/{providerId}", Name = RouteNames.ChangeProviderRequestedConfirmation)] - [DasAuthorize(EmployerFeature.ChangeOfProvider)] public async Task ChangeProviderRequested(ChangeProviderRequestedConfirmationRequest request) { var viewModel = await _modelMapper.Map(request); diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/SendNewTrainingProviderRequestMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/SendNewTrainingProviderRequestMapper.cs index 3024aa5a9..fd087c190 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/SendNewTrainingProviderRequestMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/SendNewTrainingProviderRequestMapper.cs @@ -1,6 +1,6 @@ -using System.Threading.Tasks; -using SFA.DAS.CommitmentsV2.Shared.Interfaces; +using SFA.DAS.CommitmentsV2.Shared.Interfaces; using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; +using System.Threading.Tasks; namespace SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice { diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/WhoWillEnterTheDetailsRequestMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/WhoWillEnterTheDetailsRequestMapper.cs new file mode 100644 index 000000000..3222fd254 --- /dev/null +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/WhoWillEnterTheDetailsRequestMapper.cs @@ -0,0 +1,21 @@ +using System.Threading.Tasks; +using SFA.DAS.CommitmentsV2.Shared.Interfaces; +using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; + +namespace SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice +{ + public class WhoWillEnterTheDetailsRequestMapper : IMapper + { + public Task Map(EnterNewTrainingProviderViewModel source) + { + var result = new WhoWillEnterTheDetailsRequest + { + AccountHashedId = source.AccountHashedId, + ApprenticeshipHashedId = source.ApprenticeshipHashedId, + ProviderId = source.Ukprn + }; + + return Task.FromResult(result); + } + } +} diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/WhoWillEnterTheDetailsViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/WhoWillEnterTheDetailsViewModelMapper.cs new file mode 100644 index 000000000..311830b30 --- /dev/null +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/WhoWillEnterTheDetailsViewModelMapper.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using SFA.DAS.CommitmentsV2.Api.Client; +using SFA.DAS.CommitmentsV2.Shared.Interfaces; +using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; + +namespace SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice +{ + public class WhoWillEnterTheDetailsViewModelMapper : IMapper + { + private readonly ICommitmentsApiClient _client; + + public WhoWillEnterTheDetailsViewModelMapper(ICommitmentsApiClient client) + { + _client = client; + } + + public async Task Map(WhoWillEnterTheDetailsRequest source) + { + var provider = await _client.GetProvider(source.ProviderId); + + return new WhoWillEnterTheDetailsViewModel + { + AccountHashedId = source.AccountHashedId, + ApprenticeshipHashedId = source.ApprenticeshipHashedId, + ProviderName = provider.Name, + ProviderId = source.ProviderId + }; + } + } +} diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Apprentice/WhoWillEnterTheDetailsRequest.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Apprentice/WhoWillEnterTheDetailsRequest.cs new file mode 100644 index 000000000..61b785a5b --- /dev/null +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Apprentice/WhoWillEnterTheDetailsRequest.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Mvc; +using SFA.DAS.Authorization.ModelBinding; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice +{ + public class WhoWillEnterTheDetailsRequest : IAuthorizationContextModel + { + [FromRoute] + public string AccountHashedId { get; set; } + [FromRoute] + public string ApprenticeshipHashedId { get; set; } + + public long ProviderId { get; set; } + } +} diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Apprentice/WhoWillEnterTheDetailsViewModel.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Apprentice/WhoWillEnterTheDetailsViewModel.cs new file mode 100644 index 000000000..70b1e2e7d --- /dev/null +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Apprentice/WhoWillEnterTheDetailsViewModel.cs @@ -0,0 +1,13 @@ +using SFA.DAS.Authorization.ModelBinding; + +namespace SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice +{ + public class WhoWillEnterTheDetailsViewModel : IAuthorizationContextModel + { + public string AccountHashedId { get; set; } + public string ApprenticeshipHashedId { get; set; } + public string ProviderName { get; set; } + public long ProviderId { get; set; } + public bool? EmployerWillAdd { get; set; } + } +} diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/RouteValues/RouteNames.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/RouteValues/RouteNames.cs index 06e7b2fd6..7a8dc61d4 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/RouteValues/RouteNames.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/RouteValues/RouteNames.cs @@ -11,6 +11,8 @@ public static class RouteNames public const string ChangeProviderInform = "change-provider-inform"; public const string ApprenticeNotStoppedError = "aprentice-not-stopped-error"; public const string EnterNewTrainingProvider = "select-provider"; + public const string WhoWillEnterTheDetails = "who-will-enter-the-details"; + public const string WhatIsTheNewStartDate = "what-is-the-new-start-date"; public const string SendRequestNewTrainingProvider = "send-request-new"; public const string ChangeProviderRequestedConfirmation = "change-provider-requested"; public const string ViewChanges = "view-changes"; diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Validators/EditEndDateRequestValidator.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Validators/EditEndDateRequestValidator.cs index db86250e4..f258bc302 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Validators/EditEndDateRequestValidator.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Validators/EditEndDateRequestValidator.cs @@ -1,9 +1,5 @@ using FluentValidation; using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace SFA.DAS.EmployerCommitmentsV2.Web.Validators { diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Validators/WhoWillEnterTheDetailsViewModelValidator.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Validators/WhoWillEnterTheDetailsViewModelValidator.cs new file mode 100644 index 000000000..1f6271523 --- /dev/null +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Validators/WhoWillEnterTheDetailsViewModelValidator.cs @@ -0,0 +1,13 @@ +using FluentValidation; +using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice; + +namespace SFA.DAS.EmployerCommitmentsV2.Web.Validators +{ + public class WhoWillEnterTheDetailsViewModelValidator : AbstractValidator + { + public WhoWillEnterTheDetailsViewModelValidator() + { + RuleFor(r => r.EmployerWillAdd).NotNull().WithMessage("Select who will enter the new course dates and price"); + } + } +} diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Apprentice/WhatIsTheNewStartDate.cshtml b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Apprentice/WhatIsTheNewStartDate.cshtml new file mode 100644 index 000000000..b70ed9464 --- /dev/null +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Apprentice/WhatIsTheNewStartDate.cshtml @@ -0,0 +1,6 @@ + +@* + Placeholder for CON-2519 +*@ + +

Enter start date

\ No newline at end of file diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Apprentice/WhoWillEnterNewDetails.cshtml b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Apprentice/WhoWillEnterNewDetails.cshtml deleted file mode 100644 index ffe10ae33..000000000 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Apprentice/WhoWillEnterNewDetails.cshtml +++ /dev/null @@ -1,6 +0,0 @@ - -@* - Placeholder for CON-2506 -*@ - -

Who will enter the new price

diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Apprentice/WhoWillEnterTheDetails.cshtml b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Apprentice/WhoWillEnterTheDetails.cshtml new file mode 100644 index 000000000..29e498da4 --- /dev/null +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Views/Apprentice/WhoWillEnterTheDetails.cshtml @@ -0,0 +1,57 @@ +@using SFA.DAS.CommitmentsV2.Shared.Extensions +@using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice +@model SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice.WhoWillEnterTheDetailsViewModel + +@{ + ViewData["Title"] = "Who will enter the new course dates and price? - Apprenticeship service - GOV.UK"; +} + +
+
+ + +

+ Who will enter the new course dates and price? +

+ +
+ @Html.AntiForgeryToken() + + +
+
+

+ If your training provider adds the new course dates and price, you'll need to check and agree to them before any payments are made. +

+ + @if (!ViewData.ModelState.IsValid) + { + + Error: @ViewData.ModelState[nameof(WhoWillEnterTheDetailsViewModel.EmployerWillAdd)].Errors.First().ErrorMessage + + } + +
+
+ + +
+ +
+ + +
+
+ +
+
+ + +
+
+
+ +@section Back +{ + +} \ No newline at end of file