From 8a54e6a0eca5cb8c1416caec1b937203d928ee9c Mon Sep 17 00:00:00 2001 From: FILLAU Jean-Maxime Date: Tue, 16 May 2017 18:46:26 +0200 Subject: [PATCH] Adding "sides" params for the sides option tests into java script Signed-off-by: FILLAU Jean-Maxime --- features/step_definitions/routability.js | 2 +- features/support/route.js | 10 +++++++++- features/support/shared_steps.js | 21 ++++++++++++++++----- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/features/step_definitions/routability.js b/features/step_definitions/routability.js index ceeff4384..f9e8a01be 100644 --- a/features/step_definitions/routability.js +++ b/features/step_definitions/routability.js @@ -121,7 +121,7 @@ module.exports = function () { r.which = dir; - this.requestRoute((dir === 'forw' ? [a, b] : [b, a]), [], this.queryParams, (err, res, body) => { + this.requestRoute((dir === 'forw' ? [a, b] : [b, a]), [], [], this.queryParams, (err, res, body) => { if (err) return callback(err); r.query = this.query; diff --git a/features/support/route.js b/features/support/route.js index e3c714bf5..b5e108cce 100644 --- a/features/support/route.js +++ b/features/support/route.js @@ -46,8 +46,9 @@ module.exports = function () { return waypoints.map(w => [w.lon, w.lat].map(ensureDecimal).join(',')); }; - this.requestRoute = (waypoints, bearings, userParams, callback) => { + this.requestRoute = (waypoints, bearings, sides, userParams, callback) => { if (bearings.length && bearings.length !== waypoints.length) throw new Error('*** number of bearings does not equal the number of waypoints'); + if (sides.length && sides.length !== waypoints.length) throw new Error('*** number of sides does not equal the number of waypoints'); var defaults = { output: 'json', @@ -67,6 +68,9 @@ module.exports = function () { }).join(';'); } + if (sides.length) { + params.sides = sides.join(';'); + } return this.requestPath('route', params, callback); }; @@ -163,6 +167,10 @@ module.exports = function () { ('out' in s.intersections[0] ? s.intersections[0].bearings[s.intersections[0].out] : 0)); }; + this.sideList = (instructions) => { + return this.extractInstructionList(instructions, s => s.sides || ''); + }; + this.annotationList = (instructions) => { if (!('annotation' in instructions.legs[0])) return ''; diff --git a/features/support/shared_steps.js b/features/support/shared_steps.js index fb21e17bf..c87d21a93 100644 --- a/features/support/shared_steps.js +++ b/features/support/shared_steps.js @@ -35,7 +35,7 @@ module.exports = function () { if (err) return cb(err); if (body && body.length) { let destinations, pronunciations, instructions, refs, bearings, turns, modes, times, - distances, summary, intersections, lanes, locations, annotation, weight_name, weights; + distances, summary, intersections, lanes, locations, annotation, weight_name, weights, sides; let json = JSON.parse(body); @@ -60,6 +60,7 @@ module.exports = function () { annotation = this.annotationList(json.routes[0]); weight_name = this.weightName(json.routes[0]); weights = this.weightList(json.routes[0]); + sides = this.sideList(json.routes[0]); } if (headers.has('status')) { @@ -146,7 +147,10 @@ module.exports = function () { if (headers.has('locations')){ got.locations = (locations || '').trim(); } - +/* + if (headers.has('sides')){ + got.sides = (sides || '').trim(); + }*/ // if header matches 'a:*', parse out the values for * // and return in that header headers.forEach((k) => { @@ -176,6 +180,7 @@ module.exports = function () { putValue('weight_name', weight_name); putValue('weights', weights); putValue('weight', weight); + putValue('side', sides); for (var key in row) { if (this.FuzzyMatch.match(got[key], row[key])) { @@ -210,13 +215,19 @@ module.exports = function () { var params = this.overwriteParams(defaultParams, userParams), waypoints = [], - bearings = []; + bearings = [], + sides = []; if (row.bearings) { got.bearings = row.bearings; bearings = row.bearings.split(' ').filter(b => !!b); } + if (row.sides) { + got.sides = row.sides; + sides = row.sides.split(' ').filter(b => !!b); + } + if (row.from && row.to) { var fromNode = this.findNodeByName(row.from); if (!fromNode) return cb(new Error(util.format('*** unknown from-node "%s"', row.from))); @@ -228,7 +239,7 @@ module.exports = function () { got.from = row.from; got.to = row.to; - this.requestRoute(waypoints, bearings, params, afterRequest); + this.requestRoute(waypoints, bearings, sides, params, afterRequest); } else if (row.waypoints) { row.waypoints.split(',').forEach((n) => { var node = this.findNodeByName(n.trim()); @@ -236,7 +247,7 @@ module.exports = function () { waypoints.push(node); }); got.waypoints = row.waypoints; - this.requestRoute(waypoints, bearings, params, afterRequest); + this.requestRoute(waypoints, bearings, sides, params, afterRequest); } else { return cb(new Error('*** no waypoints')); }