diff --git a/src/Employer/Employer.Web/Controllers/VacancyCheckYourAnswersController.cs b/src/Employer/Employer.Web/Controllers/VacancyCheckYourAnswersController.cs index 55943ee22f..31c0a95b6c 100644 --- a/src/Employer/Employer.Web/Controllers/VacancyCheckYourAnswersController.cs +++ b/src/Employer/Employer.Web/Controllers/VacancyCheckYourAnswersController.cs @@ -6,6 +6,7 @@ using Esfa.Recruit.Employer.Web.Orchestrators; using Esfa.Recruit.Employer.Web.RouteModel; using Esfa.Recruit.Employer.Web.ViewModels.Preview; +using Esfa.Recruit.Employer.Web.ViewModels.VacancyPreview; using Esfa.Recruit.Shared.Web.Extensions; using Esfa.Recruit.Shared.Web.ViewModels; using Microsoft.AspNetCore.Mvc; @@ -26,9 +27,13 @@ public VacancyCheckYourAnswersController (VacancyTaskListOrchestrator orchestrat public async Task CheckYourAnswers(VacancyRouteModel vrm) { - var viewModel = await _orchestrator.GetVacancyTaskListModel(vrm); + var viewModel = await _orchestrator.GetVacancyTaskListModel(vrm, User.ToVacancyUser()); viewModel.CanHideValidationSummary = true; viewModel.SetSectionStates(viewModel, ModelState); + if (viewModel.TaskListSectionFourState == VacancyTaskListSectionState.InProgress) + { + return RedirectToRoute(RouteNames.EmployerTaskListGet); + } if (TempData.ContainsKey(TempDataKeys.VacancyClonedInfoMessage)) viewModel.VacancyClonedInfoMessage = TempData[TempDataKeys.VacancyClonedInfoMessage].ToString(); @@ -60,7 +65,7 @@ public async Task CheckYourAnswers(SubmitReviewModel m) { VacancyId = m.VacancyId, EmployerAccountId = m.EmployerAccountId - }); + }, User.ToVacancyUser()); viewModel.SoftValidationErrors = null; viewModel.SubmitToEsfa = m.SubmitToEsfa; viewModel.RejectedReason = m.RejectedReason; @@ -91,7 +96,7 @@ public async Task CheckYourAnswers(SubmitEditModel m) throw new Exception("Unknown submit state"); } - var viewModel = await _orchestrator.GetVacancyTaskListModel(m); + var viewModel = await _orchestrator.GetVacancyTaskListModel(m, User.ToVacancyUser()); viewModel.SoftValidationErrors = null; viewModel.SetSectionStates(viewModel, ModelState); viewModel.ValidationErrors = new ValidationSummaryViewModel diff --git a/src/Employer/Employer.Web/Controllers/VacancyManageController.cs b/src/Employer/Employer.Web/Controllers/VacancyManageController.cs index c3d12b2e65..cf9091587c 100644 --- a/src/Employer/Employer.Web/Controllers/VacancyManageController.cs +++ b/src/Employer/Employer.Web/Controllers/VacancyManageController.cs @@ -111,26 +111,12 @@ private void EnsureProposedChangesCookiesAreCleared(Guid vacancyId) private IActionResult HandleRedirectOfEditableVacancy(Vacancy vacancy) { - if (_feature.IsFeatureEnabled(FeatureNames.EmployerTaskList)) + if (_utility.IsTaskListCompleted(vacancy)) { - if (_utility.IsTaskListCompleted(vacancy)) - { - return RedirectToRoute(RouteNames.EmployerCheckYourAnswersGet); - } - return RedirectToRoute(RouteNames.EmployerTaskListGet); + return RedirectToRoute(RouteNames.EmployerCheckYourAnswersGet); } - - if (_utility.VacancyHasCompletedPartOne(vacancy)) - { - if (_utility.VacancyHasStartedPartTwo(vacancy) == false) - return RedirectToRoute(RouteNames.Part1Complete_Get); - - return RedirectToRoute(RouteNames.Vacancy_Preview_Get); - } - - var resumeRouteName = _utility.GetPermittedRoutesForVacancy(vacancy).Last(); - - return RedirectToRoute(resumeRouteName); + return RedirectToRoute(RouteNames.EmployerTaskListGet); + } } } \ No newline at end of file diff --git a/src/Employer/Employer.Web/Controllers/VacancyTaskListController.cs b/src/Employer/Employer.Web/Controllers/VacancyTaskListController.cs index 1b379afcd0..76efcfc1a6 100644 --- a/src/Employer/Employer.Web/Controllers/VacancyTaskListController.cs +++ b/src/Employer/Employer.Web/Controllers/VacancyTaskListController.cs @@ -1,5 +1,6 @@ using System.Threading.Tasks; using Esfa.Recruit.Employer.Web.Configuration.Routing; +using Esfa.Recruit.Employer.Web.Extensions; using Esfa.Recruit.Employer.Web.Orchestrators; using Esfa.Recruit.Employer.Web.RouteModel; using Esfa.Recruit.Employer.Web.ViewModels.VacancyPreview; @@ -37,7 +38,7 @@ public async Task CreateEmployerTaskList(VacancyRouteModel vrm) public async Task EmployerTaskList(VacancyRouteModel vrm) { - var viewModel = await _orchestrator.GetVacancyTaskListModel(vrm); + var viewModel = await _orchestrator.GetVacancyTaskListModel(vrm, User.ToVacancyUser()); viewModel.SetSectionStates(viewModel, ModelState); diff --git a/src/Employer/Employer.Web/Orchestrators/VacancyTaskListOrchestrator.cs b/src/Employer/Employer.Web/Orchestrators/VacancyTaskListOrchestrator.cs index 051ba3202e..f878f4716a 100644 --- a/src/Employer/Employer.Web/Orchestrators/VacancyTaskListOrchestrator.cs +++ b/src/Employer/Employer.Web/Orchestrators/VacancyTaskListOrchestrator.cs @@ -29,12 +29,12 @@ public class VacancyTaskListOrchestrator : EntityValidatingOrchestrator logger,IRecruitVacancyClient recruitVacancyClient, IUtility utility, - IEmployerVacancyClient employerVacancyClient, DisplayVacancyViewModelMapper displayVacancyViewModelMapper,IReviewSummaryService reviewSummaryService, - ILegalEntityAgreementService legalEntityAgreementService, IMessaging messaging) : base(logger) + public VacancyTaskListOrchestrator(ILogger logger,IRecruitVacancyClient recruitVacancyClient, IUtility utility, ILegalEntityAgreementService legalEntityAgreementService, IMessaging messaging, + IEmployerVacancyClient employerVacancyClient, DisplayVacancyViewModelMapper displayVacancyViewModelMapper,IReviewSummaryService reviewSummaryService, IRecruitVacancyClient vacancyClient) : base(logger) { _recruitVacancyClient = recruitVacancyClient; _utility = utility; @@ -43,9 +43,10 @@ public VacancyTaskListOrchestrator(ILogger logger,I _reviewSummaryService = reviewSummaryService; _legalEntityAgreementService = legalEntityAgreementService; _messaging = messaging; + _vacancyClient = vacancyClient; } - public async Task GetVacancyTaskListModel(VacancyRouteModel vrm) + public async Task GetVacancyTaskListModel(VacancyRouteModel vrm, VacancyUser user) { var vacancyTask = _utility.GetAuthorisedVacancyForEditAsync(vrm, RouteNames.EmployerTaskListGet); var programmesTask = _recruitVacancyClient.GetActiveApprenticeshipProgrammesAsync(); @@ -53,9 +54,32 @@ public async Task GetVacancyTaskListModel(VacancyRouteM await Task.WhenAll(vacancyTask, programmesTask, getEmployerDataTask); + var employerInfo = getEmployerDataTask.Result; var vacancy = vacancyTask.Result; var programme = programmesTask.Result.SingleOrDefault(p => p.Id == vacancy.ProgrammeId); + if (employerInfo.LegalEntities.FirstOrDefault(c => + c.AccountLegalEntityPublicHashedId.Equals(vacancy.AccountLegalEntityPublicHashedId)) == null) + { + if (employerInfo.LegalEntities.Count() == 1) + { + vacancy.LegalEntityName = employerInfo.LegalEntities.FirstOrDefault()?.Name; + vacancy.AccountLegalEntityPublicHashedId = employerInfo.LegalEntities.FirstOrDefault()?.AccountLegalEntityPublicHashedId; + } + else + { + vacancy.LegalEntityName = null; + vacancy.AccountLegalEntityPublicHashedId = null; + } + vacancy.EmployerName = null; + + vacancy.EmployerLocation = null; + + vacancy.EmployerNameOption = null; + vacancy.EmployerDescription = null; + await _vacancyClient.UpdateDraftVacancyAsync(vacancy, user); + } + var vm = new VacancyPreviewViewModel(); await _displayVacancyViewModelMapper.MapFromVacancyAsync(vm, vacancy); @@ -76,7 +100,7 @@ public async Task GetVacancyTaskListModel(VacancyRouteM ReviewFieldMappingLookups.GetPreviewReviewFieldIndicators()); } - vm.AccountLegalEntityCount = getEmployerDataTask.Result.LegalEntities.Count(); + vm.AccountLegalEntityCount = employerInfo.LegalEntities.Count(); return vm; } diff --git a/src/Employer/Employer.Web/Utility.cs b/src/Employer/Employer.Web/Utility.cs index f766cd3d13..a347255ecb 100644 --- a/src/Employer/Employer.Web/Utility.cs +++ b/src/Employer/Employer.Web/Utility.cs @@ -10,7 +10,6 @@ using Esfa.Recruit.Employer.Web.Exceptions; using Esfa.Recruit.Employer.Web.Models; using Esfa.Recruit.Employer.Web.RouteModel; -using Esfa.Recruit.Shared.Web.FeatureToggle; using Esfa.Recruit.Shared.Web.Models; using Esfa.Recruit.Shared.Web.ViewModels; using Esfa.Recruit.Vacancies.Client.Infrastructure.Client; @@ -24,21 +23,6 @@ public interface IUtility : IVacancyTaskListStatusService Task GetAuthorisedVacancyAsync(VacancyRouteModel vrm, string routeName); void CheckCanEdit(Vacancy vacancy); void CheckAuthorisedAccess(Vacancy vacancy, string employerAccountId); - void CheckRouteIsValidForVacancy(Vacancy vacancy, string currentRouteName); - - /// - /// Returns a list of routes the user may access based on the current - /// state of the vacancy. - /// - /// - /// - /// - null if section 1 of the wizard is complete - /// - otherwise a list of accessible routes, where the last entry is the page to start the user on when editing the vacancy - /// - IList GetPermittedRoutesForVacancy(Vacancy vacancy); - - bool VacancyHasCompletedPartOne(Vacancy vacancy); - bool VacancyHasStartedPartTwo(Vacancy vacancy); PartOnePageInfoViewModel GetPartOnePageInfo(Vacancy vacancy); Task GetAuthorisedApplicationReviewAsync(ApplicationReviewRouteModel rm); @@ -49,12 +33,10 @@ Task UpdateEmployerProfile(VacancyEmployerInfoModel employerInfoModel, public class Utility : VacancyTaskListStatusService, IUtility { private readonly IRecruitVacancyClient _vacancyClient; - private readonly IFeature _feature; - public Utility (IRecruitVacancyClient vacancyClient, IFeature feature) + public Utility (IRecruitVacancyClient vacancyClient) { _vacancyClient = vacancyClient; - _feature = feature; } public async Task GetAuthorisedVacancyForEditAsync(VacancyRouteModel vrm, string routeName) @@ -72,8 +54,6 @@ public async Task GetAuthorisedVacancyAsync(VacancyRouteModel vrm, stri CheckAuthorisedAccess(vacancy, vrm.EmployerAccountId); - CheckRouteIsValidForVacancy(vacancy, routeName); - return vacancy; } @@ -92,162 +72,9 @@ public void CheckAuthorisedAccess(Vacancy vacancy, string employerAccountId) throw new AuthorisationException(string.Format(ExceptionMessages.UserIsNotTheOwner, OwnerType.Employer)); } - public void CheckRouteIsValidForVacancy(Vacancy vacancy, string currentRouteName) - { - var validRoutes = GetPermittedRoutesForVacancy(vacancy); - - if (validRoutes == null || validRoutes.Contains(currentRouteName)) - { - return; - } - - var redirectRoute = validRoutes.Last(); - - throw new InvalidRouteForVacancyException(string.Format(RecruitWebExceptionMessages.RouteNotValidForVacancy, currentRouteName, redirectRoute), - redirectRoute, new VacancyRouteModel{ EmployerAccountId = vacancy.EmployerAccountId, VacancyId = vacancy.Id }); - } - - /// - /// Returns a list of routes the user may access based on the current - /// state of the vacancy. - /// - /// - /// - /// - null if section 1 of the wizard is complete - /// - otherwise a list of accessible routes, where the last entry is the page to start the user on when editing the vacancy - /// - public IList GetPermittedRoutesForVacancy(Vacancy vacancy) - { - var validRoutes = new List(); - - validRoutes.AddRange(new [] {RouteNames.Title_Post, RouteNames.Title_Get}); - - if (_feature.IsFeatureEnabled(FeatureNames.EmployerTaskList)) - { - validRoutes.AddRange( new[] - { - RouteNames.EmployerTaskListGet, - RouteNames.EmployerCheckYourAnswersGet, - RouteNames.Employer_Post, - RouteNames.Employer_Get, - RouteNames.EmployerName_Post, - RouteNames.EmployerName_Get, - }); - } - - if (string.IsNullOrWhiteSpace(vacancy.Title)) - return validRoutes; - - validRoutes.AddRange(new[] - { - RouteNames.Training_Help_Get, - RouteNames.Training_First_Time_Post, - RouteNames.Training_First_Time_Get, - RouteNames.Training_Confirm_Post, - RouteNames.Training_Confirm_Get, - RouteNames.Training_Post, - RouteNames.Training_Get - }); - if (string.IsNullOrWhiteSpace(vacancy.ProgrammeId)) - return validRoutes; - - validRoutes.AddRange(new[] { - RouteNames.TrainingProvider_Confirm_Post, - RouteNames.TrainingProvider_Confirm_Get, - RouteNames.TrainingProvider_Select_Post, - RouteNames.TrainingProvider_Select_Get, - RouteNames.NumberOfPositions_Post, - RouteNames.NumberOfPositions_Get - }); - - if (vacancy.TrainingProvider == null && string.IsNullOrWhiteSpace(vacancy.NumberOfPositions?.ToString())) - { - //Move Training Provider Get to last valid route for resuming - validRoutes.Remove(RouteNames.TrainingProvider_Select_Get); - validRoutes.Add(RouteNames.TrainingProvider_Select_Get); - } - - if (_feature.IsFeatureEnabled(FeatureNames.EmployerTaskList)) - { - validRoutes.AddRange(new [] - { - RouteNames.ShortDescription_Get, - RouteNames.ShortDescription_Post, - RouteNames.VacancyDescription_Index_Post, - RouteNames.VacancyDescription_Index_Get, - RouteNames.Dates_Post, - RouteNames.Dates_Get, - RouteNames.Duration_Post, - RouteNames.Duration_Get, - RouteNames.Wage_Post, - RouteNames.Wage_Get, - RouteNames.Skills_Post, - RouteNames.Skills_Get, - RouteNames.Qualification_Add_Post, - RouteNames.Qualification_Delete_Post, - RouteNames.Qualification_Edit_Post, - RouteNames.Qualification_Edit_Get, - RouteNames.Qualification_Add_Get, - RouteNames.Qualifications_Get, - RouteNames.FutureProspects_Get, - RouteNames.FutureProspects_Post, - RouteNames.Considerations_Post, - RouteNames.Considerations_Get, - - RouteNames.AboutEmployer_Post, - RouteNames.AboutEmployer_Get, - RouteNames.EmployerContactDetails_Post, - RouteNames.EmployerContactDetails_Get, - RouteNames.ApplicationProcess_Post, - RouteNames.ApplicationProcess_Get - }); - } - else - { - if (!vacancy.NumberOfPositions.HasValue) - return validRoutes; - } - - - validRoutes.AddRange(new[] - { - RouteNames.LegalEntityAgreement_SoftStop_Get, - RouteNames.Location_Get, - RouteNames.Location_Post, - RouteNames.EmployerName_Post, - RouteNames.EmployerName_Get, - RouteNames.Employer_Post, - RouteNames.Employer_Get - }); - - if (string.IsNullOrWhiteSpace(vacancy.LegalEntityName) - || vacancy.EmployerNameOption == null - || string.IsNullOrWhiteSpace(vacancy.EmployerLocation?.Postcode)) - return validRoutes; - - validRoutes.AddRange(new[] { RouteNames.Dates_Post, RouteNames.Dates_Get }); - if (vacancy.StartDate == null) - return validRoutes; - - validRoutes.AddRange(new[] { RouteNames.Duration_Post, RouteNames.Duration_Get }); - if (vacancy.Wage?.Duration == null) - return validRoutes; - - validRoutes.AddRange(new[] { RouteNames.Wage_Post, RouteNames.Wage_Get}); - if (vacancy.Wage?.WageType == null) - return validRoutes; - - return null; - } - public bool VacancyHasCompletedPartOne(Vacancy vacancy) { - if (_feature.IsFeatureEnabled(FeatureNames.EmployerTaskList)) - { - return vacancy.ApplicationMethod != null; - } - - return GetPermittedRoutesForVacancy(vacancy) == null; + return vacancy.ApplicationMethod != null; } public bool VacancyHasStartedPartTwo(Vacancy vacancy) diff --git a/src/Employer/Employer.Web/Views/Vacancies/Vacancies.cshtml b/src/Employer/Employer.Web/Views/Vacancies/Vacancies.cshtml index 54f024409f..7f73c62a90 100644 --- a/src/Employer/Employer.Web/Views/Vacancies/Vacancies.cshtml +++ b/src/Employer/Employer.Web/Views/Vacancies/Vacancies.cshtml @@ -150,7 +150,6 @@ Manage - @if (vacancy.Status == VacancyStatus.Referred || vacancy.Status == VacancyStatus.Rejected || vacancy.Status == VacancyStatus.Review || vacancy.IsTaskListCompleted) { @GetLinkText(vacancy) @@ -159,12 +158,6 @@ { @GetLinkText(vacancy) } - - - - @GetLinkText(vacancy) - - } diff --git a/src/Employer/UnitTests/Employer.Web/Orchestrators/CloneVacancyOrchestratorTest/CloneVacancyOrchestratorTestBase.cs b/src/Employer/UnitTests/Employer.Web/Orchestrators/CloneVacancyOrchestratorTest/CloneVacancyOrchestratorTestBase.cs index 51afbf28c1..a054015b5e 100644 --- a/src/Employer/UnitTests/Employer.Web/Orchestrators/CloneVacancyOrchestratorTest/CloneVacancyOrchestratorTestBase.cs +++ b/src/Employer/UnitTests/Employer.Web/Orchestrators/CloneVacancyOrchestratorTest/CloneVacancyOrchestratorTestBase.cs @@ -2,7 +2,6 @@ using Esfa.Recruit.Employer.Web; using Esfa.Recruit.Employer.Web.Orchestrators; using Esfa.Recruit.Employer.Web.RouteModel; -using Esfa.Recruit.Shared.Web.FeatureToggle; using Esfa.Recruit.Vacancies.Client.Application.Providers; using Esfa.Recruit.Vacancies.Client.Domain.Entities; using Esfa.Recruit.Vacancies.Client.Infrastructure.Client; @@ -45,7 +44,7 @@ internal CloneVacancyOrchestrator GetSut(Vacancy vacancy) .Setup(c => c.GetVacancyAsync(It.IsAny())) .ReturnsAsync(vacancy); - var utility = new Utility(recruitClientMock.Object, Mock.Of()); + var utility = new Utility(recruitClientMock.Object); return new CloneVacancyOrchestrator(recruitClientMock.Object, timeProviderMock.Object, loggerMock.Object, utility); diff --git a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/DatesOrchestratorTests.cs b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/DatesOrchestratorTests.cs index e116301dfb..81feedf2c2 100644 --- a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/DatesOrchestratorTests.cs +++ b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/DatesOrchestratorTests.cs @@ -7,7 +7,6 @@ using Esfa.Recruit.Employer.Web.Orchestrators.Part1; using Esfa.Recruit.Employer.Web.ViewModels.Part1.Dates; using Esfa.Recruit.Shared.Web.Extensions; -using Esfa.Recruit.Shared.Web.FeatureToggle; using Esfa.Recruit.Shared.Web.Mappers; using Esfa.Recruit.Shared.Web.Services; using Esfa.Recruit.Vacancies.Client.Application.Providers; @@ -97,7 +96,7 @@ public void Setup() MockRecruitVacancyClient.Setup(x => x.UpdateDraftVacancyAsync(It.IsAny(), User)); MockRecruitVacancyClient.Setup(x => x.UpdateEmployerProfileAsync(It.IsAny(), User)); - var utility = new Utility(MockRecruitVacancyClient.Object, Mock.Of()); + var utility = new Utility(MockRecruitVacancyClient.Object); Sut = new DatesOrchestrator(MockRecruitVacancyClient.Object, Mock.Of>(), Mock.Of(),Mock.Of(), Mock.Of(), utility); diff --git a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/DurationOrchestratorTests.cs b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/DurationOrchestratorTests.cs index 7b6864775b..76cc5a9d96 100644 --- a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/DurationOrchestratorTests.cs +++ b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/DurationOrchestratorTests.cs @@ -7,7 +7,6 @@ using Esfa.Recruit.Employer.Web.ViewModels.Part1.Dates; using Esfa.Recruit.Employer.Web.ViewModels.Part1.Duration; using Esfa.Recruit.Shared.Web.Extensions; -using Esfa.Recruit.Shared.Web.FeatureToggle; using Esfa.Recruit.Shared.Web.Mappers; using Esfa.Recruit.Shared.Web.Services; using Esfa.Recruit.Vacancies.Client.Application.Providers; @@ -107,7 +106,7 @@ public void Setup() MockRecruitVacancyClient.Setup(x => x.Validate(Vacancy, ValidationRules)).Returns(new EntityValidationResult()); MockRecruitVacancyClient.Setup(x => x.UpdateDraftVacancyAsync(It.IsAny(), User)); MockRecruitVacancyClient.Setup(x => x.UpdateEmployerProfileAsync(It.IsAny(), User)); - var utility = new Utility(MockRecruitVacancyClient.Object, Mock.Of()); + var utility = new Utility(MockRecruitVacancyClient.Object); Sut = new DurationOrchestrator(MockClient.Object, MockRecruitVacancyClient.Object, Mock.Of>(), Mock.Of(), utility); diff --git a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/LocationOrchestratorTests.cs b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/LocationOrchestratorTests.cs index 1afe869a97..c4c08e0cf4 100644 --- a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/LocationOrchestratorTests.cs +++ b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/LocationOrchestratorTests.cs @@ -5,7 +5,6 @@ using Esfa.Recruit.Employer.Web.Models; using Esfa.Recruit.Employer.Web.Orchestrators.Part1; using Esfa.Recruit.Employer.Web.ViewModels.Part1.Location; -using Esfa.Recruit.Shared.Web.FeatureToggle; using Esfa.Recruit.Shared.Web.Mappers; using Esfa.Recruit.Shared.Web.Models; using Esfa.Recruit.Shared.Web.Services; @@ -230,7 +229,7 @@ public void Setup() MockRecruitVacancyClient.Setup(x => x.UpdateDraftVacancyAsync(It.IsAny(), User)); MockRecruitVacancyClient.Setup(x => x.UpdateEmployerProfileAsync(It.IsAny(), User)); MockAddressesClient.Setup(x => x.GetAddresses(It.IsAny())).ReturnsAsync(AddressesListResponse); - var utility = new Utility(MockRecruitVacancyClient.Object, Mock.Of()); + var utility = new Utility(MockRecruitVacancyClient.Object); Sut = new LocationOrchestrator(MockClient.Object, MockRecruitVacancyClient.Object, Mock.Of>(), Mock.Of(), MockAddressesClient.Object, utility); } diff --git a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/NumberOfPositionsOrchestratorTests.cs b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/NumberOfPositionsOrchestratorTests.cs index 432a8da3f0..16f6d4cec0 100644 --- a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/NumberOfPositionsOrchestratorTests.cs +++ b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/NumberOfPositionsOrchestratorTests.cs @@ -4,7 +4,6 @@ using Esfa.Recruit.Employer.Web; using Esfa.Recruit.Employer.Web.Orchestrators.Part1; using Esfa.Recruit.Employer.Web.ViewModels.Part1.NumberOfPositions; -using Esfa.Recruit.Shared.Web.FeatureToggle; using Esfa.Recruit.Shared.Web.Mappers; using Esfa.Recruit.Shared.Web.Services; using Esfa.Recruit.Vacancies.Client.Application.Validation; @@ -75,7 +74,7 @@ public void Setup() MockRecruitVacancyClient.Setup(x => x.Validate(Vacancy, ValidationRules)).Returns(new EntityValidationResult()); MockRecruitVacancyClient.Setup(x => x.UpdateDraftVacancyAsync(It.IsAny(), User)); MockRecruitVacancyClient.Setup(x => x.UpdateEmployerProfileAsync(It.IsAny(), User)); - var utility = new Utility(MockRecruitVacancyClient.Object, Mock.Of()); + var utility = new Utility(MockRecruitVacancyClient.Object); Sut = new NumberOfPositionsOrchestrator(MockRecruitVacancyClient.Object, Mock.Of>(), Mock.Of(), utility); } diff --git a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/TitleOrchestratorTests.cs b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/TitleOrchestratorTests.cs index 5a709abc44..7c083baa3b 100644 --- a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/TitleOrchestratorTests.cs +++ b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/TitleOrchestratorTests.cs @@ -6,7 +6,6 @@ using Esfa.Recruit.Employer.Web.Orchestrators.Part1; using Esfa.Recruit.Employer.Web.RouteModel; using Esfa.Recruit.Employer.Web.ViewModels.Part1.Title; -using Esfa.Recruit.Shared.Web.FeatureToggle; using Esfa.Recruit.Shared.Web.Mappers; using Esfa.Recruit.Shared.Web.Services; using Esfa.Recruit.Vacancies.Client.Application.Validation; @@ -96,7 +95,7 @@ public void Setup() MockRecruitVacancyClient.Setup(x => x.Validate(Vacancy, ValidationRules)).Returns(new EntityValidationResult()); MockRecruitVacancyClient.Setup(x => x.UpdateDraftVacancyAsync(It.IsAny(), User)); MockRecruitVacancyClient.Setup(x => x.UpdateEmployerProfileAsync(It.IsAny(), User)); - var utility = new Utility(MockRecruitVacancyClient.Object, Mock.Of()); + var utility = new Utility(MockRecruitVacancyClient.Object); Sut = new TitleOrchestrator(MockClient.Object, MockRecruitVacancyClient.Object, Mock.Of>(), Mock.Of(), Mock.Of(), utility); diff --git a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/TrainingOrchestratorTests.cs b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/TrainingOrchestratorTests.cs index 58ead92ea5..50fbab7a0c 100644 --- a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/TrainingOrchestratorTests.cs +++ b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/TrainingOrchestratorTests.cs @@ -6,7 +6,6 @@ using Esfa.Recruit.Employer.Web.Orchestrators.Part1; using Esfa.Recruit.Employer.Web.ViewModels.Part1.Title; using Esfa.Recruit.Employer.Web.ViewModels.Part1.Training; -using Esfa.Recruit.Shared.Web.FeatureToggle; using Esfa.Recruit.Shared.Web.Mappers; using Esfa.Recruit.Shared.Web.Services; using Esfa.Recruit.Vacancies.Client.Application.Validation; @@ -92,7 +91,7 @@ public void Setup() new LegalEntity() } }); - var utility = new Utility(MockRecruitVacancyClient.Object, Mock.Of()); + var utility = new Utility(MockRecruitVacancyClient.Object); Sut = new TrainingOrchestrator(MockClient.Object, MockRecruitVacancyClient.Object, Mock.Of>(), Mock.Of(), utility, MockEmployerVacancyClient.Object); diff --git a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/TrainingProviderOrchestratorTests.cs b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/TrainingProviderOrchestratorTests.cs index 7363983c9d..ea5da96c60 100644 --- a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/TrainingProviderOrchestratorTests.cs +++ b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/TrainingProviderOrchestratorTests.cs @@ -8,7 +8,6 @@ using Esfa.Recruit.Employer.Web.Models; using Esfa.Recruit.Employer.Web.Orchestrators.Part1; using Esfa.Recruit.Employer.Web.ViewModels.Part1.TrainingProvider; -using Esfa.Recruit.Shared.Web.FeatureToggle; using Esfa.Recruit.Shared.Web.Mappers; using Esfa.Recruit.Shared.Web.Orchestrators; using Esfa.Recruit.Shared.Web.Services; @@ -273,7 +272,7 @@ public void Setup() Ukprn = EsfaTestTrainingProvider.Ukprn }); - var utility = new Utility(MockRecruitVacancyClient.Object, Mock.Of()); + var utility = new Utility(MockRecruitVacancyClient.Object); Sut = new TrainingProviderOrchestrator(MockRecruitVacancyClient.Object, Mock.Of>(), Mock.Of(), MockTrainingProviderSummaryProvider.Object, MockTrainingProviderService.Object, utility, new RecruitConfiguration(EmployerAccountId)); diff --git a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/WageOrchestratorTests.cs b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/WageOrchestratorTests.cs index c7b5cf28b3..02f7433289 100644 --- a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/WageOrchestratorTests.cs +++ b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part1/WageOrchestratorTests.cs @@ -5,7 +5,6 @@ using Esfa.Recruit.Employer.Web.Orchestrators.Part1; using Esfa.Recruit.Employer.Web.ViewModels.Part1.Duration; using Esfa.Recruit.Employer.Web.ViewModels.Part1.Wage; -using Esfa.Recruit.Shared.Web.FeatureToggle; using Esfa.Recruit.Shared.Web.Mappers; using Esfa.Recruit.Shared.Web.Services; using Esfa.Recruit.Vacancies.Client.Application.Providers; @@ -95,7 +94,7 @@ public void Setup() MockRecruitVacancyClient.Setup(x => x.Validate(Vacancy, ValidationRules)).Returns(new EntityValidationResult()); MockRecruitVacancyClient.Setup(x => x.UpdateDraftVacancyAsync(It.IsAny(), User)); MockRecruitVacancyClient.Setup(x => x.UpdateEmployerProfileAsync(It.IsAny(), User)); - var utility = new Utility(MockRecruitVacancyClient.Object, Mock.Of()); + var utility = new Utility(MockRecruitVacancyClient.Object); Sut = new WageOrchestrator(MockRecruitVacancyClient.Object, Mock.Of>(), Mock.Of(), Mock.Of(), utility); diff --git a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/AboutEmployerOrchestratorTests.cs b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/AboutEmployerOrchestratorTests.cs index 80c75dc744..bea34daa2b 100644 --- a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/AboutEmployerOrchestratorTests.cs +++ b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/AboutEmployerOrchestratorTests.cs @@ -4,7 +4,6 @@ using Esfa.Recruit.Employer.Web; using Esfa.Recruit.Employer.Web.Orchestrators.Part2; using Esfa.Recruit.Employer.Web.ViewModels; -using Esfa.Recruit.Shared.Web.FeatureToggle; using Esfa.Recruit.Shared.Web.Mappers; using Esfa.Recruit.Shared.Web.Services; using Esfa.Recruit.Vacancies.Client.Application.Validation; @@ -98,7 +97,7 @@ public void Setup() MockRecruitVacancyClient.Setup(x => x.UpdateDraftVacancyAsync(It.IsAny(), User)); MockRecruitVacancyClient.Setup(x => x.UpdateEmployerProfileAsync(It.IsAny(), User)); - var utility = new Utility(MockRecruitVacancyClient.Object, Mock.Of()); + var utility = new Utility(MockRecruitVacancyClient.Object); Sut = new AboutEmployerOrchestrator(MockRecruitVacancyClient.Object, Mock.Of>(), Mock.Of(), utility); } diff --git a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/ApplicationProcessOrchestratorTests.cs b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/ApplicationProcessOrchestratorTests.cs index a5e8954a3d..884ab1118e 100644 --- a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/ApplicationProcessOrchestratorTests.cs +++ b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/ApplicationProcessOrchestratorTests.cs @@ -6,7 +6,6 @@ using Esfa.Recruit.Employer.Web.Configuration; using Esfa.Recruit.Employer.Web.Orchestrators.Part2; using Esfa.Recruit.Employer.Web.ViewModels; -using Esfa.Recruit.Shared.Web.FeatureToggle; using Esfa.Recruit.Shared.Web.Mappers; using Esfa.Recruit.Shared.Web.Services; using Esfa.Recruit.Vacancies.Client.Application.Validation; @@ -211,7 +210,7 @@ public void Setup() MockRecruitVacancyClient.Setup(x => x.Validate(Vacancy, ValidationRules)).Returns(new EntityValidationResult()); MockRecruitVacancyClient.Setup(x => x.UpdateDraftVacancyAsync(It.IsAny(), User)); MockRecruitVacancyClient.Setup(x => x.UpdateEmployerProfileAsync(It.IsAny(), User)); - var utility = new Utility(MockRecruitVacancyClient.Object, Mock.Of()); + var utility = new Utility(MockRecruitVacancyClient.Object); Sut = new ApplicationProcessOrchestrator(MockRecruitVacancyClient.Object, Options.Create(new ExternalLinksConfiguration()), Mock.Of>(), Mock.Of(), utility); } diff --git a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/ConsiderationsOrchestratorTests.cs b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/ConsiderationsOrchestratorTests.cs index 52560b3957..3b5bbda9e4 100644 --- a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/ConsiderationsOrchestratorTests.cs +++ b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/ConsiderationsOrchestratorTests.cs @@ -4,7 +4,6 @@ using Esfa.Recruit.Employer.Web; using Esfa.Recruit.Employer.Web.Orchestrators.Part2; using Esfa.Recruit.Employer.Web.ViewModels; -using Esfa.Recruit.Shared.Web.FeatureToggle; using Esfa.Recruit.Shared.Web.Mappers; using Esfa.Recruit.Shared.Web.Services; using Esfa.Recruit.Vacancies.Client.Application.Validation; @@ -92,7 +91,7 @@ public void Setup() MockRecruitVacancyClient.Setup(x => x.Validate(Vacancy, ValidationRules)).Returns(new EntityValidationResult()); MockRecruitVacancyClient.Setup(x => x.UpdateDraftVacancyAsync(It.IsAny(), User)); MockRecruitVacancyClient.Setup(x => x.UpdateEmployerProfileAsync(It.IsAny(), User)); - var utility = new Utility(MockRecruitVacancyClient.Object, Mock.Of()); + var utility = new Utility(MockRecruitVacancyClient.Object); Sut = new ConsiderationsOrchestrator(Mock.Of>(), MockRecruitVacancyClient.Object, Mock.Of(), utility); } diff --git a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/EmployerContactDetailsOrchestratorTests.cs b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/EmployerContactDetailsOrchestratorTests.cs index 2b9a6ad578..03017d58b8 100644 --- a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/EmployerContactDetailsOrchestratorTests.cs +++ b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/EmployerContactDetailsOrchestratorTests.cs @@ -4,7 +4,6 @@ using Esfa.Recruit.Employer.Web; using Esfa.Recruit.Employer.Web.Orchestrators.Part2; using Esfa.Recruit.Employer.Web.ViewModels; -using Esfa.Recruit.Shared.Web.FeatureToggle; using Esfa.Recruit.Shared.Web.Mappers; using Esfa.Recruit.Shared.Web.Services; using Esfa.Recruit.Vacancies.Client.Application.Validation; @@ -129,7 +128,7 @@ public void Setup() MockRecruitVacancyClient.Setup(x => x.Validate(Vacancy, ValidationRules)).Returns(new EntityValidationResult()); MockRecruitVacancyClient.Setup(x => x.UpdateDraftVacancyAsync(It.IsAny(), User)); MockRecruitVacancyClient.Setup(x => x.UpdateEmployerProfileAsync(It.IsAny(), User)); - var utility = new Utility(MockRecruitVacancyClient.Object, Mock.Of()); + var utility = new Utility(MockRecruitVacancyClient.Object); Sut = new EmployerContactDetailsOrchestrator(MockRecruitVacancyClient.Object, Mock.Of>(), Mock.Of(), utility); } diff --git a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/QualificationsOrchestratorTests.cs b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/QualificationsOrchestratorTests.cs index 520d7079ef..e02aba1503 100644 --- a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/QualificationsOrchestratorTests.cs +++ b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/QualificationsOrchestratorTests.cs @@ -322,7 +322,7 @@ public void Setup() .Returns(Task.FromResult(0)); MockRecruitVacancyClient.Setup(x => x.UpdateEmployerProfileAsync(It.IsAny(), User)); - var utility = new Utility(MockRecruitVacancyClient.Object, Mock.Of()); + var utility = new Utility(MockRecruitVacancyClient.Object); Sut = new QualificationsOrchestrator(MockClient.Object, MockRecruitVacancyClient.Object, Mock.Of>(), Mock.Of(), utility, Mock.Of()); } diff --git a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/ShortDescriptionOrchestratorTests.cs b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/ShortDescriptionOrchestratorTests.cs index 6448ed0244..a7e8aa67ee 100644 --- a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/ShortDescriptionOrchestratorTests.cs +++ b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/ShortDescriptionOrchestratorTests.cs @@ -5,7 +5,6 @@ using Esfa.Recruit.Employer.Web.Orchestrators.Part2; using Esfa.Recruit.Employer.Web.ViewModels; using Esfa.Recruit.Employer.Web.ViewModels.Part2.ShortDescription; -using Esfa.Recruit.Shared.Web.FeatureToggle; using Esfa.Recruit.Shared.Web.Mappers; using Esfa.Recruit.Shared.Web.Services; using Esfa.Recruit.Vacancies.Client.Application.Validation; @@ -93,7 +92,7 @@ public void Setup() MockRecruitVacancyClient.Setup(x => x.Validate(Vacancy, ValidationRules)).Returns(new EntityValidationResult()); MockRecruitVacancyClient.Setup(x => x.UpdateDraftVacancyAsync(It.IsAny(), User)); MockRecruitVacancyClient.Setup(x => x.UpdateEmployerProfileAsync(It.IsAny(), User)); - var utility = new Utility(MockRecruitVacancyClient.Object, Mock.Of()); + var utility = new Utility(MockRecruitVacancyClient.Object); Sut = new ShortDescriptionOrchestrator(MockRecruitVacancyClient.Object, Mock.Of>(), Mock.Of(), utility); } diff --git a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/SkillOrchestratorTests.cs b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/SkillOrchestratorTests.cs index 4d10287155..fdc7b560d0 100644 --- a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/SkillOrchestratorTests.cs +++ b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/SkillOrchestratorTests.cs @@ -6,7 +6,6 @@ using Esfa.Recruit.Employer.Web.Orchestrators.Part2; using Esfa.Recruit.Employer.Web.RouteModel; using Esfa.Recruit.Employer.Web.ViewModels.Part2.Skills; -using Esfa.Recruit.Shared.Web.FeatureToggle; using Esfa.Recruit.Shared.Web.Mappers; using Esfa.Recruit.Shared.Web.Services; using Esfa.Recruit.Vacancies.Client.Application.Validation; @@ -298,7 +297,7 @@ public void Setup() MockRecruitVacancyClient.Setup(x => x.Validate(Vacancy, ValidationRules)).Returns(new EntityValidationResult()); MockRecruitVacancyClient.Setup(x => x.UpdateDraftVacancyAsync(It.IsAny(), User)); MockRecruitVacancyClient.Setup(x => x.UpdateEmployerProfileAsync(It.IsAny(), User)); - var utility = new Utility(MockRecruitVacancyClient.Object, Mock.Of()); + var utility = new Utility(MockRecruitVacancyClient.Object); Sut = new SkillsOrchestrator(MockRecruitVacancyClient.Object, Mock.Of>(), Mock.Of(), utility); } diff --git a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/VacancyDescriptionOrchestratorTests.cs b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/VacancyDescriptionOrchestratorTests.cs index 5b918ecc2e..85c7f1eec5 100644 --- a/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/VacancyDescriptionOrchestratorTests.cs +++ b/src/Employer/UnitTests/Employer.Web/Orchestrators/Part2/VacancyDescriptionOrchestratorTests.cs @@ -7,7 +7,6 @@ using Esfa.Recruit.Employer.Web.ViewModels; using Esfa.Recruit.Employer.Web.ViewModels.Part2.ShortDescription; using Esfa.Recruit.Employer.Web.ViewModels.Part2.VacancyDescription; -using Esfa.Recruit.Shared.Web.FeatureToggle; using Esfa.Recruit.Shared.Web.Mappers; using Esfa.Recruit.Shared.Web.Services; using Esfa.Recruit.Vacancies.Client.Application.Validation; @@ -112,7 +111,7 @@ public void Setup() MockRecruitVacancyClient.Setup(x => x.Validate(Vacancy, ValidationRules)).Returns(new EntityValidationResult()); MockRecruitVacancyClient.Setup(x => x.UpdateDraftVacancyAsync(It.IsAny(), User)); MockRecruitVacancyClient.Setup(x => x.UpdateEmployerProfileAsync(It.IsAny(), User)); - var utility = new Utility(MockRecruitVacancyClient.Object, Mock.Of()); + var utility = new Utility(MockRecruitVacancyClient.Object); Sut = new VacancyDescriptionOrchestrator(MockRecruitVacancyClient.Object, Mock.Of>(), Mock.Of(), utility); } diff --git a/src/Employer/UnitTests/Employer.Web/Orchestrators/VacancyPreviewOrchestratorTests.cs b/src/Employer/UnitTests/Employer.Web/Orchestrators/VacancyPreviewOrchestratorTests.cs index 4de24e2b8e..58070bc64e 100644 --- a/src/Employer/UnitTests/Employer.Web/Orchestrators/VacancyPreviewOrchestratorTests.cs +++ b/src/Employer/UnitTests/Employer.Web/Orchestrators/VacancyPreviewOrchestratorTests.cs @@ -15,7 +15,6 @@ using Xunit; using System.Threading.Tasks; using Esfa.Recruit.Employer.Web; -using Esfa.Recruit.Shared.Web.FeatureToggle; namespace Esfa.Recruit.Employer.UnitTests.Employer.Web.Orchestrators { @@ -76,7 +75,7 @@ public async Task ApproveJobAdvertAsync_ShouldNotSubmitWhenMissingAgreements( var legalEntityAgreement = new Mock(); legalEntityAgreement.Setup(l => l.HasLegalEntityAgreementAsync(vacancy.EmployerAccountId, vacancy.AccountLegalEntityPublicHashedId)) .ReturnsAsync(hasLegalEntityAgreement); - var utility = new Utility(_mockRecruitVacancyClient.Object, Mock.Of()); + var utility = new Utility(_mockRecruitVacancyClient.Object); var sut = new VacancyPreviewOrchestrator(_mockRecruitVacancyClient.Object, Mock.Of>(), mapper, @@ -130,7 +129,7 @@ public async Task RejectJobAdvertAsync_ShouldSendCommand() var externalLinks = new Mock>(); var mapper = new DisplayVacancyViewModelMapper(geocodeImageService.Object, externalLinks.Object, _mockRecruitVacancyClient.Object); var legalEntityAgreement = new Mock(); - var utility = new Utility(_mockRecruitVacancyClient.Object, Mock.Of()); + var utility = new Utility(_mockRecruitVacancyClient.Object); var sut = new VacancyPreviewOrchestrator(_mockRecruitVacancyClient.Object, Mock.Of>(), mapper, diff --git a/src/Employer/UnitTests/Employer.Web/Orchestrators/VacancyTaskListOrchestratorTests.cs b/src/Employer/UnitTests/Employer.Web/Orchestrators/VacancyTaskListOrchestratorTests.cs index 175cb77f66..276d48551a 100644 --- a/src/Employer/UnitTests/Employer.Web/Orchestrators/VacancyTaskListOrchestratorTests.cs +++ b/src/Employer/UnitTests/Employer.Web/Orchestrators/VacancyTaskListOrchestratorTests.cs @@ -32,7 +32,8 @@ public async Task Then_The_Vacancy_Is_Retrieved_And_Mapped( VacancyRouteModel routeModel, ApprenticeshipProgramme programme, Vacancy vacancy, - List legalEntities, + VacancyUser user, + EmployerEditVacancyInfo employerInfo, [Frozen] Mock> externalLinksConfiguration, [Frozen] Mock utility, [Frozen] Mock recruitVacancyClient, @@ -44,8 +45,9 @@ public async Task Then_The_Vacancy_Is_Retrieved_And_Mapped( programme.Id = vacancy.ProgrammeId; programme.EducationLevelNumber = 3; programme.ApprenticeshipLevel = ApprenticeshipLevel.Higher; - employerVacancyClient.Setup(x => x.GetEmployerLegalEntitiesAsync(routeModel.EmployerAccountId)) - .ReturnsAsync(legalEntities); + employerInfo.LegalEntities.FirstOrDefault().AccountLegalEntityPublicHashedId = vacancy.AccountLegalEntityPublicHashedId; + employerVacancyClient.Setup(x => x.GetEditVacancyInfoAsync(routeModel.EmployerAccountId)) + .ReturnsAsync(employerInfo); utility.Setup(x => x.GetAuthorisedVacancyForEditAsync(It.Is( c => c.VacancyId.Equals(routeModel.VacancyId) && c.EmployerAccountId.Equals(routeModel.EmployerAccountId)), RouteNames.EmployerTaskListGet)) @@ -61,7 +63,7 @@ public async Task Then_The_Vacancy_Is_Retrieved_And_Mapped( var mapper = new DisplayVacancyViewModelMapper(Mock.Of(), externalLinksConfiguration.Object, recruitVacancyClient.Object); - var viewModel = await orchestrator.GetVacancyTaskListModel(routeModel); + var viewModel = await orchestrator.GetVacancyTaskListModel(routeModel, user); await mapper.MapFromVacancyAsync(expectedViewModel, vacancy); @@ -79,22 +81,135 @@ public async Task Then_The_Vacancy_Is_Retrieved_And_Mapped( .Excluding(c=>c.HasSoftValidationErrors) ); viewModel.ApprenticeshipLevel.Should().Be(programme.ApprenticeshipLevel); - viewModel.AccountLegalEntityCount.Should().Be(legalEntities.Count); + viewModel.AccountLegalEntityCount.Should().Be(employerInfo.LegalEntities.Count()); viewModel.HasSelectedEmployerNameOption.Should().BeTrue(); } + [Test, MoqAutoData] + public async Task Then_If_The_Legal_Entity_Is_No_Longer_Available_Then_LegalEntity_Values_Cleared( + string findAnApprenticeshipUrl, + VacancyRouteModel routeModel, + ApprenticeshipProgramme programme, + Vacancy vacancy, + VacancyUser user, + EmployerEditVacancyInfo employerInfo, + [Frozen] Mock> externalLinksConfiguration, + [Frozen] Mock utility, + [Frozen] Mock recruitVacancyClient, + [Frozen] Mock employerVacancyClient, + VacancyTaskListOrchestrator orchestrator) + { + vacancy.EmployerLocation = null; + vacancy.EmployerNameOption = EmployerNameOption.RegisteredName; + programme.Id = vacancy.ProgrammeId; + programme.EducationLevelNumber = 3; + programme.ApprenticeshipLevel = ApprenticeshipLevel.Higher; + employerVacancyClient.Setup(x => x.GetEditVacancyInfoAsync(routeModel.EmployerAccountId)) + .ReturnsAsync(employerInfo); + utility.Setup(x => x.GetAuthorisedVacancyForEditAsync(It.Is( + c => c.VacancyId.Equals(routeModel.VacancyId) && + c.EmployerAccountId.Equals(routeModel.EmployerAccountId)), RouteNames.EmployerTaskListGet)) + .ReturnsAsync(vacancy); + recruitVacancyClient.Setup(x => x.GetActiveApprenticeshipProgrammesAsync()) + .ReturnsAsync(new List{ programme}); + recruitVacancyClient.Setup(x => x.GetApprenticeshipProgrammeAsync(programme.Id)) + .ReturnsAsync(programme); + recruitVacancyClient.Setup(x => x.GetEmployerDescriptionAsync(vacancy)).ReturnsAsync(""); + recruitVacancyClient.Setup(x => x.GetEmployerNameAsync(vacancy)).ReturnsAsync(""); + externalLinksConfiguration.Object.Value.FindAnApprenticeshipUrl = findAnApprenticeshipUrl; + var expectedViewModel = new VacancyPreviewViewModel(); + var mapper = new DisplayVacancyViewModelMapper(Mock.Of(), + externalLinksConfiguration.Object, recruitVacancyClient.Object); + + var viewModel = await orchestrator.GetVacancyTaskListModel(routeModel, user); + + await mapper.MapFromVacancyAsync(expectedViewModel, vacancy); + + recruitVacancyClient.Verify(x=>x.UpdateDraftVacancyAsync(It.Is(c=> + c.EmployerName == null + && c.LegalEntityName == null + && c.AccountLegalEntityPublicHashedId == null + && c.EmployerNameOption == null + && c.EmployerDescription == null + && c.EmployerLocation == null + ), user), Times.Once); + viewModel.EmployerName.Should().BeNullOrEmpty(); + viewModel.AccountLegalEntityPublicHashedId.Should().BeNullOrEmpty(); + viewModel.EmployerAddressSectionState.Should().Be(VacancyPreviewSectionState.Incomplete); + viewModel.HasSelectedEmployerNameOption.Should().BeFalse(); + viewModel.HasEmployerDescription.Should().BeFalse(); + } + + [Test, MoqAutoData] + public async Task If_Legal_Entity_No_Longer_Exists_And_Only_One_Available_Then_Updated_To_That_Legal_Entity( + string findAnApprenticeshipUrl, + VacancyRouteModel routeModel, + ApprenticeshipProgramme programme, + Vacancy vacancy, + VacancyUser user, + LegalEntity legalEntity, + [Frozen] Mock> externalLinksConfiguration, + [Frozen] Mock utility, + [Frozen] Mock recruitVacancyClient, + [Frozen] Mock employerVacancyClient, + VacancyTaskListOrchestrator orchestrator) + { + vacancy.EmployerLocation = null; + vacancy.EmployerNameOption = EmployerNameOption.RegisteredName; + programme.Id = vacancy.ProgrammeId; + programme.EducationLevelNumber = 3; + programme.ApprenticeshipLevel = ApprenticeshipLevel.Higher; + employerVacancyClient.Setup(x => x.GetEditVacancyInfoAsync(routeModel.EmployerAccountId)) + .ReturnsAsync(new EmployerEditVacancyInfo + { + LegalEntities = new List{legalEntity} + }); + utility.Setup(x => x.GetAuthorisedVacancyForEditAsync(It.Is( + c => c.VacancyId.Equals(routeModel.VacancyId) && + c.EmployerAccountId.Equals(routeModel.EmployerAccountId)), RouteNames.EmployerTaskListGet)) + .ReturnsAsync(vacancy); + recruitVacancyClient.Setup(x => x.GetActiveApprenticeshipProgrammesAsync()) + .ReturnsAsync(new List{ programme}); + recruitVacancyClient.Setup(x => x.GetApprenticeshipProgrammeAsync(programme.Id)) + .ReturnsAsync(programme); + recruitVacancyClient.Setup(x => x.GetEmployerDescriptionAsync(vacancy)).ReturnsAsync(""); + recruitVacancyClient.Setup(x => x.GetEmployerNameAsync(vacancy)).ReturnsAsync(""); + externalLinksConfiguration.Object.Value.FindAnApprenticeshipUrl = findAnApprenticeshipUrl; + var expectedViewModel = new VacancyPreviewViewModel(); + var mapper = new DisplayVacancyViewModelMapper(Mock.Of(), + externalLinksConfiguration.Object, recruitVacancyClient.Object); + + var viewModel = await orchestrator.GetVacancyTaskListModel(routeModel, user); + + await mapper.MapFromVacancyAsync(expectedViewModel, vacancy); + + recruitVacancyClient.Verify(x=>x.UpdateDraftVacancyAsync(It.Is(c=> + c.EmployerName == null + && c.LegalEntityName.Equals(legalEntity.Name) + && c.AccountLegalEntityPublicHashedId.Equals(legalEntity.AccountLegalEntityPublicHashedId) + && c.EmployerNameOption == null + && c.EmployerDescription == null + && c.EmployerLocation == null + ), user), Times.Once); + viewModel.EmployerName.Should().BeNullOrEmpty(); + viewModel.AccountLegalEntityPublicHashedId.Should().Be(legalEntity.AccountLegalEntityPublicHashedId); + viewModel.EmployerAddressSectionState.Should().Be(VacancyPreviewSectionState.Incomplete); + viewModel.HasSelectedEmployerNameOption.Should().BeFalse(); + } + [Test, MoqAutoData] public async Task When_Creating_New_Then_The_Account_Legal_Entity_Count_Is_Populated( VacancyRouteModel routeModel, List legalEntities, Vacancy vacancy, + VacancyUser user, [Frozen] Mock employerVacancyClient, VacancyTaskListOrchestrator orchestrator) { employerVacancyClient.Setup(x => x.GetEmployerLegalEntitiesAsync(routeModel.EmployerAccountId)) .ReturnsAsync(legalEntities); - var viewModel = await orchestrator.GetVacancyTaskListModel(routeModel); + var viewModel = await orchestrator.GetVacancyTaskListModel(routeModel, user); viewModel.AccountLegalEntityCount.Should().Be(legalEntities.Count); } diff --git a/src/Employer/UnitTests/Employer.Web/UtilityTests/CheckRouteIsValidForVacancyTests.cs b/src/Employer/UnitTests/Employer.Web/UtilityTests/CheckRouteIsValidForVacancyTests.cs deleted file mode 100644 index 48bdc4a231..0000000000 --- a/src/Employer/UnitTests/Employer.Web/UtilityTests/CheckRouteIsValidForVacancyTests.cs +++ /dev/null @@ -1,417 +0,0 @@ -using System; -using Esfa.Recruit.Employer.Web; -using Esfa.Recruit.Employer.Web.Configuration; -using Esfa.Recruit.Employer.Web.Configuration.Routing; -using Esfa.Recruit.Employer.Web.Exceptions; -using Esfa.Recruit.Shared.Web.FeatureToggle; -using Esfa.Recruit.Vacancies.Client.Domain.Entities; -using Esfa.Recruit.Vacancies.Client.Infrastructure.Client; -using FluentAssertions; -using Moq; -using Xunit; - -namespace Esfa.Recruit.Employer.UnitTests.Employer.Web.UtilityTests -{ - public class CheckRouteIsValidForVacancyTests - { - [Theory] - [InlineData(RouteNames.Title_Get, false)] - [InlineData(RouteNames.Title_Post, false)] - [InlineData("any other route", true)] - public void ShouldRedirectToTitle(string route, bool shouldRedirect) - { - var vacancy = new Vacancy - { - EmployerAccountId = "EMPLOYER ACCOUNT ID", - Id = Guid.Parse("84af954e-5baf-4942-897d-d00180a0839e") - }; - - CheckRouteIsValidForVacancyTest(vacancy, route, shouldRedirect, RouteNames.Title_Get); - } - - [Theory] - [InlineData(RouteNames.Title_Get, false)] - [InlineData(RouteNames.Title_Post, false)] - [InlineData(RouteNames.Training_Get, false)] - [InlineData(RouteNames.Training_Post, false)] - [InlineData(RouteNames.Training_Confirm_Get, false)] - [InlineData(RouteNames.Training_Confirm_Post, false)] - [InlineData(RouteNames.Training_First_Time_Get, false)] - [InlineData(RouteNames.Training_First_Time_Post, false)] - [InlineData(RouteNames.Training_Help_Get, false)] - [InlineData("any other route", true)] - public void ShouldRedirectToTraining(string route, bool shouldRedirect) - { - var vacancy = new Vacancy - { - EmployerAccountId = "EMPLOYER ACCOUNT ID", - Id = Guid.Parse("84af954e-5baf-4942-897d-d00180a0839e"), - Title = "has a value" - }; - - CheckRouteIsValidForVacancyTest(vacancy, route, shouldRedirect, RouteNames.Training_Get); - } - - [Theory] - [InlineData(RouteNames.Title_Get, false)] - [InlineData(RouteNames.Title_Post, false)] - [InlineData(RouteNames.Training_Get, false)] - [InlineData(RouteNames.Training_Post, false)] - [InlineData(RouteNames.Training_Confirm_Get, false)] - [InlineData(RouteNames.Training_Confirm_Post, false)] - [InlineData(RouteNames.Training_First_Time_Get, false)] - [InlineData(RouteNames.Training_First_Time_Post, false)] - [InlineData(RouteNames.Training_Help_Get, false)] - [InlineData(RouteNames.TrainingProvider_Select_Get, false)] - [InlineData(RouteNames.TrainingProvider_Select_Post, false)] - [InlineData(RouteNames.TrainingProvider_Confirm_Get, false)] - [InlineData(RouteNames.TrainingProvider_Confirm_Post, false)] - [InlineData(RouteNames.NumberOfPositions_Get, false)] - [InlineData(RouteNames.NumberOfPositions_Post, false)] - [InlineData("any other route", true)] - public void ShouldRedirectToTrainingProvider(string route, bool shouldRedirect) - { - var vacancy = new Vacancy - { - EmployerAccountId = "EMPLOYER ACCOUNT ID", - Id = Guid.Parse("84af954e-5baf-4942-897d-d00180a0839e"), - Title = "has a value", - ProgrammeId = "has a value", - TrainingProvider = null, - NumberOfPositions = null - }; - - CheckRouteIsValidForVacancyTest(vacancy, route, shouldRedirect, RouteNames.TrainingProvider_Select_Get); - } - - [Theory] - [InlineData(RouteNames.Title_Get, false)] - [InlineData(RouteNames.Title_Post, false)] - [InlineData(RouteNames.Training_Get, false)] - [InlineData(RouteNames.Training_Post, false)] - [InlineData(RouteNames.Training_Confirm_Get, false)] - [InlineData(RouteNames.Training_Confirm_Post, false)] - [InlineData(RouteNames.Training_First_Time_Get, false)] - [InlineData(RouteNames.Training_First_Time_Post, false)] - [InlineData(RouteNames.Training_Help_Get, false)] - [InlineData(RouteNames.NumberOfPositions_Get, false)] - [InlineData(RouteNames.NumberOfPositions_Post, false)] - [InlineData(RouteNames.Employer_Get, false)] - [InlineData(RouteNames.Employer_Post, false)] - [InlineData("any other route", true)] - public void ShouldRedirectToEmployer(string route, bool shouldRedirect) - { - var vacancy = new Vacancy - { - EmployerAccountId = "EMPLOYER ACCOUNT ID", - Id = Guid.Parse("84af954e-5baf-4942-897d-d00180a0839e"), - Title = "has a value", - ProgrammeId = "has a value", - NumberOfPositions = 3 - }; - - CheckRouteIsValidForVacancyTest(vacancy, route, shouldRedirect, RouteNames.Employer_Get); - } - - [Theory] - [InlineData(RouteNames.Title_Get, false)] - [InlineData(RouteNames.Title_Post, false)] - [InlineData(RouteNames.Training_Get, false)] - [InlineData(RouteNames.Training_Post, false)] - [InlineData(RouteNames.Training_Confirm_Get, false)] - [InlineData(RouteNames.Training_Confirm_Post, false)] - [InlineData(RouteNames.Training_First_Time_Get, false)] - [InlineData(RouteNames.Training_First_Time_Post, false)] - [InlineData(RouteNames.Training_Help_Get, false)] - [InlineData(RouteNames.TrainingProvider_Select_Get, false)] - [InlineData(RouteNames.TrainingProvider_Select_Post, false)] - [InlineData(RouteNames.TrainingProvider_Confirm_Get, false)] - [InlineData(RouteNames.TrainingProvider_Confirm_Post, false)] - [InlineData(RouteNames.NumberOfPositions_Get, false)] - [InlineData(RouteNames.NumberOfPositions_Post, false)] - [InlineData(RouteNames.ShortDescription_Get, false, true)] - [InlineData(RouteNames.ShortDescription_Post, false, true)] - [InlineData(RouteNames.VacancyDescription_Index_Get, false, true)] - [InlineData(RouteNames.VacancyDescription_Index_Post, false, true)] - [InlineData(RouteNames.Dates_Post, false, true)] - [InlineData(RouteNames.Dates_Get, false, true)] - [InlineData(RouteNames.Duration_Post, false, true)] - [InlineData(RouteNames.Duration_Get, false, true)] - [InlineData(RouteNames.Wage_Post, false, true)] - [InlineData(RouteNames.Wage_Get, false, true)] - [InlineData(RouteNames.Skills_Post, false, true)] - [InlineData(RouteNames.Skills_Get, false, true)] - [InlineData(RouteNames.Qualification_Add_Post, false, true)] - [InlineData(RouteNames.Qualification_Delete_Post, false, true)] - [InlineData(RouteNames.Qualification_Edit_Post, false, true)] - [InlineData(RouteNames.Qualification_Edit_Get, false, true)] - [InlineData(RouteNames.Qualification_Add_Get, false, true)] - [InlineData(RouteNames.Qualifications_Get, false, true)] - [InlineData(RouteNames.Considerations_Post, false, true)] - [InlineData(RouteNames.Considerations_Get, false, true)] - [InlineData(RouteNames.EmployerName_Post, false, true)] - [InlineData(RouteNames.EmployerName_Get, false, true)] - [InlineData(RouteNames.AboutEmployer_Post, false, true)] - [InlineData(RouteNames.AboutEmployer_Get, false, true)] - [InlineData(RouteNames.EmployerContactDetails_Post, false, true)] - [InlineData(RouteNames.EmployerContactDetails_Get, false, true)] - [InlineData(RouteNames.ApplicationProcess_Post, false, true)] - [InlineData(RouteNames.ApplicationProcess_Get, false, true)] - [InlineData("any other route", true)] - public void ShouldRedirectToNumberOfPositions(string route, bool shouldRedirect, bool enableTaskList = false) - { - var vacancy = new Vacancy { - EmployerAccountId = "EMPLOYER ACCOUNT ID", - Id = Guid.Parse("84af954e-5baf-4942-897d-d00180a0839e"), - Title = "has a value", - ProgrammeId = "has a value", - TrainingProvider = new TrainingProvider(), - NumberOfPositions = null, - }; - - CheckRouteIsValidForVacancyTest(vacancy, route, shouldRedirect, RouteNames.NumberOfPositions_Get, enableTaskList); - } - - [Theory] - [InlineData(RouteNames.Title_Get, false)] - [InlineData(RouteNames.Title_Post, false)] - [InlineData(RouteNames.Training_Get, false)] - [InlineData(RouteNames.Training_Post, false)] - [InlineData(RouteNames.Training_Confirm_Get, false)] - [InlineData(RouteNames.Training_Confirm_Post, false)] - [InlineData(RouteNames.Training_First_Time_Get, false)] - [InlineData(RouteNames.Training_First_Time_Post, false)] - [InlineData(RouteNames.Training_Help_Get, false)] - [InlineData(RouteNames.NumberOfPositions_Get, false)] - [InlineData(RouteNames.NumberOfPositions_Post, false)] - [InlineData(RouteNames.Employer_Get, false)] - [InlineData(RouteNames.Employer_Post, false)] - [InlineData(RouteNames.EmployerName_Get, false)] - [InlineData(RouteNames.EmployerName_Post, false)] - [InlineData(RouteNames.Location_Get, false)] - [InlineData(RouteNames.Location_Post, false)] - [InlineData(RouteNames.LegalEntityAgreement_SoftStop_Get, false)] - [InlineData("any other route", true)] - public void ShouldRedirectToDates(string route, bool shouldRedirect) - { - var vacancy = new Vacancy - { - EmployerAccountId = "EMPLOYER ACCOUNT ID", - Id = Guid.Parse("84af954e-5baf-4942-897d-d00180a0839e"), - Title = "has a value", - ProgrammeId = "has a value", - NumberOfPositions = 3, - LegalEntityName = "legal name", - EmployerNameOption = EmployerNameOption.RegisteredName, - EmployerLocation = new Address { Postcode = "has a value" } - }; - - CheckRouteIsValidForVacancyTest(vacancy, route, shouldRedirect, RouteNames.Dates_Get); - } - - [Theory] - [InlineData(RouteNames.Title_Get, false)] - [InlineData(RouteNames.Title_Post, false)] - [InlineData(RouteNames.Training_Get, false)] - [InlineData(RouteNames.Training_Post, false)] - [InlineData(RouteNames.Training_Confirm_Get, false)] - [InlineData(RouteNames.Training_Confirm_Post, false)] - [InlineData(RouteNames.Training_First_Time_Get, false)] - [InlineData(RouteNames.Training_First_Time_Post, false)] - [InlineData(RouteNames.Training_Help_Get, false)] - [InlineData(RouteNames.NumberOfPositions_Get, false)] - [InlineData(RouteNames.NumberOfPositions_Post, false)] - [InlineData(RouteNames.Employer_Get, false)] - [InlineData(RouteNames.Employer_Post, false)] - [InlineData(RouteNames.EmployerName_Get, false)] - [InlineData(RouteNames.EmployerName_Post, false)] - [InlineData(RouteNames.Location_Get, false)] - [InlineData(RouteNames.Location_Post, false)] - [InlineData(RouteNames.LegalEntityAgreement_SoftStop_Get, false)] - [InlineData(RouteNames.Duration_Get, false)] - [InlineData(RouteNames.Duration_Post, false)] - [InlineData("any other route", true)] - public void ShouldRedirectToDuration(string route, bool shouldRedirect) - { - var vacancy = new Vacancy - { - EmployerAccountId = "EMPLOYER ACCOUNT ID", - Id = Guid.Parse("84af954e-5baf-4942-897d-d00180a0839e"), - Title = "has a value", - ProgrammeId = "has a value", - NumberOfPositions = 3, - LegalEntityName = "legal name", - EmployerNameOption = EmployerNameOption.RegisteredName, - EmployerLocation = new Address { Postcode = "has a value" }, - StartDate = DateTime.Now - }; - - CheckRouteIsValidForVacancyTest(vacancy, route, shouldRedirect, RouteNames.Duration_Get); - } - - [Theory] - [InlineData(RouteNames.Title_Get, false)] - [InlineData(RouteNames.Title_Post, false)] - [InlineData(RouteNames.Training_Get, false)] - [InlineData(RouteNames.Training_Post, false)] - [InlineData(RouteNames.Training_Confirm_Get, false)] - [InlineData(RouteNames.Training_Confirm_Post, false)] - [InlineData(RouteNames.Training_First_Time_Get, false)] - [InlineData(RouteNames.Training_First_Time_Post, false)] - [InlineData(RouteNames.Training_Help_Get, false)] - [InlineData(RouteNames.NumberOfPositions_Get, false)] - [InlineData(RouteNames.NumberOfPositions_Post, false)] - [InlineData(RouteNames.Employer_Get, false)] - [InlineData(RouteNames.Employer_Post, false)] - [InlineData(RouteNames.EmployerName_Get, false)] - [InlineData(RouteNames.EmployerName_Post, false)] - [InlineData(RouteNames.Location_Get, false)] - [InlineData(RouteNames.Location_Post, false)] - [InlineData(RouteNames.LegalEntityAgreement_SoftStop_Get, false)] - [InlineData(RouteNames.Duration_Get, false)] - [InlineData(RouteNames.Duration_Post, false)] - [InlineData(RouteNames.Wage_Get, false)] - [InlineData(RouteNames.Wage_Post, false)] - [InlineData("any other route", true)] - public void ShouldRedirectToWage(string route, bool shouldRedirect) - { - var vacancy = new Vacancy - { - EmployerAccountId = "EMPLOYER ACCOUNT ID", - Id = Guid.Parse("84af954e-5baf-4942-897d-d00180a0839e"), - Title = "has a value", - ProgrammeId = "has a value", - NumberOfPositions = 3, - LegalEntityName = "legal name", - EmployerNameOption = EmployerNameOption.RegisteredName, - EmployerLocation = new Address { Postcode = "has a value" }, - StartDate = DateTime.Now, - Wage = new Wage { Duration = 1 } - }; - - CheckRouteIsValidForVacancyTest(vacancy, route, shouldRedirect, RouteNames.Wage_Get); - } - - [Theory] - [InlineData("any other route", false)] - public void ShouldNotRedirect(string route, bool shouldRedirect) - { - var vacancy = new Vacancy - { - EmployerAccountId = "EMPLOYER ACCOUNT ID", - Id = Guid.Parse("84af954e-5baf-4942-897d-d00180a0839e"), - Title = "has a value", - ProgrammeId = "has a value", - NumberOfPositions = 3, - LegalEntityName = "legal name", - EmployerNameOption = EmployerNameOption.RegisteredName, - EmployerLocation = new Address { Postcode = "has a value" }, - StartDate = DateTime.Now, - Wage = new Wage - { - Duration = 1, - WageType = WageType.FixedWage - } - }; - - CheckRouteIsValidForVacancyTest(vacancy, route, shouldRedirect, null); - } - - [Fact] - public void ShouldRedirectToEmployerGet() - { - var vacancy = new Vacancy - { - EmployerAccountId = "EMPLOYER ACCOUNT ID", - Id = Guid.Parse("84af954e-5baf-4942-897d-d00180a0839e"), - Title = "has a value", - ProgrammeId = "has a value", - NumberOfPositions = 3, - EmployerNameOption = EmployerNameOption.RegisteredName, - EmployerLocation = new Address { Postcode = "has a value" }, - Wage = new Wage { WageType = WageType.FixedWage} - }; - - CheckRouteIsValidForVacancyTest(vacancy, RouteNames.Employer_Get, false, null); - } - - [Fact] - public void ShouldRedirectToEmployerNameGet() - { - var vacancy = new Vacancy - { - EmployerAccountId = "EMPLOYER ACCOUNT ID", - Id = Guid.Parse("84af954e-5baf-4942-897d-d00180a0839e"), - Title = "has a value", - ProgrammeId = "has a value", - NumberOfPositions = 3, - LegalEntityName = "legal name", - EmployerLocation = new Address { Postcode = "has a value" }, - Wage = new Wage { WageType = WageType.FixedWage} - }; - - CheckRouteIsValidForVacancyTest(vacancy, RouteNames.EmployerName_Get, false, null); - } - - [Fact] - public void ShouldRedirectToLocationGet() - { - var vacancy = new Vacancy - { - EmployerAccountId = "EMPLOYER ACCOUNT ID", - Id = Guid.Parse("84af954e-5baf-4942-897d-d00180a0839e"), - Title = "has a value", - ProgrammeId = "has a value", - NumberOfPositions = 3, - LegalEntityName = "legal name", - EmployerNameOption = EmployerNameOption.RegisteredName, - Wage = new Wage { WageType = WageType.FixedWage} - }; - - CheckRouteIsValidForVacancyTest(vacancy, RouteNames.Location_Get, false, null); - } - - [Fact] - public void ShouldShowTaskList() - { - var vacancy = new Vacancy - { - EmployerAccountId = "EMPLOYER ACCOUNT ID", - Id = Guid.Parse("84af954e-5baf-4942-897d-d00180a0839e") - }; - - CheckRouteIsValidForVacancyTest(vacancy, RouteNames.EmployerTaskListGet, false, null, true); - } - - [Fact] - public void ShouldShowCheckYourAnswers() - { - var vacancy = new Vacancy - { - EmployerAccountId = "EMPLOYER ACCOUNT ID", - Id = Guid.Parse("84af954e-5baf-4942-897d-d00180a0839e") - }; - - CheckRouteIsValidForVacancyTest(vacancy, RouteNames.EmployerCheckYourAnswersGet, false, null, true); - } - - private void CheckRouteIsValidForVacancyTest(Vacancy vacancy, string route, bool shouldRedirect, string expectedRedirectRoute, bool enableTaskList = false) - { - var featureMock = new Mock(); - featureMock.Setup(x=>x.IsFeatureEnabled(FeatureNames.EmployerTaskList)).Returns(enableTaskList); - var utility = new Utility(Mock.Of(), featureMock.Object); - if (!shouldRedirect) - { - utility.CheckRouteIsValidForVacancy(vacancy, route); - return; - } - - var ex = Assert.Throws(() => utility.CheckRouteIsValidForVacancy(vacancy, route)); - - ex.RouteNameToRedirectTo.Should().Be(expectedRedirectRoute); - ex.RouteValues.EmployerAccountId.Should().Be(vacancy.EmployerAccountId); - ex.RouteValues.VacancyId.Should().Be(vacancy.Id); - } - - } -} diff --git a/src/Employer/UnitTests/Employer.Web/UtilityTests/GetAuthorisedApplicationReviewAsyncTests.cs b/src/Employer/UnitTests/Employer.Web/UtilityTests/GetAuthorisedApplicationReviewAsyncTests.cs index 5667f3b9eb..5ba4766e58 100644 --- a/src/Employer/UnitTests/Employer.Web/UtilityTests/GetAuthorisedApplicationReviewAsyncTests.cs +++ b/src/Employer/UnitTests/Employer.Web/UtilityTests/GetAuthorisedApplicationReviewAsyncTests.cs @@ -2,7 +2,6 @@ using System.Threading.Tasks; using Esfa.Recruit.Employer.Web; using Esfa.Recruit.Employer.Web.RouteModel; -using Esfa.Recruit.Shared.Web.FeatureToggle; using Esfa.Recruit.Vacancies.Client.Domain.Entities; using Esfa.Recruit.Vacancies.Client.Domain.Exceptions; using Esfa.Recruit.Vacancies.Client.Infrastructure.Client; @@ -39,7 +38,7 @@ public GetAuthorisedApplicationReviewAsyncTests() Id = _vacancyId }); - _utility = new Utility(_mockVacancyClient.Object, Mock.Of()); + _utility = new Utility(_mockVacancyClient.Object); } [Fact] diff --git a/src/Employer/UnitTests/Employer.Web/UtilityTests/VacancyHasStartedPartTwoTests.cs b/src/Employer/UnitTests/Employer.Web/UtilityTests/VacancyHasStartedPartTwoTests.cs index 001e15b39f..84cbad0274 100644 --- a/src/Employer/UnitTests/Employer.Web/UtilityTests/VacancyHasStartedPartTwoTests.cs +++ b/src/Employer/UnitTests/Employer.Web/UtilityTests/VacancyHasStartedPartTwoTests.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using Esfa.Recruit.Employer.Web; -using Esfa.Recruit.Shared.Web.FeatureToggle; using Esfa.Recruit.Vacancies.Client.Domain.Entities; using Esfa.Recruit.Vacancies.Client.Infrastructure.Client; using FluentAssertions; @@ -14,7 +13,7 @@ public class VacancyHasStartedPartTwoTests private Utility _utility; public VacancyHasStartedPartTwoTests () { - _utility = new Utility(Mock.Of(), Mock.Of()); + _utility = new Utility(Mock.Of()); } [Fact] public void ShouldReturnTrueIfAnyPartTwoFieldsAreCompleted() diff --git a/src/Provider/Provider.Web/Controllers/VacancyCheckYourAnswersController.cs b/src/Provider/Provider.Web/Controllers/VacancyCheckYourAnswersController.cs index 2fdd9019fa..99035151ab 100644 --- a/src/Provider/Provider.Web/Controllers/VacancyCheckYourAnswersController.cs +++ b/src/Provider/Provider.Web/Controllers/VacancyCheckYourAnswersController.cs @@ -31,10 +31,15 @@ public VacancyCheckYourAnswersController (VacancyTaskListOrchestrator orchestrat [HttpGet("{vacancyId:guid}/check-your-answers", Name = RouteNames.ProviderCheckYourAnswersGet)] public async Task CheckYourAnswers(VacancyRouteModel vrm) { - var viewModel = await _orchestrator.GetVacancyTaskListModel(vrm); + var viewModel = await _orchestrator.GetVacancyTaskListModel(vrm, User.ToVacancyUser()); viewModel.CanHideValidationSummary = true; AddSoftValidationErrorsToModelState(viewModel); viewModel.SetSectionStates(viewModel, ModelState); + + if (viewModel.TaskListSectionOneState == VacancyTaskListSectionState.InProgress) + { + return RedirectToRoute(RouteNames.ProviderTaskListGet, new {vrm.Ukprn, vrm.VacancyId}); + } if (TempData.ContainsKey(TempDataKeys.VacancyPreviewInfoMessage)) viewModel.VacancyClonedInfoMessage = TempData[TempDataKeys.VacancyPreviewInfoMessage].ToString(); @@ -72,7 +77,7 @@ public async Task CheckYourAnswers(SubmitEditModel m) if(response.Errors.Errors.Any(e => e.ErrorCode == ErrorCodes.TrainingProviderMustHaveEmployerPermission)) throw new MissingPermissionsException(string.Format(RecruitWebExceptionMessages.ProviderMissingPermission, m.Ukprn)); - var viewModel = await _orchestrator.GetVacancyTaskListModel(m); + var viewModel = await _orchestrator.GetVacancyTaskListModel(m, User.ToVacancyUser()); viewModel.SoftValidationErrors = null; viewModel.SetSectionStates(viewModel, ModelState); diff --git a/src/Provider/Provider.Web/Controllers/VacancyTaskListController.cs b/src/Provider/Provider.Web/Controllers/VacancyTaskListController.cs index ee5f663c25..131621bbbe 100644 --- a/src/Provider/Provider.Web/Controllers/VacancyTaskListController.cs +++ b/src/Provider/Provider.Web/Controllers/VacancyTaskListController.cs @@ -1,6 +1,7 @@ using System.Threading.Tasks; using Esfa.Recruit.Provider.Web.Configuration; using Esfa.Recruit.Provider.Web.Configuration.Routing; +using Esfa.Recruit.Provider.Web.Extensions; using Esfa.Recruit.Provider.Web.Orchestrators; using Esfa.Recruit.Provider.Web.RouteModel; using Esfa.Recruit.Vacancies.Client.Domain.Entities; @@ -39,7 +40,7 @@ public async Task CreateProviderTaskList(VacancyRouteModel vrm, [ public async Task ProviderTaskList(VacancyRouteModel vrm) { - var viewModel = await _orchestrator.GetVacancyTaskListModel(vrm); + var viewModel = await _orchestrator.GetVacancyTaskListModel(vrm, User.ToVacancyUser()); viewModel.SetSectionStates(viewModel, ModelState); if (viewModel.Status == VacancyStatus.Rejected || viewModel.Status == VacancyStatus.Referred) diff --git a/src/Provider/Provider.Web/Orchestrators/VacancyTaskListOrchestrator.cs b/src/Provider/Provider.Web/Orchestrators/VacancyTaskListOrchestrator.cs index 3675655405..e1759f9420 100644 --- a/src/Provider/Provider.Web/Orchestrators/VacancyTaskListOrchestrator.cs +++ b/src/Provider/Provider.Web/Orchestrators/VacancyTaskListOrchestrator.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -55,7 +56,7 @@ public VacancyTaskListOrchestrator(ILogger logger, _serviceParameters = serviceParameters; } - public async Task GetVacancyTaskListModel(VacancyRouteModel routeModel) + public async Task GetVacancyTaskListModel(VacancyRouteModel routeModel, VacancyUser user) { var vacancyTask = _utility.GetAuthorisedVacancyForEditAsync(routeModel, RouteNames.ProviderTaskListGet); var programmesTask = _vacancyClient.GetActiveApprenticeshipProgrammesAsync(); @@ -69,6 +70,30 @@ await _providerVacancyClient.GetProviderEmployerVacancyDataAsync(routeModel.Ukpr var vacancy = vacancyTask.Result; var programme = programmesTask.Result.SingleOrDefault(p => p.Id == vacancy.ProgrammeId); var hasProviderReviewPermission = await _providerRelationshipsService.HasProviderGotEmployersPermissionAsync(routeModel.Ukprn, vacancy.EmployerAccountId, vacancy.AccountLegalEntityPublicHashedId, OperationType.RecruitmentRequiresReview); + + + if (employerInfo.LegalEntities.FirstOrDefault(c => + c.AccountLegalEntityPublicHashedId.Equals(vacancy.AccountLegalEntityPublicHashedId)) == null) + { + if (employerInfo.LegalEntities.Count == 1) + { + vacancy.LegalEntityName = employerInfo.LegalEntities.FirstOrDefault()?.Name; + vacancy.AccountLegalEntityPublicHashedId = employerInfo.LegalEntities.FirstOrDefault()?.AccountLegalEntityPublicHashedId; + } + else + { + vacancy.LegalEntityName = null; + vacancy.AccountLegalEntityPublicHashedId = null; + } + vacancy.EmployerName = null; + + vacancy.EmployerLocation = null; + + vacancy.EmployerNameOption = null; + vacancy.EmployerDescription = null; + await _vacancyClient.UpdateDraftVacancyAsync(vacancy, user); + } + var vm = new VacancyPreviewViewModel(); await _vacancyDisplayMapper.MapFromVacancyAsync(vm, vacancy); diff --git a/src/Provider/UnitTests/Provider.Web/Orchestrators/VacancyTaskListOrchestratorTests.cs b/src/Provider/UnitTests/Provider.Web/Orchestrators/VacancyTaskListOrchestratorTests.cs index 6d1cc3c8eb..dbda3dc35e 100644 --- a/src/Provider/UnitTests/Provider.Web/Orchestrators/VacancyTaskListOrchestratorTests.cs +++ b/src/Provider/UnitTests/Provider.Web/Orchestrators/VacancyTaskListOrchestratorTests.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using AutoFixture.NUnit3; using Esfa.Recruit.Provider.Web; @@ -31,7 +32,8 @@ public async Task Then_The_Vacancy_Is_Retrieved_And_Mapped( VacancyRouteModel routeModel, ApprenticeshipProgramme programme, Vacancy vacancy, - List legalEntities, + EmployerInfo employerInfo, + VacancyUser user, [Frozen] Mock> externalLinksConfiguration, [Frozen] Mock utility, [Frozen] Mock recruitVacancyClient, @@ -45,6 +47,7 @@ public async Task Then_The_Vacancy_Is_Retrieved_And_Mapped( programme.Id = vacancy.ProgrammeId; programme.EducationLevelNumber = 3; programme.ApprenticeshipLevel = ApprenticeshipLevel.Higher; + employerInfo.LegalEntities.FirstOrDefault().AccountLegalEntityPublicHashedId = vacancy.AccountLegalEntityPublicHashedId; providerRelationshipsService.Setup(x => x.HasProviderGotEmployersPermissionAsync(routeModel.Ukprn, vacancy.EmployerAccountId, vacancy.AccountLegalEntityPublicHashedId, OperationType.RecruitmentRequiresReview)).ReturnsAsync(false); @@ -58,12 +61,14 @@ public async Task Then_The_Vacancy_Is_Retrieved_And_Mapped( .ReturnsAsync(programme); recruitVacancyClient.Setup(x => x.GetEmployerDescriptionAsync(vacancy)).ReturnsAsync(vacancy.EmployerDescription); recruitVacancyClient.Setup(x => x.GetEmployerNameAsync(vacancy)).ReturnsAsync(vacancy.EmployerName); + providerVacancyClient.Setup(x => x.GetProviderEmployerVacancyDataAsync(routeModel.Ukprn, vacancy.EmployerAccountId)) + .ReturnsAsync(employerInfo); externalLinksConfiguration.Object.Value.FindAnApprenticeshipUrl = findAnApprenticeshipUrl; var expectedViewModel = new VacancyPreviewViewModel(); var mapper = new DisplayVacancyViewModelMapper(Mock.Of(), externalLinksConfiguration.Object, recruitVacancyClient.Object, providerVacancyClient.Object); - var viewModel = await orchestrator.GetVacancyTaskListModel(routeModel); + var viewModel = await orchestrator.GetVacancyTaskListModel(routeModel, user); await mapper.MapFromVacancyAsync(expectedViewModel, vacancy); viewModel.Should().BeAssignableTo(); @@ -87,6 +92,125 @@ public async Task Then_The_Vacancy_Is_Retrieved_And_Mapped( viewModel.Ukprn.Should().Be(routeModel.Ukprn); viewModel.VacancyId.Should().Be(routeModel.VacancyId); } + + + [Test, MoqAutoData] + public async Task Then_If_The_Legal_Entity_Is_No_Longer_Available_Then_Employer_Options_Not_Set( + string findAnApprenticeshipUrl, + VacancyRouteModel routeModel, + ApprenticeshipProgramme programme, + Vacancy vacancy, + EmployerInfo employerInfo, + VacancyUser user, + [Frozen] Mock> externalLinksConfiguration, + [Frozen] Mock utility, + [Frozen] Mock recruitVacancyClient, + [Frozen] Mock providerVacancyClient, + [Frozen] Mock providerRelationshipsService, + VacancyTaskListOrchestrator orchestrator) + { + vacancy.EmployerLocation = null; + vacancy.EmployerNameOption = EmployerNameOption.RegisteredName; + vacancy.ClosedDate = null; + programme.Id = vacancy.ProgrammeId; + programme.EducationLevelNumber = 3; + programme.ApprenticeshipLevel = ApprenticeshipLevel.Higher; + providerRelationshipsService.Setup(x => x.HasProviderGotEmployersPermissionAsync(routeModel.Ukprn, + vacancy.EmployerAccountId, vacancy.AccountLegalEntityPublicHashedId, + OperationType.RecruitmentRequiresReview)).ReturnsAsync(false); + utility.Setup(x => x.GetAuthorisedVacancyForEditAsync(It.Is( + c => c.VacancyId.Equals(routeModel.VacancyId) && + c.Ukprn.Equals(routeModel.Ukprn)), RouteNames.ProviderTaskListGet)) + .ReturnsAsync(vacancy); + recruitVacancyClient.Setup(x => x.GetActiveApprenticeshipProgrammesAsync()) + .ReturnsAsync(new List{ programme}); + recruitVacancyClient.Setup(x => x.GetApprenticeshipProgrammeAsync(programme.Id)) + .ReturnsAsync(programme); + recruitVacancyClient.Setup(x => x.GetEmployerDescriptionAsync(vacancy)).ReturnsAsync(string.Empty); + recruitVacancyClient.Setup(x => x.GetEmployerNameAsync(vacancy)).ReturnsAsync(string.Empty); + providerVacancyClient.Setup(x => x.GetProviderEmployerVacancyDataAsync(routeModel.Ukprn, vacancy.EmployerAccountId)) + .ReturnsAsync(employerInfo); + externalLinksConfiguration.Object.Value.FindAnApprenticeshipUrl = findAnApprenticeshipUrl; + var expectedViewModel = new VacancyPreviewViewModel(); + var mapper = new DisplayVacancyViewModelMapper(Mock.Of(), + externalLinksConfiguration.Object, recruitVacancyClient.Object, providerVacancyClient.Object); + + var viewModel = await orchestrator.GetVacancyTaskListModel(routeModel, user); + + await mapper.MapFromVacancyAsync(expectedViewModel, vacancy); + recruitVacancyClient.Verify(x=>x.UpdateDraftVacancyAsync(It.Is(c=> + c.EmployerName == null + && c.LegalEntityName == null + && c.AccountLegalEntityPublicHashedId == null + && c.EmployerNameOption == null + && c.EmployerDescription == null + && c.EmployerLocation == null + ), user), Times.Once); + viewModel.EmployerName.Should().BeNullOrEmpty(); + viewModel.AccountLegalEntityPublicHashedId.Should().BeNullOrEmpty(); + viewModel.EmployerAddressSectionState.Should().Be(VacancyPreviewSectionState.Incomplete); + viewModel.HasSelectedEmployerNameOption.Should().BeFalse(); + viewModel.HasEmployerDescription.Should().BeFalse(); + } + + [Test, MoqAutoData] + public async Task If_Legal_Entity_No_Longer_Exists_And_Only_One_Available_Then_Updated_To_That_Legal_Entity( + string findAnApprenticeshipUrl, + VacancyRouteModel routeModel, + ApprenticeshipProgramme programme, + Vacancy vacancy, + LegalEntity legalEntity, + VacancyUser user, + [Frozen] Mock> externalLinksConfiguration, + [Frozen] Mock utility, + [Frozen] Mock recruitVacancyClient, + [Frozen] Mock providerVacancyClient, + [Frozen] Mock providerRelationshipsService, + VacancyTaskListOrchestrator orchestrator) + { + vacancy.EmployerLocation = null; + vacancy.EmployerNameOption = EmployerNameOption.RegisteredName; + vacancy.ClosedDate = null; + programme.Id = vacancy.ProgrammeId; + programme.EducationLevelNumber = 3; + programme.ApprenticeshipLevel = ApprenticeshipLevel.Higher; + providerRelationshipsService.Setup(x => x.HasProviderGotEmployersPermissionAsync(routeModel.Ukprn, + vacancy.EmployerAccountId, vacancy.AccountLegalEntityPublicHashedId, + OperationType.RecruitmentRequiresReview)).ReturnsAsync(false); + utility.Setup(x => x.GetAuthorisedVacancyForEditAsync(It.Is( + c => c.VacancyId.Equals(routeModel.VacancyId) && + c.Ukprn.Equals(routeModel.Ukprn)), RouteNames.ProviderTaskListGet)) + .ReturnsAsync(vacancy); + recruitVacancyClient.Setup(x => x.GetActiveApprenticeshipProgrammesAsync()) + .ReturnsAsync(new List{ programme}); + recruitVacancyClient.Setup(x => x.GetApprenticeshipProgrammeAsync(programme.Id)) + .ReturnsAsync(programme); + recruitVacancyClient.Setup(x => x.GetEmployerDescriptionAsync(vacancy)).ReturnsAsync(string.Empty); + recruitVacancyClient.Setup(x => x.GetEmployerNameAsync(vacancy)).ReturnsAsync(string.Empty); + providerVacancyClient.Setup(x => x.GetProviderEmployerVacancyDataAsync(routeModel.Ukprn, vacancy.EmployerAccountId)) + .ReturnsAsync(new EmployerInfo{LegalEntities = new List{legalEntity}}); + externalLinksConfiguration.Object.Value.FindAnApprenticeshipUrl = findAnApprenticeshipUrl; + var expectedViewModel = new VacancyPreviewViewModel(); + var mapper = new DisplayVacancyViewModelMapper(Mock.Of(), + externalLinksConfiguration.Object, recruitVacancyClient.Object, providerVacancyClient.Object); + + var viewModel = await orchestrator.GetVacancyTaskListModel(routeModel, user); + + await mapper.MapFromVacancyAsync(expectedViewModel, vacancy); + recruitVacancyClient.Verify(x=>x.UpdateDraftVacancyAsync(It.Is(c=> + c.EmployerName == null + && c.LegalEntityName.Equals(legalEntity.Name) + && c.AccountLegalEntityPublicHashedId.Equals(legalEntity.AccountLegalEntityPublicHashedId) + && c.EmployerNameOption == null + && c.EmployerDescription == null + && c.EmployerLocation == null + ), user), Times.Once); + viewModel.EmployerName.Should().BeNullOrEmpty(); + viewModel.AccountLegalEntityPublicHashedId.Should().Be(legalEntity.AccountLegalEntityPublicHashedId); + viewModel.EmployerAddressSectionState.Should().Be(VacancyPreviewSectionState.Incomplete); + viewModel.HasSelectedEmployerNameOption.Should().BeFalse(); + viewModel.HasEmployerDescription.Should().BeFalse(); + } [Test, MoqAutoData] public async Task When_Creating_New_Then_The_Account_Legal_Entity_Count_Is_Populated(