jubilee/test/directions.spec.js
2018-10-12 16:19:55 +01:00

311 lines
12 KiB
JavaScript

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': '51.508577',
'lon': '-0.067628',
'line1': '',
'line2': '',
'line3': '',
'line4': '',
'country': ''
},
{
'type': 'Destination',
'lat': '51.490002',
'lon': '-0.140245',
'line1': '',
'line2': '',
'line3': '',
'line4': '',
'country': ''
}
],
'total_distance': '7189',
'total_time': '42.0',
'total_time_with_traffic': '0.0',
'boundingbox': {
'north': '51.512259',
'south': '51.490066',
'east': '-0.06742',
'west': '-0.143531'
},
'directions': {
'route_leg': [
{
'@type': 'PrivateRouteLeg',
'number': '1',
'lat': '51.508648',
'lon': '-0.06742',
'distance': '49',
'description': 'Head northwest on Vaughan Way. Go for 49 m.',
'time': '2018-10-11T17:14:37+01:00',
'time_with_traffic': '1',
'turn_angle': '0',
'exit_num': '',
'man_type': '0',
'street': ', VAUGHAN WAY'
},
{
'@type': 'PrivateRouteLeg',
'number': '2',
'lat': '51.509045',
'lon': '-0.06772',
'distance': '340',
'description': 'Turn left onto East Smithfield. Go for 340 m.',
'time': '2018-10-11T17:15:36+01:00',
'time_with_traffic': '6',
'turn_angle': '-90',
'exit_num': '',
'man_type': '9',
'street': 'A1203, EAST SMITHFIELD'
},
{
'@type': 'PrivateRouteLeg',
'number': '3',
'lat': '51.508584',
'lon': '-0.072323',
'distance': '281',
'description': 'Turn left. Go for 281 m.',
'time': '2018-10-11T17:21:17+01:00',
'time_with_traffic': '5',
'turn_angle': '-90',
'exit_num': '',
'man_type': '9',
'street': ', '
},
{
'@type': 'PrivateRouteLeg',
'number': '4',
'lat': '51.509378',
'lon': '-0.076046',
'distance': '40',
'description': 'Turn right. Go for 40 m.',
'time': '2018-10-11T17:25:58+01:00',
'time_with_traffic': '1',
'turn_angle': '90',
'exit_num': '',
'man_type': '13',
'street': ', '
},
{
'@type': 'PrivateRouteLeg',
'number': '5',
'lat': '51.509732',
'lon': '-0.076164',
'distance': '22',
'description': 'Turn left. Go for 22 m.',
'time': '2018-10-11T17:26:38+01:00',
'time_with_traffic': '0',
'turn_angle': '-90',
'exit_num': '',
'man_type': '9',
'street': ', '
},
{
'@type': 'PublicRouteLeg',
'number': '6',
'lat': '51.509834',
'lon': '-0.076454',
'distance': '5670',
'description': 'Go to the Train station Tower Hill and take the rail District toward Ealing Broadway. Follow for 9 stations.',
'time': '2018-10-11T17:27:00+01:00',
'time_with_traffic': '16',
'stop_name': 'Tower Hill',
'platform_name': {
'@nil': 'true'
},
'platform_level': {
'@nil': 'true'
},
'line': {
'@nil': 'true'
},
'wait_time': '1'
},
{
'@type': 'PublicRouteLeg',
'number': '7',
'lat': '51.495981',
'lon': '-0.143475',
'distance': '0',
'description': 'Get off at Victoria.',
'time': '2018-10-11T17:43:00+01:00',
'time_with_traffic': '0',
'stop_name': 'Victoria',
'platform_name': {
'@nil': 'true'
},
'platform_level': {
'@nil': 'true'
},
'line': {
'@nil': 'true'
},
'wait_time': '0'
},
{
'@type': 'PrivateRouteLeg',
'number': '8',
'lat': '51.495981',
'lon': '-0.143475',
'distance': '21',
'description': 'Head northeast on Terminus Place. Go for 21 m.',
'time': '2018-10-11T17:43:00+01:00',
'time_with_traffic': '0',
'turn_angle': '0',
'exit_num': '',
'man_type': '11',
'street': ', TERMINUS PLACE'
},
{
'@type': 'PrivateRouteLeg',
'number': '9',
'lat': '51.496063',
'lon': '-0.143208',
'distance': '624',
'description': 'Turn right onto Wilton Road. Go for 624 m.',
'time': '2018-10-11T17:43:21+01:00',
'time_with_traffic': '11',
'turn_angle': '90',
'exit_num': '',
'man_type': '13',
'street': 'A202, WILTON ROAD'
},
{
'@type': 'PrivateRouteLeg',
'number': '10',
'lat': '51.491032',
'lon': '-0.139561',
'distance': '22',
'description': 'Turn left onto Belgrave Road. Go for 22 m.',
'time': '2018-10-11T17:53:51+01:00',
'time_with_traffic': '1',
'turn_angle': '-90',
'exit_num': '',
'man_type': '9',
'street': 'A3213, BELGRAVE ROAD'
},
{
'@type': 'PrivateRouteLeg',
'number': '11',
'lat': '51.490914',
'lon': '-0.139314',
'distance': '120',
'description': 'Turn right onto Denbigh Street. Go for 120 m.',
'time': '2018-10-11T17:54:23+01:00',
'time_with_traffic': '2',
'turn_angle': '90',
'exit_num': '',
'man_type': '13',
'street': ', DENBIGH STREET'
},
{
'@type': 'PrivateRouteLeg',
'number': '12',
'lat': '51.490066',
'lon': '-0.140383',
'distance': '0',
'description': 'Arrive at Gloucester Street. Your destination is on the left.',
'time': '2018-10-11T17:56:26+01:00',
'time_with_traffic': '0',
'turn_angle': '0',
'exit_num': '',
'man_type': '2',
'street': ', '
}
]
},
'maneuverGroups': {
'maneuverGroup': [
{
'arrivalDescription': 'Arrive at Tower Hill.',
'firstManeuver': 'M1',
'lastManeuver': 'M5',
'summaryDescription': 'Walk to Train Tower Hill.',
'transportMode': 'pedestrian',
'transportModeNum': '6'
},
{
'arrivalDescription': 'Get off at Victoria.',
'firstManeuver': 'M6',
'lastManeuver': 'M7',
'publicTransportType': 'railMetro',
'publicTransportTypeNum': '5',
'summaryDescription': 'Take the rail District toward Ealing Broadway.',
'transportMode': 'pubTimeTable',
'transportModeNum': '11',
'waitDescription': '1 minutes to connect.'
},
{
'arrivalDescription': 'Arrive at Gloucester Street.',
'firstManeuver': 'M8',
'lastManeuver': 'M12',
'summaryDescription': '',
'transportMode': 'pedestrian',
'transportModeNum': '6'
}
]
},
'copy_right': 'Copyright © 2018 Yahoo! Inc. All rights reserved. © Navteq'
},
'geocode_results': null,
'source_attribution': {
'attribution': 'With the support of <span class="company"><a rel="nofollow" target="_blank" href="https://transit.api.here.com/r?appId=eAdkWGYRoc4RfxVo0Z4B&amp;u=https://www.networkrail.co.uk/who-we-are/transparency-and-ethics/transparency/open-data-feeds/network-rail-infrastructure-limited-data-feeds-licence/">London Underground (TfL)</a></span>. All information is provided without warranty of any kind. London Underground (TfL) <a rel="nofollow" target="_blank" href="https://transit.api.here.com/r?appId=eAdkWGYRoc4RfxVo0Z4B&amp;u=https://www.networkrail.co.uk/who-we-are/transparency-and-ethics/transparency/open-data-feeds/network-rail-infrastructure-limited-data-feeds-licence/">Contains public sector information licensed under the Open Government Licence v3.0. Contains OS data © Crown copyright and database rights 2016. Powered by TfL Open Data. Contains Information of Network Rail Infrastructure Limited licensed under the linked licence.</a>',
'sourceSuppliers': {
'href': 'https://transit.api.here.com/r?appId=eAdkWGYRoc4RfxVo0Z4B&amp;u=https://www.networkrail.co.uk/who-we-are/transparency-and-ethics/transparency/open-data-feeds/network-rail-infrastructure-limited-data-feeds-licence/',
'title': 'London Underground (TfL) <a rel="nofollow" target="_blank" href="https://transit.api.here.com/r?appId=eAdkWGYRoc4RfxVo0Z4B&amp;u=https://www.networkrail.co.uk/who-we-are/transparency-and-ethics/transparency/open-data-feeds/network-rail-infrastructure-limited-data-feeds-licence/">Contains public sector information licensed under the Open Government Licence v3.0. Contains OS data © Crown copyright and database rights 2016. Powered by TfL Open Data. Contains Information of Network Rail Infrastructure Limited licensed under the linked licence.</a>'
}
}
}
}
}
;
const goodOutput = { 'totalTime': 42,
'totalTimeWithTraffic': 0,
'readable': '42 minutes',
'timePercentage': -58,
'traffic': 'no traffic',
'className': 'trafficNone',
'directions':
[ 'Head northwest on Vaughan Way. Go for 49 m.',
'Turn left onto East Smithfield. Go for 340 m.',
'Turn left. Go for 281 m.',
'Turn right. Go for 40 m.',
'Turn left. Go for 22 m.',
'Go to the Train station Tower Hill and take the rail District toward Ealing Broadway. Follow for 9 stations.',
'Get off at Victoria.',
'Head northeast on Terminus Place. Go for 21 m.',
'Turn right onto Wilton Road. Go for 624 m.',
'Turn left onto Belgrave Road. Go for 22 m.',
'Turn right onto Denbigh Street. Go for 120 m.',
'Arrive at Gloucester Street. Your destination is on the left.' ],
'streets': [ 'A1203', 'A202', 'A3213' ] };
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();
});
});