public async Task CreatesPublishSpecificationJobForSuppliedSpecificationId() { string fundingPeriodId = NewRandomString(); ApiSpecificationSummary specificationSummary = NewApiSpecificationSummary(_ => _.WithFundingStreamIds(NewRandomString(), NewRandomString(), NewRandomString()) .WithFundingPeriodId(fundingPeriodId)); string refreshFundingJobId = NewRandomString(); ApiJob refreshFundingJob = NewJob(_ => _.WithId(refreshFundingJobId)); GivenTheApiResponseDetailsForTheSuppliedId(specificationSummary); AndTheApiResponseDetailsForTheFundingPeriodId(fundingPeriodId); AndGetPreReqCheckerLocatorReturnsRefreshPreReqChecker(); AndTheApiResponseDetailsForSpecificationsJob(refreshFundingJob); JobCreationResponse expectedJobCreationResponse = NewJobCreationResponse(_ => _.WithJobId(refreshFundingJobId)); await WhenTheSpecificationIsPublished(); ActionResult .Should() .BeOfType <OkObjectResult>() .Which .Value .Should() .BeEquivalentTo(expectedJobCreationResponse); }
public async Task CreatesPublishBatchFundingJobForSpecificationWithSuppliedId() { string publishFundingJobId = NewRandomString(); ApiJob publishFundingJob = NewJob(_ => _.WithId(publishFundingJobId)); string filteredIdOne = NewRandomString(); string filteredIdTwo = NewRandomString(); GivenTheApiResponseDetailsForTheSuppliedId(NewApiSpecificationSummary(_ => _.WithIsSelectedForFunding(true))); AndTheFilteredListOfPublishedProviderIds(filteredIdOne, filteredIdTwo); AndTheApiResponseDetailsForSpecificationsBatchProvidersJob(publishFundingJob, Core.Extensions.JsonExtensions.AsJson(new PublishedProviderIdsRequest { PublishedProviderIds = new [] { filteredIdOne, filteredIdTwo } })); await WhenBatchProvidersFundingIsPublished(); JobCreationResponse expectedJobCreationResponse = NewJobCreationResponse(_ => _.WithJobId(publishFundingJobId)); ActionResult .Should() .BeOfType <OkObjectResult>() .Which .Value .Should() .BeEquivalentTo(expectedJobCreationResponse); }
public async Task <IActionResult> CreateRefreshFundingJob(string specificationId, Reference user, string correlationId) { ValidationResult validationResult = SpecificationIdValidator.Validate(specificationId); if (!validationResult.IsValid) { return(validationResult.AsBadRequest()); } ApiResponse <ApiSpecificationSummary> specificationIdResponse = await ResiliencePolicy.ExecuteAsync(() => Specifications.GetSpecificationSummaryById(specificationId)); ApiSpecificationSummary specificationSummary = specificationIdResponse.Content; if (specificationSummary == null) { return(new NotFoundResult()); } SpecificationFundingStatus chooseCheck = await _specificationFundingStatusService.CheckChooseForFundingStatus(specificationSummary); if (chooseCheck == SpecificationFundingStatus.SharesAlreadyChosenFundingStream) { return(new ConflictResult()); } IDictionary <string, Provider> scopedProviders = await _providerService.GetScopedProvidersForSpecification(specificationSummary.Id, specificationSummary.ProviderVersionId); // Check prerequisites for this specification to be chosen/refreshed IPrerequisiteChecker prerequisiteChecker = _prerequisiteCheckerLocator.GetPreReqChecker(PrerequisiteCheckerType.Refresh); try { await prerequisiteChecker.PerformChecks( specificationSummary, null, Array.Empty <PublishedProvider>(), scopedProviders?.Values); } catch (JobPrereqFailedException ex) { return(new BadRequestObjectResult(new [] { $"Prerequisite check for refresh failed {ex.Message}" }.ToModelStateDictionary())); } ApiJob refreshFundingJob = await _refreshFundingJobs.CreateJob(specificationId, user, correlationId); Guard.ArgumentNotNull(refreshFundingJob, nameof(refreshFundingJob), "Failed to create RefreshFundingJob"); JobCreationResponse jobCreationResponse = new JobCreationResponse() { JobId = refreshFundingJob.Id, }; return(new OkObjectResult(jobCreationResponse)); }
private IActionResult ProcessJobResponse(ApiJob job, string specificationId, string jobType) { if (job != null) { JobCreationResponse jobCreationResponse = new JobCreationResponse() { JobId = job.Id, }; return(new OkObjectResult(jobCreationResponse)); } else { string errorMessage = $"Failed to create job of type '{jobType}' on specification '{specificationId}'"; return(new InternalServerErrorResult(errorMessage)); } }
public async Task CreatesPublishAllFundingJobForSpecificationWithSuppliedId() { string publishFundingJobId = NewRandomString(); ApiJob publishFundingJob = NewJob(_ => _.WithId(publishFundingJobId)); GivenTheApiResponseDetailsForTheSuppliedId(NewApiSpecificationSummary(_ => _.WithIsSelectedForFunding(true))); AndTheApiResponseDetailsForSpecificationsJob(publishFundingJob); await WhenAllProvidersFundingIsPublished(); JobCreationResponse expectedJobCreationResponse = NewJobCreationResponse(_ => _.WithJobId(publishFundingJobId)); ActionResult .Should() .BeOfType <OkObjectResult>() .Which .Value .Should() .BeEquivalentTo(expectedJobCreationResponse); }
public async Task ApproveAllProvidersFundingJobForSuppliedSpecificationId() { ApiSpecificationSummary specificationSummary = NewApiSpecificationSummary(_ => _.WithIsSelectedForFunding(true)); string approveFundingJobId = NewRandomString(); ApiJob approveFundingJob = NewJob(_ => _.WithId(approveFundingJobId)); GivenTheApiResponseDetailsForTheSuppliedId(specificationSummary); AndTheApiResponseDetailsForApproveSpecificationJob(approveFundingJob); await WhenAllProvidersAreApproved(); JobCreationResponse expectedJobCreationResponse = NewJobCreationResponse(_ => _.WithJobId(approveFundingJobId)); ActionResult .Should() .BeOfType <OkObjectResult>() .Which .Value .Should() .BeEquivalentTo(expectedJobCreationResponse); }
public async Task RunSqlImportJobDelegatesToPublishingEndPointAndReturnsJobDetails() { string specificationId = NewRandomString(); string fundingStreamId = NewRandomString(); JobCreationResponse expectedJob = new JobCreationResponse(); _authorizationHelper.DoesUserHavePermission(Arg.Any <ClaimsPrincipal>(), specificationId, SpecificationActionTypes.CanRefreshPublishedQa) .Returns(Task.FromResult(true)); _publishingApiClient .QueueSpecificationFundingStreamSqlImport(specificationId, fundingStreamId) .Returns(new ApiResponse <JobCreationResponse>(HttpStatusCode.OK, expectedJob)); OkObjectResult result = await WhenTheRunSqlJobIsCreated(specificationId, fundingStreamId) as OkObjectResult; result? .Value .Should() .BeSameAs(expectedJob); }
public async Task QueueBatchUploadValidationDelegatesToPublishingEndPoint() { BatchUploadValidationRequestViewModel request = new BatchUploadValidationRequestViewModel { BatchId = NewRandomString(), FundingPeriodId = NewRandomString(), FundingStreamId = NewRandomString() }; JobCreationResponse expectedResponse = new JobCreationResponse(); _publishingApiClient.QueueBatchUploadValidation(Arg.Is <BatchUploadValidationRequest>(req => req.BatchId == request.BatchId && req.FundingStreamId == request.FundingStreamId && req.FundingPeriodId == request.FundingPeriodId)) .Returns(new ValidatedApiResponse <JobCreationResponse>(HttpStatusCode.OK, expectedResponse)); OkObjectResult result = await _publishController.QueueBatchUploadValidation(request) as OkObjectResult; result? .Value .Should() .BeSameAs(expectedResponse); }