private void CloseVacancy(Vacancy vacancy, VacancyUser initiatingUser) { vacancy.Status = VacancyStatus.Closed; vacancy.ClosedDate = _timeProvider.Now; vacancy.ClosedByUser = initiatingUser; vacancy.ClosureReason = ClosureReason.TransferredByEmployer; }
public TransferProviderVacancyCommand(Guid vacancyId, VacancyUser user, DateTime transferredDate, TransferReason reason) { VacancyId = vacancyId; TransferredByUser = user; TransferredDate = transferredDate; Reason = reason; }
[InlineData("1", "4", "2018", "20", "4", "2019")] //BST public async Task PostCreateViewModelAsync_ShouldUseCustomTimespan(string fromDay, string fromMonth, string fromYear, string toDay, string toMonth, string toYear) { long ukprn = 12345678; var model = new ProviderApplicationsReportCreateEditModel { Ukprn = ukprn, DateRange = DateRangeType.Custom, FromDay = fromDay, FromMonth = fromMonth, FromYear = fromYear, ToDay = toDay, ToMonth = toMonth, ToYear = toYear, }; var user = new VacancyUser(); var mockClient = new Mock <IProviderVacancyClient>(); var orchestrator = GetOrchestrator(mockClient.Object, "2019-12-05Z"); var fromDateUtc = DateTimeOffset.Parse($"{fromYear}-{fromMonth}-{fromDay}Z").UtcDateTime; var toDateUtc = DateTimeOffset.Parse($"{toYear}-{toMonth}-{toDay}Z").UtcDateTime; await orchestrator.PostCreateViewModelAsync(model, user); string expectedReportName = $"{fromDateUtc.AsGdsDate()} to {toDateUtc.AsGdsDate()}"; mockClient.Verify(c => c.CreateProviderApplicationsReportAsync( ukprn, fromDateUtc, toDateUtc.AddDays(1).AddTicks(-1), user, expectedReportName), Times.Once); }
[InlineData(DateRangeType.Last30Days, "2019-04-01Z", "2019-05-01Z")] //BST public async Task PostCreateViewModelAsync_ShouldUseCorrectTimespan(DateRangeType dateRangeType, string fromDate, string toDate) { var mockClient = new Mock <IProviderVacancyClient>(); var orchestrator = GetOrchestrator(mockClient.Object, $"{toDate}"); var fromDateUtc = DateTimeOffset.Parse(fromDate).UtcDateTime; var toDateUtc = DateTimeOffset.Parse(toDate).UtcDateTime; long ukprn = 12345678; var model = new ProviderApplicationsReportCreateEditModel { Ukprn = ukprn, DateRange = dateRangeType }; var user = new VacancyUser(); await orchestrator.PostCreateViewModelAsync(model, user); string expectedReportName = $"{fromDateUtc.AsGdsDate()} to {toDateUtc.AsGdsDate()}"; mockClient.Verify(c => c.CreateProviderApplicationsReportAsync( ukprn, fromDateUtc, toDateUtc.AddDays(1).AddTicks(-1), user, expectedReportName), Times.Once); }
public GetVacanciesViewModelAsyncTests() { var userId = Guid.NewGuid(); _user = new VacancyUser { Email = "*****@*****.**", Name = "Frank Sinatra", Ukprn = 54321, UserId = userId.ToString() }; _userDetails = new User { Ukprn = _user.Ukprn, Email = _user.Email, Name = _user.Name, Id = userId }; _recruitVacancyClientMock = new Mock <IRecruitVacancyClient>(); _recruitVacancyClientMock .Setup(x => x.GetUsersDetailsAsync(_user.UserId)) .ReturnsAsync(_userDetails); _providerAlertsViewModelFactoryMock = new Mock <IProviderAlertsViewModelFactory>(); }
public async Task <DashboardViewModel> GetDashboardViewModelAsync(VacancyUser user) { var dashboardTask = _vacancyClient.GetDashboardAsync(user.Ukprn.Value, createIfNonExistent: true); var userDetailsTask = _client.GetUsersDetailsAsync(user.UserId); await Task.WhenAll(dashboardTask, userDetailsTask); var dashboard = dashboardTask.Result; var userDetails = userDetailsTask.Result; var vacancies = dashboard.Vacancies?.ToList() ?? new List <VacancySummary>(); var transferredVacancies = dashboard.TransferredVacancies?.ToList() ?? new List <ProviderDashboardTransferredVacancy>(); var vm = new DashboardViewModel { Vacancies = vacancies, HasAnyVacancies = vacancies.Any(), NoOfVacanciesClosingSoonWithNoApplications = vacancies.Count(v => v.ClosingDate <= _timeProvider.Today.AddDays(ClosingSoonDays) && v.Status == VacancyStatus.Live && v.ApplicationMethod == ApplicationMethod.ThroughFindAnApprenticeship && v.NoOfApplications == 0), NoOfVacanciesClosingSoon = vacancies.Count(v => v.ClosingDate <= _timeProvider.Today.AddDays(ClosingSoonDays) && v.Status == VacancyStatus.Live), Alerts = _providerAlertsViewModelFactory.Create(dashboard, userDetails) }; return(vm); }
public async Task GivenEmployerDescription_ThenShouldUpdateVacancyWithThatDescripion() { var expectedDescription = "updated description"; var vacancy = new Vacancy { Id = Guid.NewGuid(), EmployerDescription = "old description", IsDeleted = false, Status = VacancyStatus.Draft, VacancyReference = 1234567890 }; vacancy.OwnerType = OwnerType.Employer; var user = new VacancyUser(); var now = DateTime.Now; var message = new SubmitVacancyCommand(vacancy.Id, user, expectedDescription, OwnerType.Employer); var sut = GetSut(vacancy.Id, vacancy, now); await sut.Handle(message, new CancellationToken()); vacancy.Status.Should().Be(VacancyStatus.Submitted); vacancy.SubmittedDate.Should().Be(now); vacancy.SubmittedByUser.Should().Be(user); vacancy.LastUpdatedDate.Should().Be(now); vacancy.LastUpdatedByUser.Should().Be(user); vacancy.EmployerDescription.Should().Be(expectedDescription); }
public async Task CheckClonedVacancyHasCorrectFieldsSet() { var newVacancyId = Guid.NewGuid(); var existingVacancy = GetTestVacancy(); var currentTime = DateTime.UtcNow; Vacancy clone = null; var mockRepository = new Mock <IVacancyRepository>(); var mockTimeProvider = new Mock <ITimeProvider>(); mockTimeProvider.Setup(x => x.Now).Returns(currentTime); mockRepository.Setup(x => x.GetVacancyAsync(existingVacancy.Id)).ReturnsAsync(existingVacancy); mockRepository.Setup(x => x.CreateAsync(It.IsAny <Vacancy>())) .Callback <Vacancy>(arg => clone = arg) .Returns(Task.CompletedTask); var handler = new CloneVacancyCommandHandler( Mock.Of <ILogger <CloneVacancyCommandHandler> >(), mockRepository.Object, Mock.Of <IMessaging>(), mockTimeProvider.Object ); var user = new VacancyUser { Name = "Test", Email = "*****@*****.**", UserId = "123" }; var command = new CloneVacancyCommand(cloneVacancyId: existingVacancy.Id, newVacancyId: newVacancyId, user: user, sourceOrigin: SourceOrigin.EmployerWeb); await handler.Handle(command, new CancellationToken()); AssertUpdatedProperties(existingVacancy, currentTime, clone, command); AssertNulledOutProperties(clone); AssertUnchangedProperties(existingVacancy, clone); }
public CloneVacancyCommand(Guid cloneVacancyId, Guid newVacancyId, VacancyUser user, SourceOrigin sourceOrigin) { IdOfVacancyToClone = cloneVacancyId; NewVacancyId = newVacancyId; User = user; SourceOrigin = sourceOrigin; }
public async Task <DashboardViewModel> GetDashboardViewModelAsync(VacancyUser user) { var dashboardTask = _vacancyClient.GetDashboardAsync(user.Ukprn.Value, createIfNonExistent: true); var userDetailsTask = _client.GetUsersDetailsAsync(user.UserId); var providerTask = _providerRelationshipsService.GetLegalEntitiesForProviderAsync(user.Ukprn.Value, OperationType.RecruitmentRequiresReview); await Task.WhenAll(dashboardTask, userDetailsTask, providerTask); var dashboard = dashboardTask.Result; var userDetails = userDetailsTask.Result; var providerPermissions = providerTask.Result; var vacancies = dashboard.Vacancies?.ToList() ?? new List <VacancySummary>(); var vm = new DashboardViewModel { Vacancies = vacancies, NoOfVacanciesClosingSoonWithNoApplications = vacancies.Count(v => v.ClosingDate <= _timeProvider.Today.AddDays(ClosingSoonDays) && v.Status == VacancyStatus.Live && v.ApplicationMethod == ApplicationMethod.ThroughFindAnApprenticeship && v.NoOfApplications == 0), NoOfVacanciesClosingSoon = vacancies.Count(v => v.ClosingDate <= _timeProvider.Today.AddDays(ClosingSoonDays) && v.Status == VacancyStatus.Live), Alerts = _providerAlertsViewModelFactory.Create(dashboard, userDetails), HasEmployerReviewPermission = providerPermissions.Any() }; return(vm); }
public async Task ShouldNotChangeEmployerDescriptionIfNotSpecifiedInCommand() { var expectedDescription = "initial description"; var vacancy = new Vacancy { Id = Guid.NewGuid(), EmployerDescription = expectedDescription, IsDeleted = false, Status = VacancyStatus.Draft, VacancyReference = 1234567890 }; vacancy.OwnerType = OwnerType.Provider; var user = new VacancyUser(); var now = DateTime.Now; var message = new SubmitVacancyCommand(vacancy.Id, user, OwnerType.Provider); var sut = GetSut(vacancy.Id, vacancy, now); await sut.Handle(message, new CancellationToken()); vacancy.Status.Should().Be(VacancyStatus.Submitted); vacancy.SubmittedDate.Should().Be(now); vacancy.SubmittedByUser.Should().Be(user); vacancy.LastUpdatedDate.Should().Be(now); vacancy.LastUpdatedByUser.Should().Be(user); vacancy.EmployerDescription.Should().Be(expectedDescription); }
private async Task UpsertUserAsync(VacancyUser user, UserType userType) { var now = _timeProvider.Now; var userEntity = await _userRepository.GetAsync(user.UserId) ?? new User { Id = Guid.NewGuid(), IdamsUserId = user.UserId, UserType = userType, CreatedDate = now }; userEntity.Name = user.Name; userEntity.LastSignedInDate = now; userEntity.Email = user.Email; if (userType == UserType.Provider) { userEntity.Ukprn = user.Ukprn; } await _userRepository.UpsertUserAsync(userEntity); if (userType == UserType.Employer) { await _queueService.AddMessageAsync(new UpdateEmployerUserAccountQueueMessage { IdamsUserId = user.UserId }); } }
public Task AssignNextVacancyReviewAsync(VacancyUser user) { return(_messaging.SendCommandAsync(new AssignVacancyReviewCommand { User = user })); }
public BlockProviderCommand(long ukprn, VacancyUser qaVacancyUser, DateTime blockedDate, string blockReason) { Ukprn = ukprn; QaVacancyUser = qaVacancyUser; BlockedDate = blockedDate; Reason = blockReason; }
public ReviewVacancyCommand(Guid vacancyId, VacancyUser user, OwnerType submissionOwner, string employerDescription = null) { VacancyId = vacancyId; User = user; EmployerDescription = employerDescription; SubmissionOwner = submissionOwner; }
public async Task <OrchestratorResponse> PostEmployerNameEditModelAsync( EmployerNameEditModel model, VacancyEmployerInfoModel employerInfoModel, VacancyUser user) { var validationRules = VacancyRuleSet.EmployerNameOption; var vacancy = await Utility.GetAuthorisedVacancyForEditAsync( _providerVacancyClient, _recruitVacancyClient, model, RouteNames.EmployerName_Post); vacancy.EmployerNameOption = model.SelectedEmployerIdentityOption.HasValue ? model.SelectedEmployerIdentityOption.Value.ConvertToDomainOption() : (EmployerNameOption?)null; // temporarily set the employer name for validation if (model.SelectedEmployerIdentityOption == EmployerIdentityOption.NewTradingName) { validationRules = VacancyRuleSet.EmployerNameOption | VacancyRuleSet.TradingName; vacancy.EmployerName = model.NewTradingName; _vmPropertyToMapEmployerNameTo = vm => vm.NewTradingName; } if (model.SelectedEmployerIdentityOption == EmployerIdentityOption.Anonymous) { vacancy.EmployerName = model.AnonymousName; vacancy.AnonymousReason = model.AnonymousReason; _vmPropertyToMapEmployerNameTo = vm => vm.AnonymousName; } return(await ValidateAndExecute( vacancy, v => _recruitVacancyClient.Validate(v, validationRules), v => Task.FromResult(new OrchestratorResponse(true)))); }
public SearchResultHeaderTestBase() { var userId = Guid.NewGuid(); User = new VacancyUser { Email = "*****@*****.**", Name = "Keith Chegwin", Ukprn = 12345678, UserId = userId.ToString() }; UserDetails = new User { Email = User.Email, Name = User.Name, Ukprn = User.Ukprn, Id = userId }; RecruitVacancyClientMock = new Mock <IRecruitVacancyClient>(); RecruitVacancyClientMock .Setup(x => x.GetUsersDetailsAsync(User.UserId)) .ReturnsAsync(UserDetails); ProviderAlertsViewModelFactoryMock = new Mock <IProviderAlertsViewModelFactory>(); ProviderRelationshipsServiceMock = new Mock <IProviderRelationshipsService>(); }
public async Task IfInvalidVacancyStatus_ShouldThrowError(VacancyStatus invalidCloneStatus) { var newVacancyId = Guid.NewGuid(); var existingVacancy = _autoFixture.Build <Vacancy>().With(c => c.Status, invalidCloneStatus).Create(); var currentTime = DateTime.UtcNow; var startDate = DateTime.Now.AddDays(20); var closingDate = DateTime.Now.AddDays(10); var user = new VacancyUser { Name = "Test", Email = "*****@*****.**", UserId = "123" }; var command = new CloneVacancyCommand( cloneVacancyId: existingVacancy.Id, newVacancyId: newVacancyId, user: user, sourceOrigin: SourceOrigin.EmployerWeb, startDate: startDate, closingDate: closingDate); var mockRepository = new Mock <IVacancyRepository>(); var mockTimeProvider = new Mock <ITimeProvider>(); mockTimeProvider.Setup(x => x.Now).Returns(currentTime); mockRepository.Setup(x => x.GetVacancyAsync(existingVacancy.Id)).ReturnsAsync(existingVacancy); var handler = new CloneVacancyCommandHandler( Mock.Of <ILogger <CloneVacancyCommandHandler> >(), mockRepository.Object, Mock.Of <IMessaging>(), mockTimeProvider.Object ); await Assert.ThrowsAsync <InvalidStateException>(() => handler.Handle(command, new CancellationToken())); }
public async Task UpdateRejectedVacancyReason(SubmitReviewModel m, VacancyUser user) { var vacancy = await _utility.GetAuthorisedVacancyAsync(m, RouteNames.ApproveJobAdvert_Post); vacancy.EmployerRejectedReason = m.RejectedReason; await _vacancyClient.UpdateDraftVacancyAsync(vacancy, user); }
public Task AssignVacancyReviewAsync(VacancyUser user, Guid reviewId) { return(_messaging.SendCommandAsync(new AssignVacancyReviewCommand { User = user, ReviewId = reviewId })); }
public async Task <Guid?> AssignNextVacancyReviewAsync(VacancyUser user) { await _vacancyClient.AssignNextVacancyReviewAsync(user); var userVacancyReviews = await _vacancyClient.GetAssignedVacancyReviewsForUserAsync(user.UserId); return(userVacancyReviews.FirstOrDefault()?.Id); }
public async Task <VacanciesViewModel> GetVacanciesViewModelAsync( VacancyUser user, string filter, int page, string searchTerm) { var getDashboardTask = _providerVacancyClient.GetDashboardAsync(user.Ukprn.Value, createIfNonExistent: true); var getUserDetailsTask = _recruitVacancyClient.GetUsersDetailsAsync(user.UserId); var providerTask = _providerRelationshipsService.GetLegalEntitiesForProviderAsync(user.Ukprn.Value, OperationType.RecruitmentRequiresReview); await Task.WhenAll(getDashboardTask, getUserDetailsTask, providerTask); var dashboard = getDashboardTask.Result; var userDetails = getUserDetailsTask.Result; var providerPermissions = providerTask.Result; var alerts = _providerAlertsViewModelFactory.Create(dashboard, userDetails); var vacancies = new List <VacancySummary>(dashboard?.Vacancies ?? Array.Empty <VacancySummary>()); var filteringOption = SanitizeFilter(filter); var filteredVacancies = GetFilteredVacancies(vacancies, filteringOption, searchTerm); var filteredVacanciesTotal = filteredVacancies.Count(); page = SanitizePage(page, filteredVacanciesTotal); var skip = (page - 1) * VacanciesPerPage; var vacanciesVm = filteredVacancies .Skip(skip) .Take(VacanciesPerPage) .Select(VacancySummaryMapper.ConvertToVacancySummaryViewModel) .ToList(); var pager = new PagerViewModel( filteredVacanciesTotal, VacanciesPerPage, page, "Showing {0} to {1} of {2} vacancies", RouteNames.Vacancies_Get, new Dictionary <string, string> { { "filter", filteringOption.ToString() }, { "searchTerm", searchTerm } }); var vm = new VacanciesViewModel { Vacancies = vacanciesVm, Pager = pager, Filter = filteringOption, SearchTerm = searchTerm, ResultsHeading = VacancyFilterHeadingHelper.GetFilterHeading(Constants.VacancyTerm, filteredVacanciesTotal, filteringOption, searchTerm, UserType.Provider), Alerts = alerts, HasEmployerReviewPermission = providerPermissions.Any() }; return(vm); }
public Task DismissAlert(VacancyUser user, AlertType alertType) { return(_messaging.SendCommandAsync(new UpdateUserAlertCommand { IdamsUserId = user.UserId, AlertType = alertType, DismissedOn = _timeProvider.Now })); }
public async Task RejectJobAdvertAsync_ShouldSendCommand() { //Arrange var user = new VacancyUser { Email = "*****@*****.**", Name = "advertname", UserId = "advertId" }; var vacancy = new Vacancy { EmployerAccountId = "ABCDEF", AccountLegalEntityPublicHashedId = "XVYABD", Id = Guid.Parse("84af954e-5baf-4942-897d-d00180a0839e"), Title = "has a value", NumberOfPositions = 1, EmployerLocation = new Address { Postcode = "has a value" }, ShortDescription = "has a value", ProgrammeId = "has a value", Wage = new Wage { Duration = 1, WageType = WageType.FixedWage }, LegalEntityName = "legal name", EmployerNameOption = EmployerNameOption.RegisteredName, StartDate = DateTime.Now, Status = VacancyStatus.Review, VacancyReference = 123456 }; var rejectJobAdvertViewModel = new RejectJobAdvertViewModel { RejectJobAdvert = true, VacancyId = vacancy.Id, EmployerAccountId = "ABCDEF" }; _mockRecruitVacancyClient.Setup(x => x.GetVacancyAsync(vacancy.Id)).ReturnsAsync(vacancy); _mockRecruitVacancyClient.Setup(x => x.GetEmployerDescriptionAsync(vacancy)).ReturnsAsync("employer description"); _mockRecruitVacancyClient.Setup(x => x.GetEmployerNameAsync(vacancy)).ReturnsAsync("employer name"); _mockRecruitVacancyClient.Setup(c => c.Validate(vacancy, It.IsAny <VacancyRuleSet>())).Returns(new EntityValidationResult()); var geocodeImageService = new Mock <IGeocodeImageService>(); var externalLinks = new Mock <IOptions <ExternalLinksConfiguration> >(); var mapper = new DisplayVacancyViewModelMapper(geocodeImageService.Object, externalLinks.Object, _mockRecruitVacancyClient.Object); var legalEntityAgreement = new Mock <ILegalEntityAgreementService>(); var utility = new Utility(_mockRecruitVacancyClient.Object, Mock.Of <IFeature>()); var sut = new VacancyPreviewOrchestrator(_mockRecruitVacancyClient.Object, Mock.Of <ILogger <VacancyPreviewOrchestrator> >(), mapper, _mockReviewSummaryService.Object, legalEntityAgreement.Object, _mockmessaging.Object, Mock.Of <IOptions <ExternalLinksConfiguration> >(), utility); //Act var response = await sut.RejectJobAdvertAsync(rejectJobAdvertViewModel, user); //Assert _mockmessaging.Verify(c => c.SendCommandAsync(It.IsAny <ICommand>()), Times.Once()); response.Data.IsRejected.Should().Be(true); }
public CreateReportCommand(Guid reportId, ReportOwner owner, ReportType reportType, Dictionary <string, object> parameters, VacancyUser requestedBy, string reportName) { ReportId = reportId; Owner = owner; ReportType = reportType; Parameters = parameters; RequestedBy = requestedBy; ReportName = reportName; }
public Task SetApplicationReviewSuccessful(Guid applicationReviewId, VacancyUser user) { var command = new ApplicationReviewSuccessfulCommand { ApplicationReviewId = applicationReviewId, User = user }; return(_messaging.SendCommandAsync(command)); }
public Task DeleteVacancyAsync(Guid vacancyId, VacancyUser user) { var command = new DeleteVacancyCommand { VacancyId = vacancyId, User = user }; return(_messaging.SendCommandAsync(command)); }
public Task UpdateEmployerProfileAsync(EmployerProfile employerProfile, VacancyUser user) { var command = new UpdateEmployerProfileCommand { Profile = employerProfile, User = user }; return(_messaging.SendCommandAsync(command)); }
public Task UpdateDraftVacancyAsync(Vacancy vacancy, VacancyUser user) { var command = new UpdateDraftVacancyCommand { Vacancy = vacancy, User = user }; return(_messaging.SendCommandAsync(command)); }
public async Task CloseVacancyAsync(Guid vacancyId, VacancyUser user) { var command = new CloseVacancyCommand { VacancyId = vacancyId, User = user }; await _messaging.SendCommandAsync(command); }