var util = require('util'); module.exports = function () { this.When(/^I plan a trip I should get$/, (table, callback) => { var got; this.reprocessAndLoadData(() => { var testRow = (row, ri, cb) => { var afterRequest = (err, res) => { if (err) return cb(err); var headers = new Set(table.raw()[0]); for (var k in row) { var match = k.match(/param:(.*)/); if (match) { if (row[k] === '(nil)') { params[match[1]] = null; } else if (row[k]) { params[match[1]] = [row[k]]; } got[k] = row[k]; } } var json; if (res.body.length) { json = JSON.parse(res.body); } if (headers.has('status')) { got.status = json.status.toString(); } if (headers.has('message')) { got.message = json.status_message; } if (headers.has('#')) { // comment column got['#'] = row['#']; } var subTrips; if (res.statusCode === 200) { if (headers.has('trips')) { subTrips = json.trips.filter(t => !!t).map(t => t.legs).map(tl => Array.prototype.concat.apply([], tl.map((sl, i) => { var toAdd = []; if (i === 0) toAdd.push(sl.steps[0].maneuver.location); toAdd.push(sl.steps[sl.steps.length-1].maneuver.location); return toAdd; }))); } } var ok = true, encodedResult = '', extendedTarget = ''; row.trips.split(',').forEach((sub, si) => { if (si >= subTrips.length) { ok = false; } else { ok = false; // TODO: Check all rotations of the round trip for (var ni=0; ni { var node = this.findNodeByName(n); if (!node) throw new Error(util.format('*** unknown waypoint node "%s"', n.trim())); waypoints.push(node); }); got = { waypoints: row.waypoints }; this.requestTrip(waypoints, params, afterRequest); } else { throw new Error('*** no waypoints'); } } }; this.processRowsAndDiff(table, testRow, callback); }); }); };