Skip to content

Commit

Permalink
Con 2567 create cohort request cop (#149)
Browse files Browse the repository at this point in the history
* CON-2567-Added Api call to create cohort request for  Cop

* CON-2567-package updated

* con-2567-updated package

* CON-2567 Added Unit Test
  • Loading branch information
VasanthaKasirajan3008 authored Nov 16, 2020
1 parent 9414552 commit 9099e89
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand Down Expand Up @@ -67,9 +89,9 @@ public WhenPostingSendRequestNewTrainingProviderTestsFixture()
_linkGenerator.Object);
}

public IActionResult SendRequestNewTrainingProvider()
public async Task<IActionResult> SendRequestNewTrainingProvider()
{
return _controller.SendRequestNewTrainingProvider(_viewModel);
return await _controller.SendRequestNewTrainingProvider(_viewModel);
}

public WhenPostingSendRequestNewTrainingProviderTestsFixture SetConfirm(bool confirm)
Expand All @@ -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<long>() ,It.IsAny<CreateChangeOfPartyRequestRequest>(), It.IsAny<CancellationToken>()), Times.Once);
}
}
}
Original file line number Diff line number Diff line change
@@ -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<long>(),
AccountHashedId = fixture.Create<string>(),
AccountId = fixture.Create<long>(),
Confirm = fixture.Create<bool>(),
OldProviderName = fixture.Create<string>(),
NewProviderName = fixture.Create<string>(),
EmployerName = fixture.Create<string>(),
ApprenticeName = fixture.Create<string>(),
ApprenticeshipStatus = ApprenticeshipStatus.Stopped,
ApprenticeshipId = fixture.Create<int>(),
ApprenticeshipHashedId = fixture.Create<string>()
};
_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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Client" Version="4.4.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Shared" Version="4.4.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Client" Version="4.9.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Shared" Version="4.9.0" />
<PackageReference Include="SFA.DAS.Testing" Version="3.0.22" />
<PackageReference Include="SFA.DAS.Testing.AutoFixture" Version="3.0.121" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,12 @@ public async Task<IActionResult> SendRequestNewTrainingProvider(SendNewTrainingP
[Route("{apprenticeshipHashedId}/change-provider/send-request", Name = RouteNames.SendRequestNewTrainingProvider)]
[HttpPost]
[DasAuthorize(EmployerFeature.ChangeOfProvider)]
public IActionResult SendRequestNewTrainingProvider(SendNewTrainingProviderViewModel request)
public async Task<IActionResult> SendRequestNewTrainingProvider(SendNewTrainingProviderViewModel request)
{
if (request.Confirm.Value)
{
var apiRequest = await _modelMapper.Map<CreateChangeOfPartyRequestRequest>(request);
await _commitmentsApiClient.CreateChangeOfPartyRequest(request.ApprenticeshipId, apiRequest);
return RedirectToRoute(RouteNames.ChangeProviderRequestedConfirmation, new { request.AccountHashedId, request.ApprenticeshipHashedId, request.ProviderId });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<SendNewTrainingProviderViewModel, CreateChangeOfPartyRequestRequest>
{
public Task<CreateChangeOfPartyRequestRequest> Map(SendNewTrainingProviderViewModel source)
{
return Task.FromResult(new CreateChangeOfPartyRequestRequest
{
ChangeOfPartyRequestType = ChangeOfPartyRequestType.ChangeProvider,
NewPartyId = source.ProviderId
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<PackageReference Include="NLog.Schema" Version="4.5.11" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.8.0" />
<PackageReference Include="SFA.DAS.Authorization.Mvc" Version="6.0.59" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Client" Version="4.4.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Shared" Version="4.4.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Client" Version="4.9.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Shared" Version="4.9.0" />
<PackageReference Include="SFA.DAS.Employer.Shared.UI" Version="2.0.15" />
<PackageReference Include="SFA.DAS.Configuration.AzureTableStorage" Version="3.0.77" />
<PackageReference Include="SFA.DAS.EmployerUrlHelper" Version="3.0.22" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<PackageReference Include="SFA.DAS.Authorization.CommitmentPermissions" Version="6.0.59" />
<PackageReference Include="SFA.DAS.Authorization.EmployerFeatures" Version="6.0.59" />
<PackageReference Include="SFA.DAS.Authorization.EmployerUserRoles" Version="6.0.59" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Client" Version="4.4.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Shared" Version="4.4.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Types" Version="4.4.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Client" Version="4.9.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Shared" Version="4.9.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Types" Version="4.9.0" />
<PackageReference Include="SFA.DAS.EmployerAccounts.Api.Client" Version="1.6.2086" />
<PackageReference Include="SFA.DAS.EmployerUrlHelper" Version="3.0.22" />
<PackageReference Include="SFA.DAS.Encoding" Version="1.1.61" />
Expand Down

0 comments on commit 9099e89

Please sign in to comment.