From 25e40d723afd2511e5022cb084f59ea4b4c90bf8 Mon Sep 17 00:00:00 2001 From: Jeff Miccolis Date: Mon, 28 Mar 2016 17:49:29 -0400 Subject: [PATCH] Better handling of test response payloads --- features/support/route.js | 45 +++++++++----------------------- features/support/shared_steps.js | 7 +++-- 2 files changed, 15 insertions(+), 37 deletions(-) diff --git a/features/support/route.js b/features/support/route.js index 172cda58f..8fc3b4790 100644 --- a/features/support/route.js +++ b/features/support/route.js @@ -111,10 +111,9 @@ module.exports = function () { this.extractInstructionList = (instructions, keyFinder, postfix) => { postfix = postfix || null; if (instructions) { - return Array.prototype.concat.apply([], - instructions.legs.map(l => l.steps)) - .filter(s => s.maneuver.type !== 'arrive') - .map(keyFinder) + return instructions.legs.reduce((m, v) => m.concat(v.steps), []) + .filter(v => v.maneuver.type !== 'arrive') + .map(keyFinder) .join(','); } }; @@ -124,49 +123,29 @@ module.exports = function () { }; this.compassList = (instructions) => { - return this.extractInstructionList(instructions, 6); + return this.extractInstructionList(instructions, s => 'n'); // TODO fixme }; this.bearingList = (instructions) => { - return this.extractInstructionList(instructions, 7); + return this.extractInstructionList(instructions, s => s.bearing_after); }; this.turnList = (instructions) => { - var types = { - '0': 'none', - '1': 'straight', - '2': 'slight_right', - '3': 'right', - '4': 'sharp_right', - '5': 'u_turn', - '6': 'sharp_left', - '7': 'left', - '8': 'slight_left', - '9': 'via', - '10': 'head', - '11': 'enter_roundabout', - '12': 'leave_roundabout', - '13': 'stay_roundabout', - '14': 'start_end_of_street', - '15': 'destination', - '16': 'name_changes', - '17': 'enter_contraflow', - '18': 'leave_contraflow' - }; - - // replace instructions codes with strings, e.g. '11-3' gets converted to 'enter_roundabout-3' - return instructions ? instructions.map(r => r[0].toString().replace(/^(\d*)/, (match, num) => types[num])).join(',') : instructions; + return instructions.legs.reduce((m, v) => m.concat(v.steps), []) + .filter(v => v.maneuver.modifier) + .map(v => v.maneuver.modifier) + .join(','); }; this.modeList = (instructions) => { - return this.extractInstructionList(instructions, 8); + return this.extractInstructionList(instructions, s => s.mode); }; this.timeList = (instructions) => { - return this.extractInstructionList(instructions, 4, 's'); + return this.extractInstructionList(instructions, s => s.duration + 's'); }; this.distanceList = (instructions) => { - return this.extractInstructionList(instructions, 2, 'm'); + return this.extractInstructionList(instructions, s => s.distance + 'm'); }; }; diff --git a/features/support/shared_steps.js b/features/support/shared_steps.js index 591192f53..d4fd1f09d 100644 --- a/features/support/shared_steps.js +++ b/features/support/shared_steps.js @@ -26,17 +26,16 @@ module.exports = function () { var headers = new Set(table.raw()[0]); var requestRow = (row, ri, cb) => { - var got, - json; + var got; var afterRequest = (err, res, body) => { if (err) return cb(err); if (body && body.length) { var instructions, bearings, compasses, turns, modes, times, distances; - json = JSON.parse(body); + var json = JSON.parse(body); - var hasRoute = json.status === 200; + var hasRoute = json.code === 'ok'; if (hasRoute) { instructions = this.wayList(json.routes[0]);