Skip to content

Commit 0eedcf6

Browse files
committed
Fix checking columns if route is not specified
1 parent 62abea3 commit 0eedcf6

File tree

1 file changed

+81
-81
lines changed

1 file changed

+81
-81
lines changed

features/support/shared_steps.js

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -79,101 +79,101 @@ module.exports = function () {
7979

8080
if (headers.has('route')) {
8181
got.route = (instructions || '').trim();
82+
}
8283

83-
if (headers.has('summary')) {
84-
got.summary = (summary || '').trim();
85-
}
84+
if (headers.has('summary')) {
85+
got.summary = (summary || '').trim();
86+
}
8687

87-
if (headers.has('alternative')) {
88-
// TODO examine more than first alternative?
89-
got.alternative ='';
90-
if (json.routes && json.routes.length > 1)
91-
got.alternative = this.wayList(json.routes[1]);
92-
}
88+
if (headers.has('alternative')) {
89+
// TODO examine more than first alternative?
90+
got.alternative ='';
91+
if (json.routes && json.routes.length > 1)
92+
got.alternative = this.wayList(json.routes[1]);
93+
}
9394

94-
var distance = hasRoute && json.routes[0].distance,
95-
time = hasRoute && json.routes[0].duration,
96-
weight = hasRoute && json.routes[0].weight;
97-
98-
if (headers.has('distance')) {
99-
if (row.distance.length) {
100-
if (!row.distance.match(/\d+m/))
101-
return cb(new Error('*** Distance must be specified in meters. (ex: 250m)'));
102-
got.distance = instructions ? util.format('%dm', distance) : '';
103-
} else {
104-
got.distance = '';
105-
}
95+
var distance = hasRoute && json.routes[0].distance,
96+
time = hasRoute && json.routes[0].duration,
97+
weight = hasRoute && json.routes[0].weight;
98+
99+
if (headers.has('distance')) {
100+
if (row.distance.length) {
101+
if (!row.distance.match(/\d+m/))
102+
return cb(new Error('*** Distance must be specified in meters. (ex: 250m)'));
103+
got.distance = instructions ? util.format('%dm', distance) : '';
104+
} else {
105+
got.distance = '';
106106
}
107+
}
107108

108-
if (headers.has('weight')) {
109-
if (row.weight.length) {
110-
if (!row.weight.match(/[\d\.]+/))
111-
return cb(new Error('*** Weight must be specified as a numeric value. (ex: 8)'));
112-
got.weight = instructions ? util.format('%d', weight) : '';
113-
} else {
114-
got.weight = '';
115-
}
109+
if (headers.has('weight')) {
110+
if (row.weight.length) {
111+
if (!row.weight.match(/[\d\.]+/))
112+
return cb(new Error('*** Weight must be specified as a numeric value. (ex: 8)'));
113+
got.weight = instructions ? util.format('%d', weight) : '';
114+
} else {
115+
got.weight = '';
116116
}
117+
}
117118

118-
if (headers.has('time')) {
119-
if (!row.time.match(/\d+s/))
120-
return cb(new Error('*** Time must be specied in seconds. (ex: 60s)'));
121-
got.time = instructions ? util.format('%ds', time) : '';
122-
}
119+
if (headers.has('time')) {
120+
if (!row.time.match(/\d+s/))
121+
return cb(new Error('*** Time must be specied in seconds. (ex: 60s)'));
122+
got.time = instructions ? util.format('%ds', time) : '';
123+
}
123124

124-
if (headers.has('lanes')) {
125-
got.lanes = (lanes || '').trim();
126-
}
125+
if (headers.has('lanes')) {
126+
got.lanes = (lanes || '').trim();
127+
}
127128

128-
if (headers.has('speed')) {
129-
if (row.speed !== '' && instructions) {
130-
if (!row.speed.match(/\d+ km\/h/))
131-
cb(new Error('*** Speed must be specied in km/h. (ex: 50 km/h)'));
132-
var speed = time > 0 ? Math.round(3.6*distance/time) : null;
133-
got.speed = util.format('%d km/h', speed);
134-
} else {
135-
got.speed = '';
136-
}
129+
if (headers.has('speed')) {
130+
if (row.speed !== '' && instructions) {
131+
if (!row.speed.match(/\d+ km\/h/))
132+
cb(new Error('*** Speed must be specied in km/h. (ex: 50 km/h)'));
133+
var speed = time > 0 ? Math.round(3.6*distance/time) : null;
134+
got.speed = util.format('%d km/h', speed);
135+
} else {
136+
got.speed = '';
137137
}
138+
}
138139

139-
if (headers.has('intersections')) {
140-
got.intersections = (intersections || '').trim();
141-
}
140+
if (headers.has('intersections')) {
141+
got.intersections = (intersections || '').trim();
142+
}
142143

143-
if (headers.has('locations')){
144-
got.locations = (locations || '').trim();
144+
if (headers.has('locations')){
145+
got.locations = (locations || '').trim();
146+
}
147+
148+
// if header matches 'a:*', parse out the values for *
149+
// and return in that header
150+
headers.forEach((k) => {
151+
let whitelist = ['duration', 'distance', 'datasources', 'nodes', 'weight', 'speed'];
152+
if (k.match(/^a:/)) {
153+
let a_type = k.slice(2);
154+
if (whitelist.indexOf(a_type) == -1)
155+
return cb(new Error('Unrecognized annotation field', a_type));
156+
if (annotation && !annotation[a_type])
157+
return cb(new Error('Annotation not found in response', a_type));
158+
got[k] = annotation && annotation[a_type] || '';
145159
}
160+
});
146161

147-
// if header matches 'a:*', parse out the values for *
148-
// and return in that header
149-
headers.forEach((k) => {
150-
let whitelist = ['duration', 'distance', 'datasources', 'nodes', 'weight', 'speed'];
151-
if (k.match(/^a:/)) {
152-
let a_type = k.slice(2);
153-
if (whitelist.indexOf(a_type) == -1)
154-
return cb(new Error('Unrecognized annotation field', a_type));
155-
if (annotation && !annotation[a_type])
156-
return cb(new Error('Annotation not found in response', a_type));
157-
got[k] = annotation && annotation[a_type] || '';
158-
}
159-
});
160-
161-
var putValue = (key, value) => {
162-
if (headers.has(key)) got[key] = instructions ? value : '';
163-
};
164-
165-
putValue('ref', refs);
166-
putValue('bearing', bearings);
167-
putValue('turns', turns);
168-
putValue('modes', modes);
169-
putValue('times', times);
170-
putValue('distances', distances);
171-
putValue('pronunciations', pronunciations);
172-
putValue('destinations', destinations);
173-
putValue('weight_name', weight_name);
174-
putValue('weights', weights);
175-
putValue('weight', weight);
176-
}
162+
var putValue = (key, value) => {
163+
if (headers.has(key)) got[key] = instructions ? value : '';
164+
};
165+
166+
putValue('ref', refs);
167+
putValue('bearing', bearings);
168+
putValue('turns', turns);
169+
putValue('modes', modes);
170+
putValue('times', times);
171+
putValue('distances', distances);
172+
putValue('pronunciations', pronunciations);
173+
putValue('destinations', destinations);
174+
putValue('weight_name', weight_name);
175+
putValue('weights', weights);
176+
putValue('weight', weight);
177177

178178
for (var key in row) {
179179
if (this.FuzzyMatch.match(got[key], row[key])) {

0 commit comments

Comments
 (0)