Skip to content
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
@@ -0,0 +1,7 @@
namespace SFA.DAS.CommitmentsV2.Api.Types.Responses;

public class GetPendingLearnerChangeCountsForEmployerQueryResponse
{
public int ManualPendingChangeCount { get; set; }
public int IlrPendingChangeCount { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Microsoft.AspNetCore.Mvc;
using Moq;
using SFA.DAS.CommitmentsV2.Api.Controllers;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.CommitmentsV2.Application.Queries.GetAccountStatus;
using SFA.DAS.CommitmentsV2.Application.Queries.GetAccountSummary;
using SFA.DAS.CommitmentsV2.Application.Queries.GetAccountTransferStatus;
using SFA.DAS.CommitmentsV2.Application.Queries.GetApprovedProviders;
using SFA.DAS.CommitmentsV2.Application.Queries.GetPendingLearnerChangeCount;
using SFA.DAS.CommitmentsV2.Application.Queries.GetProviderPaymentsPriority;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;

Expand Down Expand Up @@ -56,6 +58,13 @@ public async Task GetProviderPaymentPriorities_Should_Return_Valid_Result()
_fixture.VerifyGetProviderPaymentsPriorityResponse();
}

[Test]
public async Task GetPendingLearnerChangeCount_Should_Return_Valid_Result()
{
await _fixture.GetPendingLearnerChangeCount();
_fixture.VerifyGetPendingLearnerChangeCountResponse();
}

private class AccountControllerTestsFixture
{
private AccountController Controller { get; }
Expand All @@ -72,6 +81,7 @@ private class AccountControllerTestsFixture

private GetProviderPaymentsPriorityQueryResult ProviderPaymentsPriorityQueryResult { get; }
private GetProviderPaymentsPriorityResponse GetProviderPaymentsPriorityResponse { get; }
private GetPendingLearnerChangeCountsForEmployerQueryResult GetPendingLearnerChangeCountsForEmployerQueryResult { get; }

private IActionResult Result { get; set; }

Expand All @@ -96,6 +106,10 @@ public AccountControllerTestsFixture()
Mediator.Setup(x => x.Send(It.IsAny<GetApprovedProvidersQuery>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(ApprovedProviderQueryResult);

GetPendingLearnerChangeCountsForEmployerQueryResult = autoFixture.Create<GetPendingLearnerChangeCountsForEmployerQueryResult>();
Mediator.Setup(x => x.Send(It.IsAny<GetPendingLearnerChangeCountsForEmployerQuery>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(GetPendingLearnerChangeCountsForEmployerQueryResult);

ModelMapper = new Mock<IModelMapper>();

ProviderPaymentsPriorityQueryResult = new GetProviderPaymentsPriorityQueryResult
Expand Down Expand Up @@ -152,6 +166,12 @@ public async Task GetProviderPaymentsPriority()
Result = await Controller.GetProviderPaymentsPriority(AccountId);
}

public async Task GetPendingLearnerChangeCount()
{
Result = await Controller.GetPendingLearnerChangeCount(AccountId);
}


public void VerifyAccountRepsonse()
{
Assert.Multiple(() =>
Expand Down Expand Up @@ -242,5 +262,15 @@ public void VerifyGetProviderPaymentsPriorityResponse()
}
});
}

public void VerifyGetPendingLearnerChangeCountResponse()
{
Result.Should().BeOfType<OkObjectResult>();
var objectResult = (OkObjectResult)Result;
objectResult.Value.Should().BeOfType<GetPendingLearnerChangeCountsForEmployerQueryResponse>();
var response = (GetPendingLearnerChangeCountsForEmployerQueryResponse)objectResult.Value;
response.ManualPendingChangeCount.Should().Be(GetPendingLearnerChangeCountsForEmployerQueryResult.ManualPendingChangeCount);
response.IlrPendingChangeCount.Should().Be(GetPendingLearnerChangeCountsForEmployerQueryResult.IlrPendingChangeCount);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeshipStatusSummary;
using SFA.DAS.CommitmentsV2.Application.Queries.GetApprovedProviders;
using SFA.DAS.CommitmentsV2.Application.Queries.GetPendingApprenticeChanges;
using SFA.DAS.CommitmentsV2.Application.Queries.GetPendingLearnerChangeCount;
using SFA.DAS.CommitmentsV2.Application.Queries.GetProviderPaymentsPriority;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;

Expand Down Expand Up @@ -116,6 +117,22 @@ public async Task<IActionResult> GetPendingApprenticeChanges(long accountId)
return Ok(response);
}

[HttpGet]
[Route("pending-learner-change-counts")]
public async Task<IActionResult> GetPendingLearnerChangeCount(long accountId)
{
var query = new GetPendingLearnerChangeCountsForEmployerQuery(accountId);
var result = await mediator.Send(query);

if (result == null) { return NotFound(); }

return Ok(new GetPendingLearnerChangeCountsForEmployerQueryResponse
{
ManualPendingChangeCount = result.ManualPendingChangeCount,
IlrPendingChangeCount = result.IlrPendingChangeCount
});
}

[HttpPost]
[Route("update-provider-payments-priority")]
public async Task<IActionResult> UpdateProviderPaymentsPriority(long accountId, [FromBody] UpdateProviderPaymentsPriorityRequest request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ private Apprenticeship GenerateApprenticeshipDetails(Cohort cohort)
.Without(s => s.EmailAddressConfirmed)
.Without(s => s.ApprenticeshipConfirmationStatus)
.Without(s => s.EmployerVerificationRequest)
.Without(s => s.ApprovalRequests)
.Create();
return apprenticeshipDetails1;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
using SFA.DAS.CommitmentsV2.Application.Queries.GetPendingLearnerChangeCount;
using SFA.DAS.CommitmentsV2.Data;
using SFA.DAS.CommitmentsV2.Models;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.Testing.Builders;

namespace SFA.DAS.CommitmentsV2.UnitTests.Application.Queries.GetPendingLearnerChangeCount
{
[TestFixture]
public class GetPendingLearnerChangeCountsForEmployerQueryHandlerTests
{
private GetPendingLearnerChangeCountsForEmployerQueryHandlerTestsFixture _fixture;

[SetUp]
public void Arrange()
{
_fixture = new GetPendingLearnerChangeCountsForEmployerQueryHandlerTestsFixture();
}

[TearDown]
public void TearDown()
{
_fixture?.Dispose();
}

[Test]
public async Task Handle_ThenShouldFindNoPendingRequests()
{
var result = await _fixture.Handle(222);

result.ManualPendingChangeCount.Should().Be(0);
result.IlrPendingChangeCount.Should().Be(0);
}

[Test]
public async Task Handle_ThenShouldFindPendingManualRequests()
{
var result = await _fixture.AddApprenticeshipUpdates().Handle(222);

result.ManualPendingChangeCount.Should().Be(2);
result.IlrPendingChangeCount.Should().Be(0);
}

[Test]
public async Task Handle_ThenShouldFindPendingIlrRequests()
{
var result = await _fixture.AddIlrUpdates().Handle(222);

result.ManualPendingChangeCount.Should().Be(0);
result.IlrPendingChangeCount.Should().Be(2);
}

[Test]
public async Task Handle_ThenShouldFindPendingIlrAndManualRequests()
{
var result = await _fixture.AddApprenticeshipUpdates().AddIlrUpdates().Handle(222);

result.ManualPendingChangeCount.Should().Be(2);
result.IlrPendingChangeCount.Should().Be(2);
}

Comment thread
cofaulco marked this conversation as resolved.
[Test]
public async Task Handle_ThenShouldNotFindPendingIlrAndManualRequestsWhenLookingForAnotherEmployer()
{
var result = await _fixture.AddApprenticeshipUpdates().AddIlrUpdates().Handle(123);

result.ManualPendingChangeCount.Should().Be(0);
result.IlrPendingChangeCount.Should().Be(0);
}

[TestCase(CocApprovalResultStatus.Complete)]
[TestCase(CocApprovalResultStatus.Superseded)]
[TestCase(CocApprovalResultStatus.Cancelled)]
public async Task Handle_ThenShouldNotFindPendingIlrRequestsWhenStatusIs(CocApprovalResultStatus status)
{
var result = await _fixture.AddIlrUpdates(status).Handle(222);

result.IlrPendingChangeCount.Should().Be(0);
}

[TestCase(ApprenticeshipUpdateStatus.Approved)]
[TestCase(ApprenticeshipUpdateStatus.Rejected)]
[TestCase(ApprenticeshipUpdateStatus.Deleted)]
[TestCase(ApprenticeshipUpdateStatus.Superceded)]
[TestCase(ApprenticeshipUpdateStatus.Expired)]
public async Task Handle_ThenShouldNotFindPendingManualRequestsWhenStatusIs(ApprenticeshipUpdateStatus status)
{
var result = await _fixture.AddApprenticeshipUpdates(status).Handle(222);

result.ManualPendingChangeCount.Should().Be(0);
}

public class GetPendingLearnerChangeCountsForEmployerQueryHandlerTestsFixture : IDisposable
{
private readonly GetPendingLearnerChangeCountsForEmployerQueryHandler _handler;
private readonly ProviderCommitmentsDbContext _db;
private GetPendingLearnerChangeCountsForEmployerQueryResult _result;
private readonly Fixture _autoFixture;

public GetPendingLearnerChangeCountsForEmployerQueryHandlerTestsFixture()
{
_autoFixture = new Fixture();
_autoFixture.Behaviors.Add(new OmitOnRecursionBehavior());

_db = new ProviderCommitmentsDbContext(new DbContextOptionsBuilder<ProviderCommitmentsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString(), b => b.EnableNullChecks(false)).Options);

SeedData();

_handler = new GetPendingLearnerChangeCountsForEmployerQueryHandler(new Lazy<ProviderCommitmentsDbContext>(() => _db));
}

public async Task<GetPendingLearnerChangeCountsForEmployerQueryResult> Handle(long employerAccountId)
{
_result = await _handler.Handle(new GetPendingLearnerChangeCountsForEmployerQuery(employerAccountId), new CancellationToken());
return _result;
}


public void SeedData()
{
var cohort = new Cohort()
.Set(c => c.Id, 111)
.Set(c => c.EmployerAccountId, 222)
.Set(c => c.ProviderId, 333)
.Set(c => c.AccountLegalEntity, new AccountLegalEntity());

for (var i = 1001; i < 1005; i++)
{
var apprenticeship = _autoFixture.Build<Apprenticeship>()
.With(s => s.Cohort, cohort)
.With(s => s.PaymentStatus, PaymentStatus.Active)
.With(s => s.EndDate, DateTime.UtcNow.AddYears(1))
.With(s => s.StartDate, DateTime.UtcNow.AddDays(-10))
.Without(s => s.DataLockStatus)
.Without(s => s.EpaOrg)
.Without(s => s.ApprenticeshipUpdate)
.Without(s => s.ApprovalRequests)
.Without(s => s.Continuation)
.Without(s => s.PreviousApprenticeship)
.Without(s => s.CompletionDate)
.Without(s => s.EmailAddressConfirmed)
.Without(s => s.ApprenticeshipConfirmationStatus)
.Create();
cohort.Apprenticeships.Add(apprenticeship);
_db.Apprenticeships.Add(apprenticeship);
}

_db.Cohorts.Add(cohort);
_db.SaveChanges();
}

public GetPendingLearnerChangeCountsForEmployerQueryHandlerTestsFixture AddApprenticeshipUpdates(
ApprenticeshipUpdateStatus withStatus = ApprenticeshipUpdateStatus.Pending)
{

var apprenticeship1 = _db.Apprenticeships.First();
_db.ApprenticeshipUpdates.Add(CreateManualUpdate(apprenticeship1));
var apprenticeship2 = _db.Apprenticeships.Last();
_db.ApprenticeshipUpdates.Add(CreateManualUpdate(apprenticeship2));

_db.SaveChanges();
return this;

ApprenticeshipUpdate CreateManualUpdate(Apprenticeship apprenticeship) => _autoFixture.Build<ApprenticeshipUpdate>()
.With(s => s.ApprenticeshipId, apprenticeship.Id)
.With(s => s.Originator, Originator.Provider)
.With(s => s.Status, withStatus)
.With(s => s.Apprenticeship, apprenticeship)
.Without(s => s.DataLockStatus)
.Create();
}

public GetPendingLearnerChangeCountsForEmployerQueryHandlerTestsFixture AddIlrUpdates(
CocApprovalResultStatus withStatus = CocApprovalResultStatus.Pending)
{
var apprenticeship1 = _db.Apprenticeships.First();
_db.ApprovalRequests.Add(CreateIlrUpdate(apprenticeship1));
var apprenticeship2 = _db.Apprenticeships.Last();
_db.ApprovalRequests.Add(CreateIlrUpdate(apprenticeship2));

_db.SaveChanges();
return this;

ApprovalRequest CreateIlrUpdate(Apprenticeship apprenticeship) => _autoFixture.Build<ApprovalRequest>()
.With(s => s.ApprenticeshipId, apprenticeship.Id)
.With(s => s.Status, withStatus)
.With(s => s.Apprenticeship, apprenticeship)
.Create();
}

public void Dispose()
{
_db?.Dispose();
GC.SuppressFinalize(this);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ private void SeedData()
.Without(s => s.ApprenticeshipConfirmationStatus)
.Without(s => s.OverlappingTrainingDateRequests)
.Without(s => s.EmployerVerificationRequest)
.Without(s => s.ApprovalRequests)
.Create();

Db.Apprenticeships.Add(ApprenticeshipDetails);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace SFA.DAS.CommitmentsV2.Application.Queries.GetPendingLearnerChangeCount;

public class GetPendingLearnerChangeCountsForEmployerQuery : IRequest<GetPendingLearnerChangeCountsForEmployerQueryResult>
{
public long EmployerAccountId { get; }

public GetPendingLearnerChangeCountsForEmployerQuery(long employerAccountId)
{
EmployerAccountId = employerAccountId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using SFA.DAS.CommitmentsV2.Data;
using SFA.DAS.CommitmentsV2.Models;
using SFA.DAS.CommitmentsV2.Types;

namespace SFA.DAS.CommitmentsV2.Application.Queries.GetPendingLearnerChangeCount;

public class GetPendingLearnerChangeCountsForEmployerQueryHandler(Lazy<ProviderCommitmentsDbContext> db) : IRequestHandler<GetPendingLearnerChangeCountsForEmployerQuery, GetPendingLearnerChangeCountsForEmployerQueryResult>
{
public async Task<GetPendingLearnerChangeCountsForEmployerQueryResult> Handle(GetPendingLearnerChangeCountsForEmployerQuery request, CancellationToken cancellationToken)
{
var apprenticeshipUpdates = db.Value.ApprenticeshipUpdates
.Where(u => u.Apprenticeship.Cohort.EmployerAccountId == request.EmployerAccountId)
.Where(u => u.Status == ApprenticeshipUpdateStatus.Pending
&& u.Originator == Originator.Provider
);

var pendingCocRequests = db.Value.ApprovalRequests
.Where(r => r.Apprenticeship.Cohort.EmployerAccountId == request.EmployerAccountId)
.Where(r => r.Status == CocApprovalResultStatus.Pending);

return new GetPendingLearnerChangeCountsForEmployerQueryResult
{
ManualPendingChangeCount = await apprenticeshipUpdates.CountAsync(cancellationToken),
IlrPendingChangeCount = await pendingCocRequests.CountAsync(cancellationToken)
};
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace SFA.DAS.CommitmentsV2.Application.Queries.GetPendingLearnerChangeCount;

public class GetPendingLearnerChangeCountsForEmployerQueryResult
{
public int ManualPendingChangeCount { get; set; }
public int IlrPendingChangeCount { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using FluentValidation;

namespace SFA.DAS.CommitmentsV2.Application.Queries.GetPendingLearnerChangeCount;

public class GetPendingLearnerChangeCountsForEmployerQueryValidator : AbstractValidator<GetPendingLearnerChangeCountsForEmployerQuery>
{
public GetPendingLearnerChangeCountsForEmployerQueryValidator()
{
RuleFor(x => x.EmployerAccountId).GreaterThan(0);
}
}
Loading
Loading