Skip to content

Commit

Permalink
Merge pull request #159 from SkillsFundingAgency/CON-2598-Enable-empl…
Browse files Browse the repository at this point in the history
…oyer-to-choose-who-enters-price-and-dates

CON-2598 Add who will enter details page
  • Loading branch information
narendranogothu authored Jan 15, 2021
2 parents 21753ea + 8d212a6 commit 253e821
Show file tree
Hide file tree
Showing 30 changed files with 605 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,7 +56,8 @@ public WhenCallingChangeProviderRequestedConfirmationPageTestsFixture()
Mock.Of<ICookieStorageService<IndexRequest>>(),
Mock.Of<ICommitmentsApiClient>(),
Mock.Of<ILinkGenerator>(),
Mock.Of<ILogger<ApprenticeController>>());
Mock.Of<ILogger<ApprenticeController>>(),
Mock.Of<IAuthorizationService>());
}

public async Task<IActionResult> ChangeProviderRequested()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,7 +55,8 @@ public WhenCallingGetEnterNewTrainingProviderTestsFixture()
Mock.Of<ICookieStorageService<IndexRequest>>(),
Mock.Of<ICommitmentsApiClient>(),
Mock.Of<ILinkGenerator>(),
Mock.Of<ILogger<ApprenticeController>>());
Mock.Of<ILogger<ApprenticeController>>(),
Mock.Of<IAuthorizationService>());
}

public async Task<IActionResult> EnterNewTrainingProvider()
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -56,7 +55,8 @@ public WhenCallingGetSendRequestNewTrainingProviderTestsFixture()
Mock.Of<ICookieStorageService<IndexRequest>>(),
Mock.Of<ICommitmentsApiClient>(),
Mock.Of<ILinkGenerator>(),
Mock.Of<ILogger<ApprenticeController>>());
Mock.Of<ILogger<ApprenticeController>>(),
Mock.Of<IAuthorizationService>());
}

public async Task<IActionResult> SendRequestNewTrainingProvider()
Expand Down
Original file line number Diff line number Diff line change
@@ -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<IModelMapper> _mockMapper;

private readonly ApprenticeController _controller;

public WhenCallingGetWhoWillEnterTheDetailsTestsFixture()
{
var autoFixture = new Fixture();

_request = autoFixture.Create<WhoWillEnterTheDetailsRequest>();
_viewModel = autoFixture.Create<WhoWillEnterTheDetailsViewModel>();

_mockMapper = new Mock<IModelMapper>();
_mockMapper.Setup(m => m.Map<WhoWillEnterTheDetailsViewModel>(_request))
.ReturnsAsync(_viewModel);

_controller = new ApprenticeController(_mockMapper.Object,
Mock.Of<ICookieStorageService<IndexRequest>>(),
Mock.Of<ICommitmentsApiClient>(),
Mock.Of<ILinkGenerator>(),
Mock.Of<ILogger<ApprenticeController>>(),
Mock.Of<IAuthorizationService>());
}

public async Task<IActionResult> WhoWillEnterTheDetails()
{
return await _controller.WhoWillEnterTheDetails(_request);
}

public void VerifyViewModel(ViewResult viewResult)
{
var viewModel = viewResult.Model as WhoWillEnterTheDetailsViewModel;

Assert.IsInstanceOf<WhoWillEnterTheDetailsViewModel>(viewModel);
Assert.AreEqual(_viewModel, viewModel);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,7 +55,8 @@ public WhenCallingTheViewChangesPageTestsFixture()
Mock.Of<ICookieStorageService<IndexRequest>>(),
Mock.Of<ICommitmentsApiClient>(),
Mock.Of<ILinkGenerator>(),
Mock.Of<ILogger<ApprenticeController>>());
Mock.Of<ILogger<ApprenticeController>>(),
Mock.Of<IAuthorizationService>());
}

public async Task<IActionResult> ViewChanges()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,7 +22,12 @@ public void Arrange()
_mockCommitmentsApiClient = new Mock<ICommitmentsApiClient>();
_mockLinkGenerator = new Mock<ILinkGenerator>();

_controller = new ApprenticeController(_mockModelMapper.Object, _mockCookieStorageService.Object, _mockCommitmentsApiClient.Object, _mockLinkGenerator.Object, Mock.Of<ILogger<ApprenticeController>>());
_controller = new ApprenticeController(_mockModelMapper.Object,
_mockCookieStorageService.Object,
_mockCommitmentsApiClient.Object,
_mockLinkGenerator.Object,
Mock.Of<ILogger<ApprenticeController>>(),
Mock.Of<IAuthorizationService>());
}

[Test, MoqAutoData]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<IModelMapper> _mockMapper;
private readonly Mock<ILinkGenerator> _mockLinkGenerator;
private readonly Mock<IAuthorizationService> _mockAuthorizationService;

private readonly EnterNewTrainingProviderViewModel _viewModel;

private readonly ApprenticeController _controller;
Expand All @@ -50,27 +59,41 @@ public WhenPostingEnterNewTrainingProviderFixture()
_viewModel = autoFixture.Create<EnterNewTrainingProviderViewModel>();

_mockMapper = new Mock<IModelMapper>();
_mockMapper.Setup(m => m.Map<WhoWillEnterTheDetailsRequest>(_viewModel))
.ReturnsAsync(new WhoWillEnterTheDetailsRequest { AccountHashedId = _viewModel.AccountHashedId, ApprenticeshipHashedId = _viewModel.ApprenticeshipHashedId, ProviderId = _viewModel.Ukprn });
_mockMapper.Setup(m => m.Map<SendNewTrainingProviderRequest>(_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<ILinkGenerator>();
_mockLinkGenerator.Setup(x => x.CommitmentsLink(It.IsAny<string>())).Returns<string>(s => s);
_mockAuthorizationService = new Mock<IAuthorizationService>();

_controller = new ApprenticeController(_mockMapper.Object, Mock.Of<ICookieStorageService<IndexRequest>>(), Mock.Of<ICommitmentsApiClient>(), _mockLinkGenerator.Object, Mock.Of<ILogger<ApprenticeController>>());

_controller = new ApprenticeController(_mockMapper.Object,
Mock.Of<ICookieStorageService<IndexRequest>>(),
Mock.Of<ICommitmentsApiClient>(),
Mock.Of<ILinkGenerator>(),
Mock.Of<ILogger<ApprenticeController>>(),
_mockAuthorizationService.Object);
}

public async Task<IActionResult> EnterNewTrainingProvider()
public async Task<IActionResult> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,7 +26,12 @@ public void Arrange()
_mockCommitmentsApiClient = new Mock<ICommitmentsApiClient>();
_mockLinkGenerator = new Mock<ILinkGenerator>();

_controller = new ApprenticeController(_mockModelMapper.Object, _mockCookieStorageService.Object, _mockCommitmentsApiClient.Object, _mockLinkGenerator.Object, Mock.Of<ILogger<ApprenticeController>>());
_controller = new ApprenticeController(_mockModelMapper.Object,
_mockCookieStorageService.Object,
_mockCommitmentsApiClient.Object,
_mockLinkGenerator.Object,
Mock.Of<ILogger<ApprenticeController>>(),
Mock.Of<IAuthorizationService>());
}

[Test, MoqAutoData]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,7 +26,12 @@ public void Arrange()
_mockCommitmentsApiClient = new Mock<ICommitmentsApiClient>();
_mockLinkGenerator = new Mock<ILinkGenerator>();

_controller = new ApprenticeController(_mockModelMapper.Object, _mockCookieStorageService.Object, _mockCommitmentsApiClient.Object, _mockLinkGenerator.Object, Mock.Of<ILogger<ApprenticeController>>());
_controller = new ApprenticeController(_mockModelMapper.Object,
_mockCookieStorageService.Object,
_mockCommitmentsApiClient.Object,
_mockLinkGenerator.Object,
Mock.Of<ILogger<ApprenticeController>>(),
Mock.Of<IAuthorizationService>());
}

[Test, MoqAutoData]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,7 +80,6 @@ public async Task And_NewProviderIsTheSameAsCurrentProvider_Then_RedirectToError

public class WhenPostingSendRequestNewTrainingProviderTestsFixture
{
private readonly Mock<IModelMapper> _modelMapper;
private readonly Mock<ICommitmentsApiClient> _commitmentsApiClient;
private readonly Mock<ILinkGenerator> _linkGenerator;
private ApprenticeController _controller;
Expand All @@ -91,16 +91,15 @@ public WhenPostingSendRequestNewTrainingProviderTestsFixture()
_viewModel = autoFixture.Create<SendNewTrainingProviderViewModel>();

_commitmentsApiClient = new Mock<ICommitmentsApiClient>();
_modelMapper = new Mock<IModelMapper>();

_linkGenerator = new Mock<ILinkGenerator>();
_linkGenerator.Setup(x => x.CommitmentsLink(It.IsAny<string>())).Returns<string>(s => s);

_controller = new ApprenticeController(Mock.Of<IModelMapper>(),
Mock.Of<ICookieStorageService<IndexRequest>>(),
_commitmentsApiClient.Object,
_linkGenerator.Object,
Mock.Of<ILogger<ApprenticeController>>());
Mock.Of<ILogger<ApprenticeController>>(),
Mock.Of<IAuthorizationService>());
}

public async Task<IActionResult> SendRequestNewTrainingProvider()
Expand Down
Loading

0 comments on commit 253e821

Please sign in to comment.