| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 'use strict' | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | const stations = require('vbb-stations-autocomplete') | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | const a = require('assert') | 
					
						
							|  |  |  |  | const shorten = require('vbb-short-station-name') | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | const tapePromise = require('tape-promise').default | 
					
						
							|  |  |  |  | const tape = require('tape') | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | const isRoughlyEqual = require('is-roughly-equal') | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | const {createWhen} = require('./lib/util') | 
					
						
							| 
									
										
										
										
											2018-04-18 16:15:24 +02:00
										 |  |  |  | const co = require('./lib/co') | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | const createClient = require('..') | 
					
						
							|  |  |  |  | const vbbProfile = require('../p/vbb') | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | const products = require('../p/vbb/products') | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | const { | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 	station: createValidateStation, | 
					
						
							|  |  |  |  | 	line: createValidateLine, | 
					
						
							|  |  |  |  | 	journeyLeg: createValidateJourneyLeg, | 
					
						
							|  |  |  |  | 	departure: createValidateDeparture, | 
					
						
							|  |  |  |  | 	movement: _validateMovement | 
					
						
							|  |  |  |  | } = require('./lib/validators') | 
					
						
							|  |  |  |  | const createValidate = require('./lib/validate-fptf-with') | 
					
						
							| 
									
										
										
										
											2018-04-23 13:56:00 +02:00
										 |  |  |  | const testJourneysStationToStation = require('./lib/journeys-station-to-station') | 
					
						
							| 
									
										
										
										
											2018-04-24 15:42:53 +02:00
										 |  |  |  | const testJourneysStationToAddress = require('./lib/journeys-station-to-address') | 
					
						
							| 
									
										
										
										
											2018-04-24 16:10:56 +02:00
										 |  |  |  | const testJourneysStationToPoi = require('./lib/journeys-station-to-poi') | 
					
						
							| 
									
										
										
										
											2018-04-24 15:24:59 +02:00
										 |  |  |  | const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') | 
					
						
							| 
									
										
										
										
											2018-04-25 13:07:31 +02:00
										 |  |  |  | const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') | 
					
						
							| 
									
										
										
										
											2018-04-24 16:58:17 +02:00
										 |  |  |  | const testDepartures = require('./lib/departures') | 
					
						
							| 
									
										
										
										
											2018-05-13 00:34:26 +02:00
										 |  |  |  | const testJourneysWithDetour = require('./lib/journeys-with-detour') | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-28 22:57:22 +01:00
										 |  |  |  | const when = createWhen('Europe/Berlin', 'de-DE') | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | const cfg = { | 
					
						
							|  |  |  |  | 	when, | 
					
						
							|  |  |  |  | 	stationCoordsOptional: false, | 
					
						
							|  |  |  |  | 	products | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | const validateDirection = (dir, name) => { | 
					
						
							|  |  |  |  | 	if (!stations(dir, true, false)[0]) { | 
					
						
							|  |  |  |  | 		console.error(name + `: station "${dir}" is unknown`) | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // todo: coordsOptional = false
 | 
					
						
							|  |  |  |  | const _validateStation = createValidateStation(cfg) | 
					
						
							|  |  |  |  | const validateStation = (validate, s, name) => { | 
					
						
							|  |  |  |  | 	_validateStation(validate, s, name) | 
					
						
							| 
									
										
										
										
											2018-04-25 13:24:27 +02:00
										 |  |  |  | 	// todo: find station by ID
 | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 	a.equal(s.name, shorten(s.name), name + '.name must be shortened') | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | const _validateLine = createValidateLine(cfg) | 
					
						
							|  |  |  |  | const validateLine = (validate, l, name) => { | 
					
						
							|  |  |  |  | 	_validateLine(validate, l, name) | 
					
						
							|  |  |  |  | 	if (l.symbol !== null) { | 
					
						
							|  |  |  |  | 		a.strictEqual(typeof l.symbol, 'string', name + '.symbol must be a string') | 
					
						
							|  |  |  |  | 		a.ok(l.symbol, name + '.symbol must not be empty') | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	if (l.nr !== null) { | 
					
						
							|  |  |  |  | 		a.strictEqual(typeof l.nr, 'number', name + '.nr must be a string') | 
					
						
							|  |  |  |  | 		a.ok(l.nr, name + '.nr must not be empty') | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	if (l.metro !== null) { | 
					
						
							|  |  |  |  | 		a.strictEqual(typeof l.metro, 'boolean', name + '.metro must be a boolean') | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	if (l.express !== null) { | 
					
						
							|  |  |  |  | 		a.strictEqual(typeof l.express, 'boolean', name + '.express must be a boolean') | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	if (l.night !== null) { | 
					
						
							|  |  |  |  | 		a.strictEqual(typeof l.night, 'boolean', name + '.night must be a boolean') | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | const _validateJourneyLeg = createValidateJourneyLeg(cfg) | 
					
						
							|  |  |  |  | const validateJourneyLeg = (validate, l, name) => { | 
					
						
							|  |  |  |  | 	_validateJourneyLeg(validate, l, name) | 
					
						
							|  |  |  |  | 	if (l.mode !== 'walking') { | 
					
						
							|  |  |  |  | 		validateDirection(l.direction, name + '.direction') | 
					
						
							| 
									
										
										
										
											2018-04-18 15:53:08 +02:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-11 14:41:28 +01:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | const _validateDeparture = createValidateDeparture(cfg) | 
					
						
							|  |  |  |  | const validateDeparture = (validate, dep, name) => { | 
					
						
							|  |  |  |  | 	_validateDeparture(validate, dep, name) | 
					
						
							|  |  |  |  | 	validateDirection(dep.direction, name + '.direction') | 
					
						
							| 
									
										
										
										
											2017-12-11 14:51:09 +01:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | const validateMovement = (validate, m, name) => { | 
					
						
							|  |  |  |  | 	_validateMovement(validate, m, name) | 
					
						
							|  |  |  |  | 	validateDirection(m.direction, name + '.direction') | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | const validate = createValidate(cfg, { | 
					
						
							|  |  |  |  | 	station: validateStation, | 
					
						
							|  |  |  |  | 	line: validateLine, | 
					
						
							|  |  |  |  | 	journeyLeg: validateJourneyLeg, | 
					
						
							|  |  |  |  | 	departure: validateDeparture, | 
					
						
							|  |  |  |  | 	movement: validateMovement | 
					
						
							|  |  |  |  | }) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | const test = tapePromise(tape) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | const client = createClient(vbbProfile) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-20 01:05:48 +01:00
										 |  |  |  | const amrumerStr = '900000009101' | 
					
						
							|  |  |  |  | const spichernstr = '900000042101' | 
					
						
							|  |  |  |  | const bismarckstr = '900000024201' | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | const westhafen = '900000001201' | 
					
						
							|  |  |  |  | const wedding = '900000009104' | 
					
						
							|  |  |  |  | const württembergallee = '900000026153' | 
					
						
							| 
									
										
										
										
											2017-11-20 01:05:48 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-23 13:56:00 +02:00
										 |  |  |  | test('journeys – Spichernstr. to Bismarckstr.', co(function* (t) { | 
					
						
							|  |  |  |  | 	const journeys = yield client.journeys(spichernstr, bismarckstr, { | 
					
						
							| 
									
										
										
										
											2018-05-31 13:42:54 +02:00
										 |  |  |  | 		results: 3, | 
					
						
							|  |  |  |  | 		departure: when, | 
					
						
							|  |  |  |  | 		passedStations: true | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-23 13:56:00 +02:00
										 |  |  |  | 	yield testJourneysStationToStation({ | 
					
						
							|  |  |  |  | 		test: t, | 
					
						
							|  |  |  |  | 		journeys, | 
					
						
							|  |  |  |  | 		validate, | 
					
						
							|  |  |  |  | 		fromId: spichernstr, | 
					
						
							|  |  |  |  | 		toId: bismarckstr | 
					
						
							|  |  |  |  | 	}) | 
					
						
							|  |  |  |  | 	// todo: find a journey where there ticket info is always available
 | 
					
						
							| 
									
										
										
										
											2017-12-11 15:41:27 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2017-11-29 02:27:31 +01:00
										 |  |  |  | })) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-23 01:49:41 +01:00
										 |  |  |  | test('journeys – only subway', co(function* (t) { | 
					
						
							| 
									
										
										
										
											2017-11-29 02:27:31 +01:00
										 |  |  |  | 	const journeys = yield client.journeys(spichernstr, bismarckstr, { | 
					
						
							| 
									
										
										
										
											2018-05-31 13:42:54 +02:00
										 |  |  |  | 		results: 20, | 
					
						
							|  |  |  |  | 		departure: when, | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 		products: { | 
					
						
							|  |  |  |  | 			suburban: false, | 
					
						
							|  |  |  |  | 			subway:   true, | 
					
						
							|  |  |  |  | 			tram:     false, | 
					
						
							|  |  |  |  | 			bus:      false, | 
					
						
							|  |  |  |  | 			ferry:    false, | 
					
						
							|  |  |  |  | 			express:  false, | 
					
						
							|  |  |  |  | 			regional: false | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 	validate(t, journeys, 'journeys', 'journeys') | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 	t.ok(journeys.length > 1) | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 	for (let i = 0; i < journeys.length; i++) { | 
					
						
							|  |  |  |  | 		const journey = journeys[i] | 
					
						
							|  |  |  |  | 		for (let j = 0; j < journey.legs.length; j++) { | 
					
						
							|  |  |  |  | 			const leg = journey.legs[j] | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 			const name = `journeys[${i}].legs[${i}].line` | 
					
						
							| 
									
										
										
										
											2017-12-28 17:14:53 +01:00
										 |  |  |  | 			if (leg.line) { | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 				t.equal(leg.line.mode, 'train', name + '.mode is invalid') | 
					
						
							|  |  |  |  | 				t.equal(leg.line.product, 'subway', name + '.product is invalid') | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 			t.ok(journey.legs.some(l => l.line), name + '.legs has no subway leg') | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2017-11-29 02:27:31 +01:00
										 |  |  |  | })) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | test('journeys – fails with no product', (t) => { | 
					
						
							| 
									
										
										
										
											2018-04-25 13:07:31 +02:00
										 |  |  |  | 	journeysFailsWithNoProduct({ | 
					
						
							|  |  |  |  | 		test: t, | 
					
						
							|  |  |  |  | 		fetchJourneys: client.journeys, | 
					
						
							|  |  |  |  | 		fromId: spichernstr, | 
					
						
							|  |  |  |  | 		toId: bismarckstr, | 
					
						
							|  |  |  |  | 		when, | 
					
						
							|  |  |  |  | 		products | 
					
						
							|  |  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 	t.end() | 
					
						
							|  |  |  |  | }) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-04 19:54:21 +01:00
										 |  |  |  | test('earlier/later journeys', co(function* (t) { | 
					
						
							| 
									
										
										
										
											2018-04-24 15:24:59 +02:00
										 |  |  |  | 	yield testEarlierLaterJourneys({ | 
					
						
							|  |  |  |  | 		test: t, | 
					
						
							|  |  |  |  | 		fetchJourneys: client.journeys, | 
					
						
							|  |  |  |  | 		validate, | 
					
						
							|  |  |  |  | 		fromId: spichernstr, | 
					
						
							|  |  |  |  | 		toId: bismarckstr | 
					
						
							| 
									
										
										
										
											2018-03-04 19:54:21 +01:00
										 |  |  |  | 	}) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	t.end() | 
					
						
							|  |  |  |  | })) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-23 01:49:41 +01:00
										 |  |  |  | test('journey leg details', co(function* (t) { | 
					
						
							| 
									
										
										
										
											2017-11-29 02:27:31 +01:00
										 |  |  |  | 	const journeys = yield client.journeys(spichernstr, amrumerStr, { | 
					
						
							| 
									
										
										
										
											2018-05-28 20:35:01 +02:00
										 |  |  |  | 		results: 1, departure: when | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 	}) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-28 17:14:53 +01:00
										 |  |  |  | 	const p = journeys[0].legs[0] | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 	t.ok(p.id, 'precondition failed') | 
					
						
							|  |  |  |  | 	t.ok(p.line.name, 'precondition failed') | 
					
						
							| 
									
										
										
										
											2017-12-28 17:14:53 +01:00
										 |  |  |  | 	const leg = yield client.journeyLeg(p.id, p.line.name, {when}) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 	validate(t, leg, 'journeyLeg', 'leg') | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2017-11-29 02:27:31 +01:00
										 |  |  |  | })) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-23 01:49:41 +01:00
										 |  |  |  | test('journeys – station to address', co(function* (t) { | 
					
						
							| 
									
										
										
										
											2018-04-24 15:42:53 +02:00
										 |  |  |  | 	const torfstr = { | 
					
						
							| 
									
										
										
										
											2018-03-05 00:22:31 +01:00
										 |  |  |  | 		type: 'location', | 
					
						
							| 
									
										
										
										
											2018-04-24 15:42:53 +02:00
										 |  |  |  | 		address: '13353 Berlin-Wedding, Torfstr. 17', | 
					
						
							|  |  |  |  | 		latitude: 52.541797, | 
					
						
							|  |  |  |  | 		longitude: 13.350042 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	const journeys = yield client.journeys(spichernstr, torfstr, { | 
					
						
							| 
									
										
										
										
											2018-05-31 13:42:54 +02:00
										 |  |  |  | 		results: 3, | 
					
						
							|  |  |  |  | 		departure: when | 
					
						
							| 
									
										
										
										
											2018-04-24 15:42:53 +02:00
										 |  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-24 15:42:53 +02:00
										 |  |  |  | 	yield testJourneysStationToAddress({ | 
					
						
							|  |  |  |  | 		test: t, | 
					
						
							|  |  |  |  | 		journeys, | 
					
						
							|  |  |  |  | 		validate, | 
					
						
							|  |  |  |  | 		fromId: spichernstr, | 
					
						
							|  |  |  |  | 		to: torfstr | 
					
						
							|  |  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2017-11-29 02:27:31 +01:00
										 |  |  |  | })) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-23 01:49:41 +01:00
										 |  |  |  | test('journeys – station to POI', co(function* (t) { | 
					
						
							| 
									
										
										
										
											2018-04-24 16:10:56 +02:00
										 |  |  |  | 	const atze = { | 
					
						
							| 
									
										
										
										
											2018-03-05 00:22:31 +01:00
										 |  |  |  | 		type: 'location', | 
					
						
							| 
									
										
										
										
											2018-04-24 16:10:56 +02:00
										 |  |  |  | 		id: '900980720', | 
					
						
							| 
									
										
										
										
											2018-03-05 00:22:31 +01:00
										 |  |  |  | 		name: 'Berlin, Atze Musiktheater für Kinder', | 
					
						
							| 
									
										
										
										
											2018-04-24 16:10:56 +02:00
										 |  |  |  | 		latitude: 52.543333, | 
					
						
							|  |  |  |  | 		longitude: 13.351686 | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	const journeys = yield client.journeys(spichernstr, atze, { | 
					
						
							| 
									
										
										
										
											2018-05-31 13:42:54 +02:00
										 |  |  |  | 		results: 3, | 
					
						
							|  |  |  |  | 		departure: when | 
					
						
							| 
									
										
										
										
											2018-04-24 16:10:56 +02:00
										 |  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-24 16:10:56 +02:00
										 |  |  |  | 	yield testJourneysStationToPoi({ | 
					
						
							|  |  |  |  | 		test: t, | 
					
						
							|  |  |  |  | 		journeys, | 
					
						
							|  |  |  |  | 		validate, | 
					
						
							|  |  |  |  | 		fromId: spichernstr, | 
					
						
							|  |  |  |  | 		to: atze | 
					
						
							|  |  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2017-11-29 02:27:31 +01:00
										 |  |  |  | })) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-16 14:30:49 +01:00
										 |  |  |  | test('journeys: via works – with detour', co(function* (t) { | 
					
						
							|  |  |  |  | 	// Going from Westhafen to Wedding via Württembergalle without detour
 | 
					
						
							| 
									
										
										
										
											2018-03-16 14:34:37 +01:00
										 |  |  |  | 	// is currently impossible. We check if the routing engine computes a detour.
 | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 	const journeys = yield client.journeys(westhafen, wedding, { | 
					
						
							| 
									
										
										
										
											2018-03-06 02:47:05 +01:00
										 |  |  |  | 		via: württembergallee, | 
					
						
							|  |  |  |  | 		results: 1, | 
					
						
							| 
									
										
										
										
											2018-05-28 20:35:01 +02:00
										 |  |  |  | 		departure: when, | 
					
						
							| 
									
										
										
										
											2018-03-16 14:30:49 +01:00
										 |  |  |  | 		passedStations: true | 
					
						
							| 
									
										
										
										
											2018-01-19 16:58:39 +01:00
										 |  |  |  | 	}) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-13 00:34:26 +02:00
										 |  |  |  | 	yield testJourneysWithDetour({ | 
					
						
							|  |  |  |  | 		test: t, | 
					
						
							|  |  |  |  | 		journeys, | 
					
						
							|  |  |  |  | 		validate, | 
					
						
							|  |  |  |  | 		detourIds: [württembergallee] | 
					
						
							| 
									
										
										
										
											2018-03-06 02:47:05 +01:00
										 |  |  |  | 	}) | 
					
						
							|  |  |  |  | 	t.end() | 
					
						
							|  |  |  |  | })) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-25 13:24:27 +02:00
										 |  |  |  | // todo: without detour test
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-23 01:49:41 +01:00
										 |  |  |  | test('departures', co(function* (t) { | 
					
						
							| 
									
										
										
										
											2018-04-24 16:58:17 +02:00
										 |  |  |  | 	const departures = yield client.departures(spichernstr, { | 
					
						
							|  |  |  |  | 		duration: 5, when | 
					
						
							|  |  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-24 16:58:17 +02:00
										 |  |  |  | 	yield testDepartures({ | 
					
						
							|  |  |  |  | 		test: t, | 
					
						
							|  |  |  |  | 		departures, | 
					
						
							|  |  |  |  | 		validate, | 
					
						
							|  |  |  |  | 		id: spichernstr | 
					
						
							|  |  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2017-11-29 02:27:31 +01:00
										 |  |  |  | })) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-23 01:49:41 +01:00
										 |  |  |  | test('departures with station object', co(function* (t) { | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 	const deps = yield client.departures({ | 
					
						
							| 
									
										
										
										
											2018-01-04 16:19:42 +01:00
										 |  |  |  | 		type: 'station', | 
					
						
							|  |  |  |  | 		id: spichernstr, | 
					
						
							|  |  |  |  | 		name: 'U Spichernstr', | 
					
						
							|  |  |  |  | 		location: { | 
					
						
							|  |  |  |  | 			type: 'location', | 
					
						
							|  |  |  |  | 			latitude: 1.23, | 
					
						
							|  |  |  |  | 			longitude: 2.34 | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	}, {when}) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 	validate(t, deps, 'departures', 'departures') | 
					
						
							| 
									
										
										
										
											2018-01-04 16:19:42 +01:00
										 |  |  |  | 	t.end() | 
					
						
							|  |  |  |  | })) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-23 01:49:41 +01:00
										 |  |  |  | test('departures at 7-digit station', co(function* (t) { | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 	const eisenach = '8010097' // see derhuerst/vbb-hafas#22
 | 
					
						
							| 
									
										
										
										
											2017-12-16 03:22:36 +01:00
										 |  |  |  | 	yield client.departures(eisenach, {when}) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 	t.pass('did not fail') | 
					
						
							|  |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2017-11-29 02:27:31 +01:00
										 |  |  |  | })) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-23 01:49:41 +01:00
										 |  |  |  | test('nearby', co(function* (t) { | 
					
						
							| 
									
										
										
										
											2018-05-13 01:03:10 +02:00
										 |  |  |  | 	const berlinerStr = '900000044201' | 
					
						
							|  |  |  |  | 	const landhausstr = '900000043252' | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 	// Berliner Str./Bundesallee
 | 
					
						
							| 
									
										
										
										
											2018-01-05 14:53:03 +01:00
										 |  |  |  | 	const nearby = yield client.nearby({ | 
					
						
							|  |  |  |  | 		type: 'location', | 
					
						
							|  |  |  |  | 		latitude: 52.4873452, | 
					
						
							|  |  |  |  | 		longitude: 13.3310411 | 
					
						
							|  |  |  |  | 	}, {distance: 200}) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 	validate(t, nearby, 'locations', 'nearby') | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 	t.equal(nearby[0].id, berlinerStr) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 	t.equal(nearby[0].name, 'U Berliner Str.') | 
					
						
							|  |  |  |  | 	t.ok(nearby[0].distance > 0) | 
					
						
							|  |  |  |  | 	t.ok(nearby[0].distance < 100) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 	t.equal(nearby[1].id, landhausstr) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 	t.equal(nearby[1].name, 'Landhausstr.') | 
					
						
							|  |  |  |  | 	t.ok(nearby[1].distance > 100) | 
					
						
							|  |  |  |  | 	t.ok(nearby[1].distance < 200) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2017-11-29 02:27:31 +01:00
										 |  |  |  | })) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-23 01:49:41 +01:00
										 |  |  |  | test('locations', co(function* (t) { | 
					
						
							| 
									
										
										
										
											2018-02-15 17:31:43 +01:00
										 |  |  |  | 	const locations = yield client.locations('Alexanderplatz', {results: 20}) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 	validate(t, locations, 'locations', 'locations') | 
					
						
							| 
									
										
										
										
											2018-02-15 17:31:43 +01:00
										 |  |  |  | 	t.ok(locations.length <= 20) | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-11 19:53:26 +01:00
										 |  |  |  | 	t.ok(locations.find(s => s.type === 'station')) | 
					
						
							|  |  |  |  | 	t.ok(locations.find(s => s.id && s.name)) // POIs
 | 
					
						
							|  |  |  |  | 	t.ok(locations.find(s => !s.name && s.address)) // addresses
 | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2017-11-29 02:27:31 +01:00
										 |  |  |  | })) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-04 19:01:21 +02:00
										 |  |  |  | test('station', co(function* (t) { | 
					
						
							| 
									
										
										
										
											2018-06-10 14:57:51 +02:00
										 |  |  |  | 	const s = yield client.station(spichernstr) | 
					
						
							| 
									
										
										
										
											2018-01-26 17:08:07 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 	validate(t, s, 'station', 'station') | 
					
						
							|  |  |  |  | 	t.equal(s.id, spichernstr) | 
					
						
							| 
									
										
										
										
											2018-01-26 17:40:14 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-26 17:08:07 +01:00
										 |  |  |  | 	t.end() | 
					
						
							|  |  |  |  | })) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-23 01:49:41 +01:00
										 |  |  |  | test('radar', co(function* (t) { | 
					
						
							| 
									
										
										
										
											2018-03-16 17:28:20 +01:00
										 |  |  |  | 	const vehicles = yield client.radar({ | 
					
						
							|  |  |  |  | 		north: 52.52411, | 
					
						
							|  |  |  |  | 		west: 13.41002, | 
					
						
							|  |  |  |  | 		south: 52.51942, | 
					
						
							|  |  |  |  | 		east: 13.41709 | 
					
						
							|  |  |  |  | 	}, { | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 		duration: 5 * 60, when | 
					
						
							|  |  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-11-14 02:50:24 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 23:56:11 +02:00
										 |  |  |  | 	validate(t, vehicles, 'movements', 'vehicles') | 
					
						
							| 
									
										
										
										
											2017-11-14 02:59:17 +01:00
										 |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2017-11-29 02:27:31 +01:00
										 |  |  |  | })) |