public async Task <DetailsViewModel> Map(DetailsRequest source) { GetCohortResponse cohort; Task <bool> IsAgreementSigned(long accountLegalEntityId) { var request = new AgreementSignedRequest { AccountLegalEntityId = accountLegalEntityId }; if (cohort.IsFundedByTransfer) { request.AgreementFeatures = new AgreementFeature[] { AgreementFeature.Transfers }; } return(_commitmentsApiClient.IsAgreementSigned(request)); } var cohortTask = _commitmentsApiClient.GetCohort(source.CohortId); var draftApprenticeshipsTask = _commitmentsApiClient.GetDraftApprenticeships(source.CohortId); var emailOverlapsTask = _commitmentsApiClient.GetEmailOverlapChecks(source.CohortId); await Task.WhenAll(cohortTask, draftApprenticeshipsTask, emailOverlapsTask); cohort = await cohortTask; var draftApprenticeships = (await draftApprenticeshipsTask).DraftApprenticeships; var emailOverlaps = (await emailOverlapsTask).ApprenticeshipEmailOverlaps.ToList(); var courses = await GroupCourses(draftApprenticeships, emailOverlaps, cohort); var viewOrApprove = cohort.WithParty == CommitmentsV2.Types.Party.Employer ? "Approve" : "View"; var isAgreementSigned = await IsAgreementSigned(cohort.AccountLegalEntityId); return(new DetailsViewModel { AccountHashedId = source.AccountHashedId, CohortReference = source.CohortReference, WithParty = cohort.WithParty, AccountLegalEntityHashedId = _encodingService.Encode(cohort.AccountLegalEntityId, EncodingType.PublicAccountLegalEntityId), LegalEntityName = cohort.LegalEntityName, ProviderName = cohort.ProviderName, TransferSenderHashedId = cohort.TransferSenderId == null ? null : _encodingService.Encode(cohort.TransferSenderId.Value, EncodingType.PublicAccountId), EncodedPledgeApplicationId = cohort.PledgeApplicationId == null ? null : _encodingService.Encode(cohort.PledgeApplicationId.Value, EncodingType.PledgeApplicationId), Message = cohort.LatestMessageCreatedByProvider, Courses = courses, PageTitle = draftApprenticeships.Count == 1 ? $"{viewOrApprove} apprentice details" : $"{viewOrApprove} {draftApprenticeships.Count} apprentices' details", IsApprovedByProvider = cohort.IsApprovedByProvider, IsAgreementSigned = isAgreementSigned, IsCompleteForEmployer = cohort.IsCompleteForEmployer, HasEmailOverlaps = emailOverlaps.Any(), ShowAddAnotherApprenticeOption = !cohort.IsLinkedToChangeOfPartyRequest }); }
public async Task IsAgreementSigned_When_OneFeaturesSpecified_VerifyNoUrlDataIsPassedIn() { var request = new AgreementSignedRequest { AccountLegalEntityId = 123, AgreementFeatures = new AgreementFeature[] { AgreementFeature.Transfers } }; await _fixture.CommitmentsApiClient.IsAgreementSigned(request, CancellationToken.None); _fixture.MockRestHttpClient.Verify(c => c.Get <bool>("api/employer-agreements/123/signed?agreementFeatures=Transfers", null, CancellationToken.None)); }
public Task <bool> IsAgreementSigned(AgreementSignedRequest request, CancellationToken cancellationToken) { string queryString = null; if (request.AgreementFeatures?.Length > 0) { foreach (var agreementFeature in request.AgreementFeatures) { if (queryString == null) { queryString = $"?agreementFeatures={agreementFeature}"; } else { queryString += $"&agreementFeatures={agreementFeature}"; } } } return(_client.Get <bool>($"api/employer-agreements/{request.AccountLegalEntityId}/signed{queryString}", null, cancellationToken)); }