diff --git a/src/Approvals/SFA.DAS.Approvals.Api.UnitTests/Controllers/SelectDirectConnection/WhenGettingSelectDirectConnection.cs b/src/Approvals/SFA.DAS.Approvals.Api.UnitTests/Controllers/SelectDirectConnection/WhenGettingSelectDirectConnection.cs index d3753eb1c2..b7c0f71268 100644 --- a/src/Approvals/SFA.DAS.Approvals.Api.UnitTests/Controllers/SelectDirectConnection/WhenGettingSelectDirectConnection.cs +++ b/src/Approvals/SFA.DAS.Approvals.Api.UnitTests/Controllers/SelectDirectConnection/WhenGettingSelectDirectConnection.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Net; using System.Threading; using System.Threading.Tasks; @@ -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; @@ -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 mockMediator, @@ -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 mockMediator, + [Greedy] SelectDirectConnectionController controller) + { + mockMediator.Setup(mediator => mediator.Send( + It.Is(x => x.AccountId == accountId), + It.IsAny())) + .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] diff --git a/src/Approvals/SFA.DAS.Approvals.Api/Controllers/SelectDirectConnectionController.cs b/src/Approvals/SFA.DAS.Approvals.Api/Controllers/SelectDirectConnectionController.cs index 7a2b07a713..ff30a05fdf 100644 --- a/src/Approvals/SFA.DAS.Approvals.Api/Controllers/SelectDirectConnectionController.cs +++ b/src/Approvals/SFA.DAS.Approvals.Api/Controllers/SelectDirectConnectionController.cs @@ -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 @@ -28,7 +29,7 @@ public async Task 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) { diff --git a/src/Approvals/SFA.DAS.Approvals.Api/Models/GetSelectDirectConnectionResponse.cs b/src/Approvals/SFA.DAS.Approvals.Api/Models/GetSelectDirectConnectionResponse.cs new file mode 100644 index 0000000000..ae650c0703 --- /dev/null +++ b/src/Approvals/SFA.DAS.Approvals.Api/Models/GetSelectDirectConnectionResponse.cs @@ -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 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; } + } +} \ No newline at end of file diff --git a/src/Shared/SFA.DAS.SharedOuterApi/InnerApi/Responses/EmployerFinance/GetTransferConnectionsResponse.cs b/src/Shared/SFA.DAS.SharedOuterApi/InnerApi/Responses/EmployerFinance/GetTransferConnectionsResponse.cs index b04f59d9bd..c2fa594d89 100644 --- a/src/Shared/SFA.DAS.SharedOuterApi/InnerApi/Responses/EmployerFinance/GetTransferConnectionsResponse.cs +++ b/src/Shared/SFA.DAS.SharedOuterApi/InnerApi/Responses/EmployerFinance/GetTransferConnectionsResponse.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace SFA.DAS.SharedOuterApi.InnerApi.Responses.EmployerFinance { @@ -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; } } } } \ No newline at end of file