From b8709c5b628f4401be0fe2e2e21db839b140d345 Mon Sep 17 00:00:00 2001 From: Jawwad Baig Date: Tue, 19 Apr 2022 19:33:48 +0100 Subject: [PATCH] TM-302 Financial Breakdown page with committed funds --- .../TransfersControllerTests.cs | 95 +++++++++++++++++++ .../WhenGettingTransfersFinancialBreakdown.cs | 81 ++++++++++++++++ .../Views/Transfers/FinancialBreakdown.cshtml | 2 +- .../GetFinancialBreakdownResponse.cs | 10 +- 4 files changed, 182 insertions(+), 6 deletions(-) create mode 100644 src/SFA.DAS.EmployerFinance.Web.UnitTests/Controllers/TransfersControllerTests/TransfersControllerTests.cs create mode 100644 src/SFA.DAS.EmployerFinance.Web.UnitTests/Orchestrators/WhenGettingTransfersFinancialBreakdown.cs diff --git a/src/SFA.DAS.EmployerFinance.Web.UnitTests/Controllers/TransfersControllerTests/TransfersControllerTests.cs b/src/SFA.DAS.EmployerFinance.Web.UnitTests/Controllers/TransfersControllerTests/TransfersControllerTests.cs new file mode 100644 index 0000000000..47d09d7687 --- /dev/null +++ b/src/SFA.DAS.EmployerFinance.Web.UnitTests/Controllers/TransfersControllerTests/TransfersControllerTests.cs @@ -0,0 +1,95 @@ +using Moq; +using NUnit.Framework; +using SFA.DAS.Authorization.EmployerFeatures.Models; +using SFA.DAS.Authorization.Features.Services; +using SFA.DAS.Authorization.Services; +using SFA.DAS.EAS.Account.Api.Client; +using SFA.DAS.EAS.Account.Api.Types; +using SFA.DAS.EmployerFinance.Infrastructure.OuterApiResponses.Transfers; +using SFA.DAS.EmployerFinance.Services; +using SFA.DAS.EmployerFinance.Web.Controllers; +using SFA.DAS.EmployerFinance.Web.Orchestrators; +using SFA.DAS.EmployerFinance.Web.ViewModels.Transfers; +using SFA.DAS.HashingService; +using System; +using System.Threading.Tasks; +using System.Web.Mvc; + +namespace SFA.DAS.EmployerFinance.Web.UnitTests.Controllers.TransfersControllerTests +{ + public class TransfersControllerTests + { + private TransfersController _controller; + private Mock _orchestrator; + private Mock _hashingService; + private Mock _authorisationService; + private Mock _maService; + private Mock _accountApiClient; + private Mock> _featureTogglesService; + + private const string HashedAccountId = "123ABC"; + private const long AccountId = 1234; + + [SetUp] + public void Arrange() + { + _authorisationService = new Mock(); + _hashingService = new Mock(); + _maService = new Mock(); + _accountApiClient = new Mock(); + _featureTogglesService = new Mock>(); + + _maService.Setup(m => m.GetFinancialBreakdown(AccountId)).ReturnsAsync(new GetFinancialBreakdownResponse + { + AcceptedPledgeApplications = 2000, + ApprovedPledgeApplications = 2000, + Commitments = 2000, + NumberOfMonths = 12, + PledgeOriginatedCommitments = 2000, + ProjectionStartDate= DateTime.Now, + FundsIn = 100000, + TransferConnections = 1000 + }); + + _hashingService.Setup(h => h.DecodeValue(HashedAccountId)).Returns(AccountId); + _featureTogglesService.Setup(x => x.GetFeatureToggle(It.IsAny())).Returns(new EmployerFeatureToggle { IsEnabled = true }); + + _accountApiClient.Setup(m => m.GetAccount(HashedAccountId)).ReturnsAsync(new AccountDetailViewModel + { + AccountId = AccountId, + StartingTransferAllowance = 20000 + }); + + _orchestrator = new Mock(_authorisationService.Object, _hashingService.Object, _maService.Object, _accountApiClient.Object, _featureTogglesService.Object); + + _controller = new TransfersController(_orchestrator.Object); + } + + [Test] + public async Task FinancialBreakdownReturnsAViewModel() + { + var result = await _controller.FinancialBreakdown(HashedAccountId); + + //Assert + var view = result as ViewResult; + + var viewModel = view?.Model as OrchestratorResponse; + Assert.IsNotNull(viewModel); + Assert.AreEqual(2000, viewModel.Data.AcceptedPledgeApplications); + } + + [Test] + public async Task FinancialBreakdownPageShowsEstimatedRemainingAllowance() + { + var result = await _controller.FinancialBreakdown(HashedAccountId); + + //Assert + var view = result as ViewResult; + + var viewModel = view?.Model as OrchestratorResponse; + Assert.IsNotNull(viewModel); + var estimatedRemainingAllowance = viewModel.Data.TotalAvailableTransferAllowance - viewModel.Data.TotalEstimatedSpend; + Assert.AreEqual(estimatedRemainingAllowance, viewModel.Data.EstimatedRemainingAllowance); + } + } +} diff --git a/src/SFA.DAS.EmployerFinance.Web.UnitTests/Orchestrators/WhenGettingTransfersFinancialBreakdown.cs b/src/SFA.DAS.EmployerFinance.Web.UnitTests/Orchestrators/WhenGettingTransfersFinancialBreakdown.cs new file mode 100644 index 0000000000..bfd3cb0afc --- /dev/null +++ b/src/SFA.DAS.EmployerFinance.Web.UnitTests/Orchestrators/WhenGettingTransfersFinancialBreakdown.cs @@ -0,0 +1,81 @@ +using Moq; +using NUnit.Framework; +using SFA.DAS.Authorization.EmployerFeatures.Models; +using SFA.DAS.Authorization.Features.Services; +using SFA.DAS.Authorization.Services; +using SFA.DAS.EAS.Account.Api.Client; +using SFA.DAS.EAS.Account.Api.Types; +using SFA.DAS.EmployerFinance.Infrastructure.OuterApiResponses.Transfers; +using SFA.DAS.EmployerFinance.Services; +using SFA.DAS.EmployerFinance.Web.Orchestrators; +using SFA.DAS.HashingService; +using System.Threading.Tasks; + +namespace SFA.DAS.EmployerFinance.Web.UnitTests.Orchestrators +{ + [TestFixture] + public class WhenGettingTransfersFinancialBreakdown + { + private TransfersOrchestrator _orchestrator; + private Mock _authorisationService; + private Mock _hashingService; + private Mock _maService; + private Mock _accountApiClient; + private Mock> _featureTogglesService; + + private const string HashedAccountId = "123ABC"; + private const long AccountId = 1234; + + [SetUp] + public void Setup() + { + _authorisationService = new Mock(); + _hashingService = new Mock(); + _maService = new Mock(); + _accountApiClient = new Mock(); + _featureTogglesService = new Mock>(); + + _hashingService.Setup(h => h.DecodeValue(HashedAccountId)).Returns(AccountId); + _featureTogglesService.Setup(x => x.GetFeatureToggle(It.IsAny())).Returns(new EmployerFeatureToggle { IsEnabled = true }); + + _orchestrator = new TransfersOrchestrator(_authorisationService.Object, _hashingService.Object, _maService.Object, _accountApiClient.Object, _featureTogglesService.Object); + } + + [Test] + public async Task CheckFinancialBreakdownViewModel() + { + var financialBreakdownResponse = new GetFinancialBreakdownResponse + { + AcceptedPledgeApplications = 20000, + ApprovedPledgeApplications = 10000, + Commitments = 1000, + TransferConnections = 1000, + NumberOfMonths = 12 + }; + + _maService.Setup(o => o.GetFinancialBreakdown(AccountId)).ReturnsAsync(financialBreakdownResponse); + + SetupTheAccountApiClient(); + + var actual = await _orchestrator.GetFinancialBreakdownViewModel(HashedAccountId); + + Assert.AreEqual(financialBreakdownResponse.AcceptedPledgeApplications, actual.Data.AcceptedPledgeApplications); + Assert.AreEqual(financialBreakdownResponse.ApprovedPledgeApplications, actual.Data.ApprovedPledgeApplications); + Assert.AreEqual(financialBreakdownResponse.Commitments, actual.Data.Commitments); + Assert.AreEqual(financialBreakdownResponse.TransferConnections, actual.Data.TransferConnections); + Assert.AreEqual(financialBreakdownResponse.NumberOfMonths, actual.Data.NumberOfMonths); + } + + private void SetupTheAccountApiClient() + { + var modelToReturn = new AccountDetailViewModel + { + ApprenticeshipEmployerType = "Levy" + }; + + _accountApiClient.Setup(o => o.GetAccount(HashedAccountId)).ReturnsAsync(modelToReturn); + } + + + } +} diff --git a/src/SFA.DAS.EmployerFinance.Web/Views/Transfers/FinancialBreakdown.cshtml b/src/SFA.DAS.EmployerFinance.Web/Views/Transfers/FinancialBreakdown.cshtml index 6a32d33b84..80f06bd21c 100644 --- a/src/SFA.DAS.EmployerFinance.Web/Views/Transfers/FinancialBreakdown.cshtml +++ b/src/SFA.DAS.EmployerFinance.Web/Views/Transfers/FinancialBreakdown.cshtml @@ -85,7 +85,7 @@
How are my committed funds calculated?
-

Content

+

Your committed funds are calculated by subtracting your total estimated spend from your @Model.Data.TotalAvailableTransferAllowance.ToString("C0", culture) total available transfer allowance.

diff --git a/src/SFA.DAS.EmployerFinance/Infrastructure/OuterApiResponses/Transfers/GetFinancialBreakdownResponse.cs b/src/SFA.DAS.EmployerFinance/Infrastructure/OuterApiResponses/Transfers/GetFinancialBreakdownResponse.cs index 4f52160cfc..8d0012c297 100644 --- a/src/SFA.DAS.EmployerFinance/Infrastructure/OuterApiResponses/Transfers/GetFinancialBreakdownResponse.cs +++ b/src/SFA.DAS.EmployerFinance/Infrastructure/OuterApiResponses/Transfers/GetFinancialBreakdownResponse.cs @@ -9,11 +9,11 @@ namespace SFA.DAS.EmployerFinance.Infrastructure.OuterApiResponses.Transfers public class GetFinancialBreakdownResponse { public decimal Commitments { get; set; } - public long ApprovedPledgeApplications { get; set; } - public long AcceptedPledgeApplications { get; set; } - public long PledgeOriginatedCommitments { get; set; } - public long TransferConnections { get; set; } - public long FundsIn { get; set; } + public decimal ApprovedPledgeApplications { get; set; } + public decimal AcceptedPledgeApplications { get; set; } + public decimal PledgeOriginatedCommitments { get; set; } + public decimal TransferConnections { get; set; } + public decimal FundsIn { get; set; } public int NumberOfMonths { get; set; } public DateTime ProjectionStartDate { get; set;}