diff --git a/src/SFA.DAS.EmployerAccounts.UnitTests/Queries/GetSingleCohort/WhenIGetSingleCohort.cs b/src/SFA.DAS.EmployerAccounts.UnitTests/Queries/GetSingleCohort/WhenIGetSingleCohort.cs index a739f3ea8a..cf4ef0866d 100644 --- a/src/SFA.DAS.EmployerAccounts.UnitTests/Queries/GetSingleCohort/WhenIGetSingleCohort.cs +++ b/src/SFA.DAS.EmployerAccounts.UnitTests/Queries/GetSingleCohort/WhenIGetSingleCohort.cs @@ -44,7 +44,7 @@ public void Arrange() _hashingService = new Mock(); _hashingService.Setup(x => x.DecodeValue(hashedAccountId)).Returns(_accountId); - RequestHandler = new GetSingleCohortRequestHandler(RequestValidator.Object, _commitmentV2Service.Object, _hashingService.Object); + RequestHandler = new GetSingleCohortRequestHandler(RequestValidator.Object, _commitmentV2Service.Object, _hashingService.Object, Mock.Of()); Query = new GetSingleCohortRequest { diff --git a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenGettingAccount.cs b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenGettingAccount.cs index 6fb012bf81..b332a02a28 100644 --- a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenGettingAccount.cs +++ b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenGettingAccount.cs @@ -404,5 +404,34 @@ public async Task ThenShouldGetCohortResponse() //Assert Assert.AreEqual(1, result.Data.CallToActionViewModel.CohortsCount); } + + [Test] + [TestCase(false, false, false, false, false, Description = "All calls successful")] + [TestCase(true, false, false, false, true, Description = "Vacancy call failed")] + [TestCase(false, true, false, false, true, Description = "Vacancy call failed")] + [TestCase(false, false, true, false, true, Description = "Cohort call failed")] + public async Task ThenShouldSetUnableToDetermineCallToAction( + bool vacancyCallFailed, + bool reservationsCallFailed, + bool cohortCallFailed, + bool apprenticeshipCallFailed, + bool unableToDetermineCallToActionExpected) + { + //Arrange + _mediator.Setup(x => x.SendAsync(It.IsAny())).ReturnsAsync(new GetVacanciesResponse { Vacancies = new List(), HasFailed = vacancyCallFailed }); + + _mediator.Setup(x => x.SendAsync(It.IsAny())).ReturnsAsync(new GetReservationsResponse { Reservations = new List(), HasFailed = reservationsCallFailed }); + + _mediator.Setup(x => x.SendAsync(It.IsAny())).ReturnsAsync(new GetApprenticeshipsResponse{ Apprenticeships = new List(), HasFailed = apprenticeshipCallFailed }); + + var cohort = new Cohort() { Id = 1, NumberOfDraftApprentices = 1, Apprenticeships = new List { new Apprenticeship { FirstName = "FirstName" } } }; + _mediator.Setup(x => x.SendAsync(It.IsAny())).ReturnsAsync(new GetSingleCohortResponse { Cohort = cohort, HasFailed = cohortCallFailed }); + + //Act + var result = await _orchestrator.GetAccount(HashedAccountId, UserId); + + //Assert + Assert.AreEqual(unableToDetermineCallToActionExpected, result.Data.CallToActionViewModel.UnableToDetermineCallToAction); + } } } diff --git a/src/SFA.DAS.EmployerAccounts.Web/Orchestrators/EmployerTeamOrchestrator.cs b/src/SFA.DAS.EmployerAccounts.Web/Orchestrators/EmployerTeamOrchestrator.cs index 46d351e57c..d39d17b89f 100644 --- a/src/SFA.DAS.EmployerAccounts.Web/Orchestrators/EmployerTeamOrchestrator.cs +++ b/src/SFA.DAS.EmployerAccounts.Web/Orchestrators/EmployerTeamOrchestrator.cs @@ -273,7 +273,7 @@ public virtual async Task> GetAc { _mapper.Map(accountCohort.Cohort) }, - UnableToDetermineCallToAction = vacanciesResponse.HasFailed || reservationsResponse.HasFailed + UnableToDetermineCallToAction = vacanciesResponse.HasFailed || reservationsResponse.HasFailed || accountCohort.HasFailed || apprenticeshipsResponse.HasFailed } }; diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsHandler.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsHandler.cs index 956110e3c3..a1c4b62199 100644 --- a/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsHandler.cs +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsHandler.cs @@ -4,6 +4,7 @@ using SFA.DAS.Validation; using SFA.DAS.EmployerAccounts.Interfaces; using SFA.DAS.HashingService; +using System; namespace SFA.DAS.EmployerAccounts.Queries.GetApprenticeship { @@ -37,10 +38,21 @@ public async Task Handle(GetApprenticeshipsRequest m long accountId = _hashingService.DecodeValue(message.HashedAccountId); - return new GetApprenticeshipsResponse + try { - Apprenticeships = await _commitmentV2Service.GetApprenticeships(accountId) - }; + return new GetApprenticeshipsResponse + { + Apprenticeships = await _commitmentV2Service.GetApprenticeships(accountId) + }; + } + catch(Exception ex) + { + _logger.Error(ex, $"Failed to get Cohorts for {message.HashedAccountId}"); + return new GetApprenticeshipsResponse + { + HasFailed = true + }; + } } } } diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsResponse.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsResponse.cs index 6a4b2dd759..aa0c0747a6 100644 --- a/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsResponse.cs +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsResponse.cs @@ -6,5 +6,6 @@ namespace SFA.DAS.EmployerAccounts.Queries.GetApprenticeship public class GetApprenticeshipsResponse { public IEnumerable Apprenticeships { get; set; } + public bool HasFailed { get; set; } } } diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortRequestHandler.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortRequestHandler.cs index 9555d9c459..518ca96981 100644 --- a/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortRequestHandler.cs +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortRequestHandler.cs @@ -4,6 +4,8 @@ using SFA.DAS.EmployerAccounts.Interfaces; using System.Linq; using SFA.DAS.HashingService; +using System; +using SFA.DAS.NLog.Logger; namespace SFA.DAS.EmployerAccounts.Queries.GetSingleCohort { @@ -12,15 +14,18 @@ public class GetSingleCohortRequestHandler : IAsyncRequestHandler _validator; private readonly ICommitmentV2Service _commitmentV2Service; private readonly IHashingService _hashingService; + private readonly ILog _logger; public GetSingleCohortRequestHandler( IValidator validator, ICommitmentV2Service commitmentV2Service, - IHashingService hashingService) + IHashingService hashingService, + ILog logger) { _validator = validator; _commitmentV2Service = commitmentV2Service; _hashingService = hashingService; + _logger = logger; } public async Task Handle(GetSingleCohortRequest message) @@ -32,22 +37,33 @@ public async Task Handle(GetSingleCohortRequest message throw new InvalidRequestException(validationResult.ValidationDictionary); } - long accountId = _hashingService.DecodeValue(message.HashedAccountId); + long accountId = _hashingService.DecodeValue(message.HashedAccountId); - var cohortsResponse = await _commitmentV2Service.GetCohorts(accountId); - if (cohortsResponse.Count() != 1) return new GetSingleCohortResponse(); + try + { + var cohortsResponse = await _commitmentV2Service.GetCohorts(accountId); + if (cohortsResponse.Count() != 1) return new GetSingleCohortResponse(); - var singleCohort = cohortsResponse.Single(); + var singleCohort = cohortsResponse.Single(); - if (singleCohort.NumberOfDraftApprentices > 0) - { - singleCohort.Apprenticeships = await _commitmentV2Service.GetDraftApprenticeships(singleCohort); - } + if (singleCohort.NumberOfDraftApprentices > 0) + { + singleCohort.Apprenticeships = await _commitmentV2Service.GetDraftApprenticeships(singleCohort); + } - return new GetSingleCohortResponse + return new GetSingleCohortResponse + { + Cohort = singleCohort + }; + } + catch(Exception ex) { - Cohort = singleCohort - }; + _logger.Error(ex, $"Failed to get Cohorts for {message.HashedAccountId}"); + return new GetSingleCohortResponse + { + HasFailed = true + }; + } } } } diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortResponse.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortResponse.cs index d8f1022d15..f0c2a33c84 100644 --- a/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortResponse.cs +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortResponse.cs @@ -5,5 +5,6 @@ namespace SFA.DAS.EmployerAccounts.Queries.GetSingleCohort public class GetSingleCohortResponse { public Cohort Cohort { get; set; } + public bool HasFailed { get; set; } } }