Skip to content

Commit

Permalink
Merge pull request #2208 from SkillsFundingAgency/TM-173-LTM-Integrat…
Browse files Browse the repository at this point in the history
…ion-With-Reservations-And-Approvals

Adds "internal" api endpoint to get transfer connections
  • Loading branch information
chrisfoster76 authored Nov 1, 2021
2 parents 55bf837 + 05be832 commit 995fe73
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using SFA.DAS.EmployerAccounts.Api.Controllers;
using SFA.DAS.EmployerAccounts.Api.Types;
using SFA.DAS.EmployerAccounts.Queries.GetTransferConnections;
using SFA.DAS.HashingService;

namespace SFA.DAS.EmployerAccounts.Api.UnitTests.Controllers.TransferConnectionsControllerTests
{
Expand All @@ -15,9 +16,11 @@ public class WhenIGetTransferConnections
{
private TransferConnectionsController _controller;
private Mock<IMediator> _mediator;
private Mock<IHashingService> _hashingService;
private GetTransferConnectionsResponse _response;
private IEnumerable<TransferConnection> _transferConnections;
private string _hashedAccountId;
private readonly string _hashedAccountId = "GF3XWP";
private readonly int _accountId = 123;

[SetUp]
public void Arrange()
Expand All @@ -27,13 +30,15 @@ public void Arrange()
_transferConnections = new List<TransferConnection>();
_response = new GetTransferConnectionsResponse { TransferConnections = _transferConnections };

_hashedAccountId = "GF3XWP";
_hashingService = new Mock<IHashingService>();
_hashingService.Setup(x => x.HashValue(_accountId)).Returns(_hashedAccountId);

_mediator.Setup(
m => m.SendAsync(
It.Is<GetTransferConnectionsQuery>(q => q.HashedAccountId.Equals(_hashedAccountId))))
.ReturnsAsync(_response);

_controller = new TransferConnectionsController(_mediator.Object);
_controller = new TransferConnectionsController(_mediator.Object, _hashingService.Object);
}

[Test]
Expand All @@ -46,6 +51,16 @@ public async Task ThenAGetTransferConnectionsQueryShouldBeSent()
Times.Once);
}

[Test]
public async Task ThenAGetTransferConnectionsQueryShouldBeSentWithHashedId()
{
await _controller.GetTransferConnections(_accountId);

_mediator.Verify(
m => m.SendAsync(It.Is<GetTransferConnectionsQuery>(q => q.HashedAccountId.Equals(_hashedAccountId))),
Times.Once);
}

[Test]
public async Task ThenShouldReturnTransferConnections()
{
Expand All @@ -54,5 +69,14 @@ public async Task ThenShouldReturnTransferConnections()
Assert.That(result, Is.Not.Null);
Assert.That(result.Content, Is.SameAs(_transferConnections));
}

[Test]
public async Task ThenShouldReturnTransferConnectionsForInternal()
{
var result = await _controller.GetTransferConnections(_accountId) as OkNegotiatedContentResult<IEnumerable<TransferConnection>>;

Assert.That(result, Is.Not.Null);
Assert.That(result.Content, Is.SameAs(_transferConnections));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,37 @@
using MediatR;
using SFA.DAS.EmployerAccounts.Api.Attributes;
using SFA.DAS.EmployerAccounts.Queries.GetTransferConnections;
using SFA.DAS.HashingService;

namespace SFA.DAS.EmployerAccounts.Api.Controllers
{
[ApiAuthorize(Roles = "ReadUserAccounts")]
[RoutePrefix("api/accounts/{hashedAccountId}/transfers/connections")]
[RoutePrefix("api/accounts")]
public class TransferConnectionsController : ApiController
{
private readonly IMediator _mediator;
private readonly IHashingService _hashingService;

public TransferConnectionsController(IMediator mediator)
public TransferConnectionsController(IMediator mediator, IHashingService hashingService)
{
_mediator = mediator;
_hashingService = hashingService;
}
[Route]

[Route("{hashedAccountId}/transfers/connections")]
public async Task<IHttpActionResult> GetTransferConnections(string hashedAccountId)
{
var response = await _mediator.SendAsync( new GetTransferConnectionsQuery{ HashedAccountId = hashedAccountId});
return Ok(response.TransferConnections);
}

[Route("internal/{accountId}/transfers/connections")]
public async Task<IHttpActionResult> GetTransferConnections(long accountId)
{
var hashedAccountId = _hashingService.HashValue(accountId);

var response = await _mediator.SendAsync(new GetTransferConnectionsQuery { HashedAccountId = hashedAccountId });
return Ok(response.TransferConnections);
}
}
}

0 comments on commit 995fe73

Please sign in to comment.