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

APPMAN-1309 added status assigned on field to responses #1837

Open
wants to merge 3 commits into
base: APPMAN-1019-Add-LTM
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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,4 +1,5 @@
using System;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -9,6 +10,7 @@
using Moq;
using NUnit.Framework;
using SFA.DAS.Approvals.Api.Controllers;
using SFA.DAS.Approvals.Api.Models;
using SFA.DAS.Approvals.Application.SelectDirectTransferConnection.Queries;
using SFA.DAS.Testing.AutoFixture;

Expand All @@ -17,7 +19,7 @@ namespace SFA.DAS.Approvals.Api.UnitTests.Controllers.SelectDirectConnection;
public class WhenGettingSelectDirectConnection
{
[Test, MoqAutoData]
public async Task Then_Get_Returns_DirectConnections_From_Mediator(
public async Task Then_Get_Returns_IsLevyStatus_From_Mediator(
long accountId,
GetSelectDirectTransferConnectionQueryResult mediatorResult,
[Frozen] Mock<IMediator> mockMediator,
Expand All @@ -32,9 +34,38 @@ public async Task Then_Get_Returns_DirectConnections_From_Mediator(

controllerResult.Should().NotBeNull();
controllerResult.StatusCode.Should().Be((int)HttpStatusCode.OK);
var model = controllerResult.Value as GetSelectDirectTransferConnectionQueryResult;
var model = controllerResult.Value as GetSelectDirectConnectionResponse;
model.Should().NotBeNull();
model.IsLevyAccount.Should().Be(mediatorResult.IsLevyAccount);
}

[Test, MoqAutoData]
public async Task Then_Get_Returns_DirectConnections_From_Mediator(
long accountId,
GetSelectDirectTransferConnectionQueryResult mediatorResult,
[Frozen] Mock<IMediator> mockMediator,
[Greedy] SelectDirectConnectionController controller)
{
mockMediator.Setup(mediator => mediator.Send(
It.Is<GetSelectDirectTransferConnectionQuery>(x => x.AccountId == accountId),
It.IsAny<CancellationToken>()))
.ReturnsAsync(mediatorResult);

var controllerResult = await controller.Get(accountId) as ObjectResult;

controllerResult.Should().NotBeNull();
controllerResult.StatusCode.Should().Be((int)HttpStatusCode.OK);
var model = controllerResult.Value as GetSelectDirectConnectionResponse;
model.Should().NotBeNull();
model.Should().BeEquivalentTo(mediatorResult);
model.TransferConnections.Should().BeEquivalentTo(mediatorResult.TransferConnections.Select(x =>
new GetSelectDirectConnectionResponse.TransferDirectConnection
{
FundingEmployerAccountId = x.FundingEmployerAccountId,
FundingEmployerHashedAccountId = x.FundingEmployerHashedAccountId,
FundingEmployerPublicHashedAccountId = x.FundingEmployerPublicHashedAccountId,
FundingEmployerAccountName = x.FundingEmployerAccountName,
ApprovedOn = x.StatusAssignedOn
}));
}

[Test, MoqAutoData]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SFA.DAS.Approvals.Api.Models;
using SFA.DAS.Approvals.Application.SelectDirectTransferConnection.Queries;

namespace SFA.DAS.Approvals.Api.Controllers
Expand All @@ -28,7 +29,7 @@ public async Task<IActionResult> Get(long accountId)
{
_logger.LogInformation("Getting Direct Transfer Connections for Account {accountId}", accountId);
var result = await _mediator.Send(new GetSelectDirectTransferConnectionQuery {AccountId = accountId});
return Ok(result);
return Ok((GetSelectDirectConnectionResponse)result);
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections.Generic;
using System;
using System.Linq;
using SFA.DAS.Approvals.Application.SelectDirectTransferConnection.Queries;

namespace SFA.DAS.Approvals.Api.Models;
public class GetSelectDirectConnectionResponse
{
public bool IsLevyAccount { get; set; }
public IEnumerable<TransferDirectConnection> TransferConnections { get; set; }

public static implicit operator GetSelectDirectConnectionResponse(GetSelectDirectTransferConnectionQueryResult source)
{
return new GetSelectDirectConnectionResponse
{
IsLevyAccount = source.IsLevyAccount,
TransferConnections = source.TransferConnections.Select(x => new TransferDirectConnection
{
FundingEmployerAccountId = x.FundingEmployerAccountId,
FundingEmployerHashedAccountId = x.FundingEmployerHashedAccountId,
FundingEmployerPublicHashedAccountId = x.FundingEmployerPublicHashedAccountId,
FundingEmployerAccountName = x.FundingEmployerAccountName,
ApprovedOn = x.StatusAssignedOn
})
};
}

public class TransferDirectConnection
{
public long FundingEmployerAccountId { get; set; }
public string FundingEmployerHashedAccountId { get; set; }
public string FundingEmployerPublicHashedAccountId { get; set; }
public string FundingEmployerAccountName { get; set; }
public DateTime? ApprovedOn { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

namespace SFA.DAS.SharedOuterApi.InnerApi.Responses.EmployerFinance
{
Expand All @@ -11,6 +12,8 @@ public class TransferConnection
public string FundingEmployerHashedAccountId { get; set; }
public string FundingEmployerPublicHashedAccountId { get; set; }
public string FundingEmployerAccountName { get; set; }
public short? Status { get; set; }
public DateTime? StatusAssignedOn { get; set; }
}
}
}