Skip to content

Commit

Permalink
TM-302 Financial Breakdown page with committed funds
Browse files Browse the repository at this point in the history
  • Loading branch information
jawwadbaig committed Apr 19, 2022
1 parent c514d83 commit b8709c5
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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<TransfersOrchestrator> _orchestrator;
private Mock<IHashingService> _hashingService;
private Mock<IAuthorizationService> _authorisationService;
private Mock<IManageApprenticeshipsService> _maService;
private Mock<IAccountApiClient> _accountApiClient;
private Mock<IFeatureTogglesService<EmployerFeatureToggle>> _featureTogglesService;

private const string HashedAccountId = "123ABC";
private const long AccountId = 1234;

[SetUp]
public void Arrange()
{
_authorisationService = new Mock<IAuthorizationService>();
_hashingService = new Mock<IHashingService>();
_maService = new Mock<IManageApprenticeshipsService>();
_accountApiClient = new Mock<IAccountApiClient>();
_featureTogglesService = new Mock<IFeatureTogglesService<EmployerFeatureToggle>>();

_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<string>())).Returns(new EmployerFeatureToggle { IsEnabled = true });

_accountApiClient.Setup(m => m.GetAccount(HashedAccountId)).ReturnsAsync(new AccountDetailViewModel
{
AccountId = AccountId,
StartingTransferAllowance = 20000
});

_orchestrator = new Mock<TransfersOrchestrator>(_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<FinancialBreakdownViewModel>;
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<FinancialBreakdownViewModel>;
Assert.IsNotNull(viewModel);
var estimatedRemainingAllowance = viewModel.Data.TotalAvailableTransferAllowance - viewModel.Data.TotalEstimatedSpend;
Assert.AreEqual(estimatedRemainingAllowance, viewModel.Data.EstimatedRemainingAllowance);
}
}
}
Original file line number Diff line number Diff line change
@@ -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<IAuthorizationService> _authorisationService;
private Mock<IHashingService> _hashingService;
private Mock<IManageApprenticeshipsService> _maService;
private Mock<IAccountApiClient> _accountApiClient;
private Mock<IFeatureTogglesService<EmployerFeatureToggle>> _featureTogglesService;

private const string HashedAccountId = "123ABC";
private const long AccountId = 1234;

[SetUp]
public void Setup()
{
_authorisationService = new Mock<IAuthorizationService>();
_hashingService = new Mock<IHashingService>();
_maService = new Mock<IManageApprenticeshipsService>();
_accountApiClient = new Mock<IAccountApiClient>();
_featureTogglesService = new Mock<IFeatureTogglesService<EmployerFeatureToggle>>();

_hashingService.Setup(h => h.DecodeValue(HashedAccountId)).Returns(AccountId);
_featureTogglesService.Setup(x => x.GetFeatureToggle(It.IsAny<string>())).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);
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<details>
<summary><span class="summary">How are my committed funds calculated?</span></summary>
<div class="panel panel-border-narrow">
<p>Content</p>
<p>Your committed funds are calculated by subtracting your total estimated spend from your @Model.Data.TotalAvailableTransferAllowance.ToString("C0", culture) total available transfer allowance.</p>
</div>
</details>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;}

Expand Down

0 comments on commit b8709c5

Please sign in to comment.