diff --git a/src/.cr/personal/Navigation/RecentFilesHistory.xml b/src/.cr/personal/Navigation/RecentFilesHistory.xml new file mode 100644 index 0000000000..89fc590ebe --- /dev/null +++ b/src/.cr/personal/Navigation/RecentFilesHistory.xml @@ -0,0 +1,100 @@ + + + + + + EmployerTeamController.cs + c:\esfa\das-employerapprenticeshipsservice\src\sfa.das.employeraccounts.web\controllers\employerteamcontroller.cs + + Controllers + + C:\ESFA\das-employerapprenticeshipsservice\src\SFA.DAS.EmployerAccounts.Web\SFA.DAS.EmployerAccounts.Web.csproj + SFA.DAS.EmployerAccounts.Web + + + EmployerTeamController.cs + c:\esfa\das-employerapprenticeshipsservice\src\sfa.das.employeraccounts.web\controllers\employerteamcontroller.cs + + Controllers + + C:\ESFA\das-employerapprenticeshipsservice\src\SFA.DAS.EmployerAccounts.Web\SFA.DAS.EmployerAccounts.Web.csproj + SFA.DAS.EmployerAccounts.Web + + + UrlHelperExtensions.cs + c:\esfa\das-employerapprenticeshipsservice\src\sfa.das.employeraccounts.web\extensions\urlhelperextensions.cs + + Extensions + + C:\ESFA\das-employerapprenticeshipsservice\src\SFA.DAS.EmployerAccounts.Web\SFA.DAS.EmployerAccounts.Web.csproj + SFA.DAS.EmployerAccounts.Web + + + UrlHelperExtensions.cs + c:\esfa\das-employerapprenticeshipsservice\src\sfa.das.eas.support.web\extensions\urlhelperextensions.cs + + Extensions + + C:\ESFA\das-employerapprenticeshipsservice\src\SFA.DAS.EAS.Support.Web\SFA.DAS.EAS.Support.Web.csproj + SFA.DAS.EAS.Support.Web + + + EmployerTeamOrchestrator.cs + c:\esfa\das-employerapprenticeshipsservice\src\sfa.das.employeraccounts.web\orchestrators\employerteamorchestrator.cs + + Orchestrators + + C:\ESFA\das-employerapprenticeshipsservice\src\SFA.DAS.EmployerAccounts.Web\SFA.DAS.EmployerAccounts.Web.csproj + SFA.DAS.EmployerAccounts.Web + + + EmployerTeamController.cs + c:\esfa\das-employerapprenticeshipsservice\src\sfa.das.employeraccounts.web\controllers\employerteamcontroller.cs + + Controllers + + C:\ESFA\das-employerapprenticeshipsservice\src\SFA.DAS.EmployerAccounts.Web\SFA.DAS.EmployerAccounts.Web.csproj + SFA.DAS.EmployerAccounts.Web + + + EmployerTeam + c:\esfa\das-employerapprenticeshipsservice\src\sfa.das.employeraccounts.web\views\employerteam\ + + Views + + Folder + C:\ESFA\das-employerapprenticeshipsservice\src\SFA.DAS.EmployerAccounts.Web\SFA.DAS.EmployerAccounts.Web.csproj + SFA.DAS.EmployerAccounts.Web + + + EmployerTeamController.cs + c:\esfa\das-employerapprenticeshipsservice\src\sfa.das.employeraccounts.web\controllers\employerteamcontroller.cs + + Controllers + + C:\ESFA\das-employerapprenticeshipsservice\src\SFA.DAS.EmployerAccounts.Web\SFA.DAS.EmployerAccounts.Web.csproj + SFA.DAS.EmployerAccounts.Web + + + GetReservationsRequestHandler.cs + c:\esfa\das-employerapprenticeshipsservice\src\sfa.das.employeraccounts\queries\getreservations\getreservationsrequesthandler.cs + + Queries + GetReservations + + C:\ESFA\das-employerapprenticeshipsservice\src\SFA.DAS.EmployerAccounts\SFA.DAS.EmployerAccounts.csproj + SFA.DAS.EmployerAccounts + + + WhenGettingAccount.cs + c:\esfa\das-employerapprenticeshipsservice\src\sfa.das.employeraccounts.web.unittests\orchestrators\employerteamorchestratortests\whengettingaccount.cs + + Orchestrators + EmployerTeamOrchestratorTests + + C:\ESFA\das-employerapprenticeshipsservice\src\SFA.DAS.EmployerAccounts.Web.UnitTests\SFA.DAS.EmployerAccounts.Web.UnitTests.csproj + SFA.DAS.EmployerAccounts.Web.UnitTests + + + + \ No newline at end of file diff --git a/src/SFA.DAS.EmployerAccounts.UnitTests/Mappings/WhenAutoMapping.cs b/src/SFA.DAS.EmployerAccounts.UnitTests/Mappings/WhenAutoMapping.cs index 976f724954..f09ff9fc02 100644 --- a/src/SFA.DAS.EmployerAccounts.UnitTests/Mappings/WhenAutoMapping.cs +++ b/src/SFA.DAS.EmployerAccounts.UnitTests/Mappings/WhenAutoMapping.cs @@ -21,6 +21,8 @@ public void ThenShouldUseValidConfiguration() c.AddProfile(); c.AddProfile(); c.AddProfile(); + c.AddProfile(); + c.AddProfile(); }); config.AssertConfigurationIsValid(); diff --git a/src/SFA.DAS.EmployerAccounts.UnitTests/Queries/GetApprenticeship/WhenIGetApprenticeship.cs b/src/SFA.DAS.EmployerAccounts.UnitTests/Queries/GetApprenticeship/WhenIGetApprenticeship.cs new file mode 100644 index 0000000000..0545fb979a --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts.UnitTests/Queries/GetApprenticeship/WhenIGetApprenticeship.cs @@ -0,0 +1,78 @@ +using Moq; +using SFA.DAS.EmployerAccounts.Interfaces; +using SFA.DAS.EmployerAccounts.Queries.GetApprenticeship; +using SFA.DAS.Validation; +using System; +using NUnit.Framework; +using SFA.DAS.NLog.Logger; +using System.Threading.Tasks; +using SFA.DAS.CommitmentsV2.Api.Types.Responses; +using System.Collections.Generic; +using SFA.DAS.EmployerAccounts.Models.CommitmentsV2; +using SFA.DAS.HashingService; + +namespace SFA.DAS.EmployerAccounts.UnitTests.Queries.GetApprenticeship +{ + public class WhenIGetApprenticeship : QueryBaseTest + { + public override GetApprenticeshipsRequest Query { get; set; } + public override GetApprenticeshipsHandler RequestHandler { get; set; } + public override Mock> RequestValidator { get; set; } + + private Mock _commitmentV2Service; + private Mock _hashingService; + private Mock _logger; + private long _accountId; + private string _hashedAccountId; + + [SetUp] + public void Arrange() + { + SetUp(); + + _accountId = 123; + _hashedAccountId = "ABC123"; + _logger = new Mock(); + + _commitmentV2Service = new Mock(); + _hashingService = new Mock(); + + _commitmentV2Service.Setup(m => m.GetApprenticeships(_accountId)).ReturnsAsync(new List { new Apprenticeship { Id = 3 } }); + _hashingService = new Mock(); + _hashingService.Setup(x => x.DecodeValue(_hashedAccountId)).Returns(_accountId); + + RequestHandler = new GetApprenticeshipsHandler(RequestValidator.Object, _logger.Object, _commitmentV2Service.Object, _hashingService.Object); + + Query = new GetApprenticeshipsRequest + { + HashedAccountId = _hashedAccountId + }; + } + + + public override Task ThenIfTheMessageIsValidTheRepositoryIsCalled() + { + throw new NotImplementedException(); + } + + [Test] + public async Task ThenIfTheMessageIsValidTheServiceIsCalled() + { + //Act + await RequestHandler.Handle(Query); + + //Assert + _commitmentV2Service.Verify(x => x.GetApprenticeships(_accountId), Times.Once); + } + + [Test] + public override async Task ThenIfTheMessageIsValidTheValueIsReturnedInTheResponse() + { + //Act + var response = await RequestHandler.Handle(Query); + + //Assert + Assert.IsNotNull(response.Apprenticeships); + } + } +} diff --git a/src/SFA.DAS.EmployerAccounts.UnitTests/Queries/GetApprenticeship/WhenIValidateTheRequest.cs b/src/SFA.DAS.EmployerAccounts.UnitTests/Queries/GetApprenticeship/WhenIValidateTheRequest.cs new file mode 100644 index 0000000000..7058fb865a --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts.UnitTests/Queries/GetApprenticeship/WhenIValidateTheRequest.cs @@ -0,0 +1,47 @@ +using NUnit.Framework; +using SFA.DAS.EmployerAccounts.Queries.GetApprenticeship; + +namespace SFA.DAS.EmployerAccounts.UnitTests.Queries.GetApprenticeship +{ + public class WhenIValidateTheRequest + { + private GetApprenticeshipsValidator _validator; + + [SetUp] + public void Arrange() + { + _validator = new GetApprenticeshipsValidator(); + } + + + [Test] + public void ThenShouldReturnValidIfRequestIsValid() + { + //Act + var result = _validator.Validate(new GetApprenticeshipsRequest { HashedAccountId = "123ABC", ExternalUserId = "user123" }); + + //Assert + Assert.IsTrue(result.IsValid()); + } + + [Test] + public void ThenShouldReturnInvalidIfNoAccountIdIsProvided() + { + //Act + var result = _validator.Validate(new GetApprenticeshipsRequest { ExternalUserId = "user123" }); + + //Assert + Assert.IsFalse(result.IsValid()); + } + + [Test] + public void ThenShouldReturnInValidIfRequestIsNotValid() + { + //Act + var result = _validator.Validate(new GetApprenticeshipsRequest { }); + + //Assert + Assert.IsFalse(result.IsValid()); + } + } +} diff --git a/src/SFA.DAS.EmployerAccounts.UnitTests/Queries/GetSingleCohort/WhenIGetSingleCohort.cs b/src/SFA.DAS.EmployerAccounts.UnitTests/Queries/GetSingleCohort/WhenIGetSingleCohort.cs new file mode 100644 index 0000000000..a739f3ea8a --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts.UnitTests/Queries/GetSingleCohort/WhenIGetSingleCohort.cs @@ -0,0 +1,84 @@ +using Moq; +using NUnit.Framework; +using SFA.DAS.EmployerAccounts.Interfaces; +using SFA.DAS.EmployerAccounts.Models.CommitmentsV2; +using SFA.DAS.EmployerAccounts.Queries.GetSingleCohort; +using SFA.DAS.Encoding; +using SFA.DAS.HashingService; +using SFA.DAS.NLog.Logger; +using SFA.DAS.Validation; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace SFA.DAS.EmployerAccounts.UnitTests.Queries.GetSingleCohort +{ + public class WhenIGetSingleCohort : QueryBaseTest + { + public override GetSingleCohortRequest Query { get; set; } + public override GetSingleCohortRequestHandler RequestHandler { get; set; } + public override Mock> RequestValidator { get; set; } + private Mock _commitmentV2Service; + private Mock _hashingService; + private long _accountId; + private long _cohortId; + public string hashedAccountId; + + [SetUp] + public void Arrange() + { + SetUp(); + + _accountId = 123; + _cohortId = 1; + hashedAccountId = "Abc123"; + + _commitmentV2Service = new Mock(); + _commitmentV2Service.Setup(m => m.GetCohorts(_accountId)) + .ReturnsAsync(new List() { new Cohort { Id = _cohortId, NumberOfDraftApprentices = 1 }}); + + _commitmentV2Service.Setup(m => m.GetDraftApprenticeships(It.IsAny())) + .ReturnsAsync(new List { new Apprenticeship { CourseName = "CourseName" } }); + + _hashingService = new Mock(); + _hashingService.Setup(x => x.DecodeValue(hashedAccountId)).Returns(_accountId); + + RequestHandler = new GetSingleCohortRequestHandler(RequestValidator.Object, _commitmentV2Service.Object, _hashingService.Object); + + Query = new GetSingleCohortRequest + { + HashedAccountId = hashedAccountId + }; + } + + + [Test] + public override async Task ThenIfTheMessageIsValidTheValueIsReturnedInTheResponse() + { + //Act + var response = await RequestHandler.Handle(Query); + + //Assert + Assert.IsNotNull(response.Cohort); + Assert.IsTrue(response.Cohort.NumberOfDraftApprentices.Equals(1)); + Assert.IsTrue(response.Cohort?.Apprenticeships.Count().Equals(1)); + } + + + [Test] + public async Task ThenIfTheMessageIsValidTheServiceIsCalled() + { + //Act + await RequestHandler.Handle(Query); + + //Assert + _commitmentV2Service.Verify(x => x.GetCohorts(_accountId), Times.Once); + } + + public override Task ThenIfTheMessageIsValidTheRepositoryIsCalled() + { + return Task.CompletedTask; + } + } +} diff --git a/src/SFA.DAS.EmployerAccounts.UnitTests/Queries/GetSingleCohort/WhenIValidateTheRequest.cs b/src/SFA.DAS.EmployerAccounts.UnitTests/Queries/GetSingleCohort/WhenIValidateTheRequest.cs new file mode 100644 index 0000000000..436db00ba8 --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts.UnitTests/Queries/GetSingleCohort/WhenIValidateTheRequest.cs @@ -0,0 +1,36 @@ +using NUnit.Framework; +using SFA.DAS.EmployerAccounts.Queries.GetSingleCohort; + +namespace SFA.DAS.EmployerAccounts.UnitTests.Queries.GetSingleCohort +{ + public class WhenIValidateTheRequest + { + private GetSingleCohortRequestValidator _validator; + + [SetUp] + public void Arrange() + { + _validator = new GetSingleCohortRequestValidator(); + } + + [Test] + public void ThenShouldReturnValidIfRequestIsValid() + { + //Act + var result = _validator.Validate(new GetSingleCohortRequest { HashedAccountId = "Abc123" }); + + //Assert + Assert.IsTrue(result.IsValid()); + } + + [Test] + public void ThenShouldReturnInValidIfRequestIsNotValid() + { + //Act + var result = _validator.Validate(new GetSingleCohortRequest { HashedAccountId = string.Empty }); + + //Assert + Assert.IsFalse(result.IsValid()); + } + } +} diff --git a/src/SFA.DAS.EmployerAccounts.UnitTests/Services/AccountCohorts/WhenIGetAccountCohorts.cs b/src/SFA.DAS.EmployerAccounts.UnitTests/Services/AccountCohorts/WhenIGetAccountCohorts.cs new file mode 100644 index 0000000000..9041539bdd --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts.UnitTests/Services/AccountCohorts/WhenIGetAccountCohorts.cs @@ -0,0 +1,169 @@ +using SFA.DAS.CommitmentsV2.Api.Client; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using AutoMapper; +using Moq; +using NUnit.Framework; +using SFA.DAS.EmployerAccounts.Services; +using SFA.DAS.CommitmentsV2.Api.Types.Requests; +using System.Threading; +using SFA.DAS.CommitmentsV2.Api.Types.Responses; +using SFA.DAS.CommitmentsV2.Types; +using SFA.DAS.CommitmentsV2.Types.Dtos; +using System.Linq; +using SFA.DAS.EmployerAccounts.Models.CommitmentsV2; +using SFA.DAS.Encoding; + +namespace SFA.DAS.EmployerAccounts.UnitTests.Services.AccountCohorts +{ + public class WhenIGetAccountCohorts + { + private Mock _mockCommitmentsApiClient; + private Mock _mockEncodingService; + private Mock _mockMapper; + private long _accountId = 123; + private CommitmentsV2Service _sut; + + [SetUp] + public void Arrange() + { + _mockMapper = new Mock(); + _mockCommitmentsApiClient = new Mock(); + _mockEncodingService = new Mock(); + _sut = new CommitmentsV2Service(_mockCommitmentsApiClient.Object, _mockMapper.Object, _mockEncodingService.Object); + } + + [Test] + public async Task ThenGetApprenticeshipsResponse() + { + //Arrange + _mockCommitmentsApiClient + .Setup(c => c.GetApprenticeships(It.Is(r => r.AccountId == _accountId), CancellationToken.None)) + .Returns(Task.FromResult(CreateApprenticeshipResponse())); + var apprenticeships = new List { new Apprenticeship { ApprenticeshipStatus = EmployerAccounts.Models.CommitmentsV2.ApprenticeshipStatus.Approved, FirstName ="FirstName" , LastName = "LastName" } }; + _mockMapper + .Setup(m => m.Map, IEnumerable> + (It.IsAny>(), + It.IsAny, IEnumerable>>>())) + .Returns(apprenticeships); + + //Act + var result =await _sut.GetApprenticeships(_accountId); + + //Assert + Assert.IsNotNull(result); + Assert.IsTrue(result.Count().Equals(1)); + } + + [Test] + public async Task ThenGetCohortsResponse() + { + //Arrange + _mockCommitmentsApiClient.Setup(c => c.GetCohorts(It.Is(r => r.AccountId == _accountId), CancellationToken.None)) + .Returns(Task.FromResult(GetCohortsResponseForWithTrainingProviderStaus())); + _mockEncodingService.Setup(x => x.Encode(It.IsAny(), EncodingType.CohortReference)).Returns((long y, EncodingType z) => y + "_Encoded"); + + var cohorts = new List() + { + new Cohort { Id = 1 } + }; + + _mockMapper.Setup(m => m.Map, IEnumerable>(It.IsAny(), + It.IsAny, IEnumerable>>>())) + .Returns(cohorts); + + //Act + var result = await _sut.GetCohorts(_accountId); + + //Assert + Assert.IsNotNull(result); + Assert.IsTrue(result.Count().Equals(1)); + } + + [Test] + public async Task ThenGetDraftApprenticeshipsResponse() + { + //Arrange + _mockCommitmentsApiClient.Setup(c => c.GetDraftApprenticeships(123, It.IsAny())).Returns(Task.FromResult(GetDraftApprenticeshipsResponse())); + var apprenticeships = new List { new Apprenticeship { FirstName = "FirstName", LastName = "LastName" } }; + _mockMapper.Setup(m => m.Map, IEnumerable>(It.IsAny>(), + It.IsAny, IEnumerable>>>())) + .Returns(apprenticeships); + + + //Act + var result = await _sut.GetDraftApprenticeships(new Cohort {Id = 123}); + + //Assert + Assert.IsNotNull(result); + Assert.IsTrue(result.Count().Equals(1)); + } + + + private GetApprenticeshipsResponse CreateApprenticeshipResponse() + { + IEnumerable apprenticeships = new List() + { + new GetApprenticeshipsResponse.ApprenticeshipDetailsResponse + { + Id = 1, + FirstName = "FirstName", + LastName = "LastName", + Uln = "Uln", + EmployerName = "EmployerName", + CourseName = "CourseName", + StartDate = new DateTime(2020, 5, 1), + EndDate = new DateTime(2022, 5, 1), + ApprenticeshipStatus = SFA.DAS.CommitmentsV2.Types.ApprenticeshipStatus.Live, + ProviderName = "ProviderName" + } + }; + + return new GetApprenticeshipsResponse() { Apprenticeships = apprenticeships, TotalApprenticeships = 1, TotalApprenticeshipsFound = 1, TotalApprenticeshipsWithAlertsFound = 0 }; + } + + + private GetCohortsResponse GetCohortsResponseForWithTrainingProviderStaus() + { + IEnumerable cohorts = new List() + { + new CohortSummary + { + CohortId = 4, + AccountId = 1, + ProviderId = 4, + ProviderName = "Provider4", + NumberOfDraftApprentices = 1, + IsDraft = false, + WithParty = Party.Provider, + CreatedOn = DateTime.Now + }, + }; + + return new GetCohortsResponse(cohorts); + } + + private GetDraftApprenticeshipsResponse GetDraftApprenticeshipsResponse() + { + IReadOnlyCollection draftApprenticeships = new List() + { + new DraftApprenticeshipDto + { + Id = 1, + FirstName = "FirstName", + LastName = "LastName", + DateOfBirth = new DateTime(2000, 1 ,1 ), + Cost = 100, + StartDate = new DateTime(2020, 5, 1), + EndDate = new DateTime(2022, 5, 1), + CourseCode = "CourseCode", + CourseName = "CourseName" + } + }; + + var draftApprenticeshipsResponse = new GetDraftApprenticeshipsResponse() { DraftApprenticeships = draftApprenticeships }; + return draftApprenticeshipsResponse; + } + } +} diff --git a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/EmployerTeamControllerTests/WhenCallToActionToggleIsEnabled/WhenFundsToReserve.cs b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/EmployerTeamControllerTests/WhenCallToActionToggleIsEnabled/WhenFundsToReserve.cs index 806a1bcfb8..2a172c70cf 100644 --- a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/EmployerTeamControllerTests/WhenCallToActionToggleIsEnabled/WhenFundsToReserve.cs +++ b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/EmployerTeamControllerTests/WhenCallToActionToggleIsEnabled/WhenFundsToReserve.cs @@ -45,16 +45,17 @@ public void Arrange() public void ThenForNonLevyTheCheckFundingViewIsReturnedAtRow1Panel1() { // Arrange - var model = new AccountDashboardViewModel(); - model.PayeSchemeCount = 1; - model.CallToActionViewModel = new CallToActionViewModel + var model = new AccountDashboardViewModel() { - AgreementsToSign = false, - VacanciesViewModel = new VacanciesViewModel { VacancyCount = 0 } + PayeSchemeCount = 1, + CallToActionViewModel = new CallToActionViewModel + { + AgreementsToSign = false, + VacanciesViewModel = new VacanciesViewModel() + }, + ApprenticeshipEmployerType = Common.Domain.Types.ApprenticeshipEmployerType.NonLevy }; - model.ApprenticeshipEmployerType = Common.Domain.Types.ApprenticeshipEmployerType.NonLevy; - //Act var result = _controller.Row1Panel1(model) as PartialViewResult; @@ -74,8 +75,7 @@ public void ThenForNonLevyTheContinueSetupForSingleReservationViewIsReturnedAtRo { AgreementsToSign = false, Reservations = new List { new Reservation { Status = ReservationStatus.Pending } }, - VacanciesViewModel = new VacanciesViewModel { VacancyCount = 0 }, - ApprenticeshipAdded = false + VacanciesViewModel = new VacanciesViewModel() }; model.ApprenticeshipEmployerType = Common.Domain.Types.ApprenticeshipEmployerType.NonLevy; diff --git a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/EmployerTeamControllerTests/WhenCallToActionToggleIsEnabled/WhenSetupSingleApprentice.cs b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/EmployerTeamControllerTests/WhenCallToActionToggleIsEnabled/WhenSetupSingleApprentice.cs new file mode 100644 index 0000000000..d18178923e --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/EmployerTeamControllerTests/WhenCallToActionToggleIsEnabled/WhenSetupSingleApprentice.cs @@ -0,0 +1,85 @@ +using System.Collections.Generic; +using System.Web.Mvc; +using Moq; +using NUnit.Framework; +using SFA.DAS.Authentication; +using SFA.DAS.Authorization.Services; +using SFA.DAS.EmployerAccounts.Interfaces; +using SFA.DAS.EmployerAccounts.Models.CommitmentsV2; +using SFA.DAS.EmployerAccounts.Models.Reservations; +using SFA.DAS.EmployerAccounts.Web.Controllers; +using SFA.DAS.EmployerAccounts.Web.Orchestrators; +using SFA.DAS.EmployerAccounts.Web.ViewModels; + +namespace SFA.DAS.EmployerAccounts.Web.UnitTests.Controllers.EmployerTeamControllerTests.WhenCallToActionToggleIsEnabled +{ + public class WhenSetupSingleApprentice + { + private EmployerTeamController _controller; + + private Mock mockAuthenticationService; + private Mock mockAuthorizationService; + private Mock mockMultiVariantTestingService; + private Mock> mockCookieStorageService; + private Mock mockEmployerTeamOrchestrator; + + [SetUp] + public void Arrange() + { + mockAuthenticationService = new Mock(); + mockAuthorizationService = new Mock(); + mockMultiVariantTestingService = new Mock(); + mockCookieStorageService = new Mock>(); + mockEmployerTeamOrchestrator = new Mock(); + + mockAuthorizationService.Setup(m => m.IsAuthorized("EmployerFeature.HomePage")).Returns(false); + mockAuthorizationService.Setup(m => m.IsAuthorized("EmployerFeature.CallToAction")).Returns(true); + + _controller = new EmployerTeamController( + mockAuthenticationService.Object, + mockMultiVariantTestingService.Object, + mockCookieStorageService.Object, + mockEmployerTeamOrchestrator.Object, + mockAuthorizationService.Object); + } + + [Test] + public void ThenForNonLevyTheContinueSetupForSingleApprenticeshipViewIsReturnedAtRow1Panel1() + { + //Arrange + var model = new AccountDashboardViewModel() + { + PayeSchemeCount = 1, + ApprenticeshipEmployerType = Common.Domain.Types.ApprenticeshipEmployerType.NonLevy, + CallToActionViewModel = new CallToActionViewModel + { + Reservations = new List { new Reservation { Status = ReservationStatus.Completed } }, + Cohorts = new List + { + new CohortViewModel + { + NumberOfDraftApprentices = 1, + CohortStatus = CohortStatus.Draft, + Apprenticeships = new List + { + new ApprenticeshipViewModel + { + ApprenticeshipStatus = ApprenticeshipStatus.Draft, + NumberOfDraftApprentices = 1 + } + } + } + } + } + }; + + //Act + var result = _controller.Row1Panel1(model) as PartialViewResult; + + //Assert + Assert.IsNotNull(result); + Assert.AreEqual("SingleApprenticeshipContinueSetup", (result.Model as dynamic).ViewName); + } + + } +} diff --git a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/EmployerTeamControllerTests/WhenCallToActionToggleIsEnabled/WhenSetupSingleApprenticeByProvider.cs b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/EmployerTeamControllerTests/WhenCallToActionToggleIsEnabled/WhenSetupSingleApprenticeByProvider.cs new file mode 100644 index 0000000000..b6dd6b010a --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/EmployerTeamControllerTests/WhenCallToActionToggleIsEnabled/WhenSetupSingleApprenticeByProvider.cs @@ -0,0 +1,83 @@ +using System.Collections.Generic; +using System.Web.Mvc; +using Moq; +using NUnit.Framework; +using SFA.DAS.Authentication; +using SFA.DAS.Authorization.Services; +using SFA.DAS.EmployerAccounts.Interfaces; +using SFA.DAS.EmployerAccounts.Models.CommitmentsV2; +using SFA.DAS.EmployerAccounts.Models.Reservations; +using SFA.DAS.EmployerAccounts.Web.Controllers; +using SFA.DAS.EmployerAccounts.Web.Orchestrators; +using SFA.DAS.EmployerAccounts.Web.ViewModels; + +namespace SFA.DAS.EmployerAccounts.Web.UnitTests.Controllers.EmployerTeamControllerTests.WhenCallToActionToggleIsEnabled +{ + public class WhenSetupSingleApprenticeByProvider + { + private EmployerTeamController _controller; + + private Mock mockAuthenticationService; + private Mock mockAuthorizationService; + private Mock mockMultiVariantTestingService; + private Mock> mockCookieStorageService; + private Mock mockEmployerTeamOrchestrator; + + [SetUp] + public void Arrange() + { + mockAuthenticationService = new Mock(); + mockAuthorizationService = new Mock(); + mockMultiVariantTestingService = new Mock(); + mockCookieStorageService = new Mock>(); + mockEmployerTeamOrchestrator = new Mock(); + + mockAuthorizationService.Setup(m => m.IsAuthorized("EmployerFeature.HomePage")).Returns(false); + mockAuthorizationService.Setup(m => m.IsAuthorized("EmployerFeature.CallToAction")).Returns(true); + + _controller = new EmployerTeamController( + mockAuthenticationService.Object, + mockMultiVariantTestingService.Object, + mockCookieStorageService.Object, + mockEmployerTeamOrchestrator.Object, + mockAuthorizationService.Object); + } + + [Test] + public void ThenForNonLevyContinueSetupForSingleApprenticeshipByProviderViewIsReturnedAtRow1Panel1() + { + //Arrange + var model = new AccountDashboardViewModel() + { + PayeSchemeCount = 1, + ApprenticeshipEmployerType = Common.Domain.Types.ApprenticeshipEmployerType.NonLevy, + CallToActionViewModel = new CallToActionViewModel + { + Reservations = new List { new Reservation { Status = ReservationStatus.Completed } }, + Cohorts = new List + { + new CohortViewModel + { + NumberOfDraftApprentices = 0, + CohortStatus = CohortStatus.WithTrainingProvider, + Apprenticeships = new List() + { + new ApprenticeshipViewModel + { + ApprenticeshipStatus = ApprenticeshipStatus.Draft + } + } + } + } + } + }; + + //Act + var result = _controller.Row1Panel1(model) as PartialViewResult; + + //Assert + Assert.IsNotNull(result); + Assert.AreEqual("SingleApprenticeshipContinueWithProvider", (result.Model as dynamic).ViewName); + } + } +} diff --git a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/EmployerTeamControllerTests/WhenCallToActionToggleIsEnabled/WhenSetupSingleApprenticeStatus.cs b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/EmployerTeamControllerTests/WhenCallToActionToggleIsEnabled/WhenSetupSingleApprenticeStatus.cs new file mode 100644 index 0000000000..8efbef0d4a --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/EmployerTeamControllerTests/WhenCallToActionToggleIsEnabled/WhenSetupSingleApprenticeStatus.cs @@ -0,0 +1,156 @@ +using System.Collections.Generic; +using System.Web.Mvc; +using Moq; +using NUnit.Framework; +using SFA.DAS.Authentication; +using SFA.DAS.Authorization.Services; +using SFA.DAS.EmployerAccounts.Interfaces; +using SFA.DAS.EmployerAccounts.Models.CommitmentsV2; +using SFA.DAS.EmployerAccounts.Models.Reservations; +using SFA.DAS.EmployerAccounts.Web.Controllers; +using SFA.DAS.EmployerAccounts.Web.Orchestrators; +using SFA.DAS.EmployerAccounts.Web.ViewModels; + +namespace SFA.DAS.EmployerAccounts.Web.UnitTests.Controllers.EmployerTeamControllerTests.WhenCallToActionToggleIsEnabled +{ + public class WhenSetupSingleApprenticeStatus + { + private EmployerTeamController _controller; + + private Mock mockAuthenticationService; + private Mock mockAuthorizationService; + private Mock mockMultiVariantTestingService; + private Mock> mockCookieStorageService; + private Mock mockEmployerTeamOrchestrator; + + [SetUp] + public void Arrange() + { + mockAuthenticationService = new Mock(); + mockAuthorizationService = new Mock(); + mockMultiVariantTestingService = new Mock(); + mockCookieStorageService = new Mock>(); + mockEmployerTeamOrchestrator = new Mock(); + + mockAuthorizationService.Setup(m => m.IsAuthorized("EmployerFeature.HomePage")).Returns(false); + mockAuthorizationService.Setup(m => m.IsAuthorized("EmployerFeature.CallToAction")).Returns(true); + + _controller = new EmployerTeamController( + mockAuthenticationService.Object, + mockMultiVariantTestingService.Object, + mockCookieStorageService.Object, + mockEmployerTeamOrchestrator.Object, + mockAuthorizationService.Object); + } + + [Test] + public void ThenForNonLevyTheYourSingleApprovedApprenticeViewIsReturnedAtRow1Panel1() + { + //Arrange + var model = new AccountDashboardViewModel() + { + PayeSchemeCount = 1, + ApprenticeshipEmployerType = Common.Domain.Types.ApprenticeshipEmployerType.NonLevy, + CallToActionViewModel = new CallToActionViewModel + { + Reservations = new List { new Reservation { Status = ReservationStatus.Completed } }, + Apprenticeships = new List() + { + new ApprenticeshipViewModel() + { + ApprenticeshipStatus =ApprenticeshipStatus.Approved + } + } + } + }; + + //Act + var result = _controller.Row1Panel1(model) as PartialViewResult; + + //Assert + Assert.IsNotNull(result); + Assert.AreEqual("SingleApprenticeshipApproved", (result.Model as dynamic).ViewName); + } + + + [Test] + public void ThenForNonLevyTheYourSingleApprenticeWithTrainingProviderStatusViewIsReturnedAtRow1Panel1() + { + //Arrange + var model = new AccountDashboardViewModel() + { + PayeSchemeCount = 1, + ApprenticeshipEmployerType = Common.Domain.Types.ApprenticeshipEmployerType.NonLevy, + CallToActionViewModel = new CallToActionViewModel + { + Reservations = new List { new Reservation { Status = ReservationStatus.Completed } }, + + Cohorts = new List + { + new CohortViewModel + { + //CohortsCount = 1, + NumberOfDraftApprentices = 1, + CohortStatus = CohortStatus.WithTrainingProvider, + Apprenticeships = new List() + { + new ApprenticeshipViewModel + { + ApprenticeshipStatus = ApprenticeshipStatus.Draft, + NumberOfDraftApprentices = 1 + } + } + } + } + } + }; + + //Act + var result = _controller.Row1Panel1(model) as PartialViewResult; + + //Assert + Assert.IsNotNull(result); + Assert.AreEqual("SingleApprenticeshipWithTrainingProvider", (result.Model as dynamic).ViewName); + } + + + [Test] + public void ThenForNonLevyTheYourSingleApprenticeReadyForReviewStatusViewIsReturnedAtRow1Panel1() + { + //Arrange + var model = new AccountDashboardViewModel() + { + PayeSchemeCount = 1, + ApprenticeshipEmployerType = Common.Domain.Types.ApprenticeshipEmployerType.NonLevy, + CallToActionViewModel = new CallToActionViewModel + { + Reservations = new List { new Reservation { Status = ReservationStatus.Completed } }, + Cohorts = new List + { + new CohortViewModel + { + //CohortsCount = 1, + NumberOfDraftApprentices = 1, + CohortStatus = CohortStatus.Review, + Apprenticeships = new List() + { + new ApprenticeshipViewModel + { + ApprenticeshipStatus = ApprenticeshipStatus.Draft, + NumberOfDraftApprentices = 1 + } + } + } + } + } + }; + + //Act + var result = _controller.Row1Panel1(model) as PartialViewResult; + + //Assert + Assert.IsNotNull(result); + Assert.AreEqual("SingleApprenticeshipReadyForReview", (result.Model as dynamic).ViewName); + } + } +} diff --git a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/EmployerTeamControllerTests/WhenCallToActionToggleIsEnabled/WhenSetupSingleReservation.cs b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/EmployerTeamControllerTests/WhenCallToActionToggleIsEnabled/WhenSetupSingleReservation.cs new file mode 100644 index 0000000000..c8db181f7e --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/EmployerTeamControllerTests/WhenCallToActionToggleIsEnabled/WhenSetupSingleReservation.cs @@ -0,0 +1,71 @@ +using System.Collections.Generic; +using System.Web.Mvc; +using Moq; +using NUnit.Framework; +using SFA.DAS.Authentication; +using SFA.DAS.Authorization.Services; +using SFA.DAS.EmployerAccounts.Interfaces; +using SFA.DAS.EmployerAccounts.Models.Reservations; +using SFA.DAS.EmployerAccounts.Web.Controllers; +using SFA.DAS.EmployerAccounts.Web.Orchestrators; +using SFA.DAS.EmployerAccounts.Web.ViewModels; + +namespace SFA.DAS.EmployerAccounts.Web.UnitTests.Controllers.EmployerTeamControllerTests.WhenCallToActionToggleIsEnabled +{ + public class WhenSetupSingleReservation + { + private EmployerTeamController _controller; + + private Mock mockAuthenticationService; + private Mock mockAuthorizationService; + private Mock mockMultiVariantTestingService; + private Mock> mockCookieStorageService; + private Mock mockEmployerTeamOrchestrator; + + [SetUp] + public void Arrange() + { + mockAuthenticationService = new Mock(); + mockAuthorizationService = new Mock(); + mockMultiVariantTestingService = new Mock(); + mockCookieStorageService = new Mock>(); + mockEmployerTeamOrchestrator = new Mock(); + + mockAuthorizationService.Setup(m => m.IsAuthorized("EmployerFeature.HomePage")).Returns(false); + mockAuthorizationService.Setup(m => m.IsAuthorized("EmployerFeature.CallToAction")).Returns(true); + + _controller = new EmployerTeamController( + mockAuthenticationService.Object, + mockMultiVariantTestingService.Object, + mockCookieStorageService.Object, + mockEmployerTeamOrchestrator.Object, + mockAuthorizationService.Object); + } + + + [Test] + public void ThenForNonLevyTheContinueSetupForSingleReservationViewIsReturnedAtRow1Panel1() + { + // Arrange + var model = new AccountDashboardViewModel() + { + PayeSchemeCount = 1, + CallToActionViewModel = new CallToActionViewModel + { + Reservations = new List { new Reservation { Status = ReservationStatus.Pending } }, + VacanciesViewModel = new VacanciesViewModel() + }, + ApprenticeshipEmployerType = Common.Domain.Types.ApprenticeshipEmployerType.NonLevy + }; + + //Act + var result = _controller.Row1Panel1(model) as PartialViewResult; + + //Assert + Assert.IsNotNull(result); + Assert.AreEqual("ContinueSetupForSingleReservation", (result.Model as dynamic).ViewName); + Assert.AreEqual(PanelType.Summary, (result.Model as dynamic).PanelType); + } + + } +} diff --git a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/EmployerTeamControllerTests/WhenNoPayeScheme.cs b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/EmployerTeamControllerTests/WhenNoPayeScheme.cs index 611ba7f24e..36d7c85657 100644 --- a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/EmployerTeamControllerTests/WhenNoPayeScheme.cs +++ b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Controllers/EmployerTeamControllerTests/WhenNoPayeScheme.cs @@ -44,11 +44,7 @@ public void ThenTheAddPayeViewIsReturnedAtRow1Panel1() { // Arrange var model = new AccountDashboardViewModel(); - model.PayeSchemeCount = 0; - model.CallToActionViewModel = new CallToActionViewModel - { - ApprenticeshipAdded = false - }; + model.PayeSchemeCount = 0; //Act var result = _controller.Row1Panel1(model) as PartialViewResult; diff --git a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Extensions/CohortSummaryExtensionTests.cs b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Extensions/CohortSummaryExtensionTests.cs new file mode 100644 index 0000000000..9b5cbb81ed --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Extensions/CohortSummaryExtensionTests.cs @@ -0,0 +1,31 @@ +using NUnit.Framework; +using SFA.DAS.CommitmentsV2.Types; +using SFA.DAS.EmployerAccounts.Web.Extensions; + +namespace SFA.DAS.EmployerAccounts.Web.UnitTests.Extensions +{ + [TestFixture] + public class CohortSummaryExtensionTests + { + [TestCase(false, Party.Employer, CohortStatus.Review)] + [TestCase(true, Party.Employer, CohortStatus.Draft)] + [TestCase(false, Party.Provider, CohortStatus.WithTrainingProvider)] + [TestCase(true, Party.Provider, CohortStatus.Unknown)] + public void CohortSummary_GetStatus_Returns_Correct_Status(bool isDraft, Party withParty, CohortStatus cohortStatus) + { + //Arrange + var cohortSummary = new CohortSummary + { + CohortId = 1, + IsDraft = isDraft, + WithParty = withParty + }; + + //Act + var status = cohortSummary.GetStatus(); + + //Assert + Assert.AreEqual(cohortStatus, status); + } + } +} diff --git a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Mappings/WhenAutoMapping.cs b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Mappings/WhenAutoMapping.cs index ff3b1a71b6..5b892b4582 100644 --- a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Mappings/WhenAutoMapping.cs +++ b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Mappings/WhenAutoMapping.cs @@ -22,6 +22,7 @@ public void ThenShouldUseValidConfiguration() c.AddProfile(); c.AddProfile(); c.AddProfile(); + c.AddProfile(); }); config.AssertConfigurationIsValid(); 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 555a63c34f..6fb012bf81 100644 --- a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenGettingAccount.cs +++ b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenGettingAccount.cs @@ -1,4 +1,5 @@ -using System; + +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -6,10 +7,7 @@ using MediatR; using Moq; using NUnit.Framework; -using SFA.DAS.Authorization; using SFA.DAS.Authorization.Services; -using SFA.DAS.CommitmentsV2.Api.Client; -using SFA.DAS.Common.Domain.Types; using SFA.DAS.EAS.Account.Api.Client; using SFA.DAS.EAS.Account.Api.Types; using SFA.DAS.EmployerAccounts.Dtos; @@ -18,7 +16,9 @@ using SFA.DAS.EmployerAccounts.Models.Account; using SFA.DAS.EmployerAccounts.Models.AccountTeam; using SFA.DAS.EmployerAccounts.Models.Recruit; +using SFA.DAS.EmployerAccounts.Models.CommitmentsV2; using SFA.DAS.EmployerAccounts.Models.Reservations; +using SFA.DAS.EmployerAccounts.Queries.GetSingleCohort; using SFA.DAS.EmployerAccounts.Queries.GetAccountEmployerAgreements; using SFA.DAS.EmployerAccounts.Queries.GetAccountStats; using SFA.DAS.EmployerAccounts.Queries.GetAccountTasks; @@ -26,9 +26,11 @@ using SFA.DAS.EmployerAccounts.Queries.GetReservations; using SFA.DAS.EmployerAccounts.Queries.GetTeamUser; using SFA.DAS.EmployerAccounts.Queries.GetUserAccountRole; +using SFA.DAS.EmployerAccounts.Web.Extensions; using SFA.DAS.EmployerAccounts.Queries.GetVacancies; using SFA.DAS.EmployerAccounts.Web.Orchestrators; using SFA.DAS.EmployerAccounts.Web.ViewModels; +using SFA.DAS.EmployerAccounts.Queries.GetApprenticeship; namespace SFA.DAS.EmployerAccounts.Web.UnitTests.Orchestrators.EmployerTeamOrchestratorTests { @@ -39,11 +41,10 @@ public class WhenGettingAccount private const string UserId = "USER1"; private Mock _mediator; - private EmployerTeamOrchestrator _orchestrator; + private EmployerTeamOrchestrator _orchestrator; private AccountStats _accountStats; private Mock _currentDateTime; private Mock _accountApiClient; - private Mock _commitmentsApiClient; private Mock _mapper; private List _tasks; private AccountTask _testTask; @@ -142,29 +143,64 @@ public void Arrange() _mediator.Setup(x => x.SendAsync(It.IsAny())) .ReturnsAsync(new GetAccountStatsResponse {Stats = _accountStats}); + _mediator.Setup(m => m.SendAsync(It.Is(q => q.HashedAccountId == HashedAccountId))) - .ReturnsAsync(new GetReservationsResponse - { - Reservations = new List - { + .ReturnsAsync(new GetReservationsResponse + { + Reservations = new List + { new Reservation { AccountId = 123 } + } + }); + + _mediator.Setup(m => m.SendAsync(It.Is(q => q.HashedAccountId == HashedAccountId))) + .ReturnsAsync(new GetApprenticeshipsResponse + { + Apprenticeships = new List + { + new Apprenticeship { FirstName = "FirstName" } + } + }); + + + var Cohort = new Cohort() + { + Id = 1, + CohortStatus = EmployerAccounts.Models.CommitmentsV2.CohortStatus.WithTrainingProvider, + NumberOfDraftApprentices = 1, + Apprenticeships = new List + { + new Apprenticeship() + { + Id = 2, + FirstName = "FirstName", + LastName = "LastName", + CourseStartDate = new DateTime(2020,5,1), + CourseEndDate = new DateTime(2022,1,1), + CourseName = "CourseName" + } } + }; + _mediator.Setup(x => x.SendAsync(It.IsAny())) + .ReturnsAsync(new GetSingleCohortResponse + { + Cohort = Cohort + }); _currentDateTime = new Mock(); _accountApiClient = new Mock(); - _commitmentsApiClient = new Mock(); _accountApiClient.Setup(c => c.GetAccount(HashedAccountId)).ReturnsAsync(new AccountDetailViewModel {ApprenticeshipEmployerType = "Levy"}); - + _mapper = new Mock(); - _orchestrator = new EmployerTeamOrchestrator(_mediator.Object, _currentDateTime.Object, _accountApiClient.Object, _commitmentsApiClient.Object, _mapper.Object, Mock.Of()); + _orchestrator = new EmployerTeamOrchestrator(_mediator.Object, _currentDateTime.Object, _accountApiClient.Object, _mapper.Object, Mock.Of()); } [Test] @@ -180,16 +216,6 @@ public async Task ThenShouldGetAccountStats() Assert.AreEqual(_accountStats.TeamMemberCount, actual.Data.TeamMemberCount); } - [Test] - public async Task ThenShouldGetReservationsCount() - { - // Act - var actual = await _orchestrator.GetAccount(HashedAccountId, UserId); - - //Assert - Assert.AreEqual(1, actual.Data.CallToActionViewModel.ReservationsCount); - } - [Test] public async Task ThenShouldReturnTasks() { @@ -308,9 +334,9 @@ public async Task ThenAgreementsAreRetrievedCorrectly() Assert.AreEqual(4, actual.Data.RequiresAgreementSigning); } - [TestCase(ApprenticeshipEmployerType.Levy, "Levy")] - [TestCase(ApprenticeshipEmployerType.NonLevy, "NonLevy")] - public async Task ThenShouldReturnCorrectApprenticeshipEmployerTypeFromAccountApi(ApprenticeshipEmployerType expectedApprenticeshipEmployerType, string apiApprenticeshipEmployerType) + [TestCase(Common.Domain.Types.ApprenticeshipEmployerType.Levy, "Levy")] + [TestCase(Common.Domain.Types.ApprenticeshipEmployerType.NonLevy, "NonLevy")] + public async Task ThenShouldReturnCorrectApprenticeshipEmployerTypeFromAccountApi(Common.Domain.Types.ApprenticeshipEmployerType expectedApprenticeshipEmployerType, string apiApprenticeshipEmployerType) { //Arrange _accountApiClient @@ -331,5 +357,52 @@ public async Task ThenReturnAccountSummary() var model = await _orchestrator.GetAccountSummary(HashedAccountId, UserId); Assert.IsNotNull(model.Data); } + + [Test] + public async Task ThenShouldGetReservationsCount() + { + // Act + var result = await _orchestrator.GetAccount(HashedAccountId, UserId); + + //Assert + Assert.AreEqual(1, result.Data.CallToActionViewModel.ReservationsCount); + } + + [Test] + public async Task ThenShouldGetApprenticeshipResponse() + { + //Arrange + var apprenticeships = new List { new Apprenticeship { FirstName = "FirstName" } }; + _mediator.Setup(m => m.SendAsync(It.Is(q => q.HashedAccountId == HashedAccountId))) + .ReturnsAsync(new GetApprenticeshipsResponse { Apprenticeships = apprenticeships }); + var expectedApprenticeship = new List() {new ApprenticeshipViewModel { ApprenticeshipFullName = "FullName" }}; + _mapper.Setup(m => m.Map, IEnumerable>(apprenticeships)).Returns(expectedApprenticeship); + + //Act + var result = await _orchestrator.GetAccount(HashedAccountId, UserId); + + //Assert + Assert.IsTrue(result.Data.CallToActionViewModel.Apprenticeships.Count().Equals(1)); + } + + [Test] + public async Task ThenShouldGetCohortResponse() + { + //Arrange + 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 }); + var expectedCohort = new CohortViewModel() + { + NumberOfDraftApprentices = 1, + Apprenticeships = new List { new ApprenticeshipViewModel { ApprenticeshipFullName = "FullName" } } + }; + _mapper.Setup(m => m.Map(Cohort)).Returns(expectedCohort); + + //Act + var result = await _orchestrator.GetAccount(HashedAccountId, UserId); + + //Assert + Assert.AreEqual(1, result.Data.CallToActionViewModel.CohortsCount); + } } } diff --git a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenIChangeATeamMemberRole.cs b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenIChangeATeamMemberRole.cs index 6b33fb79fc..2519d4bf19 100644 --- a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenIChangeATeamMemberRole.cs +++ b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenIChangeATeamMemberRole.cs @@ -22,8 +22,7 @@ namespace SFA.DAS.EmployerAccounts.Web.UnitTests.Orchestrators.EmployerTeamOrche class WhenIChangeATeamMemberRole { private Mock _mediator; - private Mock _accountApiClient; - private Mock _commitmentsApiClient; + private Mock _accountApiClient; private Mock _mapper; private EmployerTeamOrchestrator _orchestrator; @@ -31,11 +30,10 @@ class WhenIChangeATeamMemberRole public void Arrange() { _mediator = new Mock(); - _accountApiClient = new Mock(); - _commitmentsApiClient = new Mock(); + _accountApiClient = new Mock(); _mapper = new Mock(); - _orchestrator = new EmployerTeamOrchestrator(_mediator.Object, Mock.Of(), _accountApiClient.Object, _commitmentsApiClient.Object, _mapper.Object, Mock.Of()); + _orchestrator = new EmployerTeamOrchestrator(_mediator.Object, Mock.Of(), _accountApiClient.Object, _mapper.Object, Mock.Of()); } [Test] diff --git a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenIGetATeamMembersDetails.cs b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenIGetATeamMembersDetails.cs index aab643d671..7e607c9ae6 100644 --- a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenIGetATeamMembersDetails.cs +++ b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenIGetATeamMembersDetails.cs @@ -23,8 +23,7 @@ class WhenIGetATeamMembersDetails private const string HashedAccountId = "ABC123"; private Mock _mediator; - private Mock _accountApiClient; - private Mock _commitmentsApiClient; + private Mock _accountApiClient; private Mock _mapper; private EmployerTeamOrchestrator _orchestrator; private GetMemberResponse _teamMemberResponse; @@ -43,11 +42,10 @@ public void Arrange() }; _mediator = new Mock(); - _accountApiClient = new Mock(); - _commitmentsApiClient = new Mock(); + _accountApiClient = new Mock(); _mapper = new Mock(); - _orchestrator = new EmployerTeamOrchestrator(_mediator.Object, Mock.Of(), _accountApiClient.Object, _commitmentsApiClient.Object, _mapper.Object, Mock.Of()); + _orchestrator = new EmployerTeamOrchestrator(_mediator.Object, Mock.Of(), _accountApiClient.Object, _mapper.Object, Mock.Of()); _mediator.Setup(x => x.SendAsync(It.IsAny())) .ReturnsAsync(_teamMemberResponse); diff --git a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenIGetMyTeamMembers.cs b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenIGetMyTeamMembers.cs index af3ada2128..fb66303035 100644 --- a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenIGetMyTeamMembers.cs +++ b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenIGetMyTeamMembers.cs @@ -17,8 +17,8 @@ namespace SFA.DAS.EmployerAccounts.Web.UnitTests.Orchestrators.EmployerTeamOrche public class WhenIGetMyTeamMembers { private Mock _mediator; - private Mock _accountApiClient; - private Mock _commitmentsApiClient; + private Mock _accountApiClient; + private Mock _mapper; private EmployerTeamOrchestrator _orchestrator; @@ -34,11 +34,10 @@ public void Arrange() TeamMembers = new List {new TeamMember()} }); - _accountApiClient = new Mock(); - _commitmentsApiClient = new Mock(); + _accountApiClient = new Mock(); _mapper = new Mock(); - _orchestrator = new EmployerTeamOrchestrator(_mediator.Object, Mock.Of(), _accountApiClient.Object, _commitmentsApiClient.Object, _mapper.Object, Mock.Of()); + _orchestrator = new EmployerTeamOrchestrator(_mediator.Object, Mock.Of(), _accountApiClient.Object, _mapper.Object, Mock.Of()); } [Test] diff --git a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenIInviteATeamMember.cs b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenIInviteATeamMember.cs index 083c7cac74..6c321417c3 100644 --- a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenIInviteATeamMember.cs +++ b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenIInviteATeamMember.cs @@ -23,8 +23,8 @@ namespace SFA.DAS.EmployerAccounts.Web.UnitTests.Orchestrators.EmployerTeamOrche class WhenIInviteATeamMember { private Mock _mediator; - private Mock _accountApiClient; - private Mock _commitmentsApiClient; + private Mock _accountApiClient; + private Mock _mapper; private EmployerTeamOrchestrator _orchestrator; @@ -33,10 +33,9 @@ class WhenIInviteATeamMember public void Arrange() { _mediator = new Mock(); - _accountApiClient = new Mock(); - _commitmentsApiClient = new Mock(); + _accountApiClient = new Mock(); _mapper = new Mock(); - _orchestrator = new EmployerTeamOrchestrator(_mediator.Object, Mock.Of(), _accountApiClient.Object, _commitmentsApiClient.Object, _mapper.Object, Mock.Of()); + _orchestrator = new EmployerTeamOrchestrator(_mediator.Object, Mock.Of(), _accountApiClient.Object, _mapper.Object, Mock.Of()); } [Test] diff --git a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenIRemoveATeamMember.cs b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenIRemoveATeamMember.cs index d8cda9df19..5bc11341f2 100644 --- a/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenIRemoveATeamMember.cs +++ b/src/SFA.DAS.EmployerAccounts.Web.UnitTests/Orchestrators/EmployerTeamOrchestratorTests/WhenIRemoveATeamMember.cs @@ -25,8 +25,7 @@ class WhenIRemoveATeamMember const string Email = "test@test.com"; private Mock _mediator; - private Mock _accountApiClient; - private Mock _commitmentsApiClient; + private Mock _accountApiClient; private Mock _mapper; private EmployerTeamOrchestrator _orchestrator; @@ -35,11 +34,10 @@ class WhenIRemoveATeamMember public void Arrange() { _mediator = new Mock(); - _accountApiClient = new Mock(); - _commitmentsApiClient = new Mock(); + _accountApiClient = new Mock(); _mapper = new Mock(); - _orchestrator = new EmployerTeamOrchestrator(_mediator.Object, Mock.Of(), _accountApiClient.Object, _commitmentsApiClient.Object, _mapper.Object, Mock.Of()); + _orchestrator = new EmployerTeamOrchestrator(_mediator.Object, Mock.Of(), _accountApiClient.Object, _mapper.Object, Mock.Of()); _mediator.Setup(x => x.SendAsync(It.IsAny())) .ReturnsAsync(new GetAccountTeamMembersResponse diff --git a/src/SFA.DAS.EmployerAccounts.Web/Controllers/EmployerTeamController.cs b/src/SFA.DAS.EmployerAccounts.Web/Controllers/EmployerTeamController.cs index e8b585cdca..59509e59af 100644 --- a/src/SFA.DAS.EmployerAccounts.Web/Controllers/EmployerTeamController.cs +++ b/src/SFA.DAS.EmployerAccounts.Web/Controllers/EmployerTeamController.cs @@ -1,19 +1,20 @@ -using System; -using System.Linq; -using System.Net; -using System.Threading.Tasks; -using System.Web; -using System.Web.Mvc; -using SFA.DAS.Authentication; +using SFA.DAS.Authentication; +using SFA.DAS.Authorization.Mvc.Attributes; +using SFA.DAS.Authorization.Services; using SFA.DAS.EmployerAccounts.Interfaces; +using SFA.DAS.EmployerAccounts.Models; using SFA.DAS.EmployerAccounts.Web.Extensions; using SFA.DAS.EmployerAccounts.Web.Helpers; using SFA.DAS.EmployerAccounts.Web.Orchestrators; using SFA.DAS.EmployerAccounts.Web.ViewModels; using SFA.DAS.Validation; -using SFA.DAS.Authorization.Mvc.Attributes; -using SFA.DAS.Authorization.Services; -using SFA.DAS.EmployerAccounts.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Threading.Tasks; +using System.Web; +using System.Web.Mvc; namespace SFA.DAS.EmployerAccounts.Web.Controllers { @@ -28,7 +29,7 @@ public EmployerTeamController( IAuthenticationService owinWrapper) : base(owinWrapper) { - _employerTeamOrchestrator = null; + _employerTeamOrchestrator = null; } public EmployerTeamController( @@ -334,6 +335,45 @@ public ActionResult ContinueSetupCreateAdvert(string hashedAccountId, bool? requ return Redirect(Url.EmployerCommitmentsAction("apprentices/inform")); } + [ChildActionOnly] + public ActionResult SingleApprenticeshipContinueSetup(AccountDashboardViewModel model) + { + return PartialView(model.CallToActionViewModel.Cohorts.Single().Apprenticeships.Single()); + } + + [ChildActionOnly] + public ActionResult SingleApprenticeshipWithTrainingProvider(AccountDashboardViewModel model) + { + return PartialView(model.CallToActionViewModel.Cohorts.Single().Apprenticeships.Single()); + } + + [ChildActionOnly] + public ActionResult SingleApprenticeshipReadyForReview(AccountDashboardViewModel model) + { + return PartialView(model.CallToActionViewModel.Cohorts.Single().Apprenticeships.Single()); + } + + [ChildActionOnly] + public ActionResult SingleApprenticeshipApproved(AccountDashboardViewModel model) + { + return PartialView(model.CallToActionViewModel.Apprenticeships.First()); + } + + [ChildActionOnly] + public ActionResult SingleApprenticeshipContinueWithProvider(AccountDashboardViewModel model) + { + model.CallToActionViewModel.Cohorts.Single().Apprenticeships = new List() + { + new ApprenticeshipViewModel() + { + CourseName = model.CallToActionViewModel.Reservations?.Single().Course?.CourseDescription, + HashedCohortId = model.CallToActionViewModel.Cohorts?.Single().HashedCohortId, + TrainingProvider = model.CallToActionViewModel.Cohorts?.Single().TrainingProvider.First() + } + }; + return PartialView(model.CallToActionViewModel.Cohorts.Single().Apprenticeships.Single()); + } + [ChildActionOnly] public override ActionResult SupportUserBanner(IAccountIdentifier model = null) { @@ -354,10 +394,10 @@ public override ActionResult SupportUserBanner(IAccountIdentifier model = null) public ActionResult Row1Panel1(AccountDashboardViewModel model) { var viewModel = new PanelViewModel { ViewName = "Empty", Data = model }; - + if (model.PayeSchemeCount == 0) { - viewModel.ViewName = "AddPAYE"; + viewModel.ViewName = "AddPAYE"; } else if (_authorizationService.IsAuthorized("EmployerFeature.CallToAction")) { @@ -494,7 +534,7 @@ public ActionResult CheckFunding(AccountDashboardViewModel model) public ActionResult ContinueSetupForSingleReservation(AccountDashboardViewModel model) { var reservation = model.CallToActionViewModel.Reservations?.FirstOrDefault(); - var viewModel = new ReservationViewModel(reservation); + var viewModel = new ReservationViewModel(reservation); return PartialView(viewModel); } @@ -575,6 +615,7 @@ public ActionResult OtherTasksPanel(AccountDashboardViewModel model) { return PartialView(model); } + private async Task> GetAccountInformation(string hashedAccountId) { diff --git a/src/SFA.DAS.EmployerAccounts.Web/DependencyResolution/IoC.cs b/src/SFA.DAS.EmployerAccounts.Web/DependencyResolution/IoC.cs index afee9b47c2..3f84a37b78 100644 --- a/src/SFA.DAS.EmployerAccounts.Web/DependencyResolution/IoC.cs +++ b/src/SFA.DAS.EmployerAccounts.Web/DependencyResolution/IoC.cs @@ -1,15 +1,15 @@ -using SFA.DAS.EmployerAccounts.Api.Client; -using SFA.DAS.EmployerAccounts.Data; using SFA.DAS.Activities.Client; using SFA.DAS.Authorization.DependencyResolution.StructureMap; using SFA.DAS.Authorization.EmployerFeatures.DependencyResolution.StructureMap; using SFA.DAS.Authorization.EmployerUserRoles.DependencyResolution.StructureMap; +using SFA.DAS.EmployerAccounts.Api.Client; +using SFA.DAS.EmployerAccounts.Data; using SFA.DAS.EmployerAccounts.DependencyResolution; -using StructureMap; -using ConfigurationRegistry = SFA.DAS.EmployerAccounts.DependencyResolution.ConfigurationRegistry; +using SFA.DAS.UnitOfWork.EntityFramework.StructureMap; +using SFA.DAS.UnitOfWork.NServiceBus.DependencyResolution.StructureMap; using SFA.DAS.UnitOfWork.NServiceBus.Features.ClientOutbox.DependencyResolution.StructureMap; -using SFA.DAS.UnitOfWork.NServiceBus.DependencyResolution.StructureMap; -using SFA.DAS.UnitOfWork.EntityFramework.StructureMap; +using StructureMap; +using ConfigurationRegistry = SFA.DAS.EmployerAccounts.DependencyResolution.ConfigurationRegistry; namespace SFA.DAS.EmployerAccounts.Web.DependencyResolution { @@ -53,7 +53,8 @@ public static IContainer Initialize() c.AddRegistry(); c.AddRegistry(); c.AddRegistry(); - c.AddRegistry(); + c.AddRegistry(); + c.AddRegistry(); c.AddRegistry(); }); } diff --git a/src/SFA.DAS.EmployerAccounts.Web/Extensions/CohortSummaryExtension.cs b/src/SFA.DAS.EmployerAccounts.Web/Extensions/CohortSummaryExtension.cs index 1adefe6eb3..8ff2ea2b83 100644 --- a/src/SFA.DAS.EmployerAccounts.Web/Extensions/CohortSummaryExtension.cs +++ b/src/SFA.DAS.EmployerAccounts.Web/Extensions/CohortSummaryExtension.cs @@ -11,7 +11,7 @@ public static CohortStatus GetStatus(this CohortSummary cohort) else if (!cohort.IsDraft && cohort.WithParty == Party.Employer) return CohortStatus.Review; else if (!cohort.IsDraft && cohort.WithParty == Party.Provider) - return CohortStatus.WithProvider; + return CohortStatus.WithTrainingProvider; else if (!cohort.IsDraft && cohort.WithParty == Party.TransferSender) return CohortStatus.WithTransferSender; else @@ -24,7 +24,7 @@ public enum CohortStatus Unknown, Draft, Review, - WithProvider, + WithTrainingProvider, WithTransferSender } } \ No newline at end of file diff --git a/src/SFA.DAS.EmployerAccounts.Web/Extensions/HtmlHelperExtensions.cs b/src/SFA.DAS.EmployerAccounts.Web/Extensions/HtmlHelperExtensions.cs index 1af75f0b14..d378469a84 100644 --- a/src/SFA.DAS.EmployerAccounts.Web/Extensions/HtmlHelperExtensions.cs +++ b/src/SFA.DAS.EmployerAccounts.Web/Extensions/HtmlHelperExtensions.cs @@ -1,12 +1,13 @@ using SFA.DAS.EmployerAccounts.Configuration; +using SFA.DAS.EmployerAccounts.Web.Helpers; +using SFA.DAS.EmployerAccounts.Web.ViewModels; +using SFA.DAS.MA.Shared.UI.Configuration; +using SFA.DAS.MA.Shared.UI.Models; +using SFA.DAS.MA.Shared.UI.Models.Links; using System; using System.Linq; using System.Security.Claims; using System.Web.Mvc; -using SFA.DAS.EmployerAccounts.Web.Helpers; -using SFA.DAS.MA.Shared.UI.Models; -using SFA.DAS.MA.Shared.UI.Configuration; -using SFA.DAS.MA.Shared.UI.Models.Links; namespace SFA.DAS.EmployerAccounts.Web.Extensions { @@ -24,7 +25,7 @@ public static MvcHtmlString CommaSeperatedAddressToHtml(this HtmlHelper htmlHelp { var htmlAddress = commaSeperatedAddress.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(line => $"{line.Trim()}
") - .Aggregate("", (x, y) => x + y); + .Aggregate(string.Empty, (x, y) => x + y); return new MvcHtmlString(htmlAddress); } @@ -127,5 +128,4 @@ public static IFooterViewModel GetFooterViewModel(this HtmlHelper html, bool use ); } } - } \ No newline at end of file diff --git a/src/SFA.DAS.EmployerAccounts.Web/Extensions/UrlHelperExtensions.cs b/src/SFA.DAS.EmployerAccounts.Web/Extensions/UrlHelperExtensions.cs index 309af12254..7aca99dbd4 100644 --- a/src/SFA.DAS.EmployerAccounts.Web/Extensions/UrlHelperExtensions.cs +++ b/src/SFA.DAS.EmployerAccounts.Web/Extensions/UrlHelperExtensions.cs @@ -18,7 +18,7 @@ public static string EmployerCommitmentsAction(this UrlHelper helper, string pat { var configuration = DependencyResolver.Current.GetService(); var baseUrl = configuration.EmployerCommitmentsBaseUrl; - + return AccountAction(helper, baseUrl, path); } @@ -26,10 +26,8 @@ public static string EmployerCommitmentsV2Action(this UrlHelper helper, string p { var configuration = DependencyResolver.Current.GetService(); var baseUrl = configuration.EmployerCommitmentsV2BaseUrl; - var hashedAccountId = helper.RequestContext.RouteData.Values[ControllerConstants.AccountHashedIdRouteKeyName]; - var accountPath = hashedAccountId == null ? $"{path}" : $"{hashedAccountId}/{path}"; - return Action(baseUrl, accountPath); + return CommitmentAction(helper, baseUrl, path); } public static string ReservationsAction(this UrlHelper helper, string path) @@ -60,7 +58,7 @@ public static string EmployerRecruitAction(this UrlHelper helper, string path = { var configuration = DependencyResolver.Current.GetService(); var baseUrl = configuration.EmployerRecruitBaseUrl; - + return AccountAction(helper, baseUrl, path); } @@ -104,6 +102,14 @@ private static string AccountAction(UrlHelper helper, string baseUrl, string pat return Action(baseUrl, accountPath); } + private static string CommitmentAction(UrlHelper helper, string baseUrl, string path) + { + var hashedAccountId = helper.RequestContext.RouteData.Values[ControllerConstants.AccountHashedIdRouteKeyName]; + var commitmentPath = hashedAccountId == null ? $"{path}" : $"{hashedAccountId}/{path}"; + + return Action(baseUrl, commitmentPath); + } + private static string Action(string baseUrl, string path) { var trimmedBaseUrl = baseUrl?.TrimEnd('/') ?? string.Empty; diff --git a/src/SFA.DAS.EmployerAccounts.Web/Helpers/ControllerConstants.cs b/src/SFA.DAS.EmployerAccounts.Web/Helpers/ControllerConstants.cs index 2e23c02df4..66351a5189 100644 --- a/src/SFA.DAS.EmployerAccounts.Web/Helpers/ControllerConstants.cs +++ b/src/SFA.DAS.EmployerAccounts.Web/Helpers/ControllerConstants.cs @@ -85,6 +85,10 @@ public static class ControllerConstants public const string Settings = "Settings"; public const string Details = "Details"; public const string CookieConsent = "CookieConsent"; - public const string Tier2UserClaim = "Tier2User"; + public const string Tier2UserClaim = "Tier2User"; + public const string EditApprentice = "EditApprentice"; + public const string ViewApprentice = "ViewApprentice"; + public const string ApproveOrRejectApprentice = "ApproveOrRejectApprentice"; + public const string ViewApprenticeBeforeApprove = "ViewApprenticeBeforeApprove"; } } \ No newline at end of file diff --git a/src/SFA.DAS.EmployerAccounts.Web/Mappings/CohortMapping.cs b/src/SFA.DAS.EmployerAccounts.Web/Mappings/CohortMapping.cs new file mode 100644 index 0000000000..c18bf23558 --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts.Web/Mappings/CohortMapping.cs @@ -0,0 +1,27 @@ +using AutoMapper; +using SFA.DAS.EmployerAccounts.Models.CommitmentsV2; +using SFA.DAS.EmployerAccounts.Web.ViewModels; + +namespace SFA.DAS.EmployerAccounts.Web.Mappings +{ + public class CohortMapping : Profile + { + public CohortMapping() + { + CreateMap() + .ForMember(dest => dest.HashedCohortId, opt => opt.MapFrom(src => src.HashedId)); + + CreateMap() + .ForMember(dest => dest.ApprenticeshipFullName, opt => opt.MapFrom(src => string.Format("{0} {1}", + src.FirstName, src.LastName))) + .ForMember(dest => dest.HashedApprenticeshipId, opt => opt.MapFrom(src => src.HashedId)) + .ForMember(dest => dest.CohortId, opt => opt.MapFrom(src => src.Cohort.Id)) + .ForMember(dest => dest.HashedCohortId, opt => opt.MapFrom(src => src.Cohort.HashedId)) + .ForMember(dest => dest.NumberOfDraftApprentices, opt => opt.MapFrom(src => src.Cohort.NumberOfDraftApprentices)) + .ForMember(dest => dest.CourseStartDateText, opt => opt.MapFrom(src => src.CourseStartDate.HasValue ? src.CourseStartDate.Value.ToString("dd MMMM yyyy") : "")) + .ForMember(dest => dest.CourseEndDateText, opt => opt.MapFrom(src => src.CourseEndDate.HasValue ? src.CourseEndDate.Value.ToString("dd MMMM yyyy") : "")); + + CreateMap(); + } + } +} \ No newline at end of file diff --git a/src/SFA.DAS.EmployerAccounts.Web/Models/TrainingDateModel.cs b/src/SFA.DAS.EmployerAccounts.Web/Models/TrainingDateModel.cs index 6893b449d3..42149f07e8 100644 --- a/src/SFA.DAS.EmployerAccounts.Web/Models/TrainingDateModel.cs +++ b/src/SFA.DAS.EmployerAccounts.Web/Models/TrainingDateModel.cs @@ -11,7 +11,7 @@ public override string ToString() { return EndDate == default(DateTime) ? $"{StartDate:MMMM yyyy}" : - $"{StartDate:MMMM yyyy} to {EndDate:MMMM yyyy}"; + $"Between {StartDate:MMMM yyyy} and {EndDate:MMMM yyyy}"; } public override bool Equals(object obj) diff --git a/src/SFA.DAS.EmployerAccounts.Web/Orchestrators/EmployerTeamOrchestrator.cs b/src/SFA.DAS.EmployerAccounts.Web/Orchestrators/EmployerTeamOrchestrator.cs index 3513cc95e3..46d351e57c 100644 --- a/src/SFA.DAS.EmployerAccounts.Web/Orchestrators/EmployerTeamOrchestrator.cs +++ b/src/SFA.DAS.EmployerAccounts.Web/Orchestrators/EmployerTeamOrchestrator.cs @@ -1,6 +1,6 @@ using AutoMapper; using MediatR; -using SFA.DAS.Common.Domain.Types; +using SFA.DAS.Authorization.Services; using SFA.DAS.EAS.Account.Api.Client; using SFA.DAS.EAS.Account.Api.Types; using SFA.DAS.EmployerAccounts.Commands.ChangeTeamMemberRole; @@ -10,19 +10,22 @@ using SFA.DAS.EmployerAccounts.Commands.ResendInvitation; using SFA.DAS.EmployerAccounts.Commands.UpdateShowWizard; using SFA.DAS.EmployerAccounts.Interfaces; +using SFA.DAS.EmployerAccounts.Models; using SFA.DAS.EmployerAccounts.Models.Account; using SFA.DAS.EmployerAccounts.Models.AccountTeam; +using SFA.DAS.EmployerAccounts.Models.CommitmentsV2; +using SFA.DAS.EmployerAccounts.Queries.GetSingleCohort; using SFA.DAS.EmployerAccounts.Queries.GetAccountEmployerAgreements; using SFA.DAS.EmployerAccounts.Queries.GetAccountStats; -using SFA.DAS.EmployerAccounts.Queries.GetAccountTasks; +using SFA.DAS.EmployerAccounts.Queries.GetAccountTasks; using SFA.DAS.EmployerAccounts.Queries.GetAccountTeamMembers; +using SFA.DAS.EmployerAccounts.Queries.GetApprenticeship; using SFA.DAS.EmployerAccounts.Queries.GetEmployerAccount; using SFA.DAS.EmployerAccounts.Queries.GetInvitation; using SFA.DAS.EmployerAccounts.Queries.GetMember; using SFA.DAS.EmployerAccounts.Queries.GetReservations; using SFA.DAS.EmployerAccounts.Queries.GetTeamUser; using SFA.DAS.EmployerAccounts.Queries.GetUser; -using SFA.DAS.EmployerAccounts.Web.Exceptions; using SFA.DAS.EmployerAccounts.Web.ViewModels; using SFA.DAS.Validation; using System; @@ -35,6 +38,8 @@ using SFA.DAS.CommitmentsV2.Api.Client; using SFA.DAS.EmployerAccounts.Queries.GetVacancies; using SFA.DAS.EmployerAccounts.Models.Recruit; +using ResourceNotFoundException = SFA.DAS.EmployerAccounts.Web.Exceptions.ResourceNotFoundException; +using SFA.DAS.Common.Domain.Types; namespace SFA.DAS.EmployerAccounts.Web.Orchestrators { @@ -42,23 +47,20 @@ public class EmployerTeamOrchestrator : UserVerificationOrchestratorBase { private readonly IMediator _mediator; private readonly ICurrentDateTime _currentDateTime; - private readonly IAccountApiClient _accountApiClient; - private readonly ICommitmentsApiClient _commitmentsApiClient; + private readonly IAccountApiClient _accountApiClient; private readonly IMapper _mapper; private readonly IAuthorizationService _authorizationService; - public EmployerTeamOrchestrator(IMediator mediator, - ICurrentDateTime currentDateTime, - IAccountApiClient accountApiClient, - ICommitmentsApiClient commitmentsApiClient, - IMapper mapper, + public EmployerTeamOrchestrator(IMediator mediator, + ICurrentDateTime currentDateTime, + IAccountApiClient accountApiClient, + IMapper mapper, IAuthorizationService authorizationService) : base(mediator) { _mediator = mediator; _currentDateTime = currentDateTime; - _accountApiClient = accountApiClient; - _commitmentsApiClient = commitmentsApiClient; + _accountApiClient = accountApiClient; _mapper = mapper; _authorizationService = authorizationService; } @@ -70,8 +72,8 @@ protected EmployerTeamOrchestrator() public async Task> Cancel(string email, string hashedAccountId, string externalUserId) { - var response = await GetTeamMembers(hashedAccountId, externalUserId); - + var response = await GetTeamMembers(hashedAccountId, externalUserId); + if (response.Status != HttpStatusCode.OK) { return response; @@ -177,22 +179,33 @@ public virtual async Task> GetAc }); var accountStatsResponseTask = _mediator.SendAsync(new GetAccountStatsQuery - { - HashedAccountId = hashedAccountId, - ExternalUserId = externalUserId - }); - - var agreementsResponseTask = _mediator.SendAsync(new GetAccountEmployerAgreementsRequest { HashedAccountId = hashedAccountId, ExternalUserId = externalUserId }); - - var reservationsResponseTask = _mediator.SendAsync(new GetReservationsRequest - { - HashedAccountId = hashedAccountId, - ExternalUserId = externalUserId + var agreementsResponseTask = _mediator.SendAsync(new GetAccountEmployerAgreementsRequest + { + HashedAccountId = hashedAccountId, + ExternalUserId = externalUserId + }); + + var reservationsResponseTask = _mediator.SendAsync(new GetReservationsRequest + { + HashedAccountId = hashedAccountId, + ExternalUserId = externalUserId + }); + + var apprenticeshipsResponseTask = _mediator.SendAsync(new GetApprenticeshipsRequest + { + HashedAccountId = hashedAccountId, + ExternalUserId = externalUserId + }); + + var accountCohortResponseTask = _mediator.SendAsync(new GetSingleCohortRequest + { + HashedAccountId = hashedAccountId, + ExternalUserId = externalUserId }); var vacanciesResponseTask = _mediator.SendAsync(new GetVacanciesRequest @@ -201,18 +214,20 @@ public virtual async Task> GetAc ExternalUserId = externalUserId }); - await Task.WhenAll(apiGetAccountTask, accountStatsResponseTask, userRoleResponseTask, userResponseTask, accountStatsResponseTask, agreementsResponseTask, reservationsResponseTask, vacanciesResponseTask).ConfigureAwait(false); - - var accountResponse = accountResponseTask.Result; - var userRoleResponse = userRoleResponseTask.Result; - var userResponse = userResponseTask.Result; - var accountStatsResponse = accountStatsResponseTask.Result; - var agreementsResponse = agreementsResponseTask.Result; - var reservationsResponse = reservationsResponseTask.Result; + await Task.WhenAll(apiGetAccountTask, accountStatsResponseTask, userRoleResponseTask, userResponseTask, accountStatsResponseTask, agreementsResponseTask, reservationsResponseTask, apprenticeshipsResponseTask, accountCohortResponseTask, vacanciesResponseTask).ConfigureAwait(false); + + var accountResponse = accountResponseTask.Result; + var userRoleResponse = userRoleResponseTask.Result; + var userResponse = userResponseTask.Result; + var accountStatsResponse = accountStatsResponseTask.Result; + var agreementsResponse = agreementsResponseTask.Result; + var reservationsResponse = reservationsResponseTask.Result; var accountDetailViewModel = apiGetAccountTask.Result; var vacanciesResponse = vacanciesResponseTask.Result; + var accountCohort = accountCohortResponseTask.Result; + var apprenticeshipsResponse = apprenticeshipsResponseTask.Result; - var apprenticeshipEmployerType = (ApprenticeshipEmployerType)Enum.Parse(typeof(ApprenticeshipEmployerType), accountDetailViewModel.ApprenticeshipEmployerType, true); + var apprenticeshipEmployerType = (Common.Domain.Types.ApprenticeshipEmployerType)Enum.Parse(typeof(Common.Domain.Types.ApprenticeshipEmployerType), accountDetailViewModel.ApprenticeshipEmployerType, true); var tasksResponse = await _mediator.SendAsync(new GetAccountTasksQuery { @@ -253,6 +268,11 @@ public virtual async Task> GetAc VacancyCount = vacanciesResponse.Vacancies.Count(), Vacancies = _mapper.Map, IEnumerable>(vacanciesResponse.Vacancies) }, + Apprenticeships = _mapper.Map, IEnumerable>(apprenticeshipsResponse?.Apprenticeships), + Cohorts = new List + { + _mapper.Map(accountCohort.Cohort) + }, UnableToDetermineCallToAction = vacanciesResponse.HasFailed || reservationsResponse.HasFailed } }; @@ -261,7 +281,7 @@ public virtual async Task> GetAc // we could blat over the existing flag, but it's much nicer to store the enum (as above) rather than a byte! //viewModel.Account.ApprenticeshipEmployerType = (byte) ((ApprenticeshipEmployerType) Enum.Parse(typeof(ApprenticeshipEmployerType), apiGetAccountTask.Result.ApprenticeshipEmployerType, true)); - return new OrchestratorResponse + return new OrchestratorResponse { Status = HttpStatusCode.OK, Data = viewModel @@ -291,8 +311,8 @@ public virtual async Task> GetAc Exception = ex }; } - } - + } + public async Task> GetInvitation(string id) { var invitationResponse = await _mediator.SendAsync(new GetInvitationRequest @@ -655,6 +675,11 @@ public void GetCallToActionViewName(PanelViewModel vi if (viewModel.Data.ApprenticeshipEmployerType == ApprenticeshipEmployerType.NonLevy) { + rules.Add(120, EvaluateSingleApprenticeshipCallToActionRule); + rules.Add(121, EvaluateSingleApprenticeshipDraftStatusCallToActionRule); + rules.Add(122, EvaluateSingleApprenticeshipsWithTrainingProviderStatusCallToActionRule); + rules.Add(123, EvaluateSingleApprenticeshipsWithReadyToReviewStatusCallToActionRule); + rules.Add(124, EvaluateContinueSetupForSingleApprenticeshipByProviderCallToActionRule); rules.Add(200, EvalutateSingleReservationCallToActionRule); rules.Add(201, EvalutateHasReservationsCallToActionRule); @@ -799,5 +824,89 @@ private bool EvalutateHasReservationsCallToActionRule(PanelViewModel viewModel) + { + if (viewModel.Data.CallToActionViewModel.ReservationsCount == 1 + && viewModel.Data.CallToActionViewModel?.ApprenticeshipsCount == 1) + { + viewModel.ViewName = "SingleApprenticeshipApproved"; + viewModel.PanelType = PanelType.Summary; + return true; + } + + return false; + } + + private bool EvaluateSingleApprenticeshipDraftStatusCallToActionRule(PanelViewModel viewModel) + { + if (viewModel.Data.CallToActionViewModel.ReservationsCount == 1 + && viewModel.Data.CallToActionViewModel.CohortsCount == 1 + && viewModel.Data.CallToActionViewModel.Cohorts.Single() != null + && viewModel.Data.CallToActionViewModel.ApprenticeshipsCount == 0 + && viewModel.Data.CallToActionViewModel.Cohorts?.Single().CohortApprenticeshipsCount == 1 + && viewModel.Data.CallToActionViewModel.Cohorts.Single().Apprenticeships.Single().HasSingleDraftApprenticeship.Equals(true) + && viewModel.Data.CallToActionViewModel.Cohorts.Single().CohortStatus.Equals(CohortStatus.Draft)) + { + viewModel.ViewName = "SingleApprenticeshipContinueSetup"; + viewModel.PanelType = PanelType.Summary; + return true; + } + + return false; + } + + private bool EvaluateSingleApprenticeshipsWithTrainingProviderStatusCallToActionRule(PanelViewModel viewModel) + { + if (viewModel.Data.CallToActionViewModel.ReservationsCount == 1 + && viewModel.Data.CallToActionViewModel.CohortsCount == 1 + && viewModel.Data.CallToActionViewModel.Cohorts.Single() != null + && viewModel.Data.CallToActionViewModel.ApprenticeshipsCount == 0 + && viewModel.Data.CallToActionViewModel.Cohorts?.Single().CohortApprenticeshipsCount == 1 + && viewModel.Data.CallToActionViewModel.Cohorts.Single().Apprenticeships.Single().HasSingleDraftApprenticeship.Equals(true) + && viewModel.Data.CallToActionViewModel.Cohorts.Single().CohortStatus.Equals(CohortStatus.WithTrainingProvider)) + { + viewModel.ViewName = "SingleApprenticeshipWithTrainingProvider"; + viewModel.PanelType = PanelType.Summary; + return true; + } + return false; + } + + + private bool EvaluateContinueSetupForSingleApprenticeshipByProviderCallToActionRule(PanelViewModel viewModel) + { + if (viewModel.Data.CallToActionViewModel.ReservationsCount == 1 + && viewModel.Data.CallToActionViewModel.CohortsCount == 1 + && viewModel.Data.CallToActionViewModel.Cohorts.Single() != null + && viewModel.Data.CallToActionViewModel.ApprenticeshipsCount == 0 + && viewModel.Data.CallToActionViewModel.HasSingleReservation + && viewModel.Data.CallToActionViewModel.Cohorts.Single().CohortStatus.Equals(CohortStatus.WithTrainingProvider)) + { + viewModel.ViewName = "SingleApprenticeshipContinueWithProvider"; + viewModel.PanelType = PanelType.Summary; + return true; + } + + return false; + } + + private bool EvaluateSingleApprenticeshipsWithReadyToReviewStatusCallToActionRule(PanelViewModel viewModel) + { + if (viewModel.Data.CallToActionViewModel.ReservationsCount == 1 + && viewModel.Data.CallToActionViewModel.CohortsCount == 1 + && viewModel.Data.CallToActionViewModel.Cohorts.Single() != null + && viewModel.Data.CallToActionViewModel.ApprenticeshipsCount == 0 + && viewModel.Data.CallToActionViewModel.Cohorts?.Single().CohortApprenticeshipsCount == 1 + && viewModel.Data.CallToActionViewModel.Cohorts.Single().Apprenticeships.Single().HasSingleDraftApprenticeship.Equals(true) + && viewModel.Data.CallToActionViewModel.Cohorts.Single().CohortStatus.Equals(CohortStatus.Review)) + { + viewModel.ViewName = "SingleApprenticeshipReadyForReview"; + viewModel.PanelType = PanelType.Summary; + return true; + } + + return false; + } } } \ No newline at end of file diff --git a/src/SFA.DAS.EmployerAccounts.Web/SFA.DAS.EmployerAccounts.Web.csproj b/src/SFA.DAS.EmployerAccounts.Web/SFA.DAS.EmployerAccounts.Web.csproj index 18ad3322fb..db2aad7080 100644 --- a/src/SFA.DAS.EmployerAccounts.Web/SFA.DAS.EmployerAccounts.Web.csproj +++ b/src/SFA.DAS.EmployerAccounts.Web/SFA.DAS.EmployerAccounts.Web.csproj @@ -119,7 +119,7 @@ 1.1.4 - 4.1.1013 + 4.1.1063 2.1.1395 @@ -249,6 +249,7 @@ + @@ -276,7 +277,9 @@ + + @@ -343,6 +346,7 @@ + @@ -873,6 +877,11 @@ + + + + + diff --git a/src/SFA.DAS.EmployerAccounts.Web/ViewModels/AccountDashboardViewModel.cs b/src/SFA.DAS.EmployerAccounts.Web/ViewModels/AccountDashboardViewModel.cs index f703ced696..043328b121 100644 --- a/src/SFA.DAS.EmployerAccounts.Web/ViewModels/AccountDashboardViewModel.cs +++ b/src/SFA.DAS.EmployerAccounts.Web/ViewModels/AccountDashboardViewModel.cs @@ -1,8 +1,8 @@ -using System.Collections.Generic; -using SFA.DAS.Common.Domain.Types; +using SFA.DAS.Common.Domain.Types; using SFA.DAS.EmployerAccounts.Interfaces; using SFA.DAS.EmployerAccounts.Models; using SFA.DAS.EmployerAccounts.Models.Account; +using System.Collections.Generic; namespace SFA.DAS.EmployerAccounts.Web.ViewModels { @@ -27,6 +27,6 @@ public class AccountDashboardViewModel : IAccountIdentifier public bool HasPayeScheme => PayeSchemeCount > 0; public AgreementInfoViewModel AgreementInfo { get; set; } public ApprenticeshipEmployerType ApprenticeshipEmployerType { get; set; } - public CallToActionViewModel CallToActionViewModel {get; set;} + public CallToActionViewModel CallToActionViewModel { get; set; } } } \ No newline at end of file diff --git a/src/SFA.DAS.EmployerAccounts.Web/ViewModels/ApprenticeshipViewModel.cs b/src/SFA.DAS.EmployerAccounts.Web/ViewModels/ApprenticeshipViewModel.cs new file mode 100644 index 0000000000..6f0714260d --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts.Web/ViewModels/ApprenticeshipViewModel.cs @@ -0,0 +1,25 @@ +using SFA.DAS.EmployerAccounts.Models.CommitmentsV2; +using System; + +namespace SFA.DAS.EmployerAccounts.Web.ViewModels +{ + public class ApprenticeshipViewModel + { + public long Id { get; set; } + public long CohortId { get; set; } + public string HashedCohortId { get; set; } + public string HashedApprenticeshipId { get; set; } + public int? NumberOfDraftApprentices { get; set; } + public string ApprenticeshipFullName { get; set; } + public string CourseName { get; set; } + public string CourseStartDateText { get; set; } + public string CourseEndDateText { get; set; } + public ApprenticeshipStatus ApprenticeshipStatus { get; set; } + public TrainingProviderViewModel TrainingProvider { get; set; } + public bool HasSingleDraftApprenticeship => NumberOfDraftApprentices == 1 && ApprenticeshipStatus == ApprenticeshipStatus.Draft; + public bool HasApprovedApprenticeship => ApprenticeshipStatus == ApprenticeshipStatus.Approved; + public string ViewOrEditApprenticeDetailsLink => $"unapproved/{HashedCohortId}/apprentices/{HashedApprenticeshipId}"; + public string ApprovedOrRejectApprenticeDetailsLink => $"unapproved/{HashedCohortId}"; + public string ViewApprovedApprenticeDetailsLink => $"apprentices/manage/{HashedApprenticeshipId}/details"; + } +} \ No newline at end of file diff --git a/src/SFA.DAS.EmployerAccounts.Web/ViewModels/CallToActionViewModel.cs b/src/SFA.DAS.EmployerAccounts.Web/ViewModels/CallToActionViewModel.cs index e8b9e91e4a..43f296ca74 100644 --- a/src/SFA.DAS.EmployerAccounts.Web/ViewModels/CallToActionViewModel.cs +++ b/src/SFA.DAS.EmployerAccounts.Web/ViewModels/CallToActionViewModel.cs @@ -1,6 +1,5 @@ -using SFA.DAS.EmployerAccounts.Models.Reservations; -using SFA.DAS.EmployerAccounts.Web.Extensions; -using System; +using SFA.DAS.EmployerAccounts.Models.Commitments; +using SFA.DAS.EmployerAccounts.Models.Reservations; using System.Collections.Generic; using System.Linq; @@ -9,27 +8,17 @@ namespace SFA.DAS.EmployerAccounts.Web.ViewModels public class CallToActionViewModel { public bool AgreementsToSign { get; set; } - public List Reservations { get; set; } public bool HasReservations => ReservationsCount > 0; public int ReservationsCount => Reservations?.Count ?? 0; public int PendingReservationsCount => Reservations?.Count(x => x.Status == ReservationStatus.Pending) ?? 0; - - public bool ApprenticeshipAdded { get; set; } - public int? CohortsCount { get; set; } - public int? ApprenticeshipsCount { get; set; } - public int? NumberOfDraftApprentices { get; set; } - public bool HasDraftApprenticeship { get; set; } - public string CourseName { get; set; } - public DateTime? CourseStartDate { get; set; } - public DateTime? CourseEndDate { get; set; } - public string ProviderName { get; set; } - public CohortStatus CohortStatus { get; set; } - public string HashedDraftApprenticeshipId { get; set; } - public string HashedCohortReference { get; set; } - public string ApprenticeName { get; set; } + public IEnumerable Apprenticeships { get; set; } + public int ApprenticeshipsCount => Apprenticeships?.Count() ?? 0; + public IEnumerable Cohorts { get; set; } + public int CohortsCount => Cohorts?.Count() ?? 0; + public bool HasSingleReservation => Reservations?.Count == 1 && CohortsCount == 1; public VacanciesViewModel VacanciesViewModel { get; set; } public bool UnableToDetermineCallToAction { get; set; } } diff --git a/src/SFA.DAS.EmployerAccounts.Web/ViewModels/CohortViewModel.cs b/src/SFA.DAS.EmployerAccounts.Web/ViewModels/CohortViewModel.cs new file mode 100644 index 0000000000..f36bd8ee15 --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts.Web/ViewModels/CohortViewModel.cs @@ -0,0 +1,16 @@ +using SFA.DAS.EmployerAccounts.Models.CommitmentsV2; +using System.Collections.Generic; +using System.Linq; + +namespace SFA.DAS.EmployerAccounts.Web.ViewModels +{ + public class CohortViewModel + { + public int? NumberOfDraftApprentices { get; set; } + public string HashedCohortId { get; set; } + public CohortStatus CohortStatus { get; set; } + public ICollection Apprenticeships { get; set; } = new List(); + public int CohortApprenticeshipsCount => Apprenticeships?.Count() ?? 0; + public ICollection TrainingProvider { get; set; } = new List(); + } +} \ No newline at end of file diff --git a/src/SFA.DAS.EmployerAccounts.Web/ViewModels/TrainingProviderViewModel.cs b/src/SFA.DAS.EmployerAccounts.Web/ViewModels/TrainingProviderViewModel.cs new file mode 100644 index 0000000000..3c47e4871a --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts.Web/ViewModels/TrainingProviderViewModel.cs @@ -0,0 +1,8 @@ +namespace SFA.DAS.EmployerAccounts.Web.ViewModels +{ + public class TrainingProviderViewModel + { + public long Id { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/src/SFA.DAS.EmployerAccounts.Web/Views/EmployerTeam/SingleApprenticeshipApproved.cshtml b/src/SFA.DAS.EmployerAccounts.Web/Views/EmployerTeam/SingleApprenticeshipApproved.cshtml new file mode 100644 index 0000000000..88945f0cc6 --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts.Web/Views/EmployerTeam/SingleApprenticeshipApproved.cshtml @@ -0,0 +1,56 @@ +@model SFA.DAS.EmployerAccounts.Web.ViewModels.ApprenticeshipViewModel + +
+

+ Your apprentice +

+ + + + + + + + + + + + + + + + + + + + + + +
+ Name + + @(Model?.ApprenticeshipFullName) +
+ Course + + @(Model?.CourseName) +
+ Training Provider + + @(Model?.TrainingProvider?.Name) +
+ Start month + + @(Model?.CourseStartDateText) +
+ Finish month + + @(Model?.CourseEndDateText) +
+

+ + View apprentice details + +

+
+ diff --git a/src/SFA.DAS.EmployerAccounts.Web/Views/EmployerTeam/SingleApprenticeshipContinueSetup.cshtml b/src/SFA.DAS.EmployerAccounts.Web/Views/EmployerTeam/SingleApprenticeshipContinueSetup.cshtml new file mode 100644 index 0000000000..f26a5d6018 --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts.Web/Views/EmployerTeam/SingleApprenticeshipContinueSetup.cshtml @@ -0,0 +1,41 @@ +@using SFA.DAS.EmployerAccounts.Web.Extensions +@model SFA.DAS.EmployerAccounts.Web.ViewModels.ApprenticeshipViewModel + +
+

+ Continue setting up an apprenticeship +

+

You've added the following details:

+ + + + + + + + + + + + + +
+ Course + + @(Model?.CourseName) +
+ Training Provider + + @(Model?.TrainingProvider?.Name) +
+ Status + + DRAFT +
+

+ + Add more details + +

+
+ diff --git a/src/SFA.DAS.EmployerAccounts.Web/Views/EmployerTeam/SingleApprenticeshipContinueWithProvider.cshtml b/src/SFA.DAS.EmployerAccounts.Web/Views/EmployerTeam/SingleApprenticeshipContinueWithProvider.cshtml new file mode 100644 index 0000000000..79d7c4ef6e --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts.Web/Views/EmployerTeam/SingleApprenticeshipContinueWithProvider.cshtml @@ -0,0 +1,42 @@ +@using SFA.DAS.EmployerAccounts.Web.Extensions +@model SFA.DAS.EmployerAccounts.Web.ViewModels.ApprenticeshipViewModel + +
+

+ Continue setting up an apprenticeship +

+ + + + + + + + + + + + + + +
+ Course + + @(Model.CourseName) +
+ Training Provider + + @(Model?.TrainingProvider?.Name) +
+ Status + + WITH TRAINING PROVIDER +
+

+ + + Add more details + +

+
+ diff --git a/src/SFA.DAS.EmployerAccounts.Web/Views/EmployerTeam/SingleApprenticeshipReadyForReview.cshtml b/src/SFA.DAS.EmployerAccounts.Web/Views/EmployerTeam/SingleApprenticeshipReadyForReview.cshtml new file mode 100644 index 0000000000..579b7d4cde --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts.Web/Views/EmployerTeam/SingleApprenticeshipReadyForReview.cshtml @@ -0,0 +1,65 @@ +@using SFA.DAS.EmployerAccounts.Web.Extensions +@model SFA.DAS.EmployerAccounts.Web.ViewModels.ApprenticeshipViewModel + +
+

+ Your apprentice +

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Name + + @(Model?.ApprenticeshipFullName) +
+ Course + + @(Model?.CourseName) +
+ Training Provider + + @(Model?.TrainingProvider?.Name) +
+ Start month + + @(Model?.CourseStartDateText) +
+ Finish month + + @(Model?.CourseEndDateText) +
+ Status + + READY FOR REVIEW +
+

+ + Approve or reject apprentice details + +

+
+ diff --git a/src/SFA.DAS.EmployerAccounts.Web/Views/EmployerTeam/SingleApprenticeshipWithTrainingProvider.cshtml b/src/SFA.DAS.EmployerAccounts.Web/Views/EmployerTeam/SingleApprenticeshipWithTrainingProvider.cshtml new file mode 100644 index 0000000000..75fa9363f2 --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts.Web/Views/EmployerTeam/SingleApprenticeshipWithTrainingProvider.cshtml @@ -0,0 +1,68 @@ +@using SFA.DAS.EmployerAccounts.Web.Extensions +@model SFA.DAS.EmployerAccounts.Web.ViewModels.ApprenticeshipViewModel + +
+

+ Your apprentice +

+

Your training provider is reviewing the following details:

+ + + + + + + + + + + + + + @if (!String.IsNullOrEmpty(Model.CourseStartDateText)) + { + + + + + + + + + } + + + + +
+ Name + + @(Model?.ApprenticeshipFullName) +
+ Course + + @(Model?.CourseName) +
+ Training Provider + + @(Model?.TrainingProvider?.Name) +
+ Start month + + @(Model?.CourseStartDateText) +
+ Finish month + + @(Model?.CourseEndDateText) +
+ Status + + WITH TRAINING PROVIDER +
+

+ + View apprentice details + +

+
+ diff --git a/src/SFA.DAS.EmployerAccounts/Configuration/ConfigurationKeys.cs b/src/SFA.DAS.EmployerAccounts/Configuration/ConfigurationKeys.cs index 5a78e035c6..528bba85e0 100644 --- a/src/SFA.DAS.EmployerAccounts/Configuration/ConfigurationKeys.cs +++ b/src/SFA.DAS.EmployerAccounts/Configuration/ConfigurationKeys.cs @@ -13,5 +13,6 @@ public static class ConfigurationKeys public const string EmployerAccountsReadStore = "SFA.DAS.EmployerAccounts.ReadStore"; public const string AuditApi = "SFA.DAS.AuditApiClient"; public const string ReservationsClientApiConfiguration = "SFA.DAS.Reservations.Api.Client"; + public const string EncodingConfig = "SFA.DAS.Encoding"; } } diff --git a/src/SFA.DAS.EmployerAccounts/DependencyResolution/CommitmentsApiClientRegistry.cs b/src/SFA.DAS.EmployerAccounts/DependencyResolution/CommitmentsApiClientRegistry.cs index e055f2d7f2..53a5ac485e 100644 --- a/src/SFA.DAS.EmployerAccounts/DependencyResolution/CommitmentsApiClientRegistry.cs +++ b/src/SFA.DAS.EmployerAccounts/DependencyResolution/CommitmentsApiClientRegistry.cs @@ -17,10 +17,10 @@ namespace SFA.DAS.EmployerAccounts.DependencyResolution { public class CommitmentsApiClientRegistry : Registry - { + { public CommitmentsApiClientRegistry() { - For().Use(c => c.GetInstance().CreateClient()).Singleton(); + For().Use(c => c.GetInstance().CreateClient()); For().Use(); For().Use(); } @@ -117,4 +117,4 @@ private Exception CreateApiModelException(HttpResponseMessage httpResponseMessag return errors; } } -} +} \ No newline at end of file diff --git a/src/SFA.DAS.EmployerAccounts/DependencyResolution/CommitmentsRegistry.cs b/src/SFA.DAS.EmployerAccounts/DependencyResolution/CommitmentsRegistry.cs index a4ba8db349..c090d5d120 100644 --- a/src/SFA.DAS.EmployerAccounts/DependencyResolution/CommitmentsRegistry.cs +++ b/src/SFA.DAS.EmployerAccounts/DependencyResolution/CommitmentsRegistry.cs @@ -1,5 +1,4 @@ -using System.Net.Http; -using SFA.DAS.AutoConfiguration; +using SFA.DAS.AutoConfiguration; using SFA.DAS.Commitments.Api.Client; using SFA.DAS.Commitments.Api.Client.Configuration; using SFA.DAS.Commitments.Api.Client.Interfaces; @@ -8,6 +7,7 @@ using SFA.DAS.Http.TokenGenerators; using SFA.DAS.NLog.Logger.Web.MessageHandlers; using StructureMap; +using System.Net.Http; namespace SFA.DAS.EmployerAccounts.DependencyResolution { diff --git a/src/SFA.DAS.EmployerAccounts/DependencyResolution/ConfigurationRegistry.cs b/src/SFA.DAS.EmployerAccounts/DependencyResolution/ConfigurationRegistry.cs index c5bbd39822..393e6758d5 100644 --- a/src/SFA.DAS.EmployerAccounts/DependencyResolution/ConfigurationRegistry.cs +++ b/src/SFA.DAS.EmployerAccounts/DependencyResolution/ConfigurationRegistry.cs @@ -4,6 +4,7 @@ using SFA.DAS.EAS.Account.Api.Client; using SFA.DAS.EmployerAccounts.Configuration; using SFA.DAS.EmployerAccounts.ReadStore.Configuration; +using SFA.DAS.Encoding; using SFA.DAS.Hmrc.Configuration; using SFA.DAS.Http.Configuration; using StructureMap; @@ -24,6 +25,7 @@ public ConfigurationRegistry() For().Use(c => c.GetInstance().Get(ConfigurationKeys.Features)).Singleton(); For().Use(c => c.GetInstance().Hmrc).Singleton(); For().Use(c => c.GetInstance().CommitmentsApi).Singleton(); + For().Use(c => c.GetInstance().Get(ConfigurationKeys.EncodingConfig)).Singleton(); } } } \ No newline at end of file diff --git a/src/SFA.DAS.EmployerAccounts/DependencyResolution/EncodingRegistry.cs b/src/SFA.DAS.EmployerAccounts/DependencyResolution/EncodingRegistry.cs new file mode 100644 index 0000000000..dadeb2b036 --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts/DependencyResolution/EncodingRegistry.cs @@ -0,0 +1,13 @@ +using SFA.DAS.Encoding; +using StructureMap; + +namespace SFA.DAS.EmployerAccounts.DependencyResolution +{ + public class EncodingRegistry : Registry + { + public EncodingRegistry() + { + For().Use().Singleton(); + } + } +} diff --git a/src/SFA.DAS.EmployerAccounts/DependencyResolution/ServicesRegistry.cs b/src/SFA.DAS.EmployerAccounts/DependencyResolution/ServicesRegistry.cs index c0b71b01c5..831e57f3b6 100644 --- a/src/SFA.DAS.EmployerAccounts/DependencyResolution/ServicesRegistry.cs +++ b/src/SFA.DAS.EmployerAccounts/DependencyResolution/ServicesRegistry.cs @@ -16,6 +16,7 @@ public ServicesRegistry() For().Use(); For().Use(); For().Use(); + For().Use(); } } } \ No newline at end of file diff --git a/src/SFA.DAS.EmployerAccounts/Interfaces/ICommitmentV2Service.cs b/src/SFA.DAS.EmployerAccounts/Interfaces/ICommitmentV2Service.cs new file mode 100644 index 0000000000..2badb392fb --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts/Interfaces/ICommitmentV2Service.cs @@ -0,0 +1,17 @@ +using SFA.DAS.EmployerAccounts.Models.CommitmentsV2; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace SFA.DAS.EmployerAccounts.Interfaces +{ + public interface ICommitmentV2Service + { + Task> GetCohorts(long? accountId); + + Task> GetDraftApprenticeships(Cohort cohort); + + Task> GetApprenticeships(long accountId); + } +} + + diff --git a/src/SFA.DAS.EmployerAccounts/Mappings/ApprenticeshipMappings.cs b/src/SFA.DAS.EmployerAccounts/Mappings/ApprenticeshipMappings.cs new file mode 100644 index 0000000000..c0dd01abd3 --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts/Mappings/ApprenticeshipMappings.cs @@ -0,0 +1,37 @@ +using AutoMapper; +using SFA.DAS.CommitmentsV2.Api.Types.Responses; +using SFA.DAS.CommitmentsV2.Types; +using SFA.DAS.CommitmentsV2.Types.Dtos; +using SFA.DAS.EmployerAccounts.Models.CommitmentsV2; + +namespace SFA.DAS.EmployerAccounts.Mappings +{ + public class ApprenticeshipMappings : Profile + { + public ApprenticeshipMappings() + { + CreateMap() + .ForMember(target => target.CourseStartDate, opt => opt.MapFrom(src => src.StartDate)) + .ForMember(target => target.CourseEndDate, opt => opt.MapFrom(src => src.EndDate)) + .ForMember(target => target.ApprenticeshipStatus, opt => opt.MapFrom(src => Models.CommitmentsV2.ApprenticeshipStatus.Draft)) + .ForMember(target => target.HashedId, opt => opt.Ignore()) + .ForMember(target => target.TrainingProvider, opt => opt.Ignore()) + .ForMember(target => target.Cohort, opt => opt.Ignore()); + + CreateMap() + .ForMember(target => target.CourseStartDate, opt => opt.MapFrom(src => src.StartDate)) + .ForMember(target => target.CourseEndDate, opt => opt.MapFrom(src => src.EndDate)) + .ForMember(target => target.ApprenticeshipStatus, opt => opt.MapFrom(src => Models.CommitmentsV2.ApprenticeshipStatus.Approved)) + .ForMember(target => target.HashedId, opt => opt.Ignore()) + .ForMember(target => target.TrainingProvider, opt => opt.Ignore()) + .ForMember(target => target.Cohort, opt => opt.Ignore()); + + CreateMap() + .ForMember(target => target.Id, opt => opt.MapFrom(src => src.ProviderId)) + .ForMember(target => target.Name, opt => opt.MapFrom(src => src.ProviderName)); + + CreateMap() + .ForMember(target => target.Name, opt => opt.MapFrom(src => src.ProviderName)); + } + } +} diff --git a/src/SFA.DAS.EmployerAccounts/Mappings/CohortMappings.cs b/src/SFA.DAS.EmployerAccounts/Mappings/CohortMappings.cs new file mode 100644 index 0000000000..48fb13be6c --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts/Mappings/CohortMappings.cs @@ -0,0 +1,35 @@ +using AutoMapper; +using SFA.DAS.CommitmentsV2.Types; +using SFA.DAS.EmployerAccounts.Models.CommitmentsV2; + +namespace SFA.DAS.EmployerAccounts.Mappings +{ + public class CohortMappings : Profile + { + public CohortMappings() + { + CreateMap() + .ForMember(target => target.Id, opt => opt.MapFrom(src => src.CohortId)) + .ForMember(target => target.NumberOfDraftApprentices, opt => opt.MapFrom(src => src.NumberOfDraftApprentices)) + .ForMember(target => target.Apprenticeships, opt => opt.Ignore()) + .ForMember(target => target.HashedId, opt => opt.Ignore()) + .ForMember(target => target.TrainingProvider, opt => opt.Ignore()) + .ForMember(target => target.CohortStatus, opt => opt.MapFrom(src => GetStatus(src))); + + } + + private CohortStatus GetStatus(CohortSummary cohort) + { + if (cohort.IsDraft && cohort.WithParty == Party.Employer) + return CohortStatus.Draft; + else if (!cohort.IsDraft && cohort.WithParty == Party.Employer) + return CohortStatus.Review; + else if (!cohort.IsDraft && cohort.WithParty == Party.Provider) + return CohortStatus.WithTrainingProvider; + else if (!cohort.IsDraft && cohort.WithParty == Party.TransferSender) + return CohortStatus.WithTransferSender; + else + return CohortStatus.Unknown; + } + } +} diff --git a/src/SFA.DAS.EmployerAccounts/Models/CommitmentsV2/Apprenticeship.cs b/src/SFA.DAS.EmployerAccounts/Models/CommitmentsV2/Apprenticeship.cs new file mode 100644 index 0000000000..aacf6f0f51 --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts/Models/CommitmentsV2/Apprenticeship.cs @@ -0,0 +1,37 @@ +using SFA.DAS.Encoding; +using System; + +namespace SFA.DAS.EmployerAccounts.Models.CommitmentsV2 +{ + public class Apprenticeship + { + public long Id { get; set; } + public string FirstName { get; set; } + public string LastName { get; set; } + public string CourseName { get; set; } + public DateTime? CourseStartDate { get; set; } + public DateTime? CourseEndDate { get; set; } + public ApprenticeshipStatus ApprenticeshipStatus { get; set; } + public TrainingProvider TrainingProvider { get; private set; } + public void SetTrainingProvider(TrainingProvider trainingProvider) + { + TrainingProvider = trainingProvider; + } + public Cohort Cohort { get; private set; } + public void SetCohort(Cohort cohort) + { + Cohort = cohort; + } + public string HashedId { get; private set; } + public void SetHashId(IEncodingService encodingService) + { + HashedId = encodingService.Encode(Id, EncodingType.ApprenticeshipId); + } + } + + public enum ApprenticeshipStatus + { + Draft = 0, + Approved = 1 + } +} diff --git a/src/SFA.DAS.EmployerAccounts/Models/CommitmentsV2/Cohort.cs b/src/SFA.DAS.EmployerAccounts/Models/CommitmentsV2/Cohort.cs new file mode 100644 index 0000000000..8a9171b2e7 --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts/Models/CommitmentsV2/Cohort.cs @@ -0,0 +1,35 @@ +using SFA.DAS.Encoding; +using System.Collections.Generic; +using System.Linq; + +namespace SFA.DAS.EmployerAccounts.Models.CommitmentsV2 +{ + public class Cohort + { + public long Id { get; set; } + + public int? NumberOfDraftApprentices { get; set; } + public CohortStatus CohortStatus { get; set; } + public IEnumerable Apprenticeships { get; set; } + public string HashedId { get; private set; } + public void SetHashId(IEncodingService encodingService) + { + HashedId = encodingService.Encode(Id, EncodingType.CohortReference); + } + public IEnumerable TrainingProvider { get; private set; } + public void SetTrainingProvider(IEnumerable trainingProvider) + { + TrainingProvider = trainingProvider; + } + } + + public enum CohortStatus + { + Unknown, + Draft, + Review, + WithTrainingProvider, + WithTransferSender, + Approved + } +} diff --git a/src/SFA.DAS.EmployerAccounts/Models/CommitmentsV2/TrainingProvider.cs b/src/SFA.DAS.EmployerAccounts/Models/CommitmentsV2/TrainingProvider.cs new file mode 100644 index 0000000000..a05ef57feb --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts/Models/CommitmentsV2/TrainingProvider.cs @@ -0,0 +1,8 @@ +namespace SFA.DAS.EmployerAccounts.Models.CommitmentsV2 +{ + public class TrainingProvider + { + public long Id { get; set; } + public string Name { get; set; } + } +} diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsHandler.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsHandler.cs new file mode 100644 index 0000000000..956110e3c3 --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsHandler.cs @@ -0,0 +1,46 @@ +using MediatR; +using System.Threading.Tasks; +using SFA.DAS.NLog.Logger; +using SFA.DAS.Validation; +using SFA.DAS.EmployerAccounts.Interfaces; +using SFA.DAS.HashingService; + +namespace SFA.DAS.EmployerAccounts.Queries.GetApprenticeship +{ + public class GetApprenticeshipsHandler : IAsyncRequestHandler + { + private readonly IValidator _validator; + private readonly ILog _logger; + private readonly ICommitmentV2Service _commitmentV2Service; + private readonly IHashingService _hashingService; + + public GetApprenticeshipsHandler( + IValidator validator, + ILog logger, + ICommitmentV2Service commitmentV2Service, + IHashingService hashingService) + { + _validator = validator; + _logger = logger; + _commitmentV2Service = commitmentV2Service; + _hashingService = hashingService; + } + + public async Task Handle(GetApprenticeshipsRequest message) + { + var validationResult = _validator.Validate(message); + + if(!validationResult.IsValid()) + { + throw new InvalidRequestException(validationResult.ValidationDictionary); + } + + long accountId = _hashingService.DecodeValue(message.HashedAccountId); + + return new GetApprenticeshipsResponse + { + Apprenticeships = await _commitmentV2Service.GetApprenticeships(accountId) + }; + } + } +} diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsRequest.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsRequest.cs new file mode 100644 index 0000000000..53d655bf43 --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsRequest.cs @@ -0,0 +1,11 @@ +using MediatR; + +namespace SFA.DAS.EmployerAccounts.Queries.GetApprenticeship +{ + public class GetApprenticeshipsRequest : IAsyncRequest + { + public string HashedAccountId { get; set; } + public string ExternalUserId { get; set; } + + } +} diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsResponse.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsResponse.cs new file mode 100644 index 0000000000..6a4b2dd759 --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsResponse.cs @@ -0,0 +1,10 @@ +using SFA.DAS.EmployerAccounts.Models.CommitmentsV2; +using System.Collections.Generic; + +namespace SFA.DAS.EmployerAccounts.Queries.GetApprenticeship +{ + public class GetApprenticeshipsResponse + { + public IEnumerable Apprenticeships { get; set; } + } +} diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsValidator.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsValidator.cs new file mode 100644 index 0000000000..908d4555c0 --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetApprenticeship/GetApprenticeshipsValidator.cs @@ -0,0 +1,31 @@ +using System.Threading.Tasks; +using SFA.DAS.Validation; + +namespace SFA.DAS.EmployerAccounts.Queries.GetApprenticeship +{ + public class GetApprenticeshipsValidator : IValidator + { + public ValidationResult Validate(GetApprenticeshipsRequest item) + { + var validationResult = new ValidationResult(); + + if (string.IsNullOrEmpty(item.ExternalUserId)) + { + validationResult.AddError(nameof(item.ExternalUserId), "ExternalUserId has not been supplied"); + } + + if (string.IsNullOrEmpty(item.HashedAccountId)) + { + validationResult.ValidationDictionary.Add(nameof(item.HashedAccountId), + "Hashed Account Id cannot be null or empty."); + } + + return validationResult; + } + + public Task ValidateAsync(GetApprenticeshipsRequest item) + { + return Task.FromResult(Validate(item)); + } + } +} diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortRequest.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortRequest.cs new file mode 100644 index 0000000000..a86bdb19ff --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortRequest.cs @@ -0,0 +1,10 @@ +using MediatR; + +namespace SFA.DAS.EmployerAccounts.Queries.GetSingleCohort +{ + public class GetSingleCohortRequest : IAsyncRequest + { + public string HashedAccountId { get; set; } + public string ExternalUserId { get; set; } + } +} diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortRequestHandler.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortRequestHandler.cs new file mode 100644 index 0000000000..9555d9c459 --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortRequestHandler.cs @@ -0,0 +1,53 @@ +using MediatR; +using System.Threading.Tasks; +using SFA.DAS.Validation; +using SFA.DAS.EmployerAccounts.Interfaces; +using System.Linq; +using SFA.DAS.HashingService; + +namespace SFA.DAS.EmployerAccounts.Queries.GetSingleCohort +{ + public class GetSingleCohortRequestHandler : IAsyncRequestHandler + { + private readonly IValidator _validator; + private readonly ICommitmentV2Service _commitmentV2Service; + private readonly IHashingService _hashingService; + + public GetSingleCohortRequestHandler( + IValidator validator, + ICommitmentV2Service commitmentV2Service, + IHashingService hashingService) + { + _validator = validator; + _commitmentV2Service = commitmentV2Service; + _hashingService = hashingService; + } + + public async Task Handle(GetSingleCohortRequest message) + { + var validationResult = _validator.Validate(message); + + if (!validationResult.IsValid()) + { + throw new InvalidRequestException(validationResult.ValidationDictionary); + } + + long accountId = _hashingService.DecodeValue(message.HashedAccountId); + + var cohortsResponse = await _commitmentV2Service.GetCohorts(accountId); + if (cohortsResponse.Count() != 1) return new GetSingleCohortResponse(); + + var singleCohort = cohortsResponse.Single(); + + if (singleCohort.NumberOfDraftApprentices > 0) + { + singleCohort.Apprenticeships = await _commitmentV2Service.GetDraftApprenticeships(singleCohort); + } + + return new GetSingleCohortResponse + { + Cohort = singleCohort + }; + } + } +} diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortRequestValidator.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortRequestValidator.cs new file mode 100644 index 0000000000..d14cbea9c6 --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortRequestValidator.cs @@ -0,0 +1,26 @@ +using SFA.DAS.Validation; +using System; +using System.Threading.Tasks; + +namespace SFA.DAS.EmployerAccounts.Queries.GetSingleCohort +{ + public class GetSingleCohortRequestValidator : IValidator + { + public ValidationResult Validate(GetSingleCohortRequest item) + { + var validationResult = new ValidationResult(); + + if (item.HashedAccountId == String.Empty) + { + validationResult.AddError(nameof(item.HashedAccountId), "HashedAccountId has not been supplied"); + } + + return validationResult; + } + + public Task ValidateAsync(GetSingleCohortRequest item) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortResponse.cs b/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortResponse.cs new file mode 100644 index 0000000000..d8f1022d15 --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts/Queries/GetSingleCohort/GetSingleCohortResponse.cs @@ -0,0 +1,9 @@ +using SFA.DAS.EmployerAccounts.Models.CommitmentsV2; + +namespace SFA.DAS.EmployerAccounts.Queries.GetSingleCohort +{ + public class GetSingleCohortResponse + { + public Cohort Cohort { get; set; } + } +} diff --git a/src/SFA.DAS.EmployerAccounts/SFA.DAS.EmployerAccounts.csproj b/src/SFA.DAS.EmployerAccounts/SFA.DAS.EmployerAccounts.csproj index 1ef9c4e7c4..c70ed7c24a 100644 --- a/src/SFA.DAS.EmployerAccounts/SFA.DAS.EmployerAccounts.csproj +++ b/src/SFA.DAS.EmployerAccounts/SFA.DAS.EmployerAccounts.csproj @@ -31,9 +31,10 @@ - + + @@ -64,6 +65,7 @@ +
diff --git a/src/SFA.DAS.EmployerAccounts/Services/CommitmentsV2Service.cs b/src/SFA.DAS.EmployerAccounts/Services/CommitmentsV2Service.cs new file mode 100644 index 0000000000..92a214220a --- /dev/null +++ b/src/SFA.DAS.EmployerAccounts/Services/CommitmentsV2Service.cs @@ -0,0 +1,84 @@ +using AutoMapper; +using SFA.DAS.CommitmentsV2.Api.Client; +using SFA.DAS.CommitmentsV2.Api.Types.Responses; +using SFA.DAS.CommitmentsV2.Types; +using SFA.DAS.CommitmentsV2.Types.Dtos; +using SFA.DAS.EmployerAccounts.Interfaces; +using SFA.DAS.EmployerAccounts.Models.CommitmentsV2; +using SFA.DAS.Encoding; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace SFA.DAS.EmployerAccounts.Services +{ + public class CommitmentsV2Service : ICommitmentV2Service + { + private readonly ICommitmentsApiClient _commitmentsApiClient; + private readonly IMapper _mapper; + private readonly IEncodingService _encodingService; + + public CommitmentsV2Service(ICommitmentsApiClient commitmentsApiClient, IMapper mapper, IEncodingService encodingService) + { + _commitmentsApiClient = commitmentsApiClient; + _mapper = mapper; + _encodingService = encodingService; + } + + public async Task> GetDraftApprenticeships(Cohort cohort) + { + var draftApprenticeshipsResponse = await _commitmentsApiClient.GetDraftApprenticeships(cohort.Id); + return _mapper.Map, IEnumerable>(draftApprenticeshipsResponse.DraftApprenticeships, + opt => + { + opt.AfterMap((src, dest) => + { + dest.ToList().ForEach(c => + { + c.SetHashId(_encodingService); + c.SetCohort(cohort); + c.SetTrainingProvider(cohort.TrainingProvider.First()); + }); + }); + }); + } + + public async Task> GetCohorts(long? accountId) + { + var cohortSummary = await _commitmentsApiClient.GetCohorts(new CommitmentsV2.Api.Types.Requests.GetCohortsRequest { AccountId = accountId }); + var trainingProvider = _mapper.Map, IEnumerable>(cohortSummary.Cohorts); + + return _mapper.Map, IEnumerable>(cohortSummary.Cohorts, + opt => + { + opt.AfterMap((src, dest) => + { + dest.ToList().ForEach(c => + { + c.SetHashId(_encodingService); + c.SetTrainingProvider(trainingProvider); + }); + }); + }); + } + + public async Task> GetApprenticeships(long accountId) + { + var apprenticeship = await _commitmentsApiClient.GetApprenticeships(new CommitmentsV2.Api.Types.Requests.GetApprenticeshipsRequest { AccountId = accountId }); + var trainingProvider = _mapper.Map, IEnumerable>(apprenticeship.Apprenticeships); + + return _mapper.Map, IEnumerable>(apprenticeship.Apprenticeships, + opt => + { + opt.AfterMap((src, dest) => + { + dest.ToList().ForEach(c => + { + c.SetHashId(_encodingService); + c.SetTrainingProvider(trainingProvider.First()); + }); + }); + }); + } + } +}