const { reduceEstDirections } = require('../server/reducers/directions'); const expect = require('expect.js'); const requestData = { '@lang': 'en-US', 'ResultSet': { '@version': '2.0', '@lang': 'en-US', 'Error': '0', 'ErrorMessage': 'No error', 'Locale': 'en-US', 'Result': { 'yahoo_driving_directions': { 'routeHandle': '0', 'address': [ { 'type': 'Origin', 'lat': '55.942592', 'lon': '-4.556346', 'line1': '', 'line2': '', 'line3': '', 'line4': '', 'country': '' }, { 'type': 'Destination', 'lat': '55.872443', 'lon': '-3.548992', 'line1': '', 'line2': '', 'line3': '', 'line4': '', 'country': '' } ], 'total_distance': '83339', 'total_time': '65.0', 'total_time_with_traffic': '70.0', 'boundingbox': { 'north': '55.942587', 'south': '55.832605', 'east': '-3.541074', 'west': '-4.556462' }, 'route_id': 'AIUACAAAAB4AAABRAAAAlgAAAKAAAAB42mNYwMDAxMQABI+6DtXs5zyRzgAFBvE1Yi4Mi6wY/v+HCDywZ0ACXEBs/kYnl4nhz5vK2okuu+Ea4+ZXi61gXmSDR2PShr4NjECL4YJs6Qcz5wJpB4aEhgeMQClGrglVHA4OTAw+/ADTGiAC9jefAA==', 'directions': { 'route_leg': [ { '@type': 'PrivateRouteLeg', 'number': '1', 'lat': '55.942587', 'lon': '-4.556462', 'distance': '2060', 'description': 'Head toward Bruce Street on Glasgow Road (A814). Go for 2.1 km.', 'time': '3', 'time_with_traffic': '3', 'turn_angle': '0', 'exit_num': '', 'man_type': '0', 'street': 'A814, GLASGOW ROAD' }, { '@type': 'PrivateRouteLeg', 'number': '2', 'lat': '55.935098', 'lon': '-4.526989', 'distance': '1616', 'description': 'Continue on Dumbarton Road (A82). Go for 1.6 km.', 'time': '2', 'time_with_traffic': '2', 'turn_angle': '0', 'exit_num': '', 'man_type': '11', 'street': 'A82, DUMBARTON ROAD' }, { '@type': 'PrivateRouteLeg', 'number': '3', 'lat': '55.931944', 'lon': '-4.503633', 'distance': '3334', 'description': 'Take the 2nd exit from Dunglass Roundabout roundabout onto Great Western Road (A82) toward Glasgow/Erskine Bridge/(A898). Go for 3.3 km.', 'time': '3', 'time_with_traffic': '3', 'turn_angle': '-90', 'exit_num': '', 'man_type': '29', 'street': 'A82, GREAT WESTERN ROAD', 'sign': '(A898), Erskine Bridge, Glasgow' }, { '@type': 'PrivateRouteLeg', 'number': '4', 'lat': '55.926161', 'lon': '-4.452403', 'distance': '2919', 'description': 'Take ramp onto A898 toward Erskine Bridge/Paisley/(M898). Go for 2.9 km.', 'time': '2', 'time_with_traffic': '2', 'turn_angle': '-30', 'exit_num': '', 'man_type': '19', 'street': 'A898, ', 'sign': '(M898), Erskine Bridge, Paisley' }, { '@type': 'PrivateRouteLeg', 'number': '5', 'lat': '55.910207', 'lon': '-4.472519', 'distance': '1152', 'description': 'Keep right onto M898 toward Paisley/Glasgow Airport/Greenock/(M8). Go for 1.2 km.', 'time': '1', 'time_with_traffic': '1', 'turn_angle': '30', 'exit_num': '', 'man_type': '23', 'street': 'M898, ', 'sign': '(M8), Glasgow Airport, Greenock, Paisley' }, { '@type': 'PrivateRouteLeg', 'number': '6', 'lat': '55.901495', 'lon': '-4.481091', 'distance': '396', 'description': 'Keep left onto M898 toward Paisley/Airports. Go for 396 m.', 'time': '0', 'time_with_traffic': '0', 'turn_angle': '-30', 'exit_num': '', 'man_type': '21', 'street': 'M898, ', 'sign': 'Airports, Paisley' }, { '@type': 'PrivateRouteLeg', 'number': '7', 'lat': '55.898287', 'lon': '-4.483226', 'distance': '64579', 'description': 'Keep left onto M8. Go for 64.6 km.', 'time': '42', 'time_with_traffic': '42', 'turn_angle': '-30', 'exit_num': '', 'man_type': '21', 'street': 'M8, ' }, { '@type': 'PrivateRouteLeg', 'number': '8', 'lat': '55.895294', 'lon': '-3.596402', 'distance': '240', 'description': 'Take exit 3A toward Bathgate/(A89)/Broxburn/Livingston West/(A779). Go for 240 m.', 'time': '0', 'time_with_traffic': '0', 'turn_angle': '-30', 'exit_num': '', 'man_type': '17', 'street': ', ', 'sign': '(A779), (A89), Bathgate, Broxburn, Livingston West' }, { '@type': 'PrivateRouteLeg', 'number': '9', 'lat': '55.897204', 'lon': '-3.595244', 'distance': '420', 'description': 'Take the 1st exit from roundabout onto Carnegie Road (A779) toward Glasgow/(M8)/Livingston/Bathgate/(A89)/Broxburn. Go for 420 m.', 'time': '1', 'time_with_traffic': '1', 'turn_angle': '-90', 'exit_num': '', 'man_type': '29', 'street': 'A779, CARNEGIE ROAD', 'sign': '(A89), (M8), A779, Bathgate, Broxburn, Glasgow, Livingston' }, { '@type': 'PrivateRouteLeg', 'number': '10', 'lat': '55.897193', 'lon': '-3.601885', 'distance': '840', 'description': 'Take the 1st exit from Boghall Roundabout roundabout onto A779 toward Glasgow/(M8)/Livingston. Go for 840 m.', 'time': '1', 'time_with_traffic': '1', 'turn_angle': '-90', 'exit_num': '', 'man_type': '29', 'street': 'A779, ', 'sign': '(M8), A779, Glasgow, Livingston' }, { '@type': 'PrivateRouteLeg', 'number': '11', 'lat': '55.890466', 'lon': '-3.596713', 'distance': '1622', 'description': 'Take the 1st exit from Starlaw West Roundabout roundabout onto Starlaw Road (A779) toward Livingston/Kirkton Campus/Alba Centre/Starlaw Park. Go for 1.6 km.', 'time': '2', 'time_with_traffic': '2', 'turn_angle': '-90', 'exit_num': '', 'man_type': '29', 'street': 'A779, STARLAW ROAD', 'sign': 'Alba Centre, Kirkton Campus, Livingston, Starlaw Park' }, { '@type': 'PrivateRouteLeg', 'number': '12', 'lat': '55.89009', 'lon': '-3.570975', 'distance': '657', 'description': 'Take the 3rd exit from Tailend Roundabout roundabout onto Starlaw Road (A779). Go for 657 m.', 'time': '1', 'time_with_traffic': '1', 'turn_angle': '-90', 'exit_num': '', 'man_type': '29', 'street': 'A779, STARLAW ROAD' }, { '@type': 'PrivateRouteLeg', 'number': '13', 'lat': '55.886743', 'lon': '-3.563787', 'distance': '486', 'description': 'Take the 2nd exit from Toll Roundabout roundabout onto A705. Go for 486 m.', 'time': '1', 'time_with_traffic': '1', 'turn_angle': '-90', 'exit_num': '', 'man_type': '29', 'street': 'A705, ' }, { '@type': 'PrivateRouteLeg', 'number': '14', 'lat': '55.885638', 'lon': '-3.557596', 'distance': '2131', 'description': 'Turn right onto Simpson Parkway (B7015). Go for 2.1 km.', 'time': '3', 'time_with_traffic': '3', 'turn_angle': '90', 'exit_num': '', 'man_type': '13', 'street': 'B7015, SIMPSON PARKWAY' }, { '@type': 'PrivateRouteLeg', 'number': '15', 'lat': '55.876765', 'lon': '-3.542415', 'distance': '345', 'description': 'Continue on Simpson Parkway. Go for 345 m.', 'time': '0', 'time_with_traffic': '0', 'turn_angle': '0', 'exit_num': '', 'man_type': '11', 'street': ', SIMPSON PARKWAY' }, { '@type': 'PrivateRouteLeg', 'number': '16', 'lat': '55.873793', 'lon': '-3.541074', 'distance': '197', 'description': 'Take the 3rd exit from Rosebank Roundabout roundabout. Go for 197 m.', 'time': '1', 'time_with_traffic': '1', 'turn_angle': '-90', 'exit_num': '', 'man_type': '29', 'street': ', ' }, { '@type': 'PrivateRouteLeg', 'number': '17', 'lat': '55.872957', 'lon': '-3.542737', 'distance': '222', 'description': 'Take the 2nd exit from Brotherton Roundabout roundabout. Go for 222 m.', 'time': '1', 'time_with_traffic': '1', 'turn_angle': '-90', 'exit_num': '', 'man_type': '29', 'street': ', ' }, { '@type': 'PrivateRouteLeg', 'number': '18', 'lat': '55.873075', 'lon': '-3.546073', 'distance': '123', 'description': 'Take the 1st exit from roundabout. Go for 123 m.', 'time': '0', 'time_with_traffic': '0', 'turn_angle': '-90', 'exit_num': '', 'man_type': '29', 'street': ', ' }, { '@type': 'PrivateRouteLeg', 'number': '19', 'lat': '55.872313', 'lon': '-3.547393', 'distance': '0', 'description': 'Arrive at your destination.', 'time': '0', 'time_with_traffic': '0', 'turn_angle': '0', 'exit_num': '', 'man_type': '2', 'street': ', ' } ] }, 'copy_right': 'Copyright © 2018 Yahoo! Inc. All rights reserved. © Navteq' }, 'geocode_results': null } } }; const goodOutput = { 'totalTime': 65, 'totalTimeWithTraffic': 70, 'readable': '1 hour, 10 minutes', 'timePercentage': 10.5, 'traffic': 'no traffic', 'className': 'trafficNone' }; describe('Directions', () => { it('should gracefully handle no data', done => { expect(reduceEstDirections()).to.eql({}); done(); }); it('Should process data correctly', done => { expect(reduceEstDirections(JSON.stringify(requestData))).to.eql(goodOutput); done(); }); });