From 104bb9dbc3ae8103497544c2a4e9fba8de95a432 Mon Sep 17 00:00:00 2001 From: Paul Howes Date: Wed, 8 Sep 2021 12:54:37 +0100 Subject: [PATCH 1/3] Added check for completed commitments --- .../WhenIRemoveALegalEntity.cs | 28 +++++++++++++++++-- .../RemoveLegalEntityCommandHandler.cs | 2 +- .../DependencyResolution/HashingRegistry.cs | 2 +- ...GetAccountLegalEntityRemoveQueryHandler.cs | 1 + 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/SFA.DAS.EmployerAccounts.UnitTests/Commands/RemoveLegalEntityTests/WhenIRemoveALegalEntity.cs b/src/SFA.DAS.EmployerAccounts.UnitTests/Commands/RemoveLegalEntityTests/WhenIRemoveALegalEntity.cs index ad200686b0..6d10bea572 100644 --- a/src/SFA.DAS.EmployerAccounts.UnitTests/Commands/RemoveLegalEntityTests/WhenIRemoveALegalEntity.cs +++ b/src/SFA.DAS.EmployerAccounts.UnitTests/Commands/RemoveLegalEntityTests/WhenIRemoveALegalEntity.cs @@ -114,7 +114,11 @@ public void Arrange() { new ApprenticeshipStatusSummary { - ActiveCount = 0,PausedCount = 0,PendingApprovalCount = 0,LegalEntityIdentifier = _expectedAgreement.LegalEntityCode + ActiveCount = 0, + PausedCount = 0, + PendingApprovalCount = 0, + CompletedCount = 0, + LegalEntityIdentifier = _expectedAgreement.LegalEntityCode } }); @@ -229,7 +233,27 @@ public async Task ThenTheAgreementIsCheckedToSeeIfItHasBeenSignedAndHasActiveCom { new ApprenticeshipStatusSummary { - ActiveCount = 1,PausedCount = 1,PendingApprovalCount = 1,LegalEntityIdentifier = _expectedAgreement.LegalEntityCode + ActiveCount = 1, + PausedCount = 1, + PendingApprovalCount = 1, + LegalEntityIdentifier = _expectedAgreement.LegalEntityCode + } + }); + + Assert.ThrowsAsync(() => _handler.Handle(_command)); + } + + [Test] + public async Task ThenTheAgreementIsCheckedToSeeIfItHasBeenSignedAndHasCompletedCommitments() + { + _commitmentsApi + .Setup(x => x.GetEmployerAccountSummary(ExpectedAccountId)) + .ReturnsAsync(new List + { + new ApprenticeshipStatusSummary + { + CompletedCount = 1, + LegalEntityIdentifier = _expectedAgreement.LegalEntityCode } }); diff --git a/src/SFA.DAS.EmployerAccounts/Commands/RemoveLegalEntity/RemoveLegalEntityCommandHandler.cs b/src/SFA.DAS.EmployerAccounts/Commands/RemoveLegalEntity/RemoveLegalEntityCommandHandler.cs index 70dc3c90aa..c9d66bbbc8 100644 --- a/src/SFA.DAS.EmployerAccounts/Commands/RemoveLegalEntity/RemoveLegalEntityCommandHandler.cs +++ b/src/SFA.DAS.EmployerAccounts/Commands/RemoveLegalEntity/RemoveLegalEntityCommandHandler.cs @@ -125,7 +125,7 @@ private async Task ValidateLegalEntityHasNoCommitments(EmployerAgreementView agr && c.LegalEntityIdentifier.Equals(agreement.LegalEntityCode) && c.LegalEntityOrganisationType == agreement.LegalEntitySource); - if (commitment != null && (commitment.ActiveCount + commitment.PausedCount + commitment.PendingApprovalCount) != 0) + if (commitment != null && (commitment.ActiveCount + commitment.PausedCount + commitment.PendingApprovalCount + commitment.CompletedCount) != 0) { validationResult.AddError(nameof(agreement.HashedAgreementId), "Agreement has already been signed and has active commitments"); throw new InvalidRequestException(validationResult.ValidationDictionary); diff --git a/src/SFA.DAS.EmployerAccounts/DependencyResolution/HashingRegistry.cs b/src/SFA.DAS.EmployerAccounts/DependencyResolution/HashingRegistry.cs index b507b69196..d1f2053b63 100644 --- a/src/SFA.DAS.EmployerAccounts/DependencyResolution/HashingRegistry.cs +++ b/src/SFA.DAS.EmployerAccounts/DependencyResolution/HashingRegistry.cs @@ -30,7 +30,7 @@ public HashingRegistry() .Ctor() .Is(c => new HashingService.HashingService( - c.GetInstance() .PublicAllowedAccountLegalEntityHashstringCharacters, + c.GetInstance().PublicAllowedAccountLegalEntityHashstringCharacters, c.GetInstance().PublicAllowedAccountLegalEntityHashstringSalt)); } diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetAccountLegalEntityRemove/GetAccountLegalEntityRemoveQueryHandler.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetAccountLegalEntityRemove/GetAccountLegalEntityRemoveQueryHandler.cs index e7d5d0f0fe..3a35efcd41 100644 --- a/src/SFA.DAS.EmployerAccounts/Queries/GetAccountLegalEntityRemove/GetAccountLegalEntityRemoveQueryHandler.cs +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetAccountLegalEntityRemove/GetAccountLegalEntityRemoveQueryHandler.cs @@ -84,6 +84,7 @@ private async Task SetRemovedStatusBasedOnCommitments(long accountId, Acco return commitmentConnectedToEntity == null || (commitmentConnectedToEntity.ActiveCount + commitmentConnectedToEntity.PendingApprovalCount + + commitmentConnectedToEntity.CompletedCount + commitmentConnectedToEntity.PausedCount) == 0; } } From ff0dd60f551136bb2060cfba78028296288b91f3 Mon Sep 17 00:00:00 2001 From: Paul Howes Date: Thu, 9 Sep 2021 09:53:52 +0100 Subject: [PATCH 2/3] Added withdrawn apprentices --- .../WhenIRemoveALegalEntity.cs | 17 +++++++++++++++++ .../RemoveLegalEntityCommandHandler.cs | 2 +- .../GetAccountLegalEntityRemoveQueryHandler.cs | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/SFA.DAS.EmployerAccounts.UnitTests/Commands/RemoveLegalEntityTests/WhenIRemoveALegalEntity.cs b/src/SFA.DAS.EmployerAccounts.UnitTests/Commands/RemoveLegalEntityTests/WhenIRemoveALegalEntity.cs index 6d10bea572..0bd3758983 100644 --- a/src/SFA.DAS.EmployerAccounts.UnitTests/Commands/RemoveLegalEntityTests/WhenIRemoveALegalEntity.cs +++ b/src/SFA.DAS.EmployerAccounts.UnitTests/Commands/RemoveLegalEntityTests/WhenIRemoveALegalEntity.cs @@ -259,5 +259,22 @@ public async Task ThenTheAgreementIsCheckedToSeeIfItHasBeenSignedAndHasCompleted Assert.ThrowsAsync(() => _handler.Handle(_command)); } + + [Test] + public async Task ThenTheAgreementIsCheckedToSeeIfItHasBeenSignedAndHasWithdrawnCommitments() + { + _commitmentsApi + .Setup(x => x.GetEmployerAccountSummary(ExpectedAccountId)) + .ReturnsAsync(new List + { + new ApprenticeshipStatusSummary + { + WithdrawnCount = 1, + LegalEntityIdentifier = _expectedAgreement.LegalEntityCode + } + }); + + Assert.ThrowsAsync(() => _handler.Handle(_command)); + } } } diff --git a/src/SFA.DAS.EmployerAccounts/Commands/RemoveLegalEntity/RemoveLegalEntityCommandHandler.cs b/src/SFA.DAS.EmployerAccounts/Commands/RemoveLegalEntity/RemoveLegalEntityCommandHandler.cs index c9d66bbbc8..e3800a7831 100644 --- a/src/SFA.DAS.EmployerAccounts/Commands/RemoveLegalEntity/RemoveLegalEntityCommandHandler.cs +++ b/src/SFA.DAS.EmployerAccounts/Commands/RemoveLegalEntity/RemoveLegalEntityCommandHandler.cs @@ -125,7 +125,7 @@ private async Task ValidateLegalEntityHasNoCommitments(EmployerAgreementView agr && c.LegalEntityIdentifier.Equals(agreement.LegalEntityCode) && c.LegalEntityOrganisationType == agreement.LegalEntitySource); - if (commitment != null && (commitment.ActiveCount + commitment.PausedCount + commitment.PendingApprovalCount + commitment.CompletedCount) != 0) + if (commitment != null && (commitment.ActiveCount + commitment.PausedCount + commitment.PendingApprovalCount + commitment.CompletedCount + commitment.WithdrawnCount) != 0) { validationResult.AddError(nameof(agreement.HashedAgreementId), "Agreement has already been signed and has active commitments"); throw new InvalidRequestException(validationResult.ValidationDictionary); diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetAccountLegalEntityRemove/GetAccountLegalEntityRemoveQueryHandler.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetAccountLegalEntityRemove/GetAccountLegalEntityRemoveQueryHandler.cs index 3a35efcd41..ec549532d2 100644 --- a/src/SFA.DAS.EmployerAccounts/Queries/GetAccountLegalEntityRemove/GetAccountLegalEntityRemoveQueryHandler.cs +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetAccountLegalEntityRemove/GetAccountLegalEntityRemoveQueryHandler.cs @@ -85,6 +85,7 @@ private async Task SetRemovedStatusBasedOnCommitments(long accountId, Acco return commitmentConnectedToEntity == null || (commitmentConnectedToEntity.ActiveCount + commitmentConnectedToEntity.PendingApprovalCount + commitmentConnectedToEntity.CompletedCount + + commitmentConnectedToEntity.WithdrawnCount + commitmentConnectedToEntity.PausedCount) == 0; } } From b6fbecb4fbe60338015e6c51e0cac3b6c18810c0 Mon Sep 17 00:00:00 2001 From: Paul Howes Date: Fri, 10 Sep 2021 16:07:07 +0100 Subject: [PATCH 3/3] Still allow completed records to be deleted --- .../WhenIRemoveALegalEntity.cs | 17 ----------------- .../RemoveLegalEntityCommandHandler.cs | 2 +- .../GetAccountLegalEntityRemoveQueryHandler.cs | 1 - 3 files changed, 1 insertion(+), 19 deletions(-) diff --git a/src/SFA.DAS.EmployerAccounts.UnitTests/Commands/RemoveLegalEntityTests/WhenIRemoveALegalEntity.cs b/src/SFA.DAS.EmployerAccounts.UnitTests/Commands/RemoveLegalEntityTests/WhenIRemoveALegalEntity.cs index 0bd3758983..8e2628ddb5 100644 --- a/src/SFA.DAS.EmployerAccounts.UnitTests/Commands/RemoveLegalEntityTests/WhenIRemoveALegalEntity.cs +++ b/src/SFA.DAS.EmployerAccounts.UnitTests/Commands/RemoveLegalEntityTests/WhenIRemoveALegalEntity.cs @@ -243,23 +243,6 @@ public async Task ThenTheAgreementIsCheckedToSeeIfItHasBeenSignedAndHasActiveCom Assert.ThrowsAsync(() => _handler.Handle(_command)); } - [Test] - public async Task ThenTheAgreementIsCheckedToSeeIfItHasBeenSignedAndHasCompletedCommitments() - { - _commitmentsApi - .Setup(x => x.GetEmployerAccountSummary(ExpectedAccountId)) - .ReturnsAsync(new List - { - new ApprenticeshipStatusSummary - { - CompletedCount = 1, - LegalEntityIdentifier = _expectedAgreement.LegalEntityCode - } - }); - - Assert.ThrowsAsync(() => _handler.Handle(_command)); - } - [Test] public async Task ThenTheAgreementIsCheckedToSeeIfItHasBeenSignedAndHasWithdrawnCommitments() { diff --git a/src/SFA.DAS.EmployerAccounts/Commands/RemoveLegalEntity/RemoveLegalEntityCommandHandler.cs b/src/SFA.DAS.EmployerAccounts/Commands/RemoveLegalEntity/RemoveLegalEntityCommandHandler.cs index e3800a7831..ad09af67e2 100644 --- a/src/SFA.DAS.EmployerAccounts/Commands/RemoveLegalEntity/RemoveLegalEntityCommandHandler.cs +++ b/src/SFA.DAS.EmployerAccounts/Commands/RemoveLegalEntity/RemoveLegalEntityCommandHandler.cs @@ -125,7 +125,7 @@ private async Task ValidateLegalEntityHasNoCommitments(EmployerAgreementView agr && c.LegalEntityIdentifier.Equals(agreement.LegalEntityCode) && c.LegalEntityOrganisationType == agreement.LegalEntitySource); - if (commitment != null && (commitment.ActiveCount + commitment.PausedCount + commitment.PendingApprovalCount + commitment.CompletedCount + commitment.WithdrawnCount) != 0) + if (commitment != null && (commitment.ActiveCount + commitment.PausedCount + commitment.PendingApprovalCount + commitment.WithdrawnCount) != 0) { validationResult.AddError(nameof(agreement.HashedAgreementId), "Agreement has already been signed and has active commitments"); throw new InvalidRequestException(validationResult.ValidationDictionary); diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetAccountLegalEntityRemove/GetAccountLegalEntityRemoveQueryHandler.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetAccountLegalEntityRemove/GetAccountLegalEntityRemoveQueryHandler.cs index ec549532d2..5bee6daeab 100644 --- a/src/SFA.DAS.EmployerAccounts/Queries/GetAccountLegalEntityRemove/GetAccountLegalEntityRemoveQueryHandler.cs +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetAccountLegalEntityRemove/GetAccountLegalEntityRemoveQueryHandler.cs @@ -84,7 +84,6 @@ private async Task SetRemovedStatusBasedOnCommitments(long accountId, Acco return commitmentConnectedToEntity == null || (commitmentConnectedToEntity.ActiveCount + commitmentConnectedToEntity.PendingApprovalCount + - commitmentConnectedToEntity.CompletedCount + commitmentConnectedToEntity.WithdrawnCount + commitmentConnectedToEntity.PausedCount) == 0; }