-
Notifications
You must be signed in to change notification settings - Fork 3
APPMAN-2710-Pending-changes-count #1549
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
Open
Pauljgraham
wants to merge
6
commits into
master
Choose a base branch
from
APPMAN-2710-Pending-changes-count
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
51bfc37
added handler and tests
Pauljgraham e23775f
fix some tests
Pauljgraham ad53f3a
code review updates
Pauljgraham 5d8e67b
fix failing tests
Pauljgraham d93af6e
Merge remote-tracking branch 'origin/master' into APPMAN-2710-Pending…
Najamuddin-Muhammad 889bddb
fixed merge issues
Pauljgraham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
...ommitmentsV2.Api.Types/Responses/GetPendingLearnerChangeCountsForEmployerQueryResponse.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
198 changes: 198 additions & 0 deletions
198
...GetPendingLearnerChangeCount/GetPendingLearnerChangeCountsForEmployerQueryHandlerTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
|
|
||
| [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); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...ion/Queries/GetPendingLearnerChangeCount/GetPendingLearnerChangeCountsForEmployerQuery.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
...ries/GetPendingLearnerChangeCount/GetPendingLearnerChangeCountsForEmployerQueryHandler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| }; | ||
| } | ||
| } | ||
|
|
7 changes: 7 additions & 0 deletions
7
...eries/GetPendingLearnerChangeCount/GetPendingLearnerChangeCountsForEmployerQueryResult.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; } | ||
| } |
11 changes: 11 additions & 0 deletions
11
...es/GetPendingLearnerChangeCount/GetPendingLearnerChangeCountsForEmployerQueryValidator.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.