-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #217 from SkillsFundingAgency/CON-3345_Migrate_tra…
…nsfers_details_to_commitments_v2 CON-3345 Migrated transfer details to v2
- Loading branch information
Showing
31 changed files
with
1,168 additions
and
10 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
...tsV2.Web.UnitTests/Controllers/TransferRequest/WhenCallingPostTransferDetailsForSender.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using AutoFixture.NUnit3; | ||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Routing; | ||
using Microsoft.Extensions.Logging; | ||
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.TransferRequest; | ||
using SFA.DAS.Testing.AutoFixture; | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.TransferRequestControllerTests | ||
{ | ||
public class WhenCallingPostTransferDetailsForSender | ||
{ | ||
[Test, MoqAutoData] | ||
public async Task And_TransferDetailsForSender_Succeeds_Then_Redirect_To_Confirmation( | ||
UpdateTransferApprovalForSenderRequest request, | ||
TransferRequestForSenderViewModel viewModel, | ||
[Frozen] Mock<IModelMapper> mockMapper, | ||
TransferRequestController controller) | ||
{ | ||
mockMapper | ||
.Setup(mapper => mapper.Map<UpdateTransferApprovalForSenderRequest>(viewModel)) | ||
.ReturnsAsync(request); | ||
|
||
var result = (await controller.TransferDetailsForSender(viewModel)) as RedirectToActionResult; | ||
|
||
result.Should().NotBeNull(); | ||
result.ActionName.Should().Be("TransferConfirmation"); | ||
result.ControllerName.Should().Be("TransferRequest"); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task And_TransferDetailsForSender_Succeeds_Then_Api_Called_To_Update( | ||
Mock<ICommitmentsApiClient> mockCommitmentsApiClient, | ||
Mock<ILogger<TransferRequestController>> mockLogger, | ||
UpdateTransferApprovalForSenderRequest request, | ||
TransferRequestForSenderViewModel viewModel, | ||
[Frozen] Mock<IModelMapper> mockMapper) | ||
{ | ||
mockMapper | ||
.Setup(mapper => mapper.Map<UpdateTransferApprovalForSenderRequest>(viewModel)) | ||
.ReturnsAsync(request); | ||
|
||
mockCommitmentsApiClient | ||
.Setup(r => r.UpdateTransferRequestForSender( | ||
It.IsAny<long>(), | ||
It.IsAny<long>(), | ||
It.IsAny<long>(), | ||
It.IsAny<UpdateTransferApprovalForSenderRequest>(), | ||
It.IsAny<CancellationToken>())) | ||
.Returns(Task.CompletedTask); | ||
|
||
TransferRequestController controller = new TransferRequestController(mockCommitmentsApiClient.Object, | ||
mockLogger.Object, mockMapper.Object); | ||
|
||
var result = (await controller.TransferDetailsForSender(viewModel)) as RedirectToActionResult; | ||
|
||
mockCommitmentsApiClient.Verify(m => m.UpdateTransferRequestForSender( | ||
It.IsAny<long>(), | ||
It.IsAny<long>(), | ||
It.IsAny<long>(), | ||
It.IsAny<UpdateTransferApprovalForSenderRequest>(), | ||
It.IsAny<CancellationToken>()), Times.Once); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task And_TransferDetailsForSender_Fails_Then_Redirect_To_Error( | ||
TransferRequestForSenderViewModel viewModel, | ||
[Frozen] Mock<IModelMapper> mockMapper, | ||
TransferRequestController controller) | ||
{ | ||
mockMapper | ||
.Setup(mapper => mapper.Map<UpdateTransferApprovalForSenderRequest>(viewModel)) | ||
.ThrowsAsync(new Exception("Some error")); | ||
|
||
var result = (await controller.TransferDetailsForSender(viewModel)) as RedirectToActionResult; | ||
|
||
result.Should().NotBeNull(); | ||
result.ActionName.Should().Be("Error"); | ||
result.ControllerName.Should().Be("Error"); | ||
result.RouteValues.Should().BeNull(); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...entsV2.Web.UnitTests/Controllers/TransferRequest/WhenCallingTransferDetailsForReceiver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Threading.Tasks; | ||
using AutoFixture.NUnit3; | ||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.CommitmentsV2.Shared.Interfaces; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Controllers; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Models.TransferRequest; | ||
using SFA.DAS.Testing.AutoFixture; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.TransferRequestControllerTests | ||
|
||
{ | ||
public class WhenCallingTransferDetailsForReceiver | ||
{ | ||
[Test, MoqAutoData] | ||
public async Task Then_Returns_View_With_Correct_Model( | ||
TransferRequestRequest request, | ||
TransferRequestForReceiverViewModel viewModel, | ||
[Frozen] Mock<IModelMapper> mockMapper, | ||
TransferRequestController controller) | ||
{ | ||
mockMapper | ||
.Setup(mapper => mapper.Map<TransferRequestForReceiverViewModel>(request)) | ||
.ReturnsAsync(viewModel); | ||
|
||
var result = await controller.TransferDetailsForReceiver(request) as ViewResult; | ||
|
||
result.ViewName.Should().BeNull(); | ||
var model = result.Model as TransferRequestForReceiverViewModel; | ||
model.Should().BeSameAs(viewModel); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...tmentsV2.Web.UnitTests/Controllers/TransferRequest/WhenCallingTransferDetailsForSender.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Threading.Tasks; | ||
using AutoFixture.NUnit3; | ||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.CommitmentsV2.Shared.Interfaces; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Controllers; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Models.TransferRequest; | ||
using SFA.DAS.Testing.AutoFixture; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.PaymentOrderControllerTests | ||
|
||
{ | ||
public class WhenCallingTransferDetailsForSender | ||
{ | ||
[Test, MoqAutoData] | ||
public async Task Then_Returns_View_With_Correct_Model( | ||
TransferRequestRequest request, | ||
TransferRequestForSenderViewModel viewModel, | ||
[Frozen] Mock<IModelMapper> mockMapper, | ||
TransferRequestController controller) | ||
{ | ||
mockMapper | ||
.Setup(mapper => mapper.Map<TransferRequestForSenderViewModel>(request)) | ||
.ReturnsAsync(viewModel); | ||
|
||
var result = await controller.TransferDetailsForSender(request) as ViewResult; | ||
|
||
result.ViewName.Should().BeNull(); | ||
var model = result.Model as TransferRequestForSenderViewModel; | ||
model.Should().BeSameAs(viewModel); | ||
} | ||
} | ||
} |
193 changes: 193 additions & 0 deletions
193
...2.Web.UnitTests/Mappers/TransferRequest/TransferRequestForReceiverViewModelMapperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
using AutoFixture; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.CommitmentsV2.Api.Client; | ||
using SFA.DAS.CommitmentsV2.Api.Types.Requests; | ||
using SFA.DAS.CommitmentsV2.Api.Types.Responses; | ||
using SFA.DAS.CommitmentsV2.Types; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.TransferRequest; | ||
using SFA.DAS.EmployerCommitmentsV2.Web.Models.TransferRequest; | ||
using SFA.DAS.Encoding; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Apprentice | ||
{ | ||
public class TransferConfirmationViewModelMapperTests | ||
{ | ||
private Mock<ICommitmentsApiClient> _mockCommitmentsApiClient; | ||
private Mock<IEncodingService> _mockEncodingService; | ||
|
||
private GetTransferRequestResponse _getTransferRequestResponse; | ||
private TransferRequestRequest _request; | ||
|
||
private TransferRequestForReceiverViewModelMapper _mapper; | ||
|
||
private const long AccountIdFirst = 12; | ||
private const long TransferRequestIdFirst = 34; | ||
private const long ReceivingEmployerAccountIdFirst = 56; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
//Arrange | ||
var autoFixture = new Fixture(); | ||
_request = autoFixture.Build<TransferRequestRequest>() | ||
.With(x => x.AccountHashedId, $"A{AccountIdFirst}") | ||
.With(x => x.TransferRequestHashedId, $"A{TransferRequestIdFirst}") | ||
.Create(); | ||
|
||
_getTransferRequestResponse = autoFixture.Build<GetTransferRequestResponse>() | ||
.With(x => x.ReceivingEmployerAccountId, ReceivingEmployerAccountIdFirst) | ||
.With(x => x.TransferRequestId, TransferRequestIdFirst) | ||
.Create(); | ||
|
||
_mockCommitmentsApiClient = new Mock<ICommitmentsApiClient>(); | ||
_mockCommitmentsApiClient.Setup(r => r.GetTransferRequestForReceiver(It.IsAny<long>(), It.IsAny<long>(), CancellationToken.None)) | ||
.ReturnsAsync(_getTransferRequestResponse); | ||
|
||
_mockEncodingService = new Mock<IEncodingService>(); | ||
|
||
_mockEncodingService.Setup(t => t.Encode(It.IsAny<long>(), EncodingType.AccountId)) | ||
.Returns((long value, EncodingType encodingType) => $"A{value}"); | ||
_mockEncodingService.Setup(t => t.Encode(It.IsAny<long>(), EncodingType.PublicAccountId)) | ||
.Returns((long value, EncodingType encodingType) => $"P{value}"); | ||
_mockEncodingService.Setup(t => t.Encode(It.IsAny<long>(), EncodingType.TransferRequestId)) | ||
.Returns((long value, EncodingType encodingType) => $"T{value}"); | ||
_mockEncodingService.Setup(t => t.Encode(It.IsAny<long>(), EncodingType.CohortReference)) | ||
.Returns((long value, EncodingType encodingType) => $"C{value}"); | ||
_mockEncodingService.Setup(t => t.Decode(It.IsAny<string>(), It.IsAny<EncodingType>())) | ||
.Returns((string value, EncodingType encodingType) => long.Parse(Regex.Replace(value, "[A-Za-z ]", ""))); | ||
|
||
_mapper = new TransferRequestForReceiverViewModelMapper(_mockCommitmentsApiClient.Object, _mockEncodingService.Object); | ||
} | ||
|
||
[Test] | ||
public async Task GetTransferRequestForReceiverIsCalled() | ||
{ | ||
//Act | ||
var result = await _mapper.Map(_request); | ||
|
||
//Assert | ||
_mockCommitmentsApiClient.Verify(t => t.GetTransferRequestForReceiver(_request.AccountId, _request.TransferRequestId, It.IsAny<CancellationToken>()), Times.Once()); | ||
} | ||
|
||
[Test] | ||
public async Task TransferReceiverHashedAccountId_IsMapped() | ||
{ | ||
//Act | ||
var result = await _mapper.Map(_request); | ||
|
||
//Assert | ||
Assert.AreEqual($"A{_getTransferRequestResponse.ReceivingEmployerAccountId}", result.TransferReceiverHashedAccountId); | ||
} | ||
|
||
[Test] | ||
public async Task TransferSenderPublicHashedAccountId_IsMapped() | ||
{ | ||
//Act | ||
var result = await _mapper.Map(_request); | ||
|
||
//Assert | ||
Assert.AreEqual($"P{_getTransferRequestResponse.SendingEmployerAccountId}", result.TransferSenderPublicHashedAccountId); | ||
} | ||
|
||
[Test] | ||
public async Task TransferSenderName_IsMapped() | ||
{ | ||
//Act | ||
var result = await _mapper.Map(_request); | ||
|
||
//Assert | ||
Assert.AreEqual(_getTransferRequestResponse.TransferSenderName, result.TransferSenderName); | ||
} | ||
|
||
[Test] | ||
public async Task HashedCohortReference_IsMapped() | ||
{ | ||
//Act | ||
var result = await _mapper.Map(_request); | ||
|
||
//Assert | ||
Assert.AreEqual($"C{_getTransferRequestResponse.CommitmentId}", result.HashedCohortReference); | ||
} | ||
|
||
[Test] | ||
public async Task TransferApprovalStatusDesc_IsMapped() | ||
{ | ||
//Act | ||
var result = await _mapper.Map(_request); | ||
|
||
//Assert | ||
Assert.AreEqual(_getTransferRequestResponse.Status.ToString(), result.TransferApprovalStatusDesc); | ||
} | ||
|
||
[Test] | ||
public async Task TransferApprovalSetBy_IsMapped() | ||
{ | ||
//Act | ||
var result = await _mapper.Map(_request); | ||
|
||
//Assert | ||
Assert.AreEqual(_getTransferRequestResponse.ApprovedOrRejectedByUserName, result.TransferApprovalSetBy); | ||
} | ||
|
||
[Test] | ||
public async Task TransferApprovalSetOn_IsMapped() | ||
{ | ||
//Act | ||
var result = await _mapper.Map(_request); | ||
|
||
//Assert | ||
Assert.AreEqual(_getTransferRequestResponse.ApprovedOrRejectedOn, result.TransferApprovalSetOn); | ||
} | ||
|
||
[Test] | ||
public async Task TotalCost_IsMapped() | ||
{ | ||
//Act | ||
var result = await _mapper.Map(_request); | ||
|
||
//Assert | ||
Assert.AreEqual(_getTransferRequestResponse.TransferCost, result.TotalCost); | ||
} | ||
|
||
[Test] | ||
public async Task FundingCap_IsMapped() | ||
{ | ||
//Act | ||
var result = await _mapper.Map(_request); | ||
|
||
//Assert | ||
Assert.AreEqual(_getTransferRequestResponse.FundingCap, result.FundingCap); | ||
} | ||
|
||
[TestCase(TransferApprovalStatus.Pending, 1500.0, 12000, true)] | ||
[TestCase(TransferApprovalStatus.Approved, 1500.0, 12000, true)] | ||
[TestCase(TransferApprovalStatus.Pending, 12000.0, 12000, false)] | ||
[TestCase(TransferApprovalStatus.Approved, 12000.0, 12000, false)] | ||
[TestCase(TransferApprovalStatus.Pending, 13000.0, 12000, false)] | ||
[TestCase(TransferApprovalStatus.Approved, 13000.0, 12000, false)] | ||
[TestCase(TransferApprovalStatus.Rejected, 1500.0, 12000, false)] | ||
[TestCase(TransferApprovalStatus.Rejected, 12000.0, 12000, false)] | ||
[TestCase(TransferApprovalStatus.Rejected, 13000.0, 12000, false)] | ||
public async Task TrainingName_IsMapped(TransferApprovalStatus transferApprovalStatus, decimal transferCost, int fundingCap, bool showFundingCapWarning) | ||
{ | ||
// Arrange | ||
_getTransferRequestResponse.Status = transferApprovalStatus; | ||
_getTransferRequestResponse.TransferCost = transferCost; | ||
_getTransferRequestResponse.FundingCap = fundingCap; | ||
|
||
//Act | ||
var result = await _mapper.Map(_request); | ||
|
||
//Assert | ||
Assert.AreEqual(showFundingCapWarning, result.ShowFundingCapWarning); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.