public async Task WhenVolunteerIsSameAsCreatedBy_ReturnsTrue() { int jobId = 1; int createdByUserID = 1; _refferingGroupID = 1; _getjobdetailsResponse = new GetJobDetailsResponse() { JobSummary = new JobSummary() { VolunteerUserID = 1 } }; Dictionary <int, List <int> > roles = new Dictionary <int, List <int> >(); roles.Add(1, new List <int>() { (int)GroupRoles.Member }); _getUserRolesResponse = new GetUserRolesResponse() { UserGroupRoles = roles }; var response = await _classUnderTest.HasPermissionToChangeStatusAsync(jobId, createdByUserID, true, CancellationToken.None); _repository.Verify(x => x.GetJobDetails(It.IsAny <int>()), Times.Once); _repository.Verify(x => x.GetReferringGroupIDForJobAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Never); _groupService.Verify(x => x.GetUserRoles(It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Never); Assert.AreEqual(true, response); }
private string GetHelpRecipient(RequestRoles requestRole, GetJobDetailsResponse job) { string recipient = string.Empty; if (job.Recipient != null) { if (job.JobSummary.RequestorType == RequestorType.Organisation && !string.IsNullOrEmpty(job.JobSummary.RecipientOrganisation)) { recipient = job.JobSummary.RecipientOrganisation; } else if (requestRole == RequestRoles.Recipient || (requestRole == RequestRoles.Requestor && job.JobSummary.RequestorType == RequestorType.Myself)) { recipient = $"You ({job.Recipient.FirstName})"; } else if (!string.IsNullOrEmpty(job.Recipient.Address.Locality)) { recipient = $"{job.Recipient.FirstName} ({job.Recipient.Address.Locality.ToLower()})"; } else { recipient = job.Recipient.FirstName; } return(_textInfo.ToTitleCase(recipient)); } else { return(string.Empty); } }
private RequestRoles GetChangedByRole(GetJobDetailsResponse job) { int lastUpdatedByUserId = _connectRequestService.GetLastUpdatedBy(job); int?currentOrLastVolunteerUserID = _connectRequestService.GetRelevantVolunteerUserID(job); return(currentOrLastVolunteerUserID.HasValue && currentOrLastVolunteerUserID.Value == lastUpdatedByUserId ? RequestRoles.Volunteer : RequestRoles.GroupAdmin); }
private string GetShiftDetails(GetJobDetailsResponse job) { if (job.RequestSummary.Shift == null) { return(string.Empty); } else { return($"{job.RequestSummary.Shift.StartDate.FormatDate(DateTimeFormat.LongDateTimeFormat)} - {job.RequestSummary.Shift.EndDate.FormatDate(DateTimeFormat.TimeFormat)}"); } }
private string GetReference(RequestRoles requestRole, GetJobDetailsResponse job) { string reference = string.Empty; if (job.JobSummary.ReferringGroupID == (int)Groups.AgeUKLSL) { var question = job.JobSummary.Questions.FirstOrDefault(x => x.Id == (int)Questions.AgeUKReference); reference = question?.Answer; } return(reference); }
public async Task <string> GetHelpRequestedFrom(GetJobDetailsResponse job) { string requestedFrom = string.Empty; if ((Groups)job.JobSummary.ReferringGroupID != Groups.Generic && !job.JobSummary.RequestorDefinedByGroup) { var group = await _connectGroupService.GetGroup(job.JobSummary.ReferringGroupID); requestedFrom = group.Group.GroupName; } return(requestedFrom); }
public int GetLastUpdatedBy(GetJobDetailsResponse getJobDetailsResponse) { var lastHistory = getJobDetailsResponse.History.OrderByDescending(x => x.StatusDate).First(); if (lastHistory != null) { return(lastHistory.CreatedByUserID.Value); } else { throw new Exception($"Unable to retrieve last updated by for job id {getJobDetailsResponse.JobSummary.JobID}"); } }
private int?GetCreatedByUserID(GetJobDetailsResponse job) { var createdBy = job.History.OrderByDescending(x => x.StatusDate).Take(1).FirstOrDefault(); if (createdBy != null) { return(createdBy.CreatedByUserID); } else { return(null); } }
public void Setup() { SetupRepository(); SetupJobService(); _classUnderTest = new GetJobDetailsHandler(_repository.Object, _jobService.Object); _response = new GetJobDetailsResponse() { JobSummary = new HelpMyStreet.Utils.Models.JobSummary() { Details = "DETAILS", JobID = 1, } }; }
public JobStatuses PreviousJobStatus(GetJobDetailsResponse getJobDetailsResponse) { var history = getJobDetailsResponse.History.OrderByDescending(x => x.StatusDate).ToList(); if (history.Count >= 2) { var previousState = history.ElementAt(1); return(previousState.JobStatus); } else { throw new Exception($"no previous job status for jobid {getJobDetailsResponse.JobSummary.JobID}"); } }
public async Task WhenVolunteerIsDiffentToCreatedByButUserIsNotTaskAdmin_ReturnsFalse() { int jobId = 1; int createdByUserID = 1; _refferingGroupID = 1; _getjobdetailsResponse = new GetJobDetailsResponse() { JobSummary = new JobSummary() { VolunteerUserID = 2 } }; Dictionary <int, List <int> > roles = new Dictionary <int, List <int> >(); roles.Add(1, new List <int>() { (int)GroupRoles.Member }); _getUserRolesResponse = new GetUserRolesResponse() { UserGroupRoles = roles }; _getGroupResponse = new GetGroupResponse() { Group = new Group() { GroupId = 1, GroupKey = "KEY", GroupName = "GroupName", ParentGroupId = 2 } }; var response = await _classUnderTest.HasPermissionToChangeStatusAsync(jobId, createdByUserID, true, CancellationToken.None); _repository.Verify(x => x.GetJobDetails(It.IsAny <int>()), Times.Once); _repository.Verify(x => x.GetReferringGroupIDForJobAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Once); _groupService.Verify(x => x.GetUserRoles(It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Once); _groupService.Verify(x => x.GetGroup(It.IsAny <int>()), Times.Once); Assert.AreEqual(false, response); }
private MessageParticipant GetToBlock(GetJobDetailsResponse job, RequestRoles requestRole) { MessageParticipant to = new MessageParticipant { RequestRoleType = new RequestRoleType { RequestRole = requestRole } }; switch (requestRole) { case RequestRoles.Recipient: to.EmailDetails = new EmailDetails { DisplayName = string.IsNullOrEmpty(job.JobSummary.RecipientOrganisation) ? job.Recipient.FirstName : job.JobSummary.RecipientOrganisation, EmailAddress = job.Recipient.EmailAddress }; break; case RequestRoles.Requestor: to.EmailDetails = new EmailDetails { DisplayName = job.Requestor.FirstName, EmailAddress = job.Requestor.EmailAddress }; break; case RequestRoles.Volunteer: to.UserId = job.JobSummary.VolunteerUserID; break; case RequestRoles.GroupAdmin: to.GroupRoleType = new GroupRoleType() { GroupId = job.JobSummary.ReferringGroupID, GroupRoles = GroupRoles.Owner }; break; default: throw new ArgumentException(message: $"Unexpected RequestRoles value: {requestRole}", paramName: nameof(requestRole)); } return(to); }
private string GetDueDate(GetJobDetailsResponse job) { string strDaysFromNow = string.Empty; DateTime dueDate = job.JobSummary.DueDate; double daysFromNow = (dueDate.Date - DateTime.Now.Date).TotalDays; switch (job.JobSummary.DueDateType) { case DueDateType.Before: strDaysFromNow += daysFromNow == 0 ? "Today" : $"On or before {dueDate.ToString(DATE_FORMAT)}"; break; case DueDateType.On: strDaysFromNow += $"On {dueDate.ToString(DATE_FORMAT)}"; break; } return(strDaysFromNow); }
private string GetLocationDetails(GetJobDetailsResponse job) { if (job.RequestSummary.Shift == null) { return(string.Empty); } else { var locationDetails = _connectAddressService.GetLocationDetails(job.RequestSummary.Shift.Location, CancellationToken.None).Result; if (locationDetails != null) { return($"{locationDetails.Name}"); } else { throw new Exception("Unable to find location details"); } } }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { GetJobDetailsResponse response = new GetJobDetailsResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("jobDetails", targetDepth)) { var unmarshaller = JobDetailsUnmarshaller.Instance; response.JobDetails = unmarshaller.Unmarshall(context); continue; } } return(response); }
private MessageParticipant GetFromBlock(User user, RequestRoles requestRole, GetJobDetailsResponse job) { MessageParticipant from = new MessageParticipant { RequestRoleType = new RequestRoleType { RequestRole = requestRole } }; switch (requestRole) { case RequestRoles.GroupAdmin: from.GroupRoleType = new GroupRoleType { GroupId = job.JobSummary.ReferringGroupID, GroupRoles = GroupRoles.Owner }; break; case RequestRoles.Volunteer: from.UserId = user.ID; break; case RequestRoles.Recipient: from.EmailDetails = new EmailDetails { DisplayName = string.IsNullOrEmpty(job.JobSummary.RecipientOrganisation) ? job.Recipient.FirstName : job.JobSummary.RecipientOrganisation }; break; case RequestRoles.Requestor: from.EmailDetails = new EmailDetails { DisplayName = job.Requestor.FirstName }; break; default: throw new ArgumentException(message: $"Unexpected RequestRoles value: {requestRole}", paramName: nameof(requestRole)); } return(from); }
private List <RequestJob> GetJobsForStandardRequest(GetRequestDetailsResponse response, List <GroupJob> groupJobs) { List <RequestJob> requestJobs = new List <RequestJob>(); string dueDateString = string.Empty; bool showJobUrl = false; string jobUrl = string.Empty; //TODO - This can be written to handle multiple jobs for a standard request. Need to tweak when repeat enquiries functionality added if (groupJobs.Count == 1) { int jobid = response.RequestSummary.JobBasics[0].JobID; GetJobDetailsResponse jobResponse = _connectRequestService.GetJobDetailsAsync(jobid).Result; if (jobResponse != null) { RequestRoles getChangedBy = GetChangedByRole(jobResponse); showJobUrl = getChangedBy == RequestRoles.Volunteer || getChangedBy == RequestRoles.GroupAdmin || (getChangedBy == RequestRoles.Requestor && jobResponse.JobSummary.RequestorDefinedByGroup); jobUrl = showJobUrl ? GetJobUrl(jobid, response.RequestSummary.RequestID, groupJobs[0].Count) : string.Empty; dueDateString = $" - Due Date: <strong>{jobResponse.JobSummary.DueDate.FormatDate(DateTimeFormat.LongDateFormat)}.</strong>"; } else { throw new Exception($"Unable to retrieve job details for jobid { jobid }"); } } foreach (GroupJob gj in groupJobs) { requestJobs.Add(new RequestJob( activity: gj.SupportActivity.FriendlyNameShort(), countString: gj.Count == 1 ? string.Empty: $" - {gj.Count} volunteers required. ", dueDateString: dueDateString, showJobUrl: showJobUrl, jobUrl: jobUrl )); } return(requestJobs); }
private async Task <string> GetVolunteer(RequestRoles requestRole, GetJobDetailsResponse job) { string volunteer = string.Empty; if (job.JobSummary.VolunteerUserID.HasValue) { var user = await _connectUserService.GetUserByIdAsync(job.JobSummary.VolunteerUserID.Value); if (requestRole == RequestRoles.Volunteer) { volunteer = $"You ({user.UserPersonalDetails.FirstName})"; } else { volunteer = user.UserPersonalDetails.FirstName; } } return(_textInfo.ToTitleCase(volunteer)); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] [RequestBodyType(typeof(GetJobDetailsRequest), "get job details request")] GetJobDetailsRequest req, CancellationToken cancellationToken) { try { _logger.LogInformation("GetJobDetails started"); GetJobDetailsResponse response = await _mediator.Send(req, cancellationToken); return(new OkObjectResult(ResponseWrapper <GetJobDetailsResponse, RequestServiceErrorCode> .CreateSuccessfulResponse(response))); } catch (Exception exc) { _logger.LogErrorAndNotifyNewRelic("Exception occured in GetJobDetails", exc); return(new ObjectResult(ResponseWrapper <GetJobDetailsResponse, RequestServiceErrorCode> .CreateUnsuccessfulResponse(RequestServiceErrorCode.InternalServerError, "Internal Error")) { StatusCode = StatusCodes.Status500InternalServerError }); } }
public int?GetRelevantVolunteerUserID(GetJobDetailsResponse getJobDetailsResponse) { int?result = null; if (getJobDetailsResponse.JobSummary.VolunteerUserID.HasValue) { result = getJobDetailsResponse.JobSummary.VolunteerUserID.Value; } else { var history = getJobDetailsResponse.History.OrderByDescending(x => x.StatusDate).ToList(); if (history.Count >= 2) { var previousState = history.ElementAt(1); if ((previousState.JobStatus == JobStatuses.InProgress || previousState.JobStatus == JobStatuses.Accepted) && previousState.VolunteerUserID.HasValue) { result = previousState.VolunteerUserID.Value; } } } return(result); }
private string GetRequestedBy(RequestRoles requestRole, GetJobDetailsResponse job) { string requestor; if (job.JobSummary.RequestorDefinedByGroup) { requestor = job.Requestor.Address.AddressLine1; } else if (requestRole == RequestRoles.Requestor || (requestRole == RequestRoles.Recipient && job.JobSummary.RequestorType == RequestorType.Myself)) { requestor = $"You ({job.Requestor.FirstName})"; } else if (!string.IsNullOrEmpty(job.Requestor.Address.Locality)) { requestor = $"{job.Requestor.FirstName} ({job.Requestor.Address.Locality.ToLower()})"; } else { requestor = job.Requestor.FirstName; } return(_textInfo.ToTitleCase(requestor)); }
private string GetFeedback(GetJobDetailsResponse job, RequestRoles requestRole) { if (job.JobSummary.JobStatus == JobStatuses.Done && (requestRole == RequestRoles.Recipient || requestRole == RequestRoles.Requestor)) { var happyFaceImage = $"{_sendGridConfig.Value.BaseUrl}/img/email-resources/great.png"; var sadFaceImage = $"{_sendGridConfig.Value.BaseUrl}/img/email-resources/not-so-great.png"; return($"<p> </p><p style='color:#001489;font-weight:bold;font-size:24px'>Tell us how it went</p><p>How was your experience with HelpMyStreet?</p>" + $"<table>" + $"<tr style='margin-left:10px'>" + $"<td><a href='{GetProtectedUrl(job.JobSummary.JobID, requestRole, FeedbackRating.HappyFace)}'><img src='{happyFaceImage}' alt='Great' width='200'></a></td>" + $"<td><a href='{GetProtectedUrl(job.JobSummary.JobID, requestRole, FeedbackRating.SadFace)}'><img src='{sadFaceImage}' alt='Not So Great' width='200'></a></td>" + $"</tr>" + $"<tr>" + $"<td colspan=2><a href='{GetProtectedUrl(job.JobSummary.JobID, requestRole,null)}'>Click here to leave your feedback</a></td>" + $"</tr>" + $"</table>" + $"<p>If you have any comments or queries, please click <a href='{GetProtectedUrl(job.JobSummary.JobID, requestRole, null)}'>here</a>, or get in touch by emailing [email protected].</p>"); } else { return("<p>If you have any comments or queries, please get in touch by emailing [email protected].</p>"); } }
private async Task <string> SenderAndContext(string senderName, string senderRequestorRole, string toRequestorRole, string senderGroupName, GetJobDetailsResponse job) { string result = string.Empty; RequestRoles senderRole = (RequestRoles)Enum.Parse(typeof(RequestRoles), senderRequestorRole); RequestRoles toRole = (RequestRoles)Enum.Parse(typeof(RequestRoles), toRequestorRole); string helpRecipient = string.Empty; if (job != null) { helpRecipient = job.Recipient?.FirstName; } switch (senderRole) { case RequestRoles.Recipient: result = SenderAndContextRecipient(senderName, toRole); break; case RequestRoles.Requestor: result = SenderAndContextRequestor(senderName, helpRecipient, toRole); break; case RequestRoles.Volunteer: result = SenderAndContextVolunteer(senderName, helpRecipient, toRole); break; case RequestRoles.GroupAdmin: result = SenderAndContextGroupAdmin(senderName, senderGroupName); break; } if (job != null) { DateTime dtStatusChanged = job.JobSummary.DateStatusLastChanged; result = $"{result} The request was for <strong>{ job.JobSummary.SupportActivity.FriendlyNameShort()}</strong> and was {Mapping.StatusMappingsNotifications[job.JobSummary.JobStatus]} <strong>{dtStatusChanged.FriendlyPastDate()}</strong>"; } return(result); }
public async Task WhenCreatedByUserIsSameAsVolunteerUserID_ReturnsSuccess(GroupRoles role) { _updateJobStatusOutcome = UpdateJobStatusOutcome.Success; _request = new PutUpdateJobStatusToInProgressRequest { CreatedByUserID = 1, JobID = 1, VolunteerUserID = 1 }; _getUserGroupsReponse = new GetUserGroupsResponse() { Groups = new List <int>() { 1 } }; _getGroupsForJobResponse = new List <int>() { 1 }; _referringGroupId = 1; Dictionary <int, List <int> > roles = new Dictionary <int, List <int> >(); roles.Add(1, new List <int>() { (int)role }); _getJobDetailsResponse = new GetJobDetailsResponse() { JobSummary = new JobSummary() { JobID = 1, SupportActivity = SupportActivities.Shopping } }; _getGroupMemberResponse = new GetGroupMemberResponse() { UserInGroup = new UserInGroup() { GroupId = 1, UserId = 1, GroupRoles = new List <GroupRoles>() { GroupRoles.Member }, ValidCredentials = new List <int>() { -1 } } }; _getGroupActivityCredentialsResponse = new GetGroupActivityCredentialsResponse() { CredentialSets = new List <List <int> > { new List <int>() { -1 } } }; _hasPermission = true; var response = await _classUnderTest.Handle(_request, CancellationToken.None); _repository.Verify(x => x.JobIsInProgressWithSameVolunteerUserId(It.IsAny <int>(), It.IsAny <int?>()), Times.Once); _groupService.Verify(x => x.GetUserGroups(It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Once); _groupService.Verify(x => x.GetGroupMember(It.IsAny <GetGroupMemberRequest>()), Times.Once); _groupService.Verify(x => x.GetGroupActivityCredentials(It.IsAny <GetGroupActivityCredentialsRequest>()), Times.Once); _repository.Verify(x => x.GetGroupsForJobAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Once); _repository.Verify(x => x.GetReferringGroupIDForJobAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Once); _groupService.Verify(x => x.GetGroupMember(It.IsAny <GetGroupMemberRequest>()), Times.Once); _groupService.Verify(x => x.GetGroupActivityCredentials(It.IsAny <GetGroupActivityCredentialsRequest>()), Times.Once); _repository.Verify(x => x.UpdateJobStatusInProgressAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Once); _communicationService.Verify(x => x.RequestCommunication(It.IsAny <RequestCommunicationRequest>(), It.IsAny <CancellationToken>()), Times.Once); Assert.AreEqual(UpdateJobStatusOutcome.Success, response.Outcome); }
public async Task <EmailBuildData> PrepareTemplateData(Guid batchId, int?recipientUserId, int?jobId, int?groupId, int?requestId, Dictionary <string, string> additionalParameters, string templateName) { if (!recipientUserId.HasValue) { throw new Exception($"RecipientID is missing"); } if (recipientUserId.Value > 0) { var user = await _connectUserService.GetUserByIdAsync(recipientUserId.Value); } var recipientDetails = await GetRecipientDetails(recipientUserId, additionalParameters); string recipientFirstName = string.Empty; string senderName = string.Empty; additionalParameters.TryGetValue("SenderRequestorRole", out string senderRequestorRole); string senderMessage = string.Empty; string emailToAddress = string.Empty; string emailToName = string.Empty; additionalParameters.TryGetValue("ToRequestorRole", out string toRequestorRole); additionalParameters.TryGetValue("SenderGroupName", out string senderGroupName); additionalParameters.TryGetValue("ToGroupName", out string toGroupName); string subject = GetSubject(toGroupName); string title = GetTitle(toGroupName); if (recipientDetails != null) { emailToAddress = recipientDetails[RECIPIENT_EMAIL_ADDRESS]; emailToName = recipientDetails[RECIPIENT_DISPLAY_NAME]; recipientFirstName = recipientDetails[RECIPIENT_FIRST_NAME]; } if (additionalParameters != null) { additionalParameters.TryGetValue("SenderMessage", out senderMessage); additionalParameters.TryGetValue("SenderName", out senderName); } GetJobDetailsResponse job = null; if (jobId.HasValue) { job = await _connectRequestService.GetJobDetailsAsync(jobId.Value); } string senderAndContext = await SenderAndContext(senderName, senderRequestorRole, toRequestorRole, senderGroupName, job); return(new EmailBuildData() { BaseDynamicData = new InterUserMessageData( title, subject, recipientFirstName, senderAndContext, senderName, senderMessage ), EmailToAddress = emailToAddress, EmailToName = emailToName, JobID = job.JobSummary.JobID, RequestID = job.JobSummary.RequestID, GroupID = job.JobSummary.ReferringGroupID, ReferencedJobs = new List <ReferencedJob>() { new ReferencedJob() { G = job.JobSummary.ReferringGroupID, R = job.JobSummary.RequestID, J = job.JobSummary.JobID } } }); }