public async Task UpdatesAppointment()
        {
            var startTime1 = DateTime.UtcNow;

            startTime1 = startTime1.AddTicks(-(startTime1.Ticks % TimeSpan.TicksPerSecond));
            var endTime1   = startTime1.AddHours(5);
            var startTime2 = startTime1.AddDays(7);
            var endTime2   = endTime1.AddDays(7);

            SetupSoapMock(startTime2, endTime2);

            SetUserRole(UserGroups.Agent);
            var result = await CreateWorkOrder(wo => wo.AssignedToPrimary.Organization.Reference.First().ID = TestDataSeeder.DRSContractor);

            // create first appointment
            SetUserRole(UserGroups.Service);
            await CreateAppointment(result, startTime1, endTime1);

            // update the appointment
            var response = await CreateAppointment(result, startTime2, endTime2);

            var appointment = GetAppointmentFromDB(result.Id);

            response.Should().NotBeNull();
            response.InnerText.Should().Be(Resources.DrsBackgroundService_BookingAccepted);
            appointment.Should().NotBeNull();
            appointment.StartTime.Should().Be(DrsHelpers.ConvertToDrsTimeZone(startTime2));
            appointment.EndTime.Should().Be(DrsHelpers.ConvertToDrsTimeZone(endTime2));
        }
Exemple #2
0
        public async Task UpdatesAssignedOperativeAndBookingWindow()
        {
            const int    workOrderId        = 1234;
            const int    operativeId        = 5678;
            const string operativePayrollId = "Z123";
            var          drsOrder           = CreateDrsOrder(operativePayrollId);

            _drsSoapMock.SelectOrderReturns(drsOrder);
            _operativesGatewayMock.Setup(x => x.GetAsync(operativePayrollId))
            .ReturnsAsync(new Operative
            {
                Id = operativeId
            });
            _repairsGatewayMock.Setup(x => x.GetWorkOrder(workOrderId))
            .ReturnsAsync(new WorkOrder {
                Id = workOrderId
            });

            await _classUnderTest.UpdateWorkOrderDetails(workOrderId);

            _operativesGatewayMock.Verify(x => x.AssignOperatives(workOrderId, OperativeAssignmentType.Automatic,
                                                                  It.Is <(int id, double jobPercentage)>(assignment => assignment.id == operativeId && assignment.jobPercentage == 100)));

            var booking = drsOrder.theBookings.Single();

            _appointmentsGatewayMock.Verify(x =>
                                            x.SetTimedBooking(workOrderId, DrsHelpers.ConvertToDrsTimeZone(booking.planningWindowStart), DrsHelpers.ConvertToDrsTimeZone(booking.planningWindowEnd),
                                                              booking.bookingReason));
        }
        public async Task GetWorkOrderUpdatesWorkOrderDetails()
        {
            const string tradeName = "trade name";
            var          result    = await CreateWorkOrder(req =>
            {
                req.WorkElement.First().Trade.First().CustomName = tradeName;
                req.AssignedToPrimary.Name = TestDataSeeder.DRSContractor;
                req.AssignedToPrimary.Organization.Reference = new List <Reference>
                {
                    new Reference
                    {
                        ID = TestDataSeeder.DRSContractor
                    }
                };
            });

            var startTime = DateTime.UtcNow;
            var endTime   = startTime.AddHours(5);

            SetupSoapMock(startTime, endTime);

            var(code, _) = await Get <RepairsApi.V2.Boundary.WorkOrderResponse>($"/api/v2/workOrders/{result.Id}");

            code.Should().Be(HttpStatusCode.OK);

            var workOrder = GetWorkOrderFromDB(result.Id, wo => wo.AssignedOperatives.Load());

            workOrder.AssignedOperatives.Should().ContainSingle(o => o.PayrollNumber == TestDataSeeder.OperativePayrollId);

            var existingAppointment = await GetAppointmentFromDB(workOrder.Id);

            existingAppointment.Should().NotBeNull();
            existingAppointment.StartTime.Should().Be(DrsHelpers.ConvertToDrsTimeZone(startTime));
            existingAppointment.EndTime.Should().Be(DrsHelpers.ConvertToDrsTimeZone(endTime));
        }
        [TestCase(6, 9, 8)] // when london is in GMT+1 shift an hour
        public void MapsFromDrsTime(int month, int hourIn, int expectedHour)
        {
            var timeIn   = new DateTime(2020, month, 01, hourIn, 00, 00, DateTimeKind.Utc);
            var expected = new DateTime(2020, month, 01, expectedHour, 00, 00, DateTimeKind.Utc);

            var result = DrsHelpers.ConvertFromDrsTimeZone(timeIn);

            result.Should().Be(expected);
        }
        private async Task AddAuditTrail(int workOrderId, bookingConfirmation bookingConfirmation)
        {
            var update = new JobStatusUpdate
            {
                EventTime          = DrsHelpers.ConvertFromDrsTimeZone(bookingConfirmation.changedDate),
                RelatedWorkOrderId = workOrderId,
                TypeCode           = JobStatusUpdateTypeCode.Other_0,
                OtherType          = CustomJobStatusUpdates.AddNote,
                Comments           = $"DRS: Appointment has been updated in DRS to {bookingConfirmation.planningWindowStart.ToDateTime()} - {bookingConfirmation.planningWindowEnd.ToDateTime()} Reason: {bookingConfirmation.bookingReason}"
            };

            await _jobStatusUpdateGateway.CreateJobStatusUpdate(update);
        }
        private async Task <order> CreateOrder(WorkOrder workOrder)
        {
            var property       = workOrder.Site?.PropertyClass.FirstOrDefault();
            var locationAlerts = property != null ? (await _alertsGateway.GetLocationAlertsAsync(property.PropertyReference)).Alerts : new List <Alert>();

            var tenureInfo = await _tenureInformationUseCase.GetTenureInformationWithPropertyReference(property?.PropertyReference);

            var personAlerts  = tenureInfo != null ? (await _alertsGateway.GetPersonAlertsAsync(tenureInfo.TenancyAgreementReference)).Alerts : new List <Alert>();
            var uniqueCodes   = locationAlerts?.Union(personAlerts);
            var orderComments =
                @$ "{uniqueCodes.ToCodeString()} {workOrder.DescriptionOfWork}".Truncate(250);

            var orderCommentsExtended = ($"Property Alerts {locationAlerts?.ToCommentsExtendedString()} " +
                                         $"Person Alerts {personAlerts?.ToCommentsExtendedString()}").Truncate(250);

            var priorityCharacter = workOrder.WorkPriority.PriorityCode.HasValue
                ? await _sorPriorityGateway.GetLegacyPriorityCode(workOrder.WorkPriority.PriorityCode.Value)
                : " ";

            var phoneNumber = workOrder.Customer.Person.Communication.GetPhoneNumber();

            return(new order
            {
                status = orderStatus.PLANNED,
                primaryOrderNumber = workOrder.Id.ToString(CultureInfo.InvariantCulture),
                orderComments = orderComments,
                contract = workOrder.AssignedToPrimary.ContractorReference,
                locationID = workOrder.Site?.PropertyClass.FirstOrDefault()?.PropertyReference,
                priority = priorityCharacter,
                targetDate =
                    workOrder.WorkPriority.RequiredCompletionDateTime.HasValue
                        ? DrsHelpers.ConvertToDrsTimeZone(workOrder.WorkPriority.RequiredCompletionDateTime.Value)
                        : DateTime.UtcNow,
                userId = workOrder.AgentEmail ?? workOrder.AgentName,
                contactName = workOrder.Customer.Name,
                phone = phoneNumber,
                orderCommentsExtended = orderCommentsExtended,
                theLocation = new location
                {
                    locationId = workOrder.Site?.PropertyClass.FirstOrDefault()?.PropertyReference,
                    name = workOrder.Site?.Name,
                    address1 = workOrder.Site?.PropertyClass.FirstOrDefault()?.Address.AddressLine,
                    postCode = workOrder.Site?.PropertyClass.FirstOrDefault()?.Address.PostalCode,
                    contract = workOrder.AssignedToPrimary.ContractorReference,
                    citizensName = workOrder.Customer.Name
                },
                theBookingCodes = await BuildBookingCodes(workOrder),
                message = phoneNumber != null && Regex.IsMatch(phoneNumber, @"^(07\d{8,12}|447\d{7,11})$")
            });
        }
Exemple #7
0
        public async Task UpdateWorkOrderDetails(int workOrderId)
        {
            _logger.LogInformation($"UpdateWorkOrderDetails for workOrderId: {workOrderId}");

            var order = await SelectOrder(workOrderId);

            if (order.theBookings.IsNullOrEmpty())
            {
                return;
            }

            var theBooking = ExtractBooking(order);;

            var theResources = theBooking.theResources;

            if (theResources.IsNullOrEmpty())
            {
                return;
            }

            var operativePayrollIds = theResources.Select(r => r.externalResourceCode);

            var operatives = (await Task.WhenAll(operativePayrollIds.Select(i => _operativesGateway.GetAsync(i))))
                             .Where(o => o != null)
                             .ToArray();

            await CheckAndAssignOperatives(workOrderId, operativePayrollIds, operatives);

            await _appointmentsGateway.SetTimedBooking(
                workOrderId,
                DrsHelpers.ConvertToDrsTimeZone(theBooking.planningWindowStart),
                DrsHelpers.ConvertToDrsTimeZone(theBooking.planningWindowEnd),
                theBooking.bookingReason
                );

            _logger.LogInformation($"WorkOrder {workOrderId}: successfully set timed booking - start: {theBooking.planningWindowStart} end: {theBooking.planningWindowEnd}");

            await _repairsGateway.UpdateWorkOrderAttributes(workOrderId, theBooking.GetPlannerComments());
        }
        public async Task AddsNote()
        {
            const int workOrderId = 1234;

            ReturnsWorkOrder(workOrderId);
            var bookingConfirmation = CreateBookingConfirmation(workOrderId);

            await _classUnderTest.ConfirmBooking(bookingConfirmation);

            var expectedComment = $"DRS: Appointment has been updated in DRS to {bookingConfirmation.planningWindowStart.ToDateTime()} - {bookingConfirmation.planningWindowEnd.ToDateTime()} Reason: {bookingConfirmation.bookingReason}";

            _jobStatusUpdateGatewayMock.Verify(x => x.CreateJobStatusUpdate(It.Is <JobStatusUpdate>(update =>
                                                                                                    update.RelatedWorkOrderId == workOrderId &&
                                                                                                    update.TypeCode == JobStatusUpdateTypeCode.Other_0 &&
                                                                                                    update.OtherType == CustomJobStatusUpdates.AddNote &&
                                                                                                    update.Comments == expectedComment &&
                                                                                                    update.EventTime == DrsHelpers.ConvertFromDrsTimeZone(bookingConfirmation.changedDate)
                                                                                                    )));
        }