diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Services/ApprenticeshipDomainServiceTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Services/ApprenticeshipDomainServiceTests.cs index ce44db0cb..d744e2940 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Services/ApprenticeshipDomainServiceTests.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Services/ApprenticeshipDomainServiceTests.cs @@ -29,7 +29,8 @@ public async Task ThenCorrectNumberOfEmployerNotifcationReturned(List i .WithApprenticeship(input.ApprenticeshipInput.AccountLegalEntityId, input.ApprenticeshipInput.LegalEntityId, input.ApprenticeshipInput.AccountId, input.ApprenticeshipInput.CohortId, input.ApprenticeshipInput.ApprenticeshipId, input.ApprenticeshipInput.PaymentStatus, input.ApprenticeshipInput.Originator) .WithDataLock(input.DataLockInput.DataLockStatusId, input.ApprenticeshipInput.ApprenticeshipId, input.DataLockInput.IsResolved, input.DataLockInput.IsExpired, input.DataLockInput.Status, - input.DataLockInput.EventStatus, input.DataLockInput.TriageStatus, input.DataLockInput.ErrorCode); + input.DataLockInput.EventStatus, input.DataLockInput.TriageStatus, input.DataLockInput.ErrorCode) + .WithApprovalRequest(input.ApprenticeshipInput.ApprenticeshipId, input.ApprovalResultStatus); } // Act @@ -80,7 +82,7 @@ public IEnumerator GetEnumerator() }; #endregion - #region single provider notification + #region single provider notification and Pending ILR Approval notification yield return new object[] { new List @@ -88,20 +90,21 @@ public IEnumerator GetEnumerator() new Input { ApprenticeshipInput = new ApprenticeshipInput { AccountLegalEntityId = 0, LegalEntityId = "LE0", AccountId = 1000, CohortId = 0, ApprenticeshipId = 1, PaymentStatus = PaymentStatus.Active, Originator = Originator.Provider }, - DataLockInput = new DataLockInput { DataLockStatusId = 0, IsResolved = true, IsExpired = true, Status = Status.Pass, EventStatus = EventStatus.Removed, TriageStatus = TriageStatus.Unknown, ErrorCode = DataLockErrorCode.None } - }, + DataLockInput = new DataLockInput { DataLockStatusId = 0, IsResolved = true, IsExpired = true, Status = Status.Pass, EventStatus = EventStatus.Removed, TriageStatus = TriageStatus.Unknown, ErrorCode = DataLockErrorCode.None }, + ApprovalResultStatus = CocApprovalResultStatus.Pending + } }, new List { new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1000", TotalCount = 1, ChangesForReviewCount = 1, RestartRequestCount = 0 + EmployerHashedAccountId = "HSH1000", TotalCount = 2, ChangesForReviewCount = 1, RestartRequestCount = 0, PendingIlrChangesCount = 1 } } }; #endregion - #region single price triage notification + #region single price triage notification and no notification for ILR as it's been completed yield return new object[] { new List @@ -109,14 +112,15 @@ public IEnumerator GetEnumerator() new Input { ApprenticeshipInput = new ApprenticeshipInput { AccountLegalEntityId = 0, LegalEntityId = "LE0", AccountId = 1000, CohortId = 0, ApprenticeshipId = 2, PaymentStatus = PaymentStatus.Active, Originator = Originator.Employer }, - DataLockInput = new DataLockInput { DataLockStatusId = 0, IsResolved = false, IsExpired = false, Status = Status.Fail, EventStatus = EventStatus.New, TriageStatus = TriageStatus.Change, ErrorCode = DataLockErrorCode.Dlock07 } + DataLockInput = new DataLockInput { DataLockStatusId = 0, IsResolved = false, IsExpired = false, Status = Status.Fail, EventStatus = EventStatus.New, TriageStatus = TriageStatus.Change, ErrorCode = DataLockErrorCode.Dlock07 }, + ApprovalResultStatus = CocApprovalResultStatus.Complete } }, new List { new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1000", TotalCount = 1, ChangesForReviewCount = 1, RestartRequestCount = 0 + EmployerHashedAccountId = "HSH1000", TotalCount = 1, ChangesForReviewCount = 1, RestartRequestCount = 0, PendingIlrChangesCount = 0 } } }; @@ -137,7 +141,7 @@ public IEnumerator GetEnumerator() { new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1000", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1 + EmployerHashedAccountId = "HSH1000", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1, PendingIlrChangesCount = 0 } } }; @@ -158,7 +162,7 @@ public IEnumerator GetEnumerator() { new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1000", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1 + EmployerHashedAccountId = "HSH1000", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1, PendingIlrChangesCount = 0 } } }; @@ -179,7 +183,7 @@ public IEnumerator GetEnumerator() { new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1000", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1 + EmployerHashedAccountId = "HSH1000", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1, PendingIlrChangesCount = 0 } } }; @@ -200,7 +204,7 @@ public IEnumerator GetEnumerator() { new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1000", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1 + EmployerHashedAccountId = "HSH1000", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1, PendingIlrChangesCount = 0 } } }; @@ -258,27 +262,27 @@ public IEnumerator GetEnumerator() { new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1001", TotalCount = 1, ChangesForReviewCount = 1, RestartRequestCount = 0 + EmployerHashedAccountId = "HSH1001", TotalCount = 1, ChangesForReviewCount = 1, RestartRequestCount = 0, PendingIlrChangesCount = 0 }, new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1002", TotalCount = 1, ChangesForReviewCount = 1, RestartRequestCount = 0 + EmployerHashedAccountId = "HSH1002", TotalCount = 1, ChangesForReviewCount = 1, RestartRequestCount = 0, PendingIlrChangesCount = 0 }, new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1003", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1 + EmployerHashedAccountId = "HSH1003", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1, PendingIlrChangesCount = 0 }, new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1004", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1 + EmployerHashedAccountId = "HSH1004", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1, PendingIlrChangesCount = 0 }, new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1005", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1 + EmployerHashedAccountId = "HSH1005", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1, PendingIlrChangesCount = 0 }, new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1006", TotalCount = 2, ChangesForReviewCount = 0, RestartRequestCount = 2 + EmployerHashedAccountId = "HSH1006", TotalCount = 2, ChangesForReviewCount = 0, RestartRequestCount = 2, PendingIlrChangesCount = 0 } } }; @@ -306,7 +310,7 @@ public IEnumerator GetEnumerator() { new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1006", TotalCount = 2, ChangesForReviewCount = 0, RestartRequestCount = 2 + EmployerHashedAccountId = "HSH1006", TotalCount = 2, ChangesForReviewCount = 0, RestartRequestCount = 2, PendingIlrChangesCount = 0 } } }; @@ -352,22 +356,23 @@ public IEnumerator GetEnumerator() new Input { ApprenticeshipInput = new ApprenticeshipInput { AccountLegalEntityId = 5, LegalEntityId = "LE5", AccountId = 1005, CohortId = 5, ApprenticeshipId = 6, PaymentStatus = PaymentStatus.Active, Originator = Originator.Employer }, - DataLockInput = new DataLockInput { DataLockStatusId = 6, IsResolved = false, IsExpired = false, Status = Status.Fail, EventStatus = EventStatus.New, TriageStatus = TriageStatus.Restart, ErrorCode = DataLockErrorCode.Dlock06 } + DataLockInput = new DataLockInput { DataLockStatusId = 6, IsResolved = false, IsExpired = false, Status = Status.Fail, EventStatus = EventStatus.New, TriageStatus = TriageStatus.Restart, ErrorCode = DataLockErrorCode.Dlock06 }, + ApprovalResultStatus = CocApprovalResultStatus.Pending } }, new List { new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1001", TotalCount = 2, ChangesForReviewCount = 2, RestartRequestCount = 0 + EmployerHashedAccountId = "HSH1001", TotalCount = 2, ChangesForReviewCount = 2, RestartRequestCount = 0, PendingIlrChangesCount = 0 }, new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1003", TotalCount = 2, ChangesForReviewCount = 2, RestartRequestCount = 0 + EmployerHashedAccountId = "HSH1003", TotalCount = 2, ChangesForReviewCount = 2, RestartRequestCount = 0, PendingIlrChangesCount = 0 }, new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1005", TotalCount = 2, ChangesForReviewCount = 0, RestartRequestCount = 2 + EmployerHashedAccountId = "HSH1005", TotalCount = 3, ChangesForReviewCount = 0, RestartRequestCount = 2, PendingIlrChangesCount = 1 } } }; @@ -401,26 +406,29 @@ public IEnumerator GetEnumerator() new Input { ApprenticeshipInput = new ApprenticeshipInput { AccountLegalEntityId = 1, LegalEntityId = "LE1", AccountId = 1001, CohortId = 1, ApprenticeshipId = 4, PaymentStatus = PaymentStatus.Active, Originator = Originator.Employer }, - DataLockInput = new DataLockInput { DataLockStatusId = 4, IsResolved = false, IsExpired = false, Status = Status.Fail, EventStatus = EventStatus.New, TriageStatus = TriageStatus.Change, ErrorCode = DataLockErrorCode.Dlock07 } + DataLockInput = new DataLockInput { DataLockStatusId = 4, IsResolved = false, IsExpired = false, Status = Status.Fail, EventStatus = EventStatus.New, TriageStatus = TriageStatus.Change, ErrorCode = DataLockErrorCode.Dlock07 }, + ApprovalResultStatus = CocApprovalResultStatus.Pending }, // single course triage notification new Input { ApprenticeshipInput = new ApprenticeshipInput { AccountLegalEntityId = 1, LegalEntityId = "LE1", AccountId = 1001, CohortId = 1, ApprenticeshipId = 5, PaymentStatus = PaymentStatus.Active, Originator = Originator.Employer }, - DataLockInput = new DataLockInput { DataLockStatusId = 5, IsResolved = false, IsExpired = false, Status = Status.Fail, EventStatus = EventStatus.New, TriageStatus = TriageStatus.Restart, ErrorCode = DataLockErrorCode.Dlock06 } + DataLockInput = new DataLockInput { DataLockStatusId = 5, IsResolved = false, IsExpired = false, Status = Status.Fail, EventStatus = EventStatus.New, TriageStatus = TriageStatus.Restart, ErrorCode = DataLockErrorCode.Dlock06 }, + ApprovalResultStatus = CocApprovalResultStatus.Pending }, // single course triage notification new Input { ApprenticeshipInput = new ApprenticeshipInput { AccountLegalEntityId = 1, LegalEntityId = "LE1", AccountId = 1001, CohortId = 1, ApprenticeshipId = 6, PaymentStatus = PaymentStatus.Active, Originator = Originator.Employer }, - DataLockInput = new DataLockInput { DataLockStatusId = 6, IsResolved = false, IsExpired = false, Status = Status.Fail, EventStatus = EventStatus.New, TriageStatus = TriageStatus.Restart, ErrorCode = DataLockErrorCode.Dlock06 } + DataLockInput = new DataLockInput { DataLockStatusId = 6, IsResolved = false, IsExpired = false, Status = Status.Fail, EventStatus = EventStatus.New, TriageStatus = TriageStatus.Restart, ErrorCode = DataLockErrorCode.Dlock06 }, + ApprovalResultStatus = CocApprovalResultStatus.Pending } }, new List { new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1001", TotalCount = 6, ChangesForReviewCount = 4, RestartRequestCount = 2 + EmployerHashedAccountId = "HSH1001", TotalCount = 9, ChangesForReviewCount = 4, RestartRequestCount = 2, PendingIlrChangesCount = 3 } } }; @@ -432,6 +440,7 @@ public class Input { public ApprenticeshipInput ApprenticeshipInput { get; set; } public DataLockInput DataLockInput { get; set; } + public CocApprovalResultStatus? ApprovalResultStatus { get; set; } } public class ApprenticeshipInput @@ -462,6 +471,7 @@ public class ApprenticeshipDomainServiceTestsFixture { public List SeedApprenticeships { get; } public List SeedDataLocks { get; } + public List SeedApprovalRequests { get; } private Mock _encodingService; @@ -469,6 +479,7 @@ public ApprenticeshipDomainServiceTestsFixture() { SeedApprenticeships = new List(); SeedDataLocks = new List(); + SeedApprovalRequests = new List(); _encodingService = new Mock(); _encodingService.Setup(s => s.Encode(It.IsAny(), EncodingType.AccountId)).Returns((value, encodingType) => $"HSH{value}"); @@ -503,6 +514,7 @@ private void SeedData(ProviderCommitmentsDbContext dbContext) { dbContext.Apprenticeships.AddRange(SeedApprenticeships); dbContext.DataLocks.AddRange(SeedDataLocks); + dbContext.ApprovalRequests.AddRange(SeedApprovalRequests); dbContext.SaveChanges(true); } @@ -555,6 +567,20 @@ public ApprenticeshipDomainServiceTestsFixture WithDataLock(long dataLockStatusI SeedDataLocks.Add(dataLock); return this; } + + public ApprenticeshipDomainServiceTestsFixture WithApprovalRequest(long apprenticeshipId, CocApprovalResultStatus? status) + { + if (status != null) + { + var approval = new ApprovalRequest() + .Set(c => c.Id, Guid.NewGuid()) + .Set(c => c.ApprenticeshipId, apprenticeshipId) + .Set(c => c.Status, status); + + SeedApprovalRequests.Add(approval); + } + return this; + } } } } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Services/EmployerAlertSummaryEmailServiceTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Services/EmployerAlertSummaryEmailServiceTests.cs index f8ca14bc5..fb08ffbd1 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Services/EmployerAlertSummaryEmailServiceTests.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Services/EmployerAlertSummaryEmailServiceTests.cs @@ -74,49 +74,6 @@ public IEnumerator GetEnumerator() }; #endregion - #region single provider notification - yield return new object[] - { - new Input - { - EmployerAlertSummaryNotifications = new List - { - new EmployerAlertSummaryNotification - { - EmployerHashedAccountId = "HSH1000", TotalCount = 1, ChangesForReviewCount = 1, RestartRequestCount = 0 - } - }, - AccountResponses = new List - { - new AccountResponse - { - AccountId = 1000, - HashedAccountId = "HSH1000", - DasAccountName = "FIRST ACCOUNT" - } - } - }, - new List - { - new Output - { - AccountId = 1000, - HashedAccountId = "HSH1000", - Tokens = new Dictionary - { - { "total_count_text", "is 1 apprentice" }, - { "account_name", "FIRST ACCOUNT" }, - { "need_needs", "needs" }, - { "changes_for_review", $"* 1 apprentice with changes for review" }, - { "requested_changes", "" }, - { "link_to_mange_apprenticeships", $"{EmployerCommitmentsBaseUrl}/HSH1000/apprentices" }, - { "link_to_unsubscribe", $"/settings/notifications/unsubscribe/HSH1000" } - } - } - } - }; - #endregion - #region single price triage notification yield return new object[] { @@ -126,7 +83,7 @@ public IEnumerator GetEnumerator() { new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1000", TotalCount = 1, ChangesForReviewCount = 1, RestartRequestCount = 0 + EmployerHashedAccountId = "HSH1000", TotalCount = 1, ChangesForReviewCount = 1, RestartRequestCount = 0, PendingIlrChangesCount = 0 } }, AccountResponses = new List @@ -147,12 +104,11 @@ public IEnumerator GetEnumerator() HashedAccountId = "HSH1000", Tokens = new Dictionary { - { "total_count_text", "is 1 apprentice" }, - { "account_name", "FIRST ACCOUNT" }, - { "need_needs", "needs" }, - { "changes_for_review", $"* 1 apprentice with changes for review" }, + { "total_count_text", "You have 1 item that needs your attention" }, + { "changes_for_review", $"* 1 learner with changes for review" }, { "requested_changes", "" }, - { "link_to_mange_apprenticeships", $"{EmployerCommitmentsBaseUrl}/HSH1000/apprentices" }, + { "ilrchanges_to_confirm", "" }, + { "link_to_mange_apprenticeships", $"Sign into your Apprenticeship Service Account" }, { "link_to_unsubscribe", $"/settings/notifications/unsubscribe/HSH1000" } } } @@ -160,91 +116,6 @@ public IEnumerator GetEnumerator() }; #endregion - #region single course triage notification - yield return new object[] - { - new Input - { - EmployerAlertSummaryNotifications = new List - { - new EmployerAlertSummaryNotification - { - EmployerHashedAccountId = "HSH1000", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1 - } - }, - AccountResponses = new List - { - new AccountResponse - { - AccountId = 1000, - HashedAccountId = "HSH1000", - DasAccountName = "FIRST ACCOUNT" - } - } - }, - new List - { - new Output - { - AccountId = 1000, - HashedAccountId = "HSH1000", - Tokens = new Dictionary - { - { "total_count_text", "is 1 apprentice" }, - { "account_name", "FIRST ACCOUNT" }, - { "need_needs", "needs" }, - { "changes_for_review", "" }, - { "requested_changes", $"* 1 apprentice with requested changes" }, - { "link_to_mange_apprenticeships", $"{EmployerCommitmentsBaseUrl}/HSH1000/apprentices" }, - { "link_to_unsubscribe", $"/settings/notifications/unsubscribe/HSH1000" } - } - } - } - }; - #endregion - - #region single course triage notification - yield return new object[] - { - new Input - { - EmployerAlertSummaryNotifications = new List - { - new EmployerAlertSummaryNotification - { - EmployerHashedAccountId = "HSH1000", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1 - } - }, - AccountResponses = new List - { - new AccountResponse - { - AccountId = 1000, - HashedAccountId = "HSH1000", - DasAccountName = "FIRST ACCOUNT" - } - } - }, - new List - { - new Output - { - AccountId = 1000, - HashedAccountId = "HSH1000", - Tokens = new Dictionary - { - { "total_count_text", "is 1 apprentice" }, - { "account_name", "FIRST ACCOUNT" }, - { "need_needs", "needs" }, - { "changes_for_review", "" }, - { "requested_changes", $"* 1 apprentice with requested changes" }, - { "link_to_mange_apprenticeships", $"{EmployerCommitmentsBaseUrl}/HSH1000/apprentices" }, - { "link_to_unsubscribe", $"/settings/notifications/unsubscribe/HSH1000" } - } - } - } - }; - #endregion #region single course triage notification yield return new object[] @@ -255,7 +126,7 @@ public IEnumerator GetEnumerator() { new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1000", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1 + EmployerHashedAccountId = "HSH1000", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1, PendingIlrChangesCount = 0 } }, AccountResponses = new List @@ -276,12 +147,11 @@ public IEnumerator GetEnumerator() HashedAccountId = "HSH1000", Tokens = new Dictionary { - { "total_count_text", "is 1 apprentice" }, - { "account_name", "FIRST ACCOUNT" }, - { "need_needs", "needs" }, + { "total_count_text", "You have 1 item that needs your attention" }, { "changes_for_review", "" }, - { "requested_changes", $"* 1 apprentice with requested changes" }, - { "link_to_mange_apprenticeships", $"{EmployerCommitmentsBaseUrl}/HSH1000/apprentices" }, + { "requested_changes", $"* 1 learner request to review" }, + { "ilrchanges_to_confirm", "" }, + { "link_to_mange_apprenticeships", $"Sign into your Apprenticeship Service Account" }, { "link_to_unsubscribe", $"/settings/notifications/unsubscribe/HSH1000" } } } @@ -289,7 +159,7 @@ public IEnumerator GetEnumerator() }; #endregion - #region single course triage notification + #region single Pending ILR CoC notification yield return new object[] { new Input @@ -298,7 +168,7 @@ public IEnumerator GetEnumerator() { new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1000", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1 + EmployerHashedAccountId = "HSH1000", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 0, PendingIlrChangesCount = 1 } }, AccountResponses = new List @@ -319,12 +189,11 @@ public IEnumerator GetEnumerator() HashedAccountId = "HSH1000", Tokens = new Dictionary { - { "total_count_text", "is 1 apprentice" }, - { "account_name", "FIRST ACCOUNT" }, - { "need_needs", "needs" }, + { "total_count_text", "You have 1 item that needs your attention" }, { "changes_for_review", "" }, - { "requested_changes", $"* 1 apprentice with requested changes" }, - { "link_to_mange_apprenticeships", $"{EmployerCommitmentsBaseUrl}/HSH1000/apprentices" }, + { "requested_changes", "" }, + { "ilrchanges_to_confirm", "* 1 learner with changes from ILR to confirm" }, + { "link_to_mange_apprenticeships", $"Sign into your Apprenticeship Service Account" }, { "link_to_unsubscribe", $"/settings/notifications/unsubscribe/HSH1000" } } } @@ -332,6 +201,7 @@ public IEnumerator GetEnumerator() }; #endregion + #region multiple notifications yield return new object[] { @@ -341,31 +211,31 @@ public IEnumerator GetEnumerator() { new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1001", TotalCount = 1, ChangesForReviewCount = 1, RestartRequestCount = 0 + EmployerHashedAccountId = "HSH1001", TotalCount = 1, ChangesForReviewCount = 1, RestartRequestCount = 0, PendingIlrChangesCount = 0 }, new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1002", TotalCount = 1, ChangesForReviewCount = 1, RestartRequestCount = 0 + EmployerHashedAccountId = "HSH1002", TotalCount = 1, ChangesForReviewCount = 1, RestartRequestCount = 0, PendingIlrChangesCount = 0 }, new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1003", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1 + EmployerHashedAccountId = "HSH1003", TotalCount = 3, ChangesForReviewCount = 0, RestartRequestCount = 1, PendingIlrChangesCount = 2 }, new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1004", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1 + EmployerHashedAccountId = "HSH1004", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1, PendingIlrChangesCount = 0 }, new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1005", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1 + EmployerHashedAccountId = "HSH1005", TotalCount = 1, ChangesForReviewCount = 0, RestartRequestCount = 1, PendingIlrChangesCount = 0 }, new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1006", TotalCount = 2, ChangesForReviewCount = 0, RestartRequestCount = 2 + EmployerHashedAccountId = "HSH1006", TotalCount = 4, ChangesForReviewCount = 0, RestartRequestCount = 2, PendingIlrChangesCount = 2 }, new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1007", TotalCount = 3, ChangesForReviewCount = 2, RestartRequestCount = 1 + EmployerHashedAccountId = "HSH1007", TotalCount = 4, ChangesForReviewCount = 2, RestartRequestCount = 1, PendingIlrChangesCount = 1 } }, AccountResponses = new List @@ -422,12 +292,11 @@ public IEnumerator GetEnumerator() HashedAccountId = "HSH1001", Tokens = new Dictionary { - { "total_count_text", "is 1 apprentice" }, - { "account_name", "ONE ACCOUNT" }, - { "need_needs", "needs" }, - { "changes_for_review", $"* 1 apprentice with changes for review" }, + { "total_count_text", "You have 1 item that needs your attention" }, + { "changes_for_review", $"* 1 learner with changes for review" }, { "requested_changes", "" }, - { "link_to_mange_apprenticeships", $"{EmployerCommitmentsBaseUrl}/HSH1001/apprentices" }, + { "ilrchanges_to_confirm", "" }, + { "link_to_mange_apprenticeships", $"Sign into your Apprenticeship Service Account" }, { "link_to_unsubscribe", $"/settings/notifications/unsubscribe/HSH1001" } } }, @@ -437,12 +306,11 @@ public IEnumerator GetEnumerator() HashedAccountId = "HSH1002", Tokens = new Dictionary { - { "total_count_text", "is 1 apprentice" }, - { "account_name", "TWO ACCOUNT" }, - { "need_needs", "needs" }, - { "changes_for_review", $"* 1 apprentice with changes for review" }, + { "total_count_text", "You have 1 item that needs your attention" }, + { "changes_for_review", $"* 1 learner with changes for review" }, { "requested_changes", "" }, - { "link_to_mange_apprenticeships", $"{EmployerCommitmentsBaseUrl}/HSH1002/apprentices" }, + { "ilrchanges_to_confirm", "" }, + { "link_to_mange_apprenticeships", $"Sign into your Apprenticeship Service Account" }, { "link_to_unsubscribe", $"/settings/notifications/unsubscribe/HSH1002" } } }, @@ -452,12 +320,11 @@ public IEnumerator GetEnumerator() HashedAccountId = "HSH1003", Tokens = new Dictionary { - { "total_count_text", "is 1 apprentice" }, - { "account_name", "THREE ACCOUNT" }, - { "need_needs", "needs" }, + { "total_count_text", "You have 3 items that need your attention" }, { "changes_for_review", "" }, - { "requested_changes", $"* 1 apprentice with requested changes" }, - { "link_to_mange_apprenticeships", $"{EmployerCommitmentsBaseUrl}/HSH1003/apprentices" }, + { "requested_changes", $"* 1 learner request to review" }, + { "ilrchanges_to_confirm", "* 2 learners with changes from ILR to confirm" }, + { "link_to_mange_apprenticeships", $"Sign into your Apprenticeship Service Account" }, { "link_to_unsubscribe", $"/settings/notifications/unsubscribe/HSH1003" } } }, @@ -467,12 +334,11 @@ public IEnumerator GetEnumerator() HashedAccountId = "HSH1004", Tokens = new Dictionary { - { "total_count_text", "is 1 apprentice" }, - { "account_name", "FOUR ACCOUNT" }, - { "need_needs", "needs" }, + { "total_count_text", "You have 1 item that needs your attention" }, { "changes_for_review", "" }, - { "requested_changes", $"* 1 apprentice with requested changes" }, - { "link_to_mange_apprenticeships", $"{EmployerCommitmentsBaseUrl}/HSH1004/apprentices" }, + { "requested_changes", $"* 1 learner request to review" }, + { "ilrchanges_to_confirm", "" }, + { "link_to_mange_apprenticeships", $"Sign into your Apprenticeship Service Account" }, { "link_to_unsubscribe", $"/settings/notifications/unsubscribe/HSH1004" } } }, @@ -482,12 +348,11 @@ public IEnumerator GetEnumerator() HashedAccountId = "HSH1005", Tokens = new Dictionary { - { "total_count_text", "is 1 apprentice" }, - { "account_name", "FIVE ACCOUNT" }, - { "need_needs", "needs" }, + { "total_count_text", "You have 1 item that needs your attention" }, { "changes_for_review", "" }, - { "requested_changes", $"* 1 apprentice with requested changes" }, - { "link_to_mange_apprenticeships", $"{EmployerCommitmentsBaseUrl}/HSH1005/apprentices" }, + { "requested_changes", $"* 1 learner request to review" }, + { "ilrchanges_to_confirm", "" }, + { "link_to_mange_apprenticeships", $"Sign into your Apprenticeship Service Account" }, { "link_to_unsubscribe", $"/settings/notifications/unsubscribe/HSH1005" } } }, @@ -497,12 +362,11 @@ public IEnumerator GetEnumerator() HashedAccountId = "HSH1006", Tokens = new Dictionary { - { "total_count_text", "are 2 apprentices" }, - { "account_name", "SIX ACCOUNT" }, - { "need_needs", "need" }, + { "total_count_text", "You have 4 items that need your attention" }, { "changes_for_review", "" }, - { "requested_changes", $"* 2 apprentices with requested changes" }, - { "link_to_mange_apprenticeships", $"{EmployerCommitmentsBaseUrl}/HSH1006/apprentices" }, + { "requested_changes", $"* 2 learner requests to review" }, + { "ilrchanges_to_confirm", "* 2 learners with changes from ILR to confirm" }, + { "link_to_mange_apprenticeships", $"Sign into your Apprenticeship Service Account" }, { "link_to_unsubscribe", $"/settings/notifications/unsubscribe/HSH1006" } } }, @@ -512,12 +376,11 @@ public IEnumerator GetEnumerator() HashedAccountId = "HSH1007", Tokens = new Dictionary { - { "total_count_text", "are 3 apprentices" }, - { "account_name", "SEVEN ACCOUNT" }, - { "need_needs", "need" }, - { "changes_for_review", $"* 2 apprentices with changes for review" }, - { "requested_changes", $"* 1 apprentice with requested changes" }, - { "link_to_mange_apprenticeships", $"{EmployerCommitmentsBaseUrl}/HSH1007/apprentices" }, + { "total_count_text", "You have 4 items that need your attention" }, + { "changes_for_review", "* 2 learners with changes for review" }, + { "requested_changes", "* 1 learner request to review" }, + { "ilrchanges_to_confirm", "* 1 learner with changes from ILR to confirm" }, + { "link_to_mange_apprenticeships", $"Sign into your Apprenticeship Service Account" }, { "link_to_unsubscribe", $"/settings/notifications/unsubscribe/HSH1007" } } } @@ -534,7 +397,7 @@ public IEnumerator GetEnumerator() { new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1006", TotalCount = 2, ChangesForReviewCount = 0, RestartRequestCount = 2 + EmployerHashedAccountId = "HSH1006", TotalCount = 2, ChangesForReviewCount = 0, RestartRequestCount = 2, PendingIlrChangesCount = 0 } }, AccountResponses = new List @@ -555,12 +418,11 @@ public IEnumerator GetEnumerator() HashedAccountId = "HSH1006", Tokens = new Dictionary { - { "total_count_text", "are 2 apprentices" }, - { "account_name", "SIX ACCOUNT" }, - { "need_needs", "need" }, + { "total_count_text", "You have 2 items that need your attention" }, { "changes_for_review", "" }, - { "requested_changes", $"* 2 apprentices with requested changes" }, - { "link_to_mange_apprenticeships", $"{EmployerCommitmentsBaseUrl}/HSH1006/apprentices" }, + { "requested_changes", "* 2 learner requests to review" }, + { "ilrchanges_to_confirm", "" }, + { "link_to_mange_apprenticeships", $"Sign into your Apprenticeship Service Account" }, { "link_to_unsubscribe", $"/settings/notifications/unsubscribe/HSH1006" } } } @@ -577,15 +439,15 @@ public IEnumerator GetEnumerator() { new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1001", TotalCount = 2, ChangesForReviewCount = 2, RestartRequestCount = 0 + EmployerHashedAccountId = "HSH1001", TotalCount = 2, ChangesForReviewCount = 2, RestartRequestCount = 0, PendingIlrChangesCount = 0 }, new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1003", TotalCount = 2, ChangesForReviewCount = 2, RestartRequestCount = 0 + EmployerHashedAccountId = "HSH1003", TotalCount = 2, ChangesForReviewCount = 2, RestartRequestCount = 0, PendingIlrChangesCount = 0 }, new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1005", TotalCount = 2, ChangesForReviewCount = 0, RestartRequestCount = 2 + EmployerHashedAccountId = "HSH1005", TotalCount = 2, ChangesForReviewCount = 0, RestartRequestCount = 2, PendingIlrChangesCount = 0 } }, AccountResponses = new List @@ -618,12 +480,11 @@ public IEnumerator GetEnumerator() HashedAccountId = "HSH1001", Tokens = new Dictionary { - { "total_count_text", "are 2 apprentices" }, - { "account_name", "ONE ACCOUNT" }, - { "need_needs", "need" }, - { "changes_for_review", $"* 2 apprentices with changes for review" }, + { "total_count_text", "You have 2 items that need your attention" }, + { "changes_for_review", $"* 2 learners with changes for review" }, { "requested_changes", "" }, - { "link_to_mange_apprenticeships", $"{EmployerCommitmentsBaseUrl}/HSH1001/apprentices" }, + { "ilrchanges_to_confirm", "" }, + { "link_to_mange_apprenticeships", $"Sign into your Apprenticeship Service Account" }, { "link_to_unsubscribe", $"/settings/notifications/unsubscribe/HSH1001" } } }, @@ -633,12 +494,11 @@ public IEnumerator GetEnumerator() HashedAccountId = "HSH1003", Tokens = new Dictionary { - { "total_count_text", "are 2 apprentices" }, - { "account_name", "THREE ACCOUNT" }, - { "need_needs", "need" }, - { "changes_for_review", $"* 2 apprentices with changes for review" }, + { "total_count_text", "You have 2 items that need your attention" }, + { "changes_for_review", "* 2 learners with changes for review" }, { "requested_changes", "" }, - { "link_to_mange_apprenticeships", $"{EmployerCommitmentsBaseUrl}/HSH1003/apprentices" }, + { "ilrchanges_to_confirm", "" }, + { "link_to_mange_apprenticeships", $"Sign into your Apprenticeship Service Account" }, { "link_to_unsubscribe", $"/settings/notifications/unsubscribe/HSH1003" } } }, @@ -648,13 +508,12 @@ public IEnumerator GetEnumerator() HashedAccountId = "HSH1005", Tokens = new Dictionary { - { "total_count_text", "are 2 apprentices" }, - { "account_name", "FIVE ACCOUNT" }, - { "need_needs", "need" }, + { "total_count_text", "You have 2 items that need your attention" }, { "changes_for_review", "" }, - { "requested_changes", $"* 2 apprentices with requested changes" }, - { "link_to_mange_apprenticeships", $"{EmployerCommitmentsBaseUrl}/HSH1005/apprentices" }, - { "link_to_unsubscribe", $"/settings/notifications/unsubscribe/HSH1005" } + { "requested_changes", "* 2 learner requests to review" }, + { "ilrchanges_to_confirm", "" }, + { "link_to_mange_apprenticeships", $"Sign into your Apprenticeship Service Account" }, + { "link_to_unsubscribe", "/settings/notifications/unsubscribe/HSH1005" } } } } @@ -670,7 +529,7 @@ public IEnumerator GetEnumerator() { new EmployerAlertSummaryNotification { - EmployerHashedAccountId = "HSH1001", TotalCount = 6, ChangesForReviewCount = 4, RestartRequestCount = 2 + EmployerHashedAccountId = "HSH1001", TotalCount = 7, ChangesForReviewCount = 4, RestartRequestCount = 2, PendingIlrChangesCount = 1 } }, AccountResponses = new List @@ -691,18 +550,18 @@ public IEnumerator GetEnumerator() HashedAccountId = "HSH1001", Tokens = new Dictionary { - { "total_count_text", $"are 6 apprentices" }, - { "account_name", "ONE ACCOUNT" }, - { "need_needs", "need" }, - { "changes_for_review", $"* 4 apprentices with changes for review" }, - { "requested_changes", $"* 2 apprentices with requested changes" }, - { "link_to_mange_apprenticeships", $"{EmployerCommitmentsBaseUrl}/HSH1001/apprentices" }, + { "total_count_text", $"You have 7 items that need your attention" }, + { "changes_for_review", $"* 4 learners with changes for review" }, + { "requested_changes", $"* 2 learner requests to review" }, + { "ilrchanges_to_confirm", "* 1 learner with changes from ILR to confirm" }, + { "link_to_mange_apprenticeships", $"Sign into your Apprenticeship Service Account" }, { "link_to_unsubscribe", $"/settings/notifications/unsubscribe/HSH1001" } } } } }; #endregion + } #region Test Data Classes @@ -736,7 +595,8 @@ public EmployerAlertSummaryEmailServiceTestsFixture() _approvalsOuterApiClient = new Mock(); commitmentsV2Configuration = new CommitmentsV2Configuration() { - EmployerCommitmentsBaseUrl = EmployerCommitmentsBaseUrl + EmployerCommitmentsBaseUrl = EmployerCommitmentsBaseUrl, + CoCApprovalsActive = true }; } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Configuration/CommitmentsV2Configuration.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Configuration/CommitmentsV2Configuration.cs index ef3c33896..f02eec714 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Configuration/CommitmentsV2Configuration.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Configuration/CommitmentsV2Configuration.cs @@ -29,4 +29,5 @@ public class CommitmentsV2Configuration public string ReplayApprenticeshipCreatedEventsJobSchedule { get; set; } public bool ReplayApprenticeshipCreatedEventsDryRun { get; set; } = true; public bool LearningWithdrawalsIsActive { get; set; } + public bool CoCApprovalsActive { get; set; } } \ No newline at end of file diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Models/EmployerAlertSummaryNotification.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Models/EmployerAlertSummaryNotification.cs index 7a9cdcf6a..cee740d55 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Models/EmployerAlertSummaryNotification.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Models/EmployerAlertSummaryNotification.cs @@ -6,4 +6,5 @@ public class EmployerAlertSummaryNotification public int TotalCount { get; set; } public int ChangesForReviewCount { get; set; } public int RestartRequestCount { get; set; } + public int PendingIlrChangesCount { get; set; } } \ No newline at end of file diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Services/ApprenticeshipDomainService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Services/ApprenticeshipDomainService.cs index 776dfc9d6..5e4b98712 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Services/ApprenticeshipDomainService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Services/ApprenticeshipDomainService.cs @@ -50,18 +50,30 @@ public async Task> GetEmployerAlertSummar .GroupBy(app => app.Cohort.EmployerAccountId) .Select(m => new { EmployerAccountId = m.Key, ChangesForReviewCount = m.Count() }); + var pendingIlrChangeOfCircs = dbContext.Value.ApprovalRequests + .Where(ar => ar.Status == CocApprovalResultStatus.Pending) + .Join(dbContext.Value.Apprenticeships, ar => ar.ApprenticeshipId, app => app.Id, (ar, app) => new { ar, app }) + .GroupBy(app => app.app.Cohort.EmployerAccountId) + .Select(m => new { EmployerAccountId = m.Key, PendingChangesForReviewCount = m.Count() }); + var pendingUpdateByProvider = await queryPendingUpdateByProvider.ToDictionaryAsync(p => p.EmployerAccountId, p => p.PendingUpdateByProviderCount); var courseTriaged = await queryCourseTriaged.ToDictionaryAsync(p => p.EmployerAccountId, p => p.RestartRequestCount); var priceTriaged = await queryPriceTriaged.ToDictionaryAsync(p => p.EmployerAccountId, p => p.ChangesForReviewCount); + var pendingIlrChanges = await pendingIlrChangeOfCircs.ToDictionaryAsync(p => p.EmployerAccountId, p => p.PendingChangesForReviewCount); - var results = pendingUpdateByProvider.Select(p => p.Key).Union(courseTriaged.Select(p => p.Key).Union(priceTriaged.Select(p => p.Key))) + var results = pendingUpdateByProvider.Select(p => p.Key) + .Union(courseTriaged.Select(p => p.Key) + .Union(priceTriaged.Select(p => p.Key)) + .Union(pendingIlrChanges.Select(p => p.Key))) .Distinct() .Select(p => new EmployerAlertSummaryNotification { EmployerHashedAccountId = encodingService.Encode(p, EncodingType.AccountId), - TotalCount = pendingUpdateByProvider.GetValueOrDefault(p, 0) + priceTriaged.GetValueOrDefault(p, 0) + courseTriaged.GetValueOrDefault(p, 0), + TotalCount = pendingUpdateByProvider.GetValueOrDefault(p, 0) + priceTriaged.GetValueOrDefault(p, 0) + + courseTriaged.GetValueOrDefault(p, 0) + pendingIlrChanges.GetValueOrDefault(p, 0), ChangesForReviewCount = pendingUpdateByProvider.GetValueOrDefault(p, 0) + priceTriaged.GetValueOrDefault(p, 0), - RestartRequestCount = courseTriaged.GetValueOrDefault(p, 0) + RestartRequestCount = courseTriaged.GetValueOrDefault(p, 0), + PendingIlrChangesCount = pendingIlrChanges.GetValueOrDefault(p, 0) }) .ToList(); diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Services/EmployerAlertSummaryEmailService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Services/EmployerAlertSummaryEmailService.cs index 264bdd46b..f88277910 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Services/EmployerAlertSummaryEmailService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Services/EmployerAlertSummaryEmailService.cs @@ -48,32 +48,31 @@ public async Task SendEmployerAlertSummaryNotifications() .Where(response => response != null) .ToList(); - accounts.ForEach(x => + accounts.ForEach(async x => { var alertSummary = employerAlertSummaryNotifications.Single(a => a.EmployerHashedAccountId == x.HashedAccountId); - SendEmail(alertSummary, x.AccountId, x.HashedAccountId, x.DasAccountName); + await SendEmail(alertSummary, x.AccountId, x.HashedAccountId); }); } - private void SendEmail(EmployerAlertSummaryNotification alertSummary, long accountId, string hashedAccountId, string accountName) + private async Task SendEmail(EmployerAlertSummaryNotification alertSummary, long accountId, string hashedAccountId) { var tokens = new Dictionary { { "total_count_text", alertSummary.TotalCount == 1 - ? "is 1 apprentice" - : $"are {alertSummary.TotalCount} apprentices" + ? "You have 1 item that needs your attention" + : $"You have {alertSummary.TotalCount} items that need your attention" }, - { "account_name", accountName }, - { "need_needs", alertSummary.TotalCount > 1 ? "need" : "needs" }, { "changes_for_review", ChangesForReviewText(alertSummary.ChangesForReviewCount) }, { "requested_changes", RestartRequestText(alertSummary.RestartRequestCount) }, - { "link_to_mange_apprenticeships", $"{_commitmentsV2Configuration.EmployerCommitmentsBaseUrl}/{hashedAccountId}/apprentices" }, + { "ilrchanges_to_confirm", IlrChangesToConfirmText(alertSummary.PendingIlrChangesCount) }, + { "link_to_mange_apprenticeships", $"Sign into your Apprenticeship Service Account" }, { "link_to_unsubscribe", $"/settings/notifications/unsubscribe/{hashedAccountId}" } }; - _messageSession.Send(new SendEmailToEmployerCommand(accountId, "EmployerAlertSummaryNotification", tokens, null, "name")); + await _messageSession.Send(new SendEmailToEmployerCommand(accountId, "EmployerAlertSummaryNotification", tokens, null, "name")); } private static string RestartRequestText(int restartRequestCount) @@ -81,8 +80,8 @@ private static string RestartRequestText(int restartRequestCount) return restartRequestCount switch { 0 => string.Empty, - 1 => $"* {restartRequestCount} apprentice with requested changes", - _ => $"* {restartRequestCount} apprentices with requested changes" + 1 => $"* {restartRequestCount} learner request to review", + _ => $"* {restartRequestCount} learner requests to review", }; } @@ -91,8 +90,23 @@ private static string ChangesForReviewText(int changesForReview) return changesForReview switch { 0 => string.Empty, - 1 => $"* {changesForReview} apprentice with changes for review", - _ => $"* {changesForReview} apprentices with changes for review" + 1 => $"* {changesForReview} learner with changes for review", + _ => $"* {changesForReview} learners with changes for review" + }; + } + + private string IlrChangesToConfirmText(int changestoConfirm) + { + if(!_commitmentsV2Configuration.CoCApprovalsActive) + { + return string.Empty; + } + + return changestoConfirm switch + { + 0 => string.Empty, + 1 => $"* {changestoConfirm} learner with changes from ILR to confirm", + _ => $"* {changestoConfirm} learners with changes from ILR to confirm", }; }