| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 'use strict' | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | const tapePromise = require('tape-promise').default | 
					
						
							|  |  |  |  | const tape = require('tape') | 
					
						
							|  |  |  |  | const isRoughlyEqual = require('is-roughly-equal') | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | const validateLine = require('validate-fptf/line') | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | const {createWhen} = require('./lib/util') | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | const createClient = require('..') | 
					
						
							|  |  |  |  | const oebbProfile = require('../p/oebb') | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | const products = require('../p/oebb/products') | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | const { | 
					
						
							| 
									
										
										
										
											2018-07-11 13:25:22 +02:00
										 |  |  |  | 	station: createValidateStation, | 
					
						
							|  |  |  |  | 	stop: validateStop | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | } = 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-07-24 18:16:46 +02:00
										 |  |  |  | const testRefreshJourney = require('./lib/refresh-journey') | 
					
						
							| 
									
										
										
										
											2018-04-25 13:07:31 +02:00
										 |  |  |  | const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') | 
					
						
							| 
									
										
										
										
											2018-05-13 00:34:26 +02:00
										 |  |  |  | const testJourneysWithDetour = require('./lib/journeys-with-detour') | 
					
						
							| 
									
										
										
										
											2018-07-07 21:26:40 +02:00
										 |  |  |  | const testDeparturesInDirection = require('./lib/departures-in-direction') | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | const when = createWhen('Europe/Vienna', 'de-AT') | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | const cfg = { | 
					
						
							|  |  |  |  | 	when, | 
					
						
							|  |  |  |  | 	stationCoordsOptional: false, | 
					
						
							| 
									
										
										
										
											2019-02-15 14:53:01 +01:00
										 |  |  |  | 	products, | 
					
						
							|  |  |  |  | 	minLatitude: 45.992803, | 
					
						
							|  |  |  |  | 	maxLatitude: 49.453517, | 
					
						
							|  |  |  |  | 	minLongitude: 8.787557, | 
					
						
							|  |  |  |  | 	maxLongitude: 17.491275 | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | // todo validateDirection: search list of stations for direction
 | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | const validate = createValidate(cfg, { | 
					
						
							|  |  |  |  | 	line: validateLine // bypass line validator in lib/validators
 | 
					
						
							|  |  |  |  | }) | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | const assertValidPrice = (t, p) => { | 
					
						
							|  |  |  |  | 	t.ok(p) | 
					
						
							|  |  |  |  | 	if (p.amount !== null) { | 
					
						
							|  |  |  |  | 		t.equal(typeof p.amount, 'number') | 
					
						
							|  |  |  |  | 		t.ok(p.amount > 0) | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	if (p.hint !== null) { | 
					
						
							|  |  |  |  | 		t.equal(typeof p.hint, 'string') | 
					
						
							|  |  |  |  | 		t.ok(p.hint) | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | const test = tapePromise(tape) | 
					
						
							| 
									
										
										
										
											2018-07-19 21:55:54 +02:00
										 |  |  |  | const client = createClient(oebbProfile, 'public-transport/hafas-client:test') | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-04 20:12:38 +01:00
										 |  |  |  | const salzburgHbf = '8100002' | 
					
						
							| 
									
										
										
										
											2018-04-23 13:56:00 +02:00
										 |  |  |  | const wienFickeystr = '911014' | 
					
						
							| 
									
										
										
										
											2018-03-04 20:12:38 +01:00
										 |  |  |  | const wien = '1190100' | 
					
						
							| 
									
										
										
										
											2018-04-23 13:56:00 +02:00
										 |  |  |  | const wienWestbahnhof = '1291501' | 
					
						
							| 
									
										
										
										
											2018-03-04 20:12:38 +01:00
										 |  |  |  | const klagenfurtHbf = '8100085' | 
					
						
							|  |  |  |  | const muenchenHbf = '8000261' | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | const wienRenngasse = '1390186' | 
					
						
							| 
									
										
										
										
											2018-07-07 21:26:40 +02:00
										 |  |  |  | const wienKarlsplatz = '1390461' | 
					
						
							|  |  |  |  | const wienPilgramgasse = '1390562' | 
					
						
							| 
									
										
										
										
											2018-03-04 20:12:38 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | test.skip('journeys – Salzburg Hbf to Wien Westbahnhof', async (t) => { | 
					
						
							|  |  |  |  | 	const journeys = await client.journeys(salzburgHbf, wienFickeystr, { | 
					
						
							| 
									
										
										
										
											2018-05-31 13:42:54 +02:00
										 |  |  |  | 		results: 3, | 
					
						
							|  |  |  |  | 		departure: when, | 
					
						
							| 
									
										
										
										
											2018-06-13 20:39:33 +02:00
										 |  |  |  | 		stopovers: true | 
					
						
							| 
									
										
										
										
											2018-04-23 13:56:00 +02:00
										 |  |  |  | 	}) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | 	await testJourneysStationToStation({ | 
					
						
							| 
									
										
										
										
											2018-04-23 13:56:00 +02:00
										 |  |  |  | 		test: t, | 
					
						
							|  |  |  |  | 		journeys, | 
					
						
							|  |  |  |  | 		validate, | 
					
						
							|  |  |  |  | 		fromId: salzburgHbf, | 
					
						
							|  |  |  |  | 		toId: wienFickeystr | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 	}) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-23 13:56:00 +02:00
										 |  |  |  | 	for (let i = 0; i < journeys.length; i++) { | 
					
						
							|  |  |  |  | 		const j = journeys[i] | 
					
						
							|  |  |  |  | 		if (j.price) assertValidPrice(t, j.price, `journeys[${i}].price`) | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | }) | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | // todo: journeys, only one product
 | 
					
						
							| 
									
										
										
										
											2018-04-25 13:07:31 +02:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | test('journeys – fails with no product', (t) => { | 
					
						
							|  |  |  |  | 	journeysFailsWithNoProduct({ | 
					
						
							|  |  |  |  | 		test: t, | 
					
						
							|  |  |  |  | 		fetchJourneys: client.journeys, | 
					
						
							|  |  |  |  | 		fromId: salzburgHbf, | 
					
						
							|  |  |  |  | 		toId: wienFickeystr, | 
					
						
							|  |  |  |  | 		when, | 
					
						
							|  |  |  |  | 		products | 
					
						
							|  |  |  |  | 	}) | 
					
						
							|  |  |  |  | 	t.end() | 
					
						
							|  |  |  |  | }) | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | test('Salzburg Hbf to 1220 Wien, Wagramer Straße 5', async (t) => { | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 	const wagramerStr = { | 
					
						
							|  |  |  |  | 		type: 'location', | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  |     	address: '1220 Wien, Wagramer Straße 5', | 
					
						
							| 
									
										
										
										
											2018-04-24 15:42:53 +02:00
										 |  |  |  |     	latitude: 48.236216, | 
					
						
							|  |  |  |  |     	longitude: 16.425863 | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | 	const journeys = await client.journeys(salzburgHbf, wagramerStr, { | 
					
						
							| 
									
										
										
										
											2018-05-31 13:42:54 +02:00
										 |  |  |  | 		results: 3, | 
					
						
							|  |  |  |  | 		departure: when | 
					
						
							| 
									
										
										
										
											2018-04-24 15:42:53 +02:00
										 |  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | 	await testJourneysStationToAddress({ | 
					
						
							| 
									
										
										
										
											2018-04-24 15:42:53 +02:00
										 |  |  |  | 		test: t, | 
					
						
							|  |  |  |  | 		journeys, | 
					
						
							|  |  |  |  | 		validate, | 
					
						
							|  |  |  |  | 		fromId: salzburgHbf, | 
					
						
							|  |  |  |  | 		to: wagramerStr | 
					
						
							|  |  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | }) | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | test('Salzburg Hbf to Albertina', async (t) => { | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 	const albertina = { | 
					
						
							|  |  |  |  | 		type: 'location', | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  |     	id: '975900003', | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  |     	name: 'Albertina', | 
					
						
							| 
									
										
										
										
											2018-04-24 16:10:56 +02:00
										 |  |  |  |     	latitude: 48.204699, | 
					
						
							|  |  |  |  |     	longitude: 16.368404 | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | 	const journeys = await client.journeys(salzburgHbf, albertina, { | 
					
						
							| 
									
										
										
										
											2018-05-31 13:42:54 +02:00
										 |  |  |  | 		results: 3, departure: when | 
					
						
							| 
									
										
										
										
											2018-04-24 16:10:56 +02:00
										 |  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | 	await testJourneysStationToPoi({ | 
					
						
							| 
									
										
										
										
											2018-04-24 16:10:56 +02:00
										 |  |  |  | 		test: t, | 
					
						
							|  |  |  |  | 		journeys, | 
					
						
							|  |  |  |  | 		validate, | 
					
						
							|  |  |  |  | 		fromId: salzburgHbf, | 
					
						
							|  |  |  |  | 		to: albertina | 
					
						
							|  |  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | }) | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | test('journeys: via works – with detour', async (t) => { | 
					
						
							| 
									
										
										
										
											2018-03-16 14:22:00 +01:00
										 |  |  |  | 	// Going from Stephansplatz to Schottenring via Donauinsel without detour
 | 
					
						
							| 
									
										
										
										
											2018-03-16 14:34:37 +01:00
										 |  |  |  | 	// is currently impossible. We check if the routing engine computes a detour.
 | 
					
						
							| 
									
										
										
										
											2019-01-16 22:05:21 +08:00
										 |  |  |  | 	const stephansplatz = '1390167' | 
					
						
							|  |  |  |  | 	const schottenring = '1390163' | 
					
						
							|  |  |  |  | 	const donauinsel = '1392277' | 
					
						
							| 
									
										
										
										
											2018-03-16 14:22:00 +01:00
										 |  |  |  | 	const donauinselPassed = '922001' | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | 	const journeys = await client.journeys(stephansplatz, schottenring, { | 
					
						
							| 
									
										
										
										
											2018-03-16 14:22:00 +01:00
										 |  |  |  | 		via: donauinsel, | 
					
						
							| 
									
										
										
										
											2018-01-24 23:32:54 +01:00
										 |  |  |  | 		results: 1, | 
					
						
							| 
									
										
										
										
											2018-05-28 20:35:01 +02:00
										 |  |  |  | 		departure: when, | 
					
						
							| 
									
										
										
										
											2018-06-13 20:39:33 +02:00
										 |  |  |  | 		stopovers: true | 
					
						
							| 
									
										
										
										
											2018-01-19 16:58:39 +01:00
										 |  |  |  | 	}) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | 	await testJourneysWithDetour({ | 
					
						
							| 
									
										
										
										
											2018-05-13 00:34:26 +02:00
										 |  |  |  | 		test: t, | 
					
						
							|  |  |  |  | 		journeys, | 
					
						
							|  |  |  |  | 		validate, | 
					
						
							|  |  |  |  | 		detourIds: [donauinsel, donauinselPassed] | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2018-03-16 14:22:00 +01:00
										 |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | }) | 
					
						
							| 
									
										
										
										
											2018-03-16 14:22:00 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | test('journeys: via works – without detour', async (t) => { | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | 	// When going from Karlsplatz to Praterstern via Museumsquartier, there is
 | 
					
						
							|  |  |  |  | 	// *no need* to change trains / no need for a "detour".
 | 
					
						
							| 
									
										
										
										
											2019-01-16 22:05:21 +08:00
										 |  |  |  | 	const karlsplatz = '1390461' | 
					
						
							|  |  |  |  | 	const praterstern = '1290201' | 
					
						
							|  |  |  |  | 	const museumsquartier = '1390171' | 
					
						
							| 
									
										
										
										
											2018-03-16 14:22:00 +01:00
										 |  |  |  | 	const museumsquartierPassed = '901014' | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | 	const journeys = await client.journeys(karlsplatz, praterstern, { | 
					
						
							| 
									
										
										
										
											2018-03-16 14:22:00 +01:00
										 |  |  |  | 		via: museumsquartier, | 
					
						
							|  |  |  |  | 		results: 1, | 
					
						
							| 
									
										
										
										
											2018-05-28 20:35:01 +02:00
										 |  |  |  | 		departure: when, | 
					
						
							| 
									
										
										
										
											2018-06-13 20:39:33 +02:00
										 |  |  |  | 		stopovers: true | 
					
						
							| 
									
										
										
										
											2018-03-16 14:22:00 +01:00
										 |  |  |  | 	}) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | 	validate(t, journeys, 'journeys', 'journeys') | 
					
						
							| 
									
										
										
										
											2018-03-16 14:22:00 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | 	const l1 = journeys[0].legs.some((leg) => { | 
					
						
							|  |  |  |  | 		return ( | 
					
						
							|  |  |  |  | 			leg.destination.id === museumsquartier || | 
					
						
							|  |  |  |  | 			leg.destination.id === museumsquartierPassed | 
					
						
							|  |  |  |  | 		) | 
					
						
							|  |  |  |  | 	}) | 
					
						
							|  |  |  |  | 	t.notOk(l1, 'transfer at Museumsquartier') | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	const l2 = journeys[0].legs.some((leg) => { | 
					
						
							| 
									
										
										
										
											2018-06-13 20:35:06 +02:00
										 |  |  |  | 		return leg.stopovers && leg.stopovers.some((stopover) => { | 
					
						
							| 
									
										
										
										
											2018-06-25 11:39:21 +02:00
										 |  |  |  | 			return stopover.stop.id === museumsquartierPassed | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | 		}) | 
					
						
							|  |  |  |  | 	}) | 
					
						
							|  |  |  |  | 	t.ok(l2, 'Museumsquartier is not being passed') | 
					
						
							| 
									
										
										
										
											2018-01-19 16:58:39 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | }) | 
					
						
							| 
									
										
										
										
											2018-01-19 16:58:39 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | test('earlier/later journeys, Salzburg Hbf -> Wien Westbahnhof', async (t) => { | 
					
						
							|  |  |  |  | 	await testEarlierLaterJourneys({ | 
					
						
							| 
									
										
										
										
											2018-04-24 15:24:59 +02:00
										 |  |  |  | 		test: t, | 
					
						
							|  |  |  |  | 		fetchJourneys: client.journeys, | 
					
						
							|  |  |  |  | 		validate, | 
					
						
							|  |  |  |  | 		fromId: salzburgHbf, | 
					
						
							| 
									
										
										
										
											2018-11-20 18:38:48 +01:00
										 |  |  |  | 		toId: wienWestbahnhof, | 
					
						
							|  |  |  |  | 		when | 
					
						
							| 
									
										
										
										
											2018-03-04 20:12:38 +01:00
										 |  |  |  | 	}) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | }) | 
					
						
							| 
									
										
										
										
											2018-03-04 20:12:38 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | test('refreshJourney', async (t) => { | 
					
						
							|  |  |  |  | 	await testRefreshJourney({ | 
					
						
							| 
									
										
										
										
											2018-07-24 18:16:46 +02:00
										 |  |  |  | 		test: t, | 
					
						
							|  |  |  |  | 		fetchJourneys: client.journeys, | 
					
						
							|  |  |  |  | 		refreshJourney: client.refreshJourney, | 
					
						
							|  |  |  |  | 		validate, | 
					
						
							|  |  |  |  | 		fromId: salzburgHbf, | 
					
						
							|  |  |  |  | 		toId: wienWestbahnhof, | 
					
						
							|  |  |  |  | 		when | 
					
						
							|  |  |  |  | 	}) | 
					
						
							|  |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | }) | 
					
						
							| 
									
										
										
										
											2018-07-24 18:16:46 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | test('trip details', async (t) => { | 
					
						
							|  |  |  |  | 	const journeys = await client.journeys(wienWestbahnhof, muenchenHbf, { | 
					
						
							| 
									
										
										
										
											2018-05-28 20:35:01 +02:00
										 |  |  |  | 		results: 1, departure: when | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 	}) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	const p = journeys[0].legs[0] | 
					
						
							|  |  |  |  | 	t.ok(p.id, 'precondition failed') | 
					
						
							|  |  |  |  | 	t.ok(p.line.name, 'precondition failed') | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | 	const trip = await client.trip(p.id, p.line.name, {when}) | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-29 14:58:43 +02:00
										 |  |  |  | 	validate(t, trip, 'journeyLeg', 'trip') | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | }) | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | test('departures at Wien Leibenfrostgasse', async (t) => { | 
					
						
							| 
									
										
										
										
											2018-04-24 16:58:17 +02:00
										 |  |  |  | 	const wienLeibenfrostgasse = '1390469' | 
					
						
							| 
									
										
										
										
											2018-05-30 15:51:58 +02:00
										 |  |  |  | 	const ids = [ | 
					
						
							|  |  |  |  | 		wienLeibenfrostgasse, // station
 | 
					
						
							|  |  |  |  | 		'904029', // stop "Wien Leibenfrostgasse (Phorusgasse)s"
 | 
					
						
							|  |  |  |  | 		'904030' // stop "Wien Leibenfrostgasse (Ziegelofengasse)"
 | 
					
						
							|  |  |  |  | 	] | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | 	const deps = await client.departures(wienLeibenfrostgasse, { | 
					
						
							| 
									
										
										
										
											2018-12-28 21:17:03 +01:00
										 |  |  |  | 		duration: 15, when, | 
					
						
							|  |  |  |  | 		stopovers: true | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 	}) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-30 15:51:58 +02:00
										 |  |  |  | 	validate(t, deps, 'departures', 'departures') | 
					
						
							|  |  |  |  | 	t.ok(deps.length > 0, 'must be >0 departures') | 
					
						
							|  |  |  |  | 	// todo: move into deps validator
 | 
					
						
							|  |  |  |  | 	t.deepEqual(deps, deps.sort((a, b) => t.when > b.when)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	for (let i = 0; i < deps.length; i++) { | 
					
						
							|  |  |  |  | 		const dep = deps[i] | 
					
						
							| 
									
										
										
										
											2018-12-03 11:47:51 +01:00
										 |  |  |  | 		t.ok(ids.includes(dep.stop.id), `deps[${i}].stop.id ("${dep.stop.id}") is invalid`) | 
					
						
							| 
									
										
										
										
											2018-05-30 15:51:58 +02:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | }) | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | test('departures with station object', async (t) => { | 
					
						
							|  |  |  |  | 	const deps = await client.departures({ | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | 		type: 'station', | 
					
						
							|  |  |  |  | 		id: salzburgHbf, | 
					
						
							|  |  |  |  | 		name: 'Salzburg Hbf', | 
					
						
							|  |  |  |  | 		location: { | 
					
						
							|  |  |  |  | 			type: 'location', | 
					
						
							|  |  |  |  | 			latitude: 1.23, | 
					
						
							|  |  |  |  | 			longitude: 2.34 | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	}, {when}) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	validate(t, deps, 'departures', 'departures') | 
					
						
							|  |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | }) | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | test('departures at Karlsplatz in direction of Pilgramgasse', async (t) => { | 
					
						
							|  |  |  |  | 	await testDeparturesInDirection({ | 
					
						
							| 
									
										
										
										
											2018-07-07 21:26:40 +02:00
										 |  |  |  | 		test: t, | 
					
						
							|  |  |  |  | 		fetchDepartures: client.departures, | 
					
						
							|  |  |  |  | 		fetchTrip: client.trip, | 
					
						
							|  |  |  |  | 		id: wienKarlsplatz, | 
					
						
							|  |  |  |  | 		directionIds: [wienPilgramgasse, '905002'], | 
					
						
							|  |  |  |  | 		when, | 
					
						
							|  |  |  |  | 		validate | 
					
						
							|  |  |  |  | 	}) | 
					
						
							|  |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | }) | 
					
						
							| 
									
										
										
										
											2018-07-07 21:26:40 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-26 17:30:46 +02:00
										 |  |  |  | // todo: arrivals
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | test('nearby Salzburg Hbf', async (t) => { | 
					
						
							|  |  |  |  | 	const nearby = await client.nearby({ | 
					
						
							| 
									
										
										
										
											2018-01-07 19:01:22 +01:00
										 |  |  |  | 		type: 'location', | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 		longitude: 13.045604, | 
					
						
							|  |  |  |  | 		latitude: 47.812851 | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | 	}, { | 
					
						
							|  |  |  |  | 		results: 5, distance: 400 | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 	}) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | 	validate(t, nearby, 'locations', 'nearby') | 
					
						
							|  |  |  |  | 	t.equal(nearby.length, 5) | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | 	const s = nearby[0] | 
					
						
							| 
									
										
										
										
											2019-01-16 22:05:21 +08:00
										 |  |  |  | 	t.equal(s.id, salzburgHbf, 'id should be ' + salzburgHbf) | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | 	t.equal(s.name, 'Salzburg Hbf') | 
					
						
							| 
									
										
										
										
											2018-05-13 01:03:10 +02:00
										 |  |  |  | 	t.ok(isRoughlyEqual(.0005, s.location.latitude, 47.812851)) | 
					
						
							|  |  |  |  | 	t.ok(isRoughlyEqual(.0005, s.location.longitude, 13.045604)) | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | 	t.ok(s.distance >= 0) | 
					
						
							|  |  |  |  | 	t.ok(s.distance <= 100) | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | }) | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | test('locations named Salzburg', async (t) => { | 
					
						
							|  |  |  |  | 	const locations = await client.locations('Salzburg', { | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | 		results: 20 | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 	}) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | 	validate(t, locations, 'locations', 'locations') | 
					
						
							|  |  |  |  | 	t.ok(locations.length <= 20) | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-11 13:25:22 +02:00
										 |  |  |  | 	t.ok(locations.find(s => s.type === 'stop' || s.type === 'station')) | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | 	t.ok(locations.find(s => s.id && s.name)) // POIs
 | 
					
						
							| 
									
										
										
										
											2018-07-11 13:25:22 +02:00
										 |  |  |  | 	t.ok(locations.some((s) => { | 
					
						
							| 
									
										
										
										
											2019-01-16 22:05:21 +08:00
										 |  |  |  | 		return s.station && s.station.id === salzburgHbf || s.id === salzburgHbf | 
					
						
							| 
									
										
										
										
											2018-07-11 13:25:22 +02:00
										 |  |  |  | 	})) | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | }) | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | test('station', async (t) => { | 
					
						
							|  |  |  |  | 	const loc = await client.station(wienRenngasse) | 
					
						
							| 
									
										
										
										
											2018-01-26 17:08:07 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 15:53:08 +02:00
										 |  |  |  | 	// todo: find a way to always get products from the API
 | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | 	// todo: cfg.stationProductsOptional option
 | 
					
						
							|  |  |  |  | 	const allProducts = products.reduce((acc, p) => (acc[p.id] = true, acc), {}) | 
					
						
							|  |  |  |  | 	const validateStation = createValidateStation(cfg) | 
					
						
							|  |  |  |  | 	const validate = createValidate(cfg, { | 
					
						
							| 
									
										
										
										
											2018-07-11 13:25:22 +02:00
										 |  |  |  | 		stop: (validate, s, name) => { | 
					
						
							|  |  |  |  | 			const withFakeProducts = Object.assign({products: allProducts}, s) | 
					
						
							|  |  |  |  | 			validateStop(validate, withFakeProducts, name) | 
					
						
							|  |  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | 		station: (validate, s, name) => { | 
					
						
							|  |  |  |  | 			const withFakeProducts = Object.assign({products: allProducts}, s) | 
					
						
							|  |  |  |  | 			validateStation(validate, withFakeProducts, name) | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2018-07-11 13:25:22 +02:00
										 |  |  |  | 	validate(t, loc, ['stop', 'station'], 'station') | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	t.equal(loc.id, wienRenngasse) | 
					
						
							| 
									
										
										
										
											2018-01-26 17:08:07 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | }) | 
					
						
							| 
									
										
										
										
											2018-01-26 17:08:07 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | test('radar Salzburg', async (t) => { | 
					
						
							|  |  |  |  | 	let vehicles = await client.radar({ | 
					
						
							| 
									
										
										
										
											2018-03-16 17:28:20 +01:00
										 |  |  |  | 		north: 47.827203, | 
					
						
							|  |  |  |  | 		west: 13.001261, | 
					
						
							|  |  |  |  | 		south: 47.773278, | 
					
						
							|  |  |  |  | 		east: 13.07562 | 
					
						
							|  |  |  |  | 	}, { | 
					
						
							| 
									
										
										
										
											2018-12-07 16:11:09 +01:00
										 |  |  |  | 		duration: 5 * 60, when | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 	}) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-20 11:04:54 +02:00
										 |  |  |  | 	// todo: find a way to always get frames from the API
 | 
					
						
							|  |  |  |  | 	vehicles = vehicles.filter(m => m.frames && m.frames.length > 0) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// todo: find a way to always get products from the API
 | 
					
						
							|  |  |  |  | 	// todo: cfg.stationProductsOptional option
 | 
					
						
							|  |  |  |  | 	const allProducts = products.reduce((acc, p) => (acc[p.id] = true, acc), {}) | 
					
						
							|  |  |  |  | 	const validateStation = createValidateStation(cfg) | 
					
						
							|  |  |  |  | 	const validate = createValidate(cfg, { | 
					
						
							|  |  |  |  | 		station: (validate, s, name) => { | 
					
						
							|  |  |  |  | 			const withFakeProducts = Object.assign({products: allProducts}, s) | 
					
						
							|  |  |  |  | 			validateStation(validate, withFakeProducts, name) | 
					
						
							|  |  |  |  | 		}, | 
					
						
							|  |  |  |  | 		line: validateLine | 
					
						
							|  |  |  |  | 	}) | 
					
						
							|  |  |  |  | 	validate(t, vehicles, 'movements', 'vehicles') | 
					
						
							| 
									
										
										
										
											2017-12-29 10:01:02 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	t.end() | 
					
						
							| 
									
										
										
										
											2018-11-21 19:07:37 +01:00
										 |  |  |  | }) |