Exemple #1
0
 public void Setup()
 {
     SetupRepository();
     SetupJobService();
     _classUnderTest = new GetRequestDetailsHandler(_repository.Object, _jobService.Object);
     _response       = new GetRequestDetailsResponse()
     {
         RequestSummary = new HelpMyStreet.Utils.Models.RequestSummary()
         {
             Shift = new HelpMyStreet.Utils.Models.Shift()
             {
                 StartDate   = DateTime.Now,
                 ShiftLength = 10
             },
             JobSummaries = new System.Collections.Generic.List <HelpMyStreet.Utils.Models.JobSummary>()
             {
                 new HelpMyStreet.Utils.Models.JobSummary()
                 {
                     JobID           = 1,
                     SupportActivity = HelpMyStreet.Utils.Enums.SupportActivities.Shopping,
                     JobStatus       = HelpMyStreet.Utils.Enums.JobStatuses.New
                 },
                 new HelpMyStreet.Utils.Models.JobSummary()
                 {
                     JobID           = 1,
                     SupportActivity = HelpMyStreet.Utils.Enums.SupportActivities.CollectingPrescriptions,
                     JobStatus       = HelpMyStreet.Utils.Enums.JobStatuses.New
                 }
             }
         }
     };
 }
        private List <RequestJob> GetJobsForShiftRequest(GetRequestDetailsResponse response, List <GroupJob> groupJobs)
        {
            List <RequestJob> requestJobs = new List <RequestJob>();

            var locationDetails = _connectAddressService.GetLocationDetails(response.RequestSummary.Shift.Location, CancellationToken.None).Result;

            if (locationDetails == null)
            {
                throw new Exception($"Unable to retrieve location details for request {response.RequestSummary.RequestID}");
            }

            string locationName = locationDetails.ShortName;

            var time = TimeSpan.FromMinutes(response.RequestSummary.Shift.ShiftLength);

            string dueDateString = $"Shift: <strong>{response.RequestSummary.Shift.StartDate.FormatDate(DateTimeFormat.LongDateTimeFormat)} - {response.RequestSummary.Shift.EndDate.FormatDate(DateTimeFormat.TimeFormat)}</strong> " +
                                   $"(Duration: {Math.Floor(time.TotalHours)} hrs {time.Minutes} mins). " +
                                   $"Location: <strong>{locationName}</strong>";

            foreach (GroupJob gj in groupJobs)
            {
                requestJobs.Add(new RequestJob(
                                    activity: gj.SupportActivity.FriendlyNameShort(),
                                    countString: gj.Count == 1 ? $" - 1 volunteer required. " : $" - {gj.Count} volunteers required. ",
                                    dueDateString: dueDateString,
                                    showJobUrl: false,
                                    jobUrl: string.Empty
                                    ));
                ;
            }
            return(requestJobs);
        }
Exemple #3
0
        private SupportActivities GetSupportActivityFromRequest(GetRequestDetailsResponse request)
        {
            var activities = request.RequestSummary.JobBasics.Select(x => x.SupportActivity).Distinct();

            if (activities.Count() == 1)
            {
                return(activities.First());
            }
            else
            {
                throw new Exception("Unable to retrive distinct support activity from request");
            }
        }
Exemple #4
0
        public async Task WhenPassesInKnownRequestIDButUserIsNotAuthorised_ReturnsNull()
        {
            _permission = false;
            _request    = new GetRequestDetailsRequest
            {
                RequestID          = 1,
                AuthorisedByUserID = -1
            };
            _response = null;

            var response = await _classUnderTest.Handle(_request, CancellationToken.None);

            Assert.AreEqual(_response, response);
        }
        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 List <RequestJob> GetJobs(GetRequestDetailsResponse response)
        {
            List <RequestJob> requestJobs = new List <RequestJob>();
            var groupJobs = response.RequestSummary.JobBasics
                            .GroupBy(x => x.SupportActivity)
                            .Select(g => new GroupJob(g.Key, g.Count()))
                            .ToList();

            switch (response.RequestSummary.RequestType)
            {
            case RequestType.Shift:
                return(GetJobsForShiftRequest(response, groupJobs));

            case RequestType.Task:
                return(GetJobsForStandardRequest(response, groupJobs));

            default:
                throw new Exception($"Unknown requestType { response.RequestSummary.RequestType }");
            }
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]
            [RequestBodyType(typeof(GetRequestDetailsRequest), "Get request details request")] GetRequestDetailsRequest req,
            CancellationToken cancellationToken)
        {
            try
            {
                _logger.LogInformation("GetJobDetails started");
                GetRequestDetailsResponse response = await _mediator.Send(req, cancellationToken);

                return(new OkObjectResult(ResponseWrapper <GetRequestDetailsResponse, RequestServiceErrorCode> .CreateSuccessfulResponse(response)));
            }
            catch (Exception exc)
            {
                _logger.LogErrorAndNotifyNewRelic("Exception occured in GetRequestDetails", exc);
                return(new ObjectResult(ResponseWrapper <GetRequestDetailsResponse, RequestServiceErrorCode> .CreateUnsuccessfulResponse(RequestServiceErrorCode.InternalServerError, "Internal Error"))
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }
        public void MissingStrategy_ThrowsException()
        {
            int?jobId           = null;
            int?groupId         = GROUPID;
            int?recipientUserId = null;
            int?requestId       = 1;

            _getRequestDetailsResponse = new GetRequestDetailsResponse()
            {
                RequestSummary = new RequestSummary()
                {
                    ReferringGroupID = GROUPID
                }
            };

            _getGroupNewRequestNotificationStrategyResponse = null;
            Exception ex = Assert.ThrowsAsync <Exception>(() => _classUnderTest.IdentifyRecipients
                                                          (
                                                              recipientUserId, jobId, groupId, requestId, null
                                                          ));

            Assert.AreEqual($"No strategy for {GROUPID}", ex.Message);
        }
        public void SetUp()
        {
            SetupGroupService();
            SetupUserService();
            SetupRequestService();

            _getGroupMembersResponse = new GetGroupMembersResponse()
            {
                Users = new List <int>()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
                }
            };

            _getRequestDetailsResponse = new GetRequestDetailsResponse()
            {
                RequestSummary = new RequestSummary()
                {
                    JobSummaries = new List <JobSummary>()
                    {
                        new JobSummary()
                        {
                            ReferringGroupID = GROUPID,
                            PostCode         = "PostCode",
                            SupportActivity  = SupportActivities.Shopping
                        }
                    },
                    ShiftJobs = new List <ShiftJob>()
                }
            };

            _classUnderTest = new TaskNotificationMessage(
                _userService.Object,
                _requestService.Object,
                _groupService.Object
                );
        }