Better handling of test response payloads
This commit is contained in:
		
							parent
							
								
									3ed46aa4c5
								
							
						
					
					
						commit
						1bcdc0fa75
					
				@ -111,9 +111,8 @@ module.exports = function () {
 | 
				
			|||||||
    this.extractInstructionList = (instructions, keyFinder, postfix) => {
 | 
					    this.extractInstructionList = (instructions, keyFinder, postfix) => {
 | 
				
			||||||
        postfix = postfix || null;
 | 
					        postfix = postfix || null;
 | 
				
			||||||
        if (instructions) {
 | 
					        if (instructions) {
 | 
				
			||||||
            return Array.prototype.concat.apply([],
 | 
					            return instructions.legs.reduce((m, v) => m.concat(v.steps), [])
 | 
				
			||||||
                instructions.legs.map(l => l.steps))
 | 
					                .filter(v => v.maneuver.type !== 'arrive')
 | 
				
			||||||
                    .filter(s => s.maneuver.type !== 'arrive')
 | 
					 | 
				
			||||||
                .map(keyFinder)
 | 
					                .map(keyFinder)
 | 
				
			||||||
                .join(',');
 | 
					                .join(',');
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -124,49 +123,29 @@ module.exports = function () {
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.compassList = (instructions) => {
 | 
					    this.compassList = (instructions) => {
 | 
				
			||||||
        return this.extractInstructionList(instructions, 6);
 | 
					        return this.extractInstructionList(instructions, s => 'n'); // TODO fixme
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.bearingList = (instructions) => {
 | 
					    this.bearingList = (instructions) => {
 | 
				
			||||||
        return this.extractInstructionList(instructions, 7);
 | 
					        return this.extractInstructionList(instructions, s => s.bearing_after);
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.turnList = (instructions) => {
 | 
					    this.turnList = (instructions) => {
 | 
				
			||||||
        var types = {
 | 
					        return instructions.legs.reduce((m, v) => m.concat(v.steps), [])
 | 
				
			||||||
            '0': 'none',
 | 
					            .filter(v => v.maneuver.modifier)
 | 
				
			||||||
            '1': 'straight',
 | 
					            .map(v => v.maneuver.modifier)
 | 
				
			||||||
            '2': 'slight_right',
 | 
					            .join(',');
 | 
				
			||||||
            '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;
 | 
					 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.modeList = (instructions) => {
 | 
					    this.modeList = (instructions) => {
 | 
				
			||||||
        return this.extractInstructionList(instructions, 8);
 | 
					        return this.extractInstructionList(instructions, s => s.mode);
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.timeList = (instructions) => {
 | 
					    this.timeList = (instructions) => {
 | 
				
			||||||
        return this.extractInstructionList(instructions, 4, 's');
 | 
					        return this.extractInstructionList(instructions, s => s.duration + 's');
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.distanceList = (instructions) => {
 | 
					    this.distanceList = (instructions) => {
 | 
				
			||||||
        return this.extractInstructionList(instructions, 2, 'm');
 | 
					        return this.extractInstructionList(instructions, s => s.distance + 'm');
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -26,17 +26,16 @@ module.exports = function () {
 | 
				
			|||||||
            var headers = new Set(table.raw()[0]);
 | 
					            var headers = new Set(table.raw()[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var requestRow = (row, ri, cb) => {
 | 
					            var requestRow = (row, ri, cb) => {
 | 
				
			||||||
                var got,
 | 
					                var got;
 | 
				
			||||||
                    json;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                var afterRequest = (err, res, body) => {
 | 
					                var afterRequest = (err, res, body) => {
 | 
				
			||||||
                    if (err) return cb(err);
 | 
					                    if (err) return cb(err);
 | 
				
			||||||
                    if (body && body.length) {
 | 
					                    if (body && body.length) {
 | 
				
			||||||
                        var instructions, bearings, compasses, turns, modes, times, distances;
 | 
					                        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) {
 | 
					                        if (hasRoute) {
 | 
				
			||||||
                            instructions = this.wayList(json.routes[0]);
 | 
					                            instructions = this.wayList(json.routes[0]);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user