Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tm 86 options to apply for transfers #2206

Merged
merged 30 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bff0df2
it now checks to see whether the user is non levy or they are a levy …
sscaife Sep 2, 2021
f2f4646
Merge branch 'master' of https://github.com/SkillsFundingAgency/das-e…
sscaife Sep 2, 2021
e23d292
altered to use the enum as requested in the pr
sscaife Sep 7, 2021
66ae20a
Merge branch 'master' of https://github.com/SkillsFundingAgency/das-e…
sscaife Sep 7, 2021
591003d
moved the heading out of the if statment and renamed the property acc…
sscaife Sep 8, 2021
dd90c52
changes to make the ApiClient abstract and then inherited so it can b…
sscaife Sep 9, 2021
9e03a98
added unit tests for the cohort service and modified the existing MA …
sscaife Sep 9, 2021
19160d5
changes around TM-133 refactoring for the tech review
sscaife Sep 14, 2021
8d54d43
Merge branch 'master' of https://github.com/SkillsFundingAgency/das-e…
sscaife Sep 14, 2021
0c2bce6
Merge branch 'master' of https://github.com/SkillsFundingAgency/das-e…
sscaife Sep 15, 2021
37b2c51
Very WIP
ConorTill Sep 15, 2021
f8c1f23
Refactoring GetPledges into GetIndex
ConorTill Sep 15, 2021
e7cb757
Revert "Very WIP"
ConorTill Sep 15, 2021
28fb521
Merge branch 'TM-133-Hide_the_option_to_create_a_transfers_pledge_fro…
ConorTill Sep 15, 2021
93414e7
Merged with conors work
sscaife Sep 15, 2021
80d2572
Retrieving IsTransferSender from apim
ConorTill Sep 15, 2021
472450c
refactoring to use the new commitments endpoint
sscaife Sep 16, 2021
88a5fac
Add IsTransferSender to viewmodel
ConorTill Sep 17, 2021
72af5e6
Adding application list feature toggle
ConorTill Sep 22, 2021
3330123
Merging TM-133
ConorTill Sep 22, 2021
981b3c2
Fixing tests
ConorTill Sep 22, 2021
5a10e18
Fixing applications links
ConorTill Sep 23, 2021
be52a22
Merging main
ConorTill Sep 23, 2021
2019f02
Merging TM-133
ConorTill Sep 23, 2021
0914a40
Merge branch 'master' of https://github.com/SkillsFundingAgency/das-e…
sscaife Sep 24, 2021
6bea710
removed the if statement and moved the boolean check to the return of…
sscaife Sep 24, 2021
e84b544
Merge branch 'TM-133-Hide_the_option_to_create_a_transfers_pledge_fro…
sscaife Sep 24, 2021
6d87a0b
Merge branch 'TM-133-Hide_the_option_to_create_a_transfers_pledge_fro…
ConorTill Sep 24, 2021
77706d6
Fixing apply section conditions
ConorTill Sep 24, 2021
40a948e
Fixing apply conditions
ConorTill Sep 24, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using FluentAssertions;
using NUnit.Framework;
using SFA.DAS.EmployerFinance.Infrastructure.OuterApiRequests;
using SFA.DAS.EmployerFinance.Infrastructure.OuterApiRequests.Transfers;

namespace SFA.DAS.EmployerFinance.UnitTests.Infrastructure.OuterApiRequests
{
Expand All @@ -9,11 +9,11 @@ public class WhenBuildingGetPledgesRequest
[Test]
public void Then_The_Url_Is_Correctly_Constructed()
{
var accountId = 123;
long accountId = 123;

var actual = new GetPledgesRequest(accountId);
var actual = new GetIndexRequest(accountId);

actual.GetUrl.Should().Be($"Pledges?accountId={accountId}");
actual.GetUrl.Should().Be($"Transfers/{accountId}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task Then_The_Endpoint_Is_Called_With_Authentication_Header_And_Dat
};
var httpMessageHandler = MessageHandler.SetupMessageHandlerMock(response, $"{config.BaseUrl}{getTestRequest.GetUrl}", config.Key);
var client = new HttpClient(httpMessageHandler.Object);
var apiClient = new ApiClient(client, config);
var apiClient = new ManageApprenticeshipsApiClient(client, config);

//Act
var actual = await apiClient.Get<List<string>>(getTestRequest);
Expand All @@ -57,7 +57,7 @@ public void Then_If_It_Is_Not_Successful_An_Exception_Is_Thrown()

var httpMessageHandler = MessageHandler.SetupMessageHandlerMock(response, $"{config.BaseUrl}{getTestRequest.GetUrl}", config.Key);
var client = new HttpClient(httpMessageHandler.Object);
var apiClient = new ApiClient(client, config);
var apiClient = new ManageApprenticeshipsApiClient(client, config);

//Act Assert
Assert.ThrowsAsync<HttpRequestException>(() => apiClient.Get<List<string>>(getTestRequest));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DocumentFormat.OpenXml.Office2010.CustomUI;
using Moq;
using NUnit.Framework;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerFinance.Infrastructure.OuterApiRequests;
using SFA.DAS.EmployerFinance.Infrastructure.OuterApiResponses;
using SFA.DAS.EmployerFinance.Interfaces.OuterApi;
using SFA.DAS.EmployerFinance.Services;

namespace SFA.DAS.EmployerFinance.UnitTests.Services.CohortsServiceTests
{
public class WhenIGetACohortsCount
{
private Mock<IApiClient> _apiClient;
private CohortsService _service;

[SetUp]
public void Setup()
{
_apiClient = new Mock<IApiClient>();
_service = new CohortsService(_apiClient.Object);
}

[Test]
public async Task ThenTheApiIsCalledWithAValidAccountIdAndTheCohortsCountIsReturned()
{
SetupApiClient(1);

var actual = await _service.GetCohortsCount(1);

Assert.AreEqual(1, actual);
}

[Test]
public async Task ThenTheApiIsCalledWithAnInvalidAccountIdAndTheCohortsCountIsZero()
{
SetupApiClient(0, false);

var actual = await _service.GetCohortsCount(0);

Assert.AreEqual(0, actual);
}

private void SetupApiClient(long accountId, bool addItem = true)
{
var items = new List<CohortSummary>();

if (addItem)
{
items = new List<CohortSummary>
{
new CohortSummary
{
AccountId = accountId
}
};
}

_apiClient.Setup(o =>
o.Get<GetCohortsResponse>(
It.Is<GetCohortsRequest>(i => i.GetUrl.Equals($"api/cohorts?accountId={accountId}"))))
.ReturnsAsync(new GetCohortsResponse
{
Cohorts = items
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using SFA.DAS.EmployerFinance.Infrastructure.OuterApiRequests;
using SFA.DAS.EmployerFinance.Infrastructure.OuterApiResponses;
using SFA.DAS.EmployerFinance.Infrastructure.OuterApiRequests.Transfers;
using SFA.DAS.EmployerFinance.Infrastructure.OuterApiResponses.Transfers;
using SFA.DAS.EmployerFinance.Interfaces.OuterApi;
using SFA.DAS.EmployerFinance.Services;

Expand All @@ -11,14 +11,14 @@ namespace SFA.DAS.EmployerFinance.UnitTests.Services.LevyTransferMatchingService
public class WhenIGetAPledgesCount
{
private Mock<IApiClient> _mockApiClient;
private LevyTransferMatchingService _levyTransferMatchingService;
private ManageApprenticeshipsService _levyTransferMatchingService;

[SetUp]
public void Arrange()
{
_mockApiClient = new Mock<IApiClient>();

_levyTransferMatchingService = new LevyTransferMatchingService(_mockApiClient.Object);
_levyTransferMatchingService = new ManageApprenticeshipsService(_mockApiClient.Object);
}

[Test]
Expand All @@ -29,13 +29,13 @@ public async Task ThenTheOuterApiIsCalledAndTotalPledgesForAccountReturned()
var accountId = 123;

_mockApiClient
.Setup(x => x.Get<GetPledgesResponse>(It.Is<GetPledgesRequest>(y => y.GetUrl.EndsWith(accountId.ToString()))))
.ReturnsAsync(new GetPledgesResponse()
.Setup(x => x.Get<GetIndexResponse>(It.Is<GetIndexRequest>(y => y.GetUrl.EndsWith(accountId.ToString()))))
.ReturnsAsync(new GetIndexResponse()
{
TotalPledges = expectedResult,
PledgesCount = expectedResult,
});

var actualResult = await _levyTransferMatchingService.GetPledgesCount(accountId);
var actualResult = await _levyTransferMatchingService.GetIndex(accountId);

Assert.AreEqual(expectedResult, actualResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public TransfersController(TransfersOrchestrator transfersOrchestrator)
[Route("transfers")]
public async Task<ActionResult> Index(string hashedAccountId)
{
var viewModel = await _transfersOrchestrator.Index(hashedAccountId);
var viewModel = await _transfersOrchestrator.GetIndexViewModel(hashedAccountId);

return View(viewModel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
using SFA.DAS.Authorization.EmployerUserRoles.Options;
using SFA.DAS.Authorization.Services;
using SFA.DAS.EmployerFinance.Services;
using SFA.DAS.EmployerFinance.Web.ViewModels;
using SFA.DAS.HashingService;
using SFA.DAS.EmployerFinance.Web.ViewModels.Transfers;

namespace SFA.DAS.EmployerFinance.Web.Orchestrators
{
public class TransfersOrchestrator
{
private readonly IAuthorizationService _authorizationService;
private readonly IHashingService _hashingService;
private readonly ILevyTransferMatchingService _levyTransferMatchingService;
private readonly IManageApprenticeshipsService _manageApprenticeshipsService;

protected TransfersOrchestrator()
{
Expand All @@ -21,31 +21,31 @@ protected TransfersOrchestrator()
public TransfersOrchestrator(
IAuthorizationService authorizationService,
IHashingService hashingService,
ILevyTransferMatchingService levyTransferMatchingService)
IManageApprenticeshipsService manageApprenticeshipsService)
{
_authorizationService = authorizationService;
_hashingService = hashingService;
_levyTransferMatchingService = levyTransferMatchingService;
_manageApprenticeshipsService = manageApprenticeshipsService;
}

public async Task<OrchestratorResponse<TransfersIndexViewModel>> Index(string hashedAccountId)
public async Task<OrchestratorResponse<IndexViewModel>> GetIndexViewModel(string hashedAccountId)
{
bool renderCreateTransfersPledgeButton = await _authorizationService.IsAuthorizedAsync(EmployerUserRole.OwnerOrTransactor);

var accountId = _hashingService.DecodeValue(hashedAccountId);
var indexTask = _manageApprenticeshipsService.GetIndex(accountId);
var renderCreateTransfersPledgeButtonTask = _authorizationService.IsAuthorizedAsync(EmployerUserRole.OwnerOrTransactor);

var pledgesCount = await _levyTransferMatchingService.GetPledgesCount(accountId);
await Task.WhenAll(indexTask, renderCreateTransfersPledgeButtonTask);

var viewModel = new OrchestratorResponse<TransfersIndexViewModel>()
return new OrchestratorResponse<IndexViewModel>
{
Data = new TransfersIndexViewModel()
Data = new IndexViewModel
{
RenderCreateTransfersPledgeButton = renderCreateTransfersPledgeButton,
PledgesCount = pledgesCount,
PledgesCount = indexTask.Result.PledgesCount,
ApplicationsCount = indexTask.Result.ApplicationsCount,
IsTransferReceiver = indexTask.Result.IsTransferReceiver,
IsTransferSender = indexTask.Result.IsTransferSender
}
};

return viewModel;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
<Compile Include="ViewModels\TransactionLineViewModel.cs" />
<Compile Include="ViewModels\TransactionViewModel.cs" />
<Compile Include="ViewModels\TransactionViewResultViewModel.cs" />
<Compile Include="ViewModels\TransfersIndexViewModel.cs" />
<Compile Include="ViewModels\Transfers\IndexViewModel.cs" />
<Compile Include="ViewModels\TransferTransactionDetailsViewModel.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace SFA.DAS.EmployerFinance.Web.ViewModels.Transfers
{
public class IndexViewModel
{
public bool IsTransferReceiver { get; set; }
public bool IsTransferSender { get; set; }
public bool RenderCreateTransfersPledgeButton { get; set; }
public int PledgesCount { get; set; }
public int ApplicationsCount { get; set; }
}
}

This file was deleted.

45 changes: 32 additions & 13 deletions src/SFA.DAS.EmployerFinance.Web/Views/Transfers/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model OrchestratorResponse<TransfersIndexViewModel>
@model OrchestratorResponse<SFA.DAS.EmployerFinance.Web.ViewModels.Transfers.IndexViewModel>

@{
ViewBag.PageID = "transfers";
Expand All @@ -9,21 +9,40 @@
}

<h1 class="heading-xlarge">Transfers</h1>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h2 class="govuk-heading-m">My pledges</h2>
<p>Create a public funding pledge which is shown online so that businesses can apply to you for a transfer of funds.</p>
<div class="panel panel-border-wide">
You have <strong>@Model.Data.PledgesCount</strong> transfer pledges.
@if (Model.Data.IsTransferReceiver)
{
<div class="govuk-grid-column-two-thirds">
<h2 class="govuk-heading-m">My pledges</h2>
<p>Create a public funding pledge which is shown online so that businesses can apply to you for a transfer of funds.</p>
<div class="panel panel-border-wide">
You have <strong>@Model.Data.PledgesCount</strong> transfer pledges.
</div>
<div class="">
@if (Model.Data.RenderCreateTransfersPledgeButton)
{
<a class="button" href="@Url.LevyMatchingTransfersAction("pledges/create/inform")" id="CreateTransfersPledgeButton">Create a transfers pledge</a>
}
<a href="@Url.LevyMatchingTransfersAction("pledges")" class="button button-secondary">View my transfer pledges and applications</a>
</div>
</div>
<div class="">
@if (Model.Data.RenderCreateTransfersPledgeButton)
{
<a class="button" href="@Url.LevyMatchingTransfersAction("pledges/create/inform")" id="CreateTransfersPledgeButton">Create a transfers pledge</a>
}
<a href="@Url.LevyMatchingTransfersAction("pledges")" class="button button-secondary">View my transfer pledges and applications</a>
}

@if (Model.Data.IsTransferSender)
{
<div class="govuk-grid-column-two-thirds">
<h2 class="govuk-heading-m">Apply for transfers funding</h2>
<p>Search transfers funding opportunities and apply for a transfer of funds.</p>
<div class="panel panel-border-wide">
You have <strong>@Model.Data.ApplicationsCount</strong> transfer applications.
</div>
<div class="govuk-button-group">
<a class="button" href="@Url.LevyMatchingTransfersAction("opportunities")" id="ApplyForTransfersButton">Apply for transfer opportunities</a>
<a href="@Url.LevyMatchingTransfersAction("applications")" class="button button-secondary">View applications I've submitted</a>
</div>
</div>
</div>
}
</div>

@section breadcrumb {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using SFA.DAS.EmployerFinance.Configuration;
using SFA.DAS.EmployerFinance.Infrastructure;
using SFA.DAS.EmployerFinance.Interfaces.OuterApi;
using SFA.DAS.EmployerFinance.Services;
using StructureMap;

namespace SFA.DAS.EmployerFinance.DependencyResolution
Expand All @@ -11,7 +12,9 @@ public class ManageApprenticeshipsOuterApiRegistry : Registry
public ManageApprenticeshipsOuterApiRegistry ()
{
For<ManageApprenticeshipsOuterApiConfiguration>().Use(c => c.GetInstance<EmployerFinanceConfiguration>().ManageApprenticeshipsOuterApiConfiguration).Singleton();
For<IApiClient>().Use<ApiClient>().Ctor<HttpClient>().Is(new HttpClient()).Singleton();
For<IApiClient>().Use<ManageApprenticeshipsApiClient>().Ctor<HttpClient>().Is(new HttpClient()).Singleton();
For<IApiClient>().Add<CommitmentsApiClient>().Named("CAPI").Ctor<HttpClient>().Is(new HttpClient()).Singleton();
For<ICohortsService>().Use<CohortsService>().Ctor<IApiClient>().IsNamedInstance("CAPI").Singleton();
}
}
}
18 changes: 6 additions & 12 deletions src/SFA.DAS.EmployerFinance/Infrastructure/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@

namespace SFA.DAS.EmployerFinance.Infrastructure
{
public class ApiClient : IApiClient
public abstract class ApiClient : IApiClient
{
private readonly HttpClient _httpClient;
private readonly ManageApprenticeshipsOuterApiConfiguration _config;

public ApiClient (
HttpClient httpClient,
ManageApprenticeshipsOuterApiConfiguration options)
protected HttpClient HttpClient => _httpClient;

protected ApiClient (
HttpClient httpClient)
{
_httpClient = httpClient;
_config = options;
_httpClient.BaseAddress = new Uri(_config.BaseUrl);
}

public async Task<TResponse> Get<TResponse>(IGetApiRequest request)
Expand All @@ -32,10 +30,6 @@ public async Task<TResponse> Get<TResponse>(IGetApiRequest request)
return JsonConvert.DeserializeObject<TResponse>(json);
}

private void AddHeaders()
{
_httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", _config.Key);
_httpClient.DefaultRequestHeaders.Add("X-Version", "1");
}
protected abstract void AddHeaders();
}
}
Loading