it('destinationCoordinates should return an error', function(done){ geo.getDrivingDistance(testData.locations.RicoAddress.coordinates, false, function(err, distance) { expect(err).to.not.be.null; expect(err.message).to.eq('destinationCoordinates are not valid'); expect(distance).to.be.null; done(); }); });
it('originCoordinates should return an error', function(done) { geo.getDrivingDistance(null, false, function (err, distance) { expect(err).to.not.be.null; expect(err.message).to.eq('originCoordinates are not valid'); expect(distance).to.be.null; done(); }); });
it ('should return the driving distance for 2 locations', function(done){ var destination = testData.locations.RicoAddress.coordinates; var origin = [6.7273549,51.2395808]; geo.getDrivingDistance(origin, destination, function(err, distance) { if (err) done(err); expect(distance).to.eq(632.49); done(); }) });
Contractor.findById(jobData.contractor, function (err, contractor) { if (err) return handleErrorResponse(res, 400, err.toString(), err); jobData.mapUrl = geo.getStaticMap(contractor.address.coordinates, coordinates); geo.getDrivingDistance(contractor.address.coordinates, coordinates, function (err, distance) { if (err) return handleErrorResponse(res, 500, err.toString(), err); jobData.invoice.travelCharge = (distance * 2) * contractor.distanceCharge; jobData.distance = distance; }); });
Contractor.FindClosest(address.coordinates, function(err, found) { if (err) return handleErrorResponse(res, 400, 'Find closest contractor failed', err); if (found.length == 0) return handleErrorResponse(res, 400, 'No contractor found'); var contractorInfo = found[0]; var source = contractorInfo.address.coordinates, destination = address.coordinates; geo.getDrivingDistance(source, destination, function(err, distance) { if (err) return handleErrorResponse(res, 400, err.toString(), err); jobData.mapUrl = geo.getStaticMap(source, destination); jobData.contractor = contractorInfo; jobData.status = lookUps.jobStatus.created; jobData.onSiteContact = {}; jobData.checkLists = []; Job.NextInvoiceNumber(function(invNumber) { jobData.invoice = { number: invNumber, fixedPrice: orderType.fee, travelCharge: (distance * 2) * contractorInfo.distanceCharge }; jobData.distance = distance; Job.create(jobData, function (err, job) { if (err) return handleErrorResponse(res, 400, err.toString(), err); var result = { job: job, workFlow: { duration: orderType.hours, distance: job.distance, travelCharge: job.invoice.travelCharge } }; res.status(200); res.send(result); }) }); }); });