mirror of
				https://github.com/public-transport/db-vendo-client.git
				synced 2025-11-01 00:26:31 +02:00 
			
		
		
		
	tests: co/yield -> async/await
This commit is contained in:
		
							parent
							
								
									bf3c4c58a1
								
							
						
					
					
						commit
						59584a3402
					
				
					 23 changed files with 557 additions and 624 deletions
				
			
		
							
								
								
									
										136
									
								
								test/bvg.js
									
										
									
									
									
								
							
							
						
						
									
										136
									
								
								test/bvg.js
									
										
									
									
									
								
							|  | @ -9,7 +9,6 @@ const tapePromise = require('tape-promise').default | |||
| const tape = require('tape') | ||||
| const isRoughlyEqual = require('is-roughly-equal') | ||||
| 
 | ||||
| const co = require('./lib/co') | ||||
| const createClient = require('..') | ||||
| const bvgProfile = require('../p/bvg') | ||||
| const products = require('../p/bvg/products') | ||||
|  | @ -66,14 +65,14 @@ const jannowitzbrücke = '900000100004' | |||
| 
 | ||||
| const hour = 60 * 60 * 1000 | ||||
| 
 | ||||
| test('journeys – Spichernstr. to Bismarckstr.', co(function* (t) { | ||||
| 	const journeys = yield client.journeys(spichernstr, bismarckstr, { | ||||
| test('journeys – Spichernstr. to Bismarckstr.', async (t) => { | ||||
| 	const journeys = await client.journeys(spichernstr, bismarckstr, { | ||||
| 		results: 3, | ||||
| 		departure: when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToStation({ | ||||
| 	await testJourneysStationToStation({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -83,10 +82,10 @@ test('journeys – Spichernstr. to Bismarckstr.', co(function* (t) { | |||
| 	// todo: find a journey where there ticket info is always available
 | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('journeys – only subway', co(function* (t) { | ||||
| 	const journeys = yield client.journeys(spichernstr, bismarckstr, { | ||||
| test('journeys – only subway', async (t) => { | ||||
| 	const journeys = await client.journeys(spichernstr, bismarckstr, { | ||||
| 		results: 20, | ||||
| 		departure: when, | ||||
| 		products: { | ||||
|  | @ -117,7 +116,7 @@ test('journeys – only subway', co(function* (t) { | |||
| 	} | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('journeys – fails with no product', (t) => { | ||||
| 	journeysFailsWithNoProduct({ | ||||
|  | @ -131,8 +130,8 @@ test('journeys – fails with no product', (t) => { | |||
| 	t.end() | ||||
| }) | ||||
| 
 | ||||
| test('earlier/later journeys', co(function* (t) { | ||||
| 	yield testEarlierLaterJourneys({ | ||||
| test('earlier/later journeys', async (t) => { | ||||
| 	await testEarlierLaterJourneys({ | ||||
| 		test: t, | ||||
| 		fetchJourneys: client.journeys, | ||||
| 		validate, | ||||
|  | @ -142,20 +141,19 @@ test('earlier/later journeys', co(function* (t) { | |||
| 	}) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test.skip('journeys – leg cycle & alternatives', co(function* (t) { | ||||
| 	yield testLegCycleAlternatives({ | ||||
| test.skip('journeys – leg cycle & alternatives', async (t) => { | ||||
| 	await testLegCycleAlternatives({ | ||||
| 		test: t, | ||||
| 		fetchJourneys: client.journeys, | ||||
| 		fromId: tiergarten, | ||||
| 		toId: jannowitzbrücke | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| 
 | ||||
| test('refreshJourney', co(function* (t) { | ||||
| 	yield testRefreshJourney({ | ||||
| }) | ||||
| test('refreshJourney', async (t) => { | ||||
| 	await testRefreshJourney({ | ||||
| 		test: t, | ||||
| 		fetchJourneys: client.journeys, | ||||
| 		refreshJourney: client.refreshJourney, | ||||
|  | @ -165,35 +163,35 @@ test('refreshJourney', co(function* (t) { | |||
| 		when | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('trip details', co(function* (t) { | ||||
| 	const journeys = yield client.journeys(spichernstr, amrumerStr, { | ||||
| test('trip details', async (t) => { | ||||
| 	const journeys = await client.journeys(spichernstr, amrumerStr, { | ||||
| 		results: 1, departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	const p = journeys[0].legs[0] | ||||
| 	t.ok(p.id, 'precondition failed') | ||||
| 	t.ok(p.line.name, 'precondition failed') | ||||
| 	const trip = yield client.trip(p.id, p.line.name, {when}) | ||||
| 	const trip = await client.trip(p.id, p.line.name, {when}) | ||||
| 
 | ||||
| 	validate(t, trip, 'journeyLeg', 'trip') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('journeys – station to address', co(function* (t) { | ||||
| test('journeys – station to address', async (t) => { | ||||
| 	const torfstr = { | ||||
| 		type: 'location', | ||||
| 		address: '13353 Berlin-Wedding, Torfstr. 17', | ||||
| 		latitude: 52.541797, | ||||
| 		longitude: 13.350042 | ||||
| 	} | ||||
| 	const journeys = yield client.journeys(spichernstr, torfstr, { | ||||
| 	const journeys = await client.journeys(spichernstr, torfstr, { | ||||
| 		results: 3, | ||||
| 		departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToAddress({ | ||||
| 	await testJourneysStationToAddress({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -201,9 +199,9 @@ test('journeys – station to address', co(function* (t) { | |||
| 		to: torfstr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('journeys – station to POI', co(function* (t) { | ||||
| test('journeys – station to POI', async (t) => { | ||||
| 	const atze = { | ||||
| 		type: 'location', | ||||
| 		id: '900980720', | ||||
|  | @ -211,12 +209,12 @@ test('journeys – station to POI', co(function* (t) { | |||
| 		latitude: 52.543333, | ||||
| 		longitude: 13.351686 | ||||
| 	} | ||||
| 	const journeys = yield client.journeys(spichernstr, atze, { | ||||
| 	const journeys = await client.journeys(spichernstr, atze, { | ||||
| 		results: 3, | ||||
| 		departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToPoi({ | ||||
| 	await testJourneysStationToPoi({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -224,46 +222,46 @@ test('journeys – station to POI', co(function* (t) { | |||
| 		to: atze | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('journeys: via works – with detour', co(function* (t) { | ||||
| test('journeys: via works – with detour', async (t) => { | ||||
| 	// Going from Westhafen to Wedding via Württembergalle without detour
 | ||||
| 	// is currently impossible. We check if the routing engine computes a detour.
 | ||||
| 	const journeys = yield client.journeys(westhafen, wedding, { | ||||
| 	const journeys = await client.journeys(westhafen, wedding, { | ||||
| 		via: württembergallee, | ||||
| 		results: 1, | ||||
| 		departure: when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysWithDetour({ | ||||
| 	await testJourneysWithDetour({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
| 		detourIds: [württembergallee] | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: without detour test
 | ||||
| 
 | ||||
| test('departures', co(function* (t) { | ||||
| 	const departures = yield client.departures(spichernstr, { | ||||
| test('departures', async (t) => { | ||||
| 	const departures = await client.departures(spichernstr, { | ||||
| 		duration: 5, when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testDepartures({ | ||||
| 	await testDepartures({ | ||||
| 		test: t, | ||||
| 		departures, | ||||
| 		validate, | ||||
| 		id: spichernstr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures with station object', co(function* (t) { | ||||
| 	const deps = yield client.departures({ | ||||
| test('departures with station object', async (t) => { | ||||
| 	const deps = await client.departures({ | ||||
| 		type: 'station', | ||||
| 		id: spichernstr, | ||||
| 		name: 'U Spichernstr', | ||||
|  | @ -276,10 +274,10 @@ test('departures with station object', co(function* (t) { | |||
| 
 | ||||
| 	validate(t, deps, 'departures', 'departures') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures at Spichernstr. in direction of Westhafen', co(function* (t) { | ||||
| 	yield testDeparturesInDirection({ | ||||
| test('departures at Spichernstr. in direction of Westhafen', async (t) => { | ||||
| 	await testDeparturesInDirection({ | ||||
| 		test: t, | ||||
| 		fetchDepartures: client.departures, | ||||
| 		fetchTrip: client.trip, | ||||
|  | @ -289,17 +287,17 @@ test('departures at Spichernstr. in direction of Westhafen', co(function* (t) { | |||
| 		validate | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures at 7-digit station', co(function* (t) { | ||||
| test('departures at 7-digit station', async (t) => { | ||||
| 	const eisenach = '8010097' // see derhuerst/vbb-hafas#22
 | ||||
| 	yield client.departures(eisenach, {when}) | ||||
| 	await client.departures(eisenach, {when}) | ||||
| 	t.pass('did not fail') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures without related stations', co(function* (t) { | ||||
| 	yield testDeparturesWithoutRelatedStations({ | ||||
| test('departures without related stations', async (t) => { | ||||
| 	await testDeparturesWithoutRelatedStations({ | ||||
| 		test: t, | ||||
| 		fetchDepartures: client.departures, | ||||
| 		id: '900000024101', // Charlottenburg
 | ||||
|  | @ -308,28 +306,28 @@ test('departures without related stations', co(function* (t) { | |||
| 		linesOfRelatedStations: ['U7'] | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('arrivals', co(function* (t) { | ||||
| 	const arrivals = yield client.arrivals(spichernstr, { | ||||
| test('arrivals', async (t) => { | ||||
| 	const arrivals = await client.arrivals(spichernstr, { | ||||
| 		duration: 5, when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testArrivals({ | ||||
| 	await testArrivals({ | ||||
| 		test: t, | ||||
| 		arrivals, | ||||
| 		validate, | ||||
| 		id: spichernstr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('nearby', co(function* (t) { | ||||
| test('nearby', async (t) => { | ||||
| 	const berlinerStr = '900000044201' | ||||
| 	const landhausstr = '900000043252' | ||||
| 
 | ||||
| 	// Berliner Str./Bundesallee
 | ||||
| 	const nearby = yield client.nearby({ | ||||
| 	const nearby = await client.nearby({ | ||||
| 		type: 'location', | ||||
| 		latitude: 52.4873452, | ||||
| 		longitude: 13.3310411 | ||||
|  | @ -348,10 +346,10 @@ test('nearby', co(function* (t) { | |||
| 	t.ok(nearby[1].distance < 200) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('locations', co(function* (t) { | ||||
| 	const locations = yield client.locations('Alexanderplatz', {results: 20}) | ||||
| test('locations', async (t) => { | ||||
| 	const locations = await client.locations('Alexanderplatz', {results: 20}) | ||||
| 
 | ||||
| 	validate(t, locations, 'locations', 'locations') | ||||
| 	t.ok(locations.length <= 20) | ||||
|  | @ -361,19 +359,19 @@ test('locations', co(function* (t) { | |||
| 	t.ok(locations.find(s => !s.name && s.address)) // addresses
 | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('station', co(function* (t) { | ||||
| 	const s = yield client.station(spichernstr) | ||||
| test('station', async (t) => { | ||||
| 	const s = await client.station(spichernstr) | ||||
| 
 | ||||
| 	validate(t, s, ['stop', 'station'], 'station') | ||||
| 	t.equal(s.id, spichernstr) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('radar', co(function* (t) { | ||||
| 	const vehicles = yield client.radar({ | ||||
| test('radar', async (t) => { | ||||
| 	const vehicles = await client.radar({ | ||||
| 		north: 52.52411, | ||||
| 		west: 13.41002, | ||||
| 		south: 52.51942, | ||||
|  | @ -384,9 +382,9 @@ test('radar', co(function* (t) { | |||
| 
 | ||||
| 	validate(t, vehicles, 'movements', 'vehicles') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('reachableFrom', co(function* (t) { | ||||
| test('reachableFrom', async (t) => { | ||||
| 	const torfstr17 = { | ||||
| 		type: 'location', | ||||
| 		address: '13353 Berlin-Wedding, Torfstr. 17', | ||||
|  | @ -394,7 +392,7 @@ test('reachableFrom', co(function* (t) { | |||
| 		longitude: 13.350042 | ||||
| 	} | ||||
| 
 | ||||
| 	yield testReachableFrom({ | ||||
| 	await testReachableFrom({ | ||||
| 		test: t, | ||||
| 		reachableFrom: client.reachableFrom, | ||||
| 		address: torfstr17, | ||||
|  | @ -403,4 +401,4 @@ test('reachableFrom', co(function* (t) { | |||
| 		validate | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
|  |  | |||
							
								
								
									
										91
									
								
								test/cmta.js
									
										
									
									
									
								
							
							
						
						
									
										91
									
								
								test/cmta.js
									
										
									
									
									
								
							|  | @ -5,7 +5,6 @@ const tapePromise = require('tape-promise').default | |||
| const tape = require('tape') | ||||
| 
 | ||||
| const {createWhen} = require('./lib/util') | ||||
| const co = require('./lib/co') | ||||
| const createClient = require('..') | ||||
| const cmtaProfile = require('../p/cmta') | ||||
| const products = require('../p/cmta/products') | ||||
|  | @ -42,14 +41,14 @@ const broadieOaks = '2370' | |||
| const domain = '5919' | ||||
| const capitol591 = '591' | ||||
| 
 | ||||
| test('journeys – Broadie Oaks to Domain', co(function* (t) { | ||||
| 	const journeys = yield client.journeys(broadieOaks, domain, { | ||||
| test('journeys – Broadie Oaks to Domain', async (t) => { | ||||
| 	const journeys = await client.journeys(broadieOaks, domain, { | ||||
| 		results: 3, | ||||
| 		departure: when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToStation({ | ||||
| 	await testJourneysStationToStation({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -57,7 +56,7 @@ test('journeys – Broadie Oaks to Domain', co(function* (t) { | |||
| 		toId: domain | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: journeys, only one product
 | ||||
| 
 | ||||
|  | @ -73,7 +72,7 @@ test('journeys – fails with no product', (t) => { | |||
| 	t.end() | ||||
| }) | ||||
| 
 | ||||
| test('Domain to 1104 Elm Street, Austin, TX 78703', co(function*(t) { | ||||
| test('Domain to 1104 Elm Street, Austin, TX 78703', async (t) => { | ||||
| 	const someAddress = { | ||||
| 		type: 'location', | ||||
| 		address: '1104 ELM ST, Austin, TX 78703', | ||||
|  | @ -81,12 +80,12 @@ test('Domain to 1104 Elm Street, Austin, TX 78703', co(function*(t) { | |||
| 		longitude: -97.758292 | ||||
| 	} | ||||
| 
 | ||||
| 	const journeys = yield client.journeys(domain, someAddress, { | ||||
| 	const journeys = await client.journeys(domain, someAddress, { | ||||
| 		results: 3, | ||||
| 		departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToAddress({ | ||||
| 	await testJourneysStationToAddress({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -94,9 +93,9 @@ test('Domain to 1104 Elm Street, Austin, TX 78703', co(function*(t) { | |||
| 		to: someAddress | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('Domain to Whole Foods Market - North Lamar Blvd', co(function*(t) { | ||||
| test('Domain to Whole Foods Market - North Lamar Blvd', async (t) => { | ||||
| 	const wholeFoodsMarket = { | ||||
| 		type: 'location', | ||||
| 		id: '9845477', | ||||
|  | @ -104,12 +103,12 @@ test('Domain to Whole Foods Market - North Lamar Blvd', co(function*(t) { | |||
| 		latitude: 30.270653, | ||||
| 		longitude: -97.753564 | ||||
| 	} | ||||
| 	const journeys = yield client.journeys(domain, wholeFoodsMarket, { | ||||
| 	const journeys = await client.journeys(domain, wholeFoodsMarket, { | ||||
| 		results: 3, | ||||
| 		departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToPoi({ | ||||
| 	await testJourneysStationToPoi({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -117,13 +116,13 @@ test('Domain to Whole Foods Market - North Lamar Blvd', co(function*(t) { | |||
| 		to: wholeFoodsMarket | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: via works – with detour
 | ||||
| // todo: without detour
 | ||||
| 
 | ||||
| test('earlier/later journeys', co(function* (t) { | ||||
| 	yield testEarlierLaterJourneys({ | ||||
| test('earlier/later journeys', async (t) => { | ||||
| 	await testEarlierLaterJourneys({ | ||||
| 		test: t, | ||||
| 		fetchJourneys: client.journeys, | ||||
| 		validate, | ||||
|  | @ -133,10 +132,10 @@ test('earlier/later journeys', co(function* (t) { | |||
| 	}) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('refreshJourney', co(function* (t) { | ||||
| 	yield testRefreshJourney({ | ||||
| test('refreshJourney', async (t) => { | ||||
| 	await testRefreshJourney({ | ||||
| 		test: t, | ||||
| 		fetchJourneys: client.journeys, | ||||
| 		refreshJourney: client.refreshJourney, | ||||
|  | @ -146,39 +145,39 @@ test('refreshJourney', co(function* (t) { | |||
| 		when | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('trip details', co(function* (t) { | ||||
| 	const journeys = yield client.journeys(broadieOaks, domain, { | ||||
| test('trip details', async (t) => { | ||||
| 	const journeys = await client.journeys(broadieOaks, domain, { | ||||
| 		results: 1, departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	const p = journeys[0].legs[0] | ||||
| 	t.ok(p.id, 'precondition failed') | ||||
| 	t.ok(p.line.name, 'precondition failed') | ||||
| 	const trip = yield client.trip(p.id, p.line.name, {when}) | ||||
| 	const trip = await client.trip(p.id, p.line.name, {when}) | ||||
| 
 | ||||
| 	validate(t, trip, 'journeyLeg', 'trip') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures at Broadie Oaks', co(function*(t) { | ||||
| 	const departures = yield client.departures(broadieOaks, { | ||||
| test('departures at Broadie Oaks', async (t) => { | ||||
| 	const departures = await client.departures(broadieOaks, { | ||||
| 		duration: 10, when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testDepartures({ | ||||
| 	await testDepartures({ | ||||
| 		test: t, | ||||
| 		departures, | ||||
| 		validate, | ||||
| 		id: broadieOaks | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures with station object', co(function* (t) { | ||||
| 	const deps = yield client.departures({ | ||||
| test('departures with station object', async (t) => { | ||||
| 	const deps = await client.departures({ | ||||
| 		type: 'station', | ||||
| 		id: broadieOaks, | ||||
| 		name: 'Magdeburg Hbf', | ||||
|  | @ -191,26 +190,26 @@ test('departures with station object', co(function* (t) { | |||
| 
 | ||||
| 	validate(t, deps, 'departures', 'departures') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('arrivals at Broadie Oaks', co(function*(t) { | ||||
| 	const arrivals = yield client.arrivals(broadieOaks, { | ||||
| test('arrivals at Broadie Oaks', async (t) => { | ||||
| 	const arrivals = await client.arrivals(broadieOaks, { | ||||
| 		duration: 10, when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testArrivals({ | ||||
| 	await testArrivals({ | ||||
| 		test: t, | ||||
| 		arrivals, | ||||
| 		validate, | ||||
| 		id: broadieOaks | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: nearby
 | ||||
| 
 | ||||
| test('locations named "Capitol"', co(function*(t) { | ||||
| 	const locations = yield client.locations('Capitol', { | ||||
| test('locations named "Capitol"', async (t) => { | ||||
| 	const locations = await client.locations('Capitol', { | ||||
| 		results: 10 | ||||
| 	}) | ||||
| 
 | ||||
|  | @ -224,19 +223,19 @@ test('locations named "Capitol"', co(function*(t) { | |||
| 	})) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('station Domain', co(function* (t) { | ||||
| 	const s = yield client.station(domain) | ||||
| test('station Domain', async (t) => { | ||||
| 	const s = await client.station(domain) | ||||
| 
 | ||||
| 	validate(t, s, ['stop', 'station'], 'station') | ||||
| 	t.equal(s.id, domain) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('radar', co(function* (t) { | ||||
| 	const vehicles = yield client.radar({ | ||||
| test('radar', async (t) => { | ||||
| 	const vehicles = await client.radar({ | ||||
| 		north: 30.240877, | ||||
| 		west: -97.804588, | ||||
| 		south: 30.225378, | ||||
|  | @ -247,10 +246,10 @@ test('radar', co(function* (t) { | |||
| 
 | ||||
| 	validate(t, vehicles, 'movements', 'vehicles') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('reachableFrom', co(function* (t) { | ||||
| 	yield testReachableFrom({ | ||||
| test('reachableFrom', async (t) => { | ||||
| 	await testReachableFrom({ | ||||
| 		test: t, | ||||
| 		reachableFrom: client.reachableFrom, | ||||
| 		address: { | ||||
|  | @ -264,4 +263,4 @@ test('reachableFrom', co(function* (t) { | |||
| 		validate | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
|  |  | |||
							
								
								
									
										123
									
								
								test/db.js
									
										
									
									
									
								
							
							
						
						
									
										123
									
								
								test/db.js
									
										
									
									
									
								
							|  | @ -7,7 +7,6 @@ const tape = require('tape') | |||
| const isRoughlyEqual = require('is-roughly-equal') | ||||
| 
 | ||||
| const {createWhen} = require('./lib/util') | ||||
| const co = require('./lib/co') | ||||
| const createClient = require('..') | ||||
| const dbProfile = require('../p/db') | ||||
| const products = require('../p/db/products') | ||||
|  | @ -88,14 +87,14 @@ const blnTiergarten = '8089091' | |||
| const blnJannowitzbrücke = '8089019' | ||||
| const potsdamHbf = '8012666' | ||||
| 
 | ||||
| test('journeys – Berlin Schwedter Str. to München Hbf', co(function* (t) { | ||||
| 	const journeys = yield client.journeys(blnSchwedterStr, münchenHbf, { | ||||
| test('journeys – Berlin Schwedter Str. to München Hbf', async (t) => { | ||||
| 	const journeys = await client.journeys(blnSchwedterStr, münchenHbf, { | ||||
| 		results: 3, | ||||
| 		departure: when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToStation({ | ||||
| 	await testJourneysStationToStation({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -108,7 +107,7 @@ test('journeys – Berlin Schwedter Str. to München Hbf', co(function* (t) { | |||
| 	} | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: journeys, only one product
 | ||||
| 
 | ||||
|  | @ -124,19 +123,19 @@ test('journeys – fails with no product', (t) => { | |||
| 	t.end() | ||||
| }) | ||||
| 
 | ||||
| test('Berlin Schwedter Str. to Torfstraße 17', co(function* (t) { | ||||
| test('Berlin Schwedter Str. to Torfstraße 17', async (t) => { | ||||
| 	const torfstr = { | ||||
| 		type: 'location', | ||||
| 		address: 'Torfstraße 17', | ||||
| 		latitude: 52.5416823, | ||||
| 		longitude: 13.3491223 | ||||
| 	} | ||||
| 	const journeys = yield client.journeys(blnSchwedterStr, torfstr, { | ||||
| 	const journeys = await client.journeys(blnSchwedterStr, torfstr, { | ||||
| 		results: 3, | ||||
| 		departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToAddress({ | ||||
| 	await testJourneysStationToAddress({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -144,9 +143,9 @@ test('Berlin Schwedter Str. to Torfstraße 17', co(function* (t) { | |||
| 		to: torfstr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('Berlin Schwedter Str. to ATZE Musiktheater', co(function* (t) { | ||||
| test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => { | ||||
| 	const atze = { | ||||
| 		type: 'location', | ||||
| 		id: '991598902', | ||||
|  | @ -154,12 +153,12 @@ test('Berlin Schwedter Str. to ATZE Musiktheater', co(function* (t) { | |||
| 		latitude: 52.542417, | ||||
| 		longitude: 13.350437 | ||||
| 	} | ||||
| 	const journeys = yield client.journeys(blnSchwedterStr, atze, { | ||||
| 	const journeys = await client.journeys(blnSchwedterStr, atze, { | ||||
| 		results: 3, | ||||
| 		departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToPoi({ | ||||
| 	await testJourneysStationToPoi({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -167,31 +166,31 @@ test('Berlin Schwedter Str. to ATZE Musiktheater', co(function* (t) { | |||
| 		to: atze | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('journeys: via works – with detour', co(function* (t) { | ||||
| test('journeys: via works – with detour', async (t) => { | ||||
| 	// Going from Westhafen to Wedding via Württembergalle without detour
 | ||||
| 	// is currently impossible. We check if the routing engine computes a detour.
 | ||||
| 	const journeys = yield client.journeys(westhafen, wedding, { | ||||
| 	const journeys = await client.journeys(westhafen, wedding, { | ||||
| 		via: württembergallee, | ||||
| 		results: 1, | ||||
| 		departure: when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysWithDetour({ | ||||
| 	await testJourneysWithDetour({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
| 		detourIds: [württembergallee] | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: without detour
 | ||||
| 
 | ||||
| test('earlier/later journeys, Jungfernheide -> München Hbf', co(function* (t) { | ||||
| 	yield testEarlierLaterJourneys({ | ||||
| test('earlier/later journeys, Jungfernheide -> München Hbf', async (t) => { | ||||
| 	await testEarlierLaterJourneys({ | ||||
| 		test: t, | ||||
| 		fetchJourneys: client.journeys, | ||||
| 		validate, | ||||
|  | @ -201,20 +200,20 @@ test('earlier/later journeys, Jungfernheide -> München Hbf', co(function* (t) { | |||
| 	}) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test.skip('journeys – leg cycle & alternatives', co(function* (t) { | ||||
| 	yield testLegCycleAlternatives({ | ||||
| test.skip('journeys – leg cycle & alternatives', async (t) => { | ||||
| 	await testLegCycleAlternatives({ | ||||
| 		test: t, | ||||
| 		fetchJourneys: client.journeys, | ||||
| 		fromId: blnTiergarten, | ||||
| 		toId: blnJannowitzbrücke | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('refreshJourney', co(function* (t) { | ||||
| 	yield testRefreshJourney({ | ||||
| test('refreshJourney', async (t) => { | ||||
| 	await testRefreshJourney({ | ||||
| 		test: t, | ||||
| 		fetchJourneys: client.journeys, | ||||
| 		refreshJourney: client.refreshJourney, | ||||
|  | @ -224,17 +223,17 @@ test('refreshJourney', co(function* (t) { | |||
| 		when | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('trip details', co(function* (t) { | ||||
| 	const journeys = yield client.journeys(berlinHbf, münchenHbf, { | ||||
| test('trip details', async (t) => { | ||||
| 	const journeys = await client.journeys(berlinHbf, münchenHbf, { | ||||
| 		results: 1, departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	const p = journeys[0].legs[0] | ||||
| 	t.ok(p.id, 'precondition failed') | ||||
| 	t.ok(p.line.name, 'precondition failed') | ||||
| 	const trip = yield client.trip(p.id, p.line.name, {when}) | ||||
| 	const trip = await client.trip(p.id, p.line.name, {when}) | ||||
| 
 | ||||
| 	const validateJourneyLeg = createValidateJourneyLeg(cfg) | ||||
| 	const validate = createValidate(cfg, { | ||||
|  | @ -246,25 +245,25 @@ test('trip details', co(function* (t) { | |||
| 	validate(t, trip, 'journeyLeg', 'trip') | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures at Berlin Schwedter Str.', co(function* (t) { | ||||
| 	const departures = yield client.departures(blnSchwedterStr, { | ||||
| test('departures at Berlin Schwedter Str.', async (t) => { | ||||
| 	const departures = await client.departures(blnSchwedterStr, { | ||||
| 		duration: 5, when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testDepartures({ | ||||
| 	await testDepartures({ | ||||
| 		test: t, | ||||
| 		departures, | ||||
| 		validate, | ||||
| 		id: blnSchwedterStr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures with station object', co(function* (t) { | ||||
| 	const deps = yield client.departures({ | ||||
| test('departures with station object', async (t) => { | ||||
| 	const deps = await client.departures({ | ||||
| 		type: 'station', | ||||
| 		id: jungfernheide, | ||||
| 		name: 'Berlin Jungfernheide', | ||||
|  | @ -277,10 +276,10 @@ test('departures with station object', co(function* (t) { | |||
| 
 | ||||
| 	validate(t, deps, 'departures', 'departures') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures at Berlin Hbf in direction of Berlin Ostbahnhof', co(function* (t) { | ||||
| 	yield testDeparturesInDirection({ | ||||
| test('departures at Berlin Hbf in direction of Berlin Ostbahnhof', async (t) => { | ||||
| 	await testDeparturesInDirection({ | ||||
| 		test: t, | ||||
| 		fetchDepartures: client.departures, | ||||
| 		fetchTrip: client.trip, | ||||
|  | @ -290,10 +289,10 @@ test('departures at Berlin Hbf in direction of Berlin Ostbahnhof', co(function* | |||
| 		validate | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures without related stations', co(function* (t) { | ||||
| 	yield testDeparturesWithoutRelatedStations({ | ||||
| test('departures without related stations', async (t) => { | ||||
| 	await testDeparturesWithoutRelatedStations({ | ||||
| 		test: t, | ||||
| 		fetchDepartures: client.departures, | ||||
| 		id: '8089051', // Berlin Yorckstr. (S1)
 | ||||
|  | @ -302,25 +301,25 @@ test('departures without related stations', co(function* (t) { | |||
| 		linesOfRelatedStations: ['S 2', 'S 25', 'S 26', 'U 7'] | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('arrivals at Berlin Schwedter Str.', co(function* (t) { | ||||
| 	const arrivals = yield client.arrivals(blnSchwedterStr, { | ||||
| test('arrivals at Berlin Schwedter Str.', async (t) => { | ||||
| 	const arrivals = await client.arrivals(blnSchwedterStr, { | ||||
| 		duration: 5, when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testArrivals({ | ||||
| 	await testArrivals({ | ||||
| 		test: t, | ||||
| 		arrivals, | ||||
| 		validate, | ||||
| 		id: blnSchwedterStr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('nearby Berlin Jungfernheide', co(function* (t) { | ||||
| 	const nearby = yield client.nearby({ | ||||
| test('nearby Berlin Jungfernheide', async (t) => { | ||||
| 	const nearby = await client.nearby({ | ||||
| 		type: 'location', | ||||
| 		latitude: 52.530273, | ||||
| 		longitude: 13.299433 | ||||
|  | @ -341,10 +340,10 @@ test('nearby Berlin Jungfernheide', co(function* (t) { | |||
| 	t.ok(s0.distance <= 100) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('locations named Jungfernheide', co(function* (t) { | ||||
| 	const locations = yield client.locations('Jungfernheide', { | ||||
| test('locations named Jungfernheide', async (t) => { | ||||
| 	const locations = await client.locations('Jungfernheide', { | ||||
| 		results: 10 | ||||
| 	}) | ||||
| 
 | ||||
|  | @ -355,27 +354,27 @@ test('locations named Jungfernheide', co(function* (t) { | |||
| 	}), 'Jungfernheide not found') | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('station', co(function* (t) { | ||||
| 	const s = yield client.station(regensburgHbf) | ||||
| test('station', async (t) => { | ||||
| 	const s = await client.station(regensburgHbf) | ||||
| 
 | ||||
| 	validate(t, s, ['stop', 'station'], 'station') | ||||
| 	t.equal(s.id, regensburgHbf) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('line with additionalName', co(function* (t) { | ||||
| 	const departures = yield client.departures(potsdamHbf, { | ||||
| test('line with additionalName', async (t) => { | ||||
| 	const departures = await client.departures(potsdamHbf, { | ||||
| 		duration: 12 * 60, // 12 minutes
 | ||||
| 		products: {bus: false, suburban: false, tram: false} | ||||
| 	}) | ||||
| 	t.ok(departures.some(d => d.line && d.line.additionalName)) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('reachableFrom', co(function* (t) { | ||||
| test('reachableFrom', async (t) => { | ||||
| 	const torfstr17 = { | ||||
| 		type: 'location', | ||||
| 		address: 'Torfstraße 17', | ||||
|  | @ -383,7 +382,7 @@ test('reachableFrom', co(function* (t) { | |||
| 		longitude: 13.3491223 | ||||
| 	} | ||||
| 
 | ||||
| 	yield testReachableFrom({ | ||||
| 	await testReachableFrom({ | ||||
| 		test: t, | ||||
| 		reachableFrom: client.reachableFrom, | ||||
| 		address: torfstr17, | ||||
|  | @ -392,4 +391,4 @@ test('reachableFrom', co(function* (t) { | |||
| 		validate | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
|  |  | |||
							
								
								
									
										93
									
								
								test/insa.js
									
										
									
									
									
								
							
							
						
						
									
										93
									
								
								test/insa.js
									
										
									
									
									
								
							|  | @ -5,7 +5,6 @@ const tape = require('tape') | |||
| const isRoughlyEqual = require('is-roughly-equal') | ||||
| 
 | ||||
| const {createWhen} = require('./lib/util') | ||||
| const co = require('./lib/co') | ||||
| const createClient = require('..') | ||||
| const insaProfile = require('../p/insa') | ||||
| const products = require('../p/insa/products') | ||||
|  | @ -47,14 +46,14 @@ const stendal = '8010334' | |||
| const dessau = '8010077' | ||||
| const universitaet = '19686' | ||||
| 
 | ||||
| test('journeys – Magdeburg Hbf to Magdeburg-Buckau', co(function* (t) { | ||||
| 	const journeys = yield client.journeys(magdeburgHbf, magdeburgBuckau, { | ||||
| test('journeys – Magdeburg Hbf to Magdeburg-Buckau', async (t) => { | ||||
| 	const journeys = await client.journeys(magdeburgHbf, magdeburgBuckau, { | ||||
| 		results: 3, | ||||
| 		departure: when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToStation({ | ||||
| 	await testJourneysStationToStation({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -62,7 +61,7 @@ test('journeys – Magdeburg Hbf to Magdeburg-Buckau', co(function* (t) { | |||
| 		toId: magdeburgBuckau | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: journeys, only one product
 | ||||
| 
 | ||||
|  | @ -78,7 +77,7 @@ test('journeys – fails with no product', (t) => { | |||
| 	t.end() | ||||
| }) | ||||
| 
 | ||||
| test('Magdeburg Hbf to 39104 Magdeburg, Sternstr. 10', co(function*(t) { | ||||
| test('Magdeburg Hbf to 39104 Magdeburg, Sternstr. 10', async (t) => { | ||||
| 	const sternStr = { | ||||
| 		type: 'location', | ||||
| 		address: 'Magdeburg - Altenstadt, Sternstraße 10', | ||||
|  | @ -86,12 +85,12 @@ test('Magdeburg Hbf to 39104 Magdeburg, Sternstr. 10', co(function*(t) { | |||
| 		longitude: 11.422332 | ||||
| 	} | ||||
| 
 | ||||
| 	const journeys = yield client.journeys(magdeburgHbf, sternStr, { | ||||
| 	const journeys = await client.journeys(magdeburgHbf, sternStr, { | ||||
| 		results: 3, | ||||
| 		departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToAddress({ | ||||
| 	await testJourneysStationToAddress({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -99,9 +98,9 @@ test('Magdeburg Hbf to 39104 Magdeburg, Sternstr. 10', co(function*(t) { | |||
| 		to: sternStr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('Magdeburg Hbf to Kloster Unser Lieben Frauen', co(function*(t) { | ||||
| test('Magdeburg Hbf to Kloster Unser Lieben Frauen', async (t) => { | ||||
| 	const kloster = { | ||||
| 		type: 'location', | ||||
| 		id: '970012223', | ||||
|  | @ -109,12 +108,12 @@ test('Magdeburg Hbf to Kloster Unser Lieben Frauen', co(function*(t) { | |||
| 		latitude: 52.127601, | ||||
| 		longitude: 11.636437 | ||||
| 	} | ||||
| 	const journeys = yield client.journeys(magdeburgHbf, kloster, { | ||||
| 	const journeys = await client.journeys(magdeburgHbf, kloster, { | ||||
| 		results: 3, | ||||
| 		departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToPoi({ | ||||
| 	await testJourneysStationToPoi({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -122,32 +121,32 @@ test('Magdeburg Hbf to Kloster Unser Lieben Frauen', co(function*(t) { | |||
| 		to: kloster | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('journeys: via works – with detour', co(function* (t) { | ||||
| test('journeys: via works – with detour', async (t) => { | ||||
| 	// Going from Magdeburg, Hasselbachplatz (Sternstr.) (Tram/Bus) to Stendal
 | ||||
| 	// via Dessau without detour is currently impossible. We check if the routing
 | ||||
| 	// engine computes a detour.
 | ||||
| 	const journeys = yield client.journeys(hasselbachplatzSternstrasse, stendal, { | ||||
| 	const journeys = await client.journeys(hasselbachplatzSternstrasse, stendal, { | ||||
| 		via: dessau, | ||||
| 		results: 1, | ||||
| 		departure: when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysWithDetour({ | ||||
| 	await testJourneysWithDetour({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
| 		detourIds: [dessau] | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: without detour
 | ||||
| 
 | ||||
| test('earlier/later journeys', co(function* (t) { | ||||
| 	yield testEarlierLaterJourneys({ | ||||
| test('earlier/later journeys', async (t) => { | ||||
| 	await testEarlierLaterJourneys({ | ||||
| 		test: t, | ||||
| 		fetchJourneys: client.journeys, | ||||
| 		validate, | ||||
|  | @ -157,39 +156,39 @@ test('earlier/later journeys', co(function* (t) { | |||
| 	}) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('trip details', co(function* (t) { | ||||
| 	const journeys = yield client.journeys(magdeburgHbf, magdeburgBuckau, { | ||||
| test('trip details', async (t) => { | ||||
| 	const journeys = await client.journeys(magdeburgHbf, magdeburgBuckau, { | ||||
| 		results: 1, departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	const p = journeys[0].legs[0] | ||||
| 	t.ok(p.id, 'precondition failed') | ||||
| 	t.ok(p.line.name, 'precondition failed') | ||||
| 	const trip = yield client.trip(p.id, p.line.name, {when}) | ||||
| 	const trip = await client.trip(p.id, p.line.name, {when}) | ||||
| 
 | ||||
| 	validate(t, trip, 'journeyLeg', 'trip') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures at Magdeburg Leiterstr.', co(function*(t) { | ||||
| 	const departures = yield client.departures(leiterstr, { | ||||
| test('departures at Magdeburg Leiterstr.', async (t) => { | ||||
| 	const departures = await client.departures(leiterstr, { | ||||
| 		duration: 5, when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testDepartures({ | ||||
| 	await testDepartures({ | ||||
| 		test: t, | ||||
| 		departures, | ||||
| 		validate, | ||||
| 		id: leiterstr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures with station object', co(function* (t) { | ||||
| 	const deps = yield client.departures({ | ||||
| test('departures with station object', async (t) => { | ||||
| 	const deps = await client.departures({ | ||||
| 		type: 'station', | ||||
| 		id: magdeburgHbf, | ||||
| 		name: 'Magdeburg Hbf', | ||||
|  | @ -202,10 +201,10 @@ test('departures with station object', co(function* (t) { | |||
| 
 | ||||
| 	validate(t, deps, 'departures', 'departures') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures at Leiterstr in direction of Universität', co(function* (t) { | ||||
| 	yield testDeparturesInDirection({ | ||||
| test('departures at Leiterstr in direction of Universität', async (t) => { | ||||
| 	await testDeparturesInDirection({ | ||||
| 		test: t, | ||||
| 		fetchDepartures: client.departures, | ||||
| 		fetchTrip: client.trip, | ||||
|  | @ -215,27 +214,27 @@ test('departures at Leiterstr in direction of Universität', co(function* (t) { | |||
| 		validate | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('arrivals at Magdeburg Leiterstr.', co(function*(t) { | ||||
| 	const arrivals = yield client.arrivals(leiterstr, { | ||||
| test('arrivals at Magdeburg Leiterstr.', async (t) => { | ||||
| 	const arrivals = await client.arrivals(leiterstr, { | ||||
| 		duration: 5, when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testArrivals({ | ||||
| 	await testArrivals({ | ||||
| 		test: t, | ||||
| 		arrivals, | ||||
| 		validate, | ||||
| 		id: leiterstr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: nearby
 | ||||
| 
 | ||||
| test('locations named Magdeburg', co(function*(t) { | ||||
| test('locations named Magdeburg', async (t) => { | ||||
| 	const nordpark = '7480' | ||||
| 	const locations = yield client.locations('nordpark', { | ||||
| 	const locations = await client.locations('nordpark', { | ||||
| 		results: 20 | ||||
| 	}) | ||||
| 
 | ||||
|  | @ -249,19 +248,19 @@ test('locations named Magdeburg', co(function*(t) { | |||
| 	})) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('station Magdeburg-Buckau', co(function* (t) { | ||||
| 	const s = yield client.station(magdeburgBuckau) | ||||
| test('station Magdeburg-Buckau', async (t) => { | ||||
| 	const s = await client.station(magdeburgBuckau) | ||||
| 
 | ||||
| 	validate(t, s, ['stop', 'station'], 'station') | ||||
| 	t.equal(s.id, magdeburgBuckau) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('radar', co(function* (t) { | ||||
| 	const vehicles = yield client.radar({ | ||||
| test('radar', async (t) => { | ||||
| 	const vehicles = await client.radar({ | ||||
| 		north: 52.148364, | ||||
| 		west: 11.600826, | ||||
| 		south: 52.108486, | ||||
|  | @ -277,4 +276,4 @@ test('radar', co(function* (t) { | |||
| 	validate(t, vehicles, 'movements', 'vehicles') | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
|  |  | |||
|  | @ -1,8 +1,6 @@ | |||
| 'use strict' | ||||
| 
 | ||||
| const co = require('./co') | ||||
| 
 | ||||
| const testArrivals = co(function* (cfg) { | ||||
| const testArrivals = async (cfg) => { | ||||
| 	const {test: t, arrivals: arrs, validate, id} = cfg | ||||
| 
 | ||||
| 	validate(t, arrs, 'arrivals', 'arrivals') | ||||
|  | @ -20,6 +18,6 @@ const testArrivals = co(function* (cfg) { | |||
| 
 | ||||
| 	// todo: move into arrivals validator
 | ||||
| 	t.deepEqual(arrs, arrs.sort((a, b) => t.when > b.when)) | ||||
| }) | ||||
| } | ||||
| 
 | ||||
| module.exports = testArrivals | ||||
|  |  | |||
|  | @ -1,33 +0,0 @@ | |||
| 'use strict' | ||||
| 
 | ||||
| // https://github.com/babel/babel/blob/3c8d831fe41f502cbe2459a271d19c7329ffe369/packages/babel-helpers/src/helpers.js#L242-L270
 | ||||
| const co = (fn) => { | ||||
| 	return function run () { | ||||
| 		const self = this, args = arguments | ||||
| 		return new Promise((resolve, reject) => { | ||||
| 			const gen = fn.apply(self, args) | ||||
| 			const step = (key, arg) => { | ||||
| 				try { | ||||
| 					var info = gen[key](arg) | ||||
| 					var value = info.value | ||||
| 				} catch (error) { | ||||
| 					reject(error) | ||||
| 					return | ||||
| 				} | ||||
| 				if (info.done) resolve(value) | ||||
| 				else Promise.resolve(value).then(_next, _throw) | ||||
| 			} | ||||
| 
 | ||||
| 			const _next = (value) => { | ||||
| 				step('next', value) | ||||
| 			} | ||||
| 			const _throw = (err) => { | ||||
| 				step('throw', err) | ||||
| 			} | ||||
| 
 | ||||
| 			_next() | ||||
| 		}) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| module.exports = co | ||||
|  | @ -1,8 +1,6 @@ | |||
| 'use strict' | ||||
| 
 | ||||
| const co = require('./co') | ||||
| 
 | ||||
| const testDeparturesInDirection = co(function* (cfg) { | ||||
| const testDeparturesInDirection = async (cfg) => { | ||||
| 	const { | ||||
| 		test: t, | ||||
| 		fetchDepartures, | ||||
|  | @ -13,7 +11,7 @@ const testDeparturesInDirection = co(function* (cfg) { | |||
| 		validate | ||||
| 	} = cfg | ||||
| 
 | ||||
| 	const deps = yield fetchDepartures(id, { | ||||
| 	const deps = await fetchDepartures(id, { | ||||
| 		direction: directionIds[0], | ||||
| 		when | ||||
| 	}) | ||||
|  | @ -25,7 +23,7 @@ const testDeparturesInDirection = co(function* (cfg) { | |||
| 		const name = `deps[${i}]` | ||||
| 
 | ||||
| 		const line = dep.line && dep.line.name | ||||
| 		const trip = yield fetchTrip(dep.tripId, line, { | ||||
| 		const trip = await fetchTrip(dep.tripId, line, { | ||||
| 			when, stopovers: true | ||||
| 		}) | ||||
| 		t.ok(trip.stopovers.some(st => ( | ||||
|  | @ -33,6 +31,6 @@ const testDeparturesInDirection = co(function* (cfg) { | |||
| 			directionIds.includes(st.stop.id) | ||||
| 		)), `trip ${dep.tripId} of ${name} has no stopover at ${directionIds}`) | ||||
| 	} | ||||
| }) | ||||
| } | ||||
| 
 | ||||
| module.exports = testDeparturesInDirection | ||||
|  |  | |||
|  | @ -1,8 +1,6 @@ | |||
| 'use strict' | ||||
| 
 | ||||
| const co = require('./co') | ||||
| 
 | ||||
| const testDeparturesWithoutUnrelatedStations = co(function* (cfg) { | ||||
| const testDeparturesWithoutUnrelatedStations = async (cfg) => { | ||||
| 	const { | ||||
| 		test: t, | ||||
| 		fetchDepartures, | ||||
|  | @ -19,14 +17,14 @@ const testDeparturesWithoutUnrelatedStations = co(function* (cfg) { | |||
| 		return relatedLines.includes(dep.line.name.toLowerCase().trim()) | ||||
| 	} | ||||
| 
 | ||||
| 	const depsWith = yield fetchDepartures(id, { | ||||
| 	const depsWith = await fetchDepartures(id, { | ||||
| 		when, | ||||
| 		duration: cfg.duration || 20, | ||||
| 		products: cfg.products || {} | ||||
| 	}) | ||||
| 	t.ok(depsWith.some(isUnrelatedLine), 'precondition failed: no line at related station found') | ||||
| 
 | ||||
| 	const depsWithout = yield fetchDepartures(id, { | ||||
| 	const depsWithout = await fetchDepartures(id, { | ||||
| 		includeRelatedStations: false, | ||||
| 		when, | ||||
| 		duration: cfg.duration || 20, | ||||
|  | @ -36,6 +34,6 @@ const testDeparturesWithoutUnrelatedStations = co(function* (cfg) { | |||
| 	const unrelatedDep = depsWithout.find(isUnrelatedLine) | ||||
| 	if (unrelatedDep) t.fail('line at related station: ' + unrelatedDep.line.name) | ||||
| 	else t.pass('no lines from related stations') | ||||
| }) | ||||
| } | ||||
| 
 | ||||
| module.exports = testDeparturesWithoutUnrelatedStations | ||||
|  |  | |||
|  | @ -1,8 +1,6 @@ | |||
| 'use strict' | ||||
| 
 | ||||
| const co = require('./co') | ||||
| 
 | ||||
| const testDepartures = co(function* (cfg) { | ||||
| const testDepartures = async (cfg) => { | ||||
| 	const {test: t, departures: deps, validate, id} = cfg | ||||
| 
 | ||||
| 	validate(t, deps, 'departures', 'departures') | ||||
|  | @ -20,6 +18,6 @@ const testDepartures = co(function* (cfg) { | |||
| 
 | ||||
| 	// todo: move into deps validator
 | ||||
| 	t.deepEqual(deps, deps.sort((a, b) => t.when > b.when)) | ||||
| }) | ||||
| } | ||||
| 
 | ||||
| module.exports = testDepartures | ||||
|  |  | |||
|  | @ -1,8 +1,6 @@ | |||
| 'use strict' | ||||
| 
 | ||||
| const co = require('./co') | ||||
| 
 | ||||
| const testEarlierLaterJourneys = co(function* (cfg) { | ||||
| const testEarlierLaterJourneys = async (cfg) => { | ||||
| 	const { | ||||
| 		test: t, | ||||
| 		fetchJourneys, | ||||
|  | @ -12,7 +10,7 @@ const testEarlierLaterJourneys = co(function* (cfg) { | |||
| 		// todo: validate
 | ||||
| 	} = cfg | ||||
| 
 | ||||
| 	const model = yield fetchJourneys(fromId, toId, { | ||||
| 	const model = await fetchJourneys(fromId, toId, { | ||||
| 		results: 3, departure: when | ||||
| 	}) | ||||
| 
 | ||||
|  | @ -60,7 +58,7 @@ const testEarlierLaterJourneys = co(function* (cfg) { | |||
| 		else if (dep > latestDep) latestDep = dep | ||||
| 	} | ||||
| 
 | ||||
| 	const earlier = yield fetchJourneys(fromId, toId, { | ||||
| 	const earlier = await fetchJourneys(fromId, toId, { | ||||
| 		results: 3, | ||||
| 		// todo: single journey ref?
 | ||||
| 		earlierThan: model.earlierRef | ||||
|  | @ -71,7 +69,7 @@ const testEarlierLaterJourneys = co(function* (cfg) { | |||
| 		t.ok(dep < earliestDep) | ||||
| 	} | ||||
| 
 | ||||
| 	const later = yield fetchJourneys(fromId, toId, { | ||||
| 	const later = await fetchJourneys(fromId, toId, { | ||||
| 		results: 3, | ||||
| 		// todo: single journey ref?
 | ||||
| 		laterThan: model.laterRef | ||||
|  | @ -81,6 +79,6 @@ const testEarlierLaterJourneys = co(function* (cfg) { | |||
| 		const dep = new Date(firstLeg.departure || firstLeg.formerScheduledDeparture) | ||||
| 		t.ok(dep > latestDep) | ||||
| 	} | ||||
| }) | ||||
| } | ||||
| 
 | ||||
| module.exports = testEarlierLaterJourneys | ||||
|  |  | |||
|  | @ -2,9 +2,7 @@ | |||
| 
 | ||||
| const isRoughlyEqual = require('is-roughly-equal') | ||||
| 
 | ||||
| const co = require('./co') | ||||
| 
 | ||||
| const testJourneysStationToAddress = co(function* (cfg) { | ||||
| const testJourneysStationToAddress = async (cfg) => { | ||||
| 	const {test: t, journeys, validate, fromId} = cfg | ||||
| 	const {address, latitude, longitude} = cfg.to | ||||
| 
 | ||||
|  | @ -25,6 +23,6 @@ const testJourneysStationToAddress = co(function* (cfg) { | |||
| 		t.ok(isRoughlyEqual(.0001, d.latitude, latitude), n + '.latitude is invalid') | ||||
| 		t.ok(isRoughlyEqual(.0001, d.longitude, longitude), n + '.longitude is invalid') | ||||
| 	} | ||||
| }) | ||||
| } | ||||
| 
 | ||||
| module.exports = testJourneysStationToAddress | ||||
|  |  | |||
|  | @ -2,9 +2,7 @@ | |||
| 
 | ||||
| const isRoughlyEqual = require('is-roughly-equal') | ||||
| 
 | ||||
| const co = require('./co') | ||||
| 
 | ||||
| const testJourneysStationToPoi = co(function* (cfg) { | ||||
| const testJourneysStationToPoi = async (cfg) => { | ||||
| 	const {test: t, journeys, validate, fromId} = cfg | ||||
| 	const {id, name, latitude, longitude} = cfg.to | ||||
| 
 | ||||
|  | @ -34,6 +32,6 @@ const testJourneysStationToPoi = co(function* (cfg) { | |||
| 		t.ok(isRoughlyEqual(.0001, d.latitude, latitude), dN + '.latitude is invalid') | ||||
| 		t.ok(isRoughlyEqual(.0001, d.longitude, longitude), dN + '.longitude is invalid') | ||||
| 	} | ||||
| }) | ||||
| } | ||||
| 
 | ||||
| module.exports = testJourneysStationToPoi | ||||
|  |  | |||
|  | @ -1,8 +1,6 @@ | |||
| 'use strict' | ||||
| 
 | ||||
| const co = require('./co') | ||||
| 
 | ||||
| const testJourneysStationToStation = co(function* (cfg) { | ||||
| const testJourneysStationToStation = async (cfg) => { | ||||
| 	const {test: t, journeys, validate, fromId, toId} = cfg | ||||
| 
 | ||||
| 	validate(t, journeys, 'journeys', 'journeys') | ||||
|  | @ -17,6 +15,6 @@ const testJourneysStationToStation = co(function* (cfg) { | |||
| 		t.strictEqual(origin.id, fromId) | ||||
| 		t.strictEqual(dest.id, toId) | ||||
| 	} | ||||
| }) | ||||
| } | ||||
| 
 | ||||
| module.exports = testJourneysStationToStation | ||||
|  |  | |||
|  | @ -1,8 +1,6 @@ | |||
| 'use strict' | ||||
| 
 | ||||
| const co = require('./co') | ||||
| 
 | ||||
| const testJourneysWithDetour = co(function* (cfg) { | ||||
| const testJourneysWithDetour = async (cfg) => { | ||||
| 	const {test: t, journeys, validate, detourIds} = cfg | ||||
| 
 | ||||
| 	// We assume that going from A to B via C *without* detour is currently
 | ||||
|  | @ -17,6 +15,6 @@ const testJourneysWithDetour = co(function* (cfg) { | |||
| 		)) | ||||
| 	}) | ||||
| 	t.ok(leg, detourIds.join('/') + ' is not being passed') | ||||
| }) | ||||
| } | ||||
| 
 | ||||
| module.exports = testJourneysWithDetour | ||||
|  |  | |||
|  | @ -2,10 +2,9 @@ | |||
| 
 | ||||
| const isRoughlyEqual = require('is-roughly-equal') | ||||
| 
 | ||||
| const co = require('./co') | ||||
| const {hour} = require('./util') | ||||
| 
 | ||||
| const testLegCycleAlternatives = co(function* (cfg) { | ||||
| const testLegCycleAlternatives = async (cfg) => { | ||||
| 	const { | ||||
| 		test: t, | ||||
| 		fetchJourneys, | ||||
|  | @ -15,7 +14,7 @@ const testLegCycleAlternatives = co(function* (cfg) { | |||
| 
 | ||||
| 	// Apparently HAFAS doesn't return the leg cycle or alternatives more
 | ||||
| 	// than ~2 hours in advance. This is why we don't pass `when` here.
 | ||||
| 	const journeys = yield fetchJourneys(fromId, toId, {results: 3}) | ||||
| 	const journeys = await fetchJourneys(fromId, toId, {results: 3}) | ||||
| 
 | ||||
| 	for (let i = 0; i < journeys.length; i++) { | ||||
| 		const journey = journeys[i] | ||||
|  | @ -42,6 +41,6 @@ const testLegCycleAlternatives = co(function* (cfg) { | |||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| }) | ||||
| } | ||||
| 
 | ||||
| module.exports = testLegCycleAlternatives | ||||
|  |  | |||
|  | @ -2,9 +2,7 @@ | |||
| 
 | ||||
| const isPlainObject = require('lodash/isPlainObject') | ||||
| 
 | ||||
| const co = require('./co') | ||||
| 
 | ||||
| const testReachableFrom = co(function* (cfg) { | ||||
| const testReachableFrom = async (cfg) => { | ||||
| 	const { | ||||
| 		test: t, | ||||
| 		reachableFrom, | ||||
|  | @ -14,7 +12,7 @@ const testReachableFrom = co(function* (cfg) { | |||
| 		validate | ||||
| 	} = cfg | ||||
| 
 | ||||
| 	const results = yield reachableFrom(address, { | ||||
| 	const results = await reachableFrom(address, { | ||||
| 		when, maxDuration | ||||
| 	}) | ||||
| 
 | ||||
|  | @ -39,6 +37,6 @@ const testReachableFrom = co(function* (cfg) { | |||
| 
 | ||||
| 	const sorted = results.sort((a, b) => a.duration - b.duration) | ||||
| 	t.deepEqual(results, sorted, 'results must be sorted by res.duration') | ||||
| }) | ||||
| } | ||||
| 
 | ||||
| module.exports = testReachableFrom | ||||
|  |  | |||
|  | @ -1,7 +1,5 @@ | |||
| 'use strict' | ||||
| 
 | ||||
| const co = require('./co') | ||||
| 
 | ||||
| const simplify = j => j.legs.map(l => { | ||||
| 	let departure = null | ||||
| 	if (l.departure) { | ||||
|  | @ -22,7 +20,7 @@ const simplify = j => j.legs.map(l => { | |||
| 	} | ||||
| }) | ||||
| 
 | ||||
| const testRefreshJourney = co(function* (cfg) { | ||||
| const testRefreshJourney = async (cfg) => { | ||||
| 	const { | ||||
| 		test: t, | ||||
| 		fetchJourneys, | ||||
|  | @ -33,7 +31,7 @@ const testRefreshJourney = co(function* (cfg) { | |||
| 		// todo: validate
 | ||||
| 	} = cfg | ||||
| 
 | ||||
| 	const [model] = yield fetchJourneys(fromId, toId, { | ||||
| 	const [model] = await fetchJourneys(fromId, toId, { | ||||
| 		results: 1, departure: when, | ||||
| 		stopovers: false | ||||
| 	}) | ||||
|  | @ -42,10 +40,10 @@ const testRefreshJourney = co(function* (cfg) { | |||
| 	t.equal(typeof model.refreshToken, 'string') | ||||
| 	t.ok(model.refreshToken) | ||||
| 
 | ||||
| 	const refreshed = yield refreshJourney(model.refreshToken, { | ||||
| 	const refreshed = await refreshJourney(model.refreshToken, { | ||||
| 		stopovers: false | ||||
| 	}) | ||||
| 	t.deepEqual(simplify(refreshed), simplify(model)) | ||||
| }) | ||||
| } | ||||
| 
 | ||||
| module.exports = testRefreshJourney | ||||
|  |  | |||
							
								
								
									
										109
									
								
								test/nahsh.js
									
										
									
									
									
								
							
							
						
						
									
										109
									
								
								test/nahsh.js
									
										
									
									
									
								
							|  | @ -5,7 +5,6 @@ const tape = require('tape') | |||
| const isRoughlyEqual = require('is-roughly-equal') | ||||
| 
 | ||||
| const {createWhen} = require('./lib/util') | ||||
| const co = require('./lib/co') | ||||
| const createClient = require('..') | ||||
| const nahshProfile = require('../p/nahsh') | ||||
| const products = require('../p/nahsh/products') | ||||
|  | @ -76,14 +75,14 @@ const ellerbekerMarkt = '9049027' | |||
| const seefischmarkt = '9049245' | ||||
| const kielRaeucherei = '9049217' | ||||
| 
 | ||||
| test('journeys – Kiel Hbf to Flensburg', co(function* (t) { | ||||
| 	const journeys = yield client.journeys(kielHbf, flensburg, { | ||||
| test('journeys – Kiel Hbf to Flensburg', async (t) => { | ||||
| 	const journeys = await client.journeys(kielHbf, flensburg, { | ||||
| 		results: 3, | ||||
| 		departure: when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToStation({ | ||||
| 	await testJourneysStationToStation({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -98,7 +97,7 @@ test('journeys – Kiel Hbf to Flensburg', co(function* (t) { | |||
| 	} | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: journeys, only one product
 | ||||
| 
 | ||||
|  | @ -114,19 +113,19 @@ test('journeys – fails with no product', (t) => { | |||
| 	t.end() | ||||
| }) | ||||
| 
 | ||||
| test('Kiel Hbf to Berliner Str. 80, Husum', co(function* (t) { | ||||
| test('Kiel Hbf to Berliner Str. 80, Husum', async (t) => { | ||||
| 	const berlinerStr = { | ||||
| 		type: 'location', | ||||
| 		address: 'Husum, Berliner Straße 80', | ||||
| 		latitude: 54.488995, | ||||
| 		longitude: 9.056263 | ||||
| 	} | ||||
| 	const journeys = yield client.journeys(kielHbf, berlinerStr, { | ||||
| 	const journeys = await client.journeys(kielHbf, berlinerStr, { | ||||
| 		results: 3, | ||||
| 		departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToAddress({ | ||||
| 	await testJourneysStationToAddress({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -134,9 +133,9 @@ test('Kiel Hbf to Berliner Str. 80, Husum', co(function* (t) { | |||
| 		to: berlinerStr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('Kiel Hbf to Holstentor', co(function* (t) { | ||||
| test('Kiel Hbf to Holstentor', async (t) => { | ||||
| 	const holstentor = { | ||||
| 		type: 'location', | ||||
| 		id: '970003118', | ||||
|  | @ -144,12 +143,12 @@ test('Kiel Hbf to Holstentor', co(function* (t) { | |||
| 		latitude: 53.866321, | ||||
| 		longitude: 10.679976 | ||||
| 	} | ||||
| 	const journeys = yield client.journeys(kielHbf, holstentor, { | ||||
| 	const journeys = await client.journeys(kielHbf, holstentor, { | ||||
| 		results: 3, | ||||
| 		departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToPoi({ | ||||
| 	await testJourneysStationToPoi({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -157,10 +156,10 @@ test('Kiel Hbf to Holstentor', co(function* (t) { | |||
| 		to: holstentor | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('Husum to Lübeck Hbf with stopover at Kiel Hbf', co(function* (t) { | ||||
| 	const journeys = yield client.journeys(husum, luebeckHbf, { | ||||
| test('Husum to Lübeck Hbf with stopover at Kiel Hbf', async (t) => { | ||||
| 	const journeys = await client.journeys(husum, luebeckHbf, { | ||||
| 		via: kielHbf, | ||||
| 		results: 1, | ||||
| 		departure: when, | ||||
|  | @ -178,10 +177,10 @@ test('Husum to Lübeck Hbf with stopover at Kiel Hbf', co(function* (t) { | |||
| 	t.ok(leg, 'Kiel Hbf is not being passed') | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('earlier/later journeys, Kiel Hbf -> Flensburg', co(function* (t) { | ||||
| 	yield testEarlierLaterJourneys({ | ||||
| test('earlier/later journeys, Kiel Hbf -> Flensburg', async (t) => { | ||||
| 	await testEarlierLaterJourneys({ | ||||
| 		test: t, | ||||
| 		fetchJourneys: client.journeys, | ||||
| 		validate, | ||||
|  | @ -191,10 +190,10 @@ test('earlier/later journeys, Kiel Hbf -> Flensburg', co(function* (t) { | |||
| 	}) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('refreshJourney', co(function* (t) { | ||||
| 	yield testRefreshJourney({ | ||||
| test('refreshJourney', async (t) => { | ||||
| 	await testRefreshJourney({ | ||||
| 		test: t, | ||||
| 		fetchJourneys: client.journeys, | ||||
| 		refreshJourney: client.refreshJourney, | ||||
|  | @ -204,42 +203,42 @@ test('refreshJourney', co(function* (t) { | |||
| 		when | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: with detour test
 | ||||
| // todo: without detour test
 | ||||
| 
 | ||||
| test('trip details', co(function* (t) { | ||||
| 	const journeys = yield client.journeys(flensburg, husum, { | ||||
| test('trip details', async (t) => { | ||||
| 	const journeys = await client.journeys(flensburg, husum, { | ||||
| 		results: 1, departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	const p = journeys[0].legs[0] | ||||
| 	t.ok(p.id, 'precondition failed') | ||||
| 	t.ok(p.line.name, 'precondition failed') | ||||
| 	const trip = yield client.trip(p.id, p.line.name, {when}) | ||||
| 	const trip = await client.trip(p.id, p.line.name, {when}) | ||||
| 
 | ||||
| 	validate(t, trip, 'journeyLeg', 'trip') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures at Kiel Räucherei', co(function* (t) { | ||||
| 	const departures = yield client.departures(kielRaeucherei, { | ||||
| test('departures at Kiel Räucherei', async (t) => { | ||||
| 	const departures = await client.departures(kielRaeucherei, { | ||||
| 		duration: 30, when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testDepartures({ | ||||
| 	await testDepartures({ | ||||
| 		test: t, | ||||
| 		departures, | ||||
| 		validate, | ||||
| 		id: kielRaeucherei | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures with station object', co(function* (t) { | ||||
| 	const deps = yield client.departures({ | ||||
| test('departures with station object', async (t) => { | ||||
| 	const deps = await client.departures({ | ||||
| 		type: 'station', | ||||
| 		id: kielHbf, | ||||
| 		name: 'Kiel Hbf', | ||||
|  | @ -252,10 +251,10 @@ test('departures with station object', co(function* (t) { | |||
| 
 | ||||
| 	validate(t, deps, 'departures', 'departures') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures at Berlin Hbf in direction of Berlin Ostbahnhof', co(function* (t) { | ||||
| 	yield testDeparturesInDirection({ | ||||
| test('departures at Berlin Hbf in direction of Berlin Ostbahnhof', async (t) => { | ||||
| 	await testDeparturesInDirection({ | ||||
| 		test: t, | ||||
| 		fetchDepartures: client.departures, | ||||
| 		fetchTrip: client.trip, | ||||
|  | @ -265,29 +264,29 @@ test('departures at Berlin Hbf in direction of Berlin Ostbahnhof', co(function* | |||
| 		validate | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('arrivals at Kiel Räucherei', co(function* (t) { | ||||
| 	const arrivals = yield client.arrivals(kielRaeucherei, { | ||||
| test('arrivals at Kiel Räucherei', async (t) => { | ||||
| 	const arrivals = await client.arrivals(kielRaeucherei, { | ||||
| 		duration: 30, when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testArrivals({ | ||||
| 	await testArrivals({ | ||||
| 		test: t, | ||||
| 		arrivals, | ||||
| 		validate, | ||||
| 		id: kielRaeucherei | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('nearby Kiel Hbf', co(function* (t) { | ||||
| test('nearby Kiel Hbf', async (t) => { | ||||
| 	const kielHbfPosition = { | ||||
| 		type: 'location', | ||||
| 		latitude: 54.314982, | ||||
| 		longitude: 10.131976 | ||||
| 	} | ||||
| 	const nearby = yield client.nearby(kielHbfPosition, { | ||||
| 	const nearby = await client.nearby(kielHbfPosition, { | ||||
| 		results: 2, distance: 400 | ||||
| 	}) | ||||
| 
 | ||||
|  | @ -302,11 +301,11 @@ test('nearby Kiel Hbf', co(function* (t) { | |||
| 	t.ok(nearby[0].distance <= 100) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('locations named "Kiel Rathaus"', co(function* (t) { | ||||
| test('locations named "Kiel Rathaus"', async (t) => { | ||||
| 	const kielRathaus = '9049200' | ||||
| 	const locations = yield client.locations('Kiel Rathaus', { | ||||
| 	const locations = await client.locations('Kiel Rathaus', { | ||||
| 		results: 15 | ||||
| 	}) | ||||
| 
 | ||||
|  | @ -318,19 +317,19 @@ test('locations named "Kiel Rathaus"', co(function* (t) { | |||
| 	t.ok(locations.some(l => l.station && l.station.id === kielRathaus || l.id === kielRathaus)) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('station', co(function* (t) { | ||||
| 	const s = yield client.station(kielHbf) | ||||
| test('station', async (t) => { | ||||
| 	const s = await client.station(kielHbf) | ||||
| 
 | ||||
| 	validate(t, s, ['stop', 'station'], 'station') | ||||
| 	t.equal(s.id, kielHbf) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('radar', co(function* (t) { | ||||
| 	const vehicles = yield client.radar({ | ||||
| test('radar', async (t) => { | ||||
| 	const vehicles = await client.radar({ | ||||
| 		north: 54.4, | ||||
| 		west: 10.0, | ||||
| 		south: 54.2, | ||||
|  | @ -354,9 +353,9 @@ test('radar', co(function* (t) { | |||
| 	validate(t, vehicles, 'movements', 'vehicles') | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('reachableFrom', co(function* (t) { | ||||
| test('reachableFrom', async (t) => { | ||||
| 	const berlinerStr = { | ||||
| 		type: 'location', | ||||
| 		address: 'Husum, Berliner Straße 80', | ||||
|  | @ -364,7 +363,7 @@ test('reachableFrom', co(function* (t) { | |||
| 		longitude: 9.056263 | ||||
| 	} | ||||
| 
 | ||||
| 	yield testReachableFrom({ | ||||
| 	await testReachableFrom({ | ||||
| 		test: t, | ||||
| 		reachableFrom: client.reachableFrom, | ||||
| 		address: berlinerStr, | ||||
|  | @ -373,4 +372,4 @@ test('reachableFrom', co(function* (t) { | |||
| 		validate | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
|  |  | |||
							
								
								
									
										101
									
								
								test/oebb.js
									
										
									
									
									
								
							
							
						
						
									
										101
									
								
								test/oebb.js
									
										
									
									
									
								
							|  | @ -6,7 +6,6 @@ const isRoughlyEqual = require('is-roughly-equal') | |||
| const validateLine = require('validate-fptf/line') | ||||
| 
 | ||||
| const {createWhen} = require('./lib/util') | ||||
| const co = require('./lib/co') | ||||
| const createClient = require('..') | ||||
| const oebbProfile = require('../p/oebb') | ||||
| const products = require('../p/oebb/products') | ||||
|  | @ -67,14 +66,14 @@ const wienRenngasse = '1390186' | |||
| const wienKarlsplatz = '1390461' | ||||
| const wienPilgramgasse = '1390562' | ||||
| 
 | ||||
| test.skip('journeys – Salzburg Hbf to Wien Westbahnhof', co(function* (t) { | ||||
| 	const journeys = yield client.journeys(salzburgHbf, wienFickeystr, { | ||||
| test.skip('journeys – Salzburg Hbf to Wien Westbahnhof', async (t) => { | ||||
| 	const journeys = await client.journeys(salzburgHbf, wienFickeystr, { | ||||
| 		results: 3, | ||||
| 		departure: when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToStation({ | ||||
| 	await testJourneysStationToStation({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -88,7 +87,7 @@ test.skip('journeys – Salzburg Hbf to Wien Westbahnhof', co(function* (t) { | |||
| 	} | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: journeys, only one product
 | ||||
| 
 | ||||
|  | @ -104,19 +103,19 @@ test('journeys – fails with no product', (t) => { | |||
| 	t.end() | ||||
| }) | ||||
| 
 | ||||
| test('Salzburg Hbf to 1220 Wien, Wagramer Straße 5', co(function* (t) { | ||||
| test('Salzburg Hbf to 1220 Wien, Wagramer Straße 5', async (t) => { | ||||
| 	const wagramerStr = { | ||||
| 		type: 'location', | ||||
|     	address: '1220 Wien, Wagramer Straße 5', | ||||
|     	latitude: 48.236216, | ||||
|     	longitude: 16.425863 | ||||
| 	} | ||||
| 	const journeys = yield client.journeys(salzburgHbf, wagramerStr, { | ||||
| 	const journeys = await client.journeys(salzburgHbf, wagramerStr, { | ||||
| 		results: 3, | ||||
| 		departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToAddress({ | ||||
| 	await testJourneysStationToAddress({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -124,9 +123,9 @@ test('Salzburg Hbf to 1220 Wien, Wagramer Straße 5', co(function* (t) { | |||
| 		to: wagramerStr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('Salzburg Hbf to Albertina', co(function* (t) { | ||||
| test('Salzburg Hbf to Albertina', async (t) => { | ||||
| 	const albertina = { | ||||
| 		type: 'location', | ||||
|     	id: '975900003', | ||||
|  | @ -134,11 +133,11 @@ test('Salzburg Hbf to Albertina', co(function* (t) { | |||
|     	latitude: 48.204699, | ||||
|     	longitude: 16.368404 | ||||
| 	} | ||||
| 	const journeys = yield client.journeys(salzburgHbf, albertina, { | ||||
| 	const journeys = await client.journeys(salzburgHbf, albertina, { | ||||
| 		results: 3, departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToPoi({ | ||||
| 	await testJourneysStationToPoi({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -146,32 +145,32 @@ test('Salzburg Hbf to Albertina', co(function* (t) { | |||
| 		to: albertina | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('journeys: via works – with detour', co(function* (t) { | ||||
| test('journeys: via works – with detour', async (t) => { | ||||
| 	// Going from Stephansplatz to Schottenring via Donauinsel without detour
 | ||||
| 	// is currently impossible. We check if the routing engine computes a detour.
 | ||||
| 	const stephansplatz = '1390167' | ||||
| 	const schottenring = '1390163' | ||||
| 	const donauinsel = '1392277' | ||||
| 	const donauinselPassed = '922001' | ||||
| 	const journeys = yield client.journeys(stephansplatz, schottenring, { | ||||
| 	const journeys = await client.journeys(stephansplatz, schottenring, { | ||||
| 		via: donauinsel, | ||||
| 		results: 1, | ||||
| 		departure: when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysWithDetour({ | ||||
| 	await testJourneysWithDetour({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
| 		detourIds: [donauinsel, donauinselPassed] | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('journeys: via works – without detour', co(function* (t) { | ||||
| test('journeys: via works – without detour', async (t) => { | ||||
| 	// When going from Karlsplatz to Praterstern via Museumsquartier, there is
 | ||||
| 	// *no need* to change trains / no need for a "detour".
 | ||||
| 	const karlsplatz = '1390461' | ||||
|  | @ -179,7 +178,7 @@ test('journeys: via works – without detour', co(function* (t) { | |||
| 	const museumsquartier = '1390171' | ||||
| 	const museumsquartierPassed = '901014' | ||||
| 
 | ||||
| 	const journeys = yield client.journeys(karlsplatz, praterstern, { | ||||
| 	const journeys = await client.journeys(karlsplatz, praterstern, { | ||||
| 		via: museumsquartier, | ||||
| 		results: 1, | ||||
| 		departure: when, | ||||
|  | @ -204,10 +203,10 @@ test('journeys: via works – without detour', co(function* (t) { | |||
| 	t.ok(l2, 'Museumsquartier is not being passed') | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('earlier/later journeys, Salzburg Hbf -> Wien Westbahnhof', co(function* (t) { | ||||
| 	yield testEarlierLaterJourneys({ | ||||
| test('earlier/later journeys, Salzburg Hbf -> Wien Westbahnhof', async (t) => { | ||||
| 	await testEarlierLaterJourneys({ | ||||
| 		test: t, | ||||
| 		fetchJourneys: client.journeys, | ||||
| 		validate, | ||||
|  | @ -217,10 +216,10 @@ test('earlier/later journeys, Salzburg Hbf -> Wien Westbahnhof', co(function* (t | |||
| 	}) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('refreshJourney', co(function* (t) { | ||||
| 	yield testRefreshJourney({ | ||||
| test('refreshJourney', async (t) => { | ||||
| 	await testRefreshJourney({ | ||||
| 		test: t, | ||||
| 		fetchJourneys: client.journeys, | ||||
| 		refreshJourney: client.refreshJourney, | ||||
|  | @ -230,23 +229,23 @@ test('refreshJourney', co(function* (t) { | |||
| 		when | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('trip details', co(function* (t) { | ||||
| 	const journeys = yield client.journeys(wienWestbahnhof, muenchenHbf, { | ||||
| test('trip details', async (t) => { | ||||
| 	const journeys = await client.journeys(wienWestbahnhof, muenchenHbf, { | ||||
| 		results: 1, departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	const p = journeys[0].legs[0] | ||||
| 	t.ok(p.id, 'precondition failed') | ||||
| 	t.ok(p.line.name, 'precondition failed') | ||||
| 	const trip = yield client.trip(p.id, p.line.name, {when}) | ||||
| 	const trip = await client.trip(p.id, p.line.name, {when}) | ||||
| 
 | ||||
| 	validate(t, trip, 'journeyLeg', 'trip') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures at Wien Leibenfrostgasse', co(function* (t) { | ||||
| test('departures at Wien Leibenfrostgasse', async (t) => { | ||||
| 	const wienLeibenfrostgasse = '1390469' | ||||
| 	const ids = [ | ||||
| 		wienLeibenfrostgasse, // station
 | ||||
|  | @ -254,7 +253,7 @@ test('departures at Wien Leibenfrostgasse', co(function* (t) { | |||
| 		'904030' // stop "Wien Leibenfrostgasse (Ziegelofengasse)"
 | ||||
| 	] | ||||
| 
 | ||||
| 	const deps = yield client.departures(wienLeibenfrostgasse, { | ||||
| 	const deps = await client.departures(wienLeibenfrostgasse, { | ||||
| 		duration: 15, when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
|  | @ -270,10 +269,10 @@ test('departures at Wien Leibenfrostgasse', co(function* (t) { | |||
| 	} | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures with station object', co(function* (t) { | ||||
| 	const deps = yield client.departures({ | ||||
| test('departures with station object', async (t) => { | ||||
| 	const deps = await client.departures({ | ||||
| 		type: 'station', | ||||
| 		id: salzburgHbf, | ||||
| 		name: 'Salzburg Hbf', | ||||
|  | @ -286,10 +285,10 @@ test('departures with station object', co(function* (t) { | |||
| 
 | ||||
| 	validate(t, deps, 'departures', 'departures') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures at Karlsplatz in direction of Pilgramgasse', co(function* (t) { | ||||
| 	yield testDeparturesInDirection({ | ||||
| test('departures at Karlsplatz in direction of Pilgramgasse', async (t) => { | ||||
| 	await testDeparturesInDirection({ | ||||
| 		test: t, | ||||
| 		fetchDepartures: client.departures, | ||||
| 		fetchTrip: client.trip, | ||||
|  | @ -299,12 +298,12 @@ test('departures at Karlsplatz in direction of Pilgramgasse', co(function* (t) { | |||
| 		validate | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: arrivals
 | ||||
| 
 | ||||
| test('nearby Salzburg Hbf', co(function* (t) { | ||||
| 	const nearby = yield client.nearby({ | ||||
| test('nearby Salzburg Hbf', async (t) => { | ||||
| 	const nearby = await client.nearby({ | ||||
| 		type: 'location', | ||||
| 		longitude: 13.045604, | ||||
| 		latitude: 47.812851 | ||||
|  | @ -324,10 +323,10 @@ test('nearby Salzburg Hbf', co(function* (t) { | |||
| 	t.ok(s.distance <= 100) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('locations named Salzburg', co(function* (t) { | ||||
| 	const locations = yield client.locations('Salzburg', { | ||||
| test('locations named Salzburg', async (t) => { | ||||
| 	const locations = await client.locations('Salzburg', { | ||||
| 		results: 20 | ||||
| 	}) | ||||
| 
 | ||||
|  | @ -341,10 +340,10 @@ test('locations named Salzburg', co(function* (t) { | |||
| 	})) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('station', co(function* (t) { | ||||
| 	const loc = yield client.station(wienRenngasse) | ||||
| test('station', async (t) => { | ||||
| 	const loc = await client.station(wienRenngasse) | ||||
| 
 | ||||
| 	// todo: find a way to always get products from the API
 | ||||
| 	// todo: cfg.stationProductsOptional option
 | ||||
|  | @ -365,10 +364,10 @@ test('station', co(function* (t) { | |||
| 	t.equal(loc.id, wienRenngasse) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('radar Salzburg', co(function* (t) { | ||||
| 	let vehicles = yield client.radar({ | ||||
| test('radar Salzburg', async (t) => { | ||||
| 	let vehicles = await client.radar({ | ||||
| 		north: 47.827203, | ||||
| 		west: 13.001261, | ||||
| 		south: 47.773278, | ||||
|  | @ -394,4 +393,4 @@ test('radar Salzburg', co(function* (t) { | |||
| 	validate(t, vehicles, 'movements', 'vehicles') | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
|  |  | |||
|  | @ -5,7 +5,6 @@ const tape = require('tape') | |||
| const isRoughlyEqual = require('is-roughly-equal') | ||||
| 
 | ||||
| const { createWhen } = require('./lib/util') | ||||
| const co = require('./lib/co') | ||||
| const createClient = require('..') | ||||
| const saarfahrplanProfile = require('../p/saarfahrplan') | ||||
| const products = require('../p/saarfahrplan/products') | ||||
|  | @ -84,13 +83,13 @@ test('journeys – fails with no product', (t) => { | |||
| 	t.end() | ||||
| }) | ||||
| 
 | ||||
| test('Saarbrücken Hbf to Neunkirchen, Thomas-Mann-Straße 1', co(function * (t) { | ||||
| 	const journeys = yield client.journeys(saarbrueckenHbf, thomasMannStr, { | ||||
| test('Saarbrücken Hbf to Neunkirchen, Thomas-Mann-Straße 1', async (t) => { | ||||
| 	const journeys = await client.journeys(saarbrueckenHbf, thomasMannStr, { | ||||
| 		results: 3, | ||||
| 		departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToAddress({ | ||||
| 	await testJourneysStationToAddress({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -98,9 +97,9 @@ test('Saarbrücken Hbf to Neunkirchen, Thomas-Mann-Straße 1', co(function * (t) | |||
| 		to: thomasMannStr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('Saarbrücken Hbf to Schlossberghöhlen', co(function * (t) { | ||||
| test('Saarbrücken Hbf to Schlossberghöhlen', async (t) => { | ||||
| 	const schlossberghoehlen = { | ||||
| 		type: 'location', | ||||
| 		latitude: 49.32071, | ||||
|  | @ -108,11 +107,11 @@ test('Saarbrücken Hbf to Schlossberghöhlen', co(function * (t) { | |||
| 		name: 'Homburg, Schlossberghöhlen', | ||||
| 		id: '9000185' | ||||
| 	} | ||||
| 	const journeys = yield client.journeys(saarbrueckenHbf, schlossberghoehlen, { | ||||
| 	const journeys = await client.journeys(saarbrueckenHbf, schlossberghoehlen, { | ||||
| 		results: 3, departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToPoi({ | ||||
| 	await testJourneysStationToPoi({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -120,32 +119,32 @@ test('Saarbrücken Hbf to Schlossberghöhlen', co(function * (t) { | |||
| 		to: schlossberghoehlen | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test.skip('journeys: via works – with detour', co(function* (t) { | ||||
| test.skip('journeys: via works – with detour', async (t) => { | ||||
| 	// Going from Stephansplatz to Schottenring via Donauinsel without detour
 | ||||
| 	// is currently impossible. We check if the routing engine computes a detour.
 | ||||
| 	const stephansplatz = '1390167' | ||||
| 	const schottenring = '1390163' | ||||
| 	const donauinsel = '1392277' | ||||
| 	const donauinselPassed = '922001' | ||||
| 	const journeys = yield client.journeys(stephansplatz, schottenring, { | ||||
| 	const journeys = await client.journeys(stephansplatz, schottenring, { | ||||
| 		via: donauinsel, | ||||
| 		results: 1, | ||||
| 		departure: when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysWithDetour({ | ||||
| 	await testJourneysWithDetour({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
| 		detourIds: [donauinsel, donauinselPassed] | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test.skip('journeys: via works – without detour', co(function* (t) { | ||||
| test.skip('journeys: via works – without detour', async (t) => { | ||||
| 	// When going from Karlsplatz to Praterstern via Museumsquartier, there is
 | ||||
| 	// *no need* to change trains / no need for a "detour".
 | ||||
| 	const karlsplatz = '1390461' | ||||
|  | @ -153,7 +152,7 @@ test.skip('journeys: via works – without detour', co(function* (t) { | |||
| 	const museumsquartier = '1390171' | ||||
| 	const museumsquartierPassed = '901014' | ||||
| 
 | ||||
| 	const journeys = yield client.journeys(karlsplatz, praterstern, { | ||||
| 	const journeys = await client.journeys(karlsplatz, praterstern, { | ||||
| 		via: museumsquartier, | ||||
| 		results: 1, | ||||
| 		departure: when, | ||||
|  | @ -178,10 +177,10 @@ test.skip('journeys: via works – without detour', co(function* (t) { | |||
| 	t.ok(l2, 'Museumsquartier is not being passed') | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('earlier/later journeys, Saarbrücken Hbf -> Saarlouis Hbf', co(function * (t) { | ||||
| 	yield testEarlierLaterJourneys({ | ||||
| test('earlier/later journeys, Saarbrücken Hbf -> Saarlouis Hbf', async (t) => { | ||||
| 	await testEarlierLaterJourneys({ | ||||
| 		test: t, | ||||
| 		fetchJourneys: client.journeys, | ||||
| 		validate, | ||||
|  | @ -191,24 +190,24 @@ test('earlier/later journeys, Saarbrücken Hbf -> Saarlouis Hbf', co(function * | |||
| 	}) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('trip details', co(function * (t) { | ||||
| 	const journeys = yield client.journeys(saarlouisHbf, metzVille, { | ||||
| test('trip details', async (t) => { | ||||
| 	const journeys = await client.journeys(saarlouisHbf, metzVille, { | ||||
| 		results: 1, departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	const p = journeys[0].legs[0] | ||||
| 	t.ok(p.id, 'precondition failed') | ||||
| 	t.ok(p.line.name, 'precondition failed') | ||||
| 	const trip = yield client.trip(p.id, p.line.name, { when }) | ||||
| 	const trip = await client.trip(p.id, p.line.name, { when }) | ||||
| 
 | ||||
| 	validate(t, trip, 'journeyLeg', 'trip') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures', co(function* (t) { | ||||
| 	const departures = yield client.departures(saarbrueckenUhlandstr, { | ||||
| test('departures', async (t) => { | ||||
| 	const departures = await client.departures(saarbrueckenUhlandstr, { | ||||
| 		duration: 5, when | ||||
| 	}) | ||||
| 
 | ||||
|  | @ -228,10 +227,10 @@ test('departures', co(function* (t) { | |||
| 	// todo: move into deps validator
 | ||||
| 	t.deepEqual(departures, departures.sort((a, b) => t.when > b.when)) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures with stop object', co(function* (t) { | ||||
| 	const deps = yield client.departures({ | ||||
| test('departures with stop object', async (t) => { | ||||
| 	const deps = await client.departures({ | ||||
| 		type: 'stop', | ||||
| 		id: '8000323', | ||||
| 		name: 'Saarbrücken Hbf', | ||||
|  | @ -244,11 +243,11 @@ test('departures with stop object', co(function* (t) { | |||
| 
 | ||||
| 	validate(t, deps, 'departures', 'departures') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures at Karlsplatz in direction of Pilgramgasse', co(function* (t) { | ||||
| test('departures at Karlsplatz in direction of Pilgramgasse', async (t) => { | ||||
| 	const saarbrueckenLandwehrplatz = '10606' | ||||
| 	yield testDeparturesInDirection({ | ||||
| 	await testDeparturesInDirection({ | ||||
| 		test: t, | ||||
| 		fetchDepartures: client.departures, | ||||
| 		fetchTrip: client.trip, | ||||
|  | @ -258,12 +257,12 @@ test('departures at Karlsplatz in direction of Pilgramgasse', co(function* (t) { | |||
| 		validate | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: arrivals
 | ||||
| 
 | ||||
| test('nearby Saarbrücken Hbf', co(function * (t) { | ||||
| 	const nearby = yield client.nearby({ | ||||
| test('nearby Saarbrücken Hbf', async (t) => { | ||||
| 	const nearby = await client.nearby({ | ||||
| 		type: 'location', | ||||
| 		latitude: 49.241066, | ||||
| 		longitude: 6.991019 | ||||
|  | @ -283,10 +282,10 @@ test('nearby Saarbrücken Hbf', co(function * (t) { | |||
| 	t.ok(s.distance <= 100) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('locations named Saarbrücken', co(function * (t) { | ||||
| 	const locations = yield client.locations('Saarbrücken', { | ||||
| test('locations named Saarbrücken', async (t) => { | ||||
| 	const locations = await client.locations('Saarbrücken', { | ||||
| 		results: 20 | ||||
| 	}) | ||||
| 
 | ||||
|  | @ -300,19 +299,19 @@ test('locations named Saarbrücken', co(function * (t) { | |||
| 	})) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('station', co(function* (t) { | ||||
| 	const s = yield client.station(saarbrueckenUhlandstr) | ||||
| test('station', async (t) => { | ||||
| 	const s = await client.station(saarbrueckenUhlandstr) | ||||
| 
 | ||||
| 	validate(t, s, ['stop', 'station'], 'station') | ||||
| 	t.equal(s.id, saarbrueckenUhlandstr) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('radar', co(function* (t) { | ||||
| 	const vehicles = yield client.radar({ | ||||
| test('radar', async (t) => { | ||||
| 	const vehicles = await client.radar({ | ||||
| 		north: 49.27, | ||||
| 		west: 6.97, | ||||
| 		south: 49.22, | ||||
|  | @ -323,4 +322,4 @@ test('radar', co(function* (t) { | |||
| 
 | ||||
| 	validate(t, vehicles, 'movements', 'vehicles') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
|  |  | |||
|  | @ -5,7 +5,6 @@ const tapePromise = require('tape-promise').default | |||
| const tape = require('tape') | ||||
| 
 | ||||
| const {createWhen} = require('./lib/util') | ||||
| const co = require('./lib/co') | ||||
| const createClient = require('..') | ||||
| const sMunichProfile = require('../p/sbahn-muenchen') | ||||
| const products = require('../p/sbahn-muenchen/products') | ||||
|  | @ -63,14 +62,14 @@ const poetschnerstr = { | |||
| 	longitude: 11.531695 | ||||
| } | ||||
| 
 | ||||
| test('journeys – Mittersendling to Karl-Theodor-Straße', co(function* (t) { | ||||
| 	const journeys = yield client.journeys(mittersendling, karlTheodorStr, { | ||||
| test('journeys – Mittersendling to Karl-Theodor-Straße', async (t) => { | ||||
| 	const journeys = await client.journeys(mittersendling, karlTheodorStr, { | ||||
| 		results: 3, | ||||
| 		departure: when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToStation({ | ||||
| 	await testJourneysStationToStation({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -78,7 +77,7 @@ test('journeys – Mittersendling to Karl-Theodor-Straße', co(function* (t) { | |||
| 		toId: karlTheodorStr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: journeys, only one product
 | ||||
| 
 | ||||
|  | @ -94,13 +93,13 @@ test('journeys – fails with no product', (t) => { | |||
| 	t.end() | ||||
| }) | ||||
| 
 | ||||
| test('Karl-Theodor-Straße to Pötschnerstraße 3, Neuhausen', co(function*(t) { | ||||
| 	const journeys = yield client.journeys(karlTheodorStr, poetschnerstr, { | ||||
| test('Karl-Theodor-Straße to Pötschnerstraße 3, Neuhausen', async (t) => { | ||||
| 	const journeys = await client.journeys(karlTheodorStr, poetschnerstr, { | ||||
| 		results: 3, | ||||
| 		departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToAddress({ | ||||
| 	await testJourneysStationToAddress({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -108,9 +107,9 @@ test('Karl-Theodor-Straße to Pötschnerstraße 3, Neuhausen', co(function*(t) { | |||
| 		to: poetschnerstr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('Karl-Theodor-Straße to Hofbräuhaus', co(function*(t) { | ||||
| test('Karl-Theodor-Straße to Hofbräuhaus', async (t) => { | ||||
| 	const hofbraeuhaus = { | ||||
| 		type: 'location', | ||||
| 		id: '970006201', | ||||
|  | @ -118,12 +117,12 @@ test('Karl-Theodor-Straße to Hofbräuhaus', co(function*(t) { | |||
| 		latitude: 48.137739, | ||||
| 		longitude: 11.579823 | ||||
| 	} | ||||
| 	const journeys = yield client.journeys(karlTheodorStr, hofbraeuhaus, { | ||||
| 	const journeys = await client.journeys(karlTheodorStr, hofbraeuhaus, { | ||||
| 		results: 3, | ||||
| 		departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToPoi({ | ||||
| 	await testJourneysStationToPoi({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -131,13 +130,13 @@ test('Karl-Theodor-Straße to Hofbräuhaus', co(function*(t) { | |||
| 		to: hofbraeuhaus | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: via works – with detour
 | ||||
| // todo: without detour
 | ||||
| 
 | ||||
| test('earlier/later journeys', co(function* (t) { | ||||
| 	yield testEarlierLaterJourneys({ | ||||
| test('earlier/later journeys', async (t) => { | ||||
| 	await testEarlierLaterJourneys({ | ||||
| 		test: t, | ||||
| 		fetchJourneys: client.journeys, | ||||
| 		validate, | ||||
|  | @ -147,10 +146,10 @@ test('earlier/later journeys', co(function* (t) { | |||
| 	}) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('refreshJourney', co(function* (t) { | ||||
| 	yield testRefreshJourney({ | ||||
| test('refreshJourney', async (t) => { | ||||
| 	await testRefreshJourney({ | ||||
| 		test: t, | ||||
| 		fetchJourneys: client.journeys, | ||||
| 		refreshJourney: client.refreshJourney, | ||||
|  | @ -160,39 +159,39 @@ test('refreshJourney', co(function* (t) { | |||
| 		when | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('trip details', co(function* (t) { | ||||
| 	const journeys = yield client.journeys(mittersendling, karlTheodorStr, { | ||||
| test('trip details', async (t) => { | ||||
| 	const journeys = await client.journeys(mittersendling, karlTheodorStr, { | ||||
| 		results: 1, departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	const p = journeys[0].legs.find(leg => leg.line) | ||||
| 	t.ok(p.id, 'precondition failed') | ||||
| 	t.ok(p.line.name, 'precondition failed') | ||||
| 	const trip = yield client.trip(p.id, p.line.name, {when}) | ||||
| 	const trip = await client.trip(p.id, p.line.name, {when}) | ||||
| 
 | ||||
| 	validate(t, trip, 'journeyLeg', 'trip') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures at Karl-Theodor-Straße', co(function*(t) { | ||||
| 	const departures = yield client.departures(karlTheodorStr, { | ||||
| test('departures at Karl-Theodor-Straße', async (t) => { | ||||
| 	const departures = await client.departures(karlTheodorStr, { | ||||
| 		duration: 10, when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testDepartures({ | ||||
| 	await testDepartures({ | ||||
| 		test: t, | ||||
| 		departures, | ||||
| 		validate, | ||||
| 		id: karlTheodorStr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures with station object', co(function* (t) { | ||||
| 	const deps = yield client.departures({ | ||||
| test('departures with station object', async (t) => { | ||||
| 	const deps = await client.departures({ | ||||
| 		type: 'station', | ||||
| 		id: mittersendling, | ||||
| 		name: 'Mittersendling', | ||||
|  | @ -205,28 +204,28 @@ test('departures with station object', co(function* (t) { | |||
| 
 | ||||
| 	validate(t, deps, 'departures', 'departures') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('arrivals at Karl-Theodor-Straße', co(function*(t) { | ||||
| 	const arrivals = yield client.arrivals(karlTheodorStr, { | ||||
| test('arrivals at Karl-Theodor-Straße', async (t) => { | ||||
| 	const arrivals = await client.arrivals(karlTheodorStr, { | ||||
| 		duration: 10, when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testArrivals({ | ||||
| 	await testArrivals({ | ||||
| 		test: t, | ||||
| 		arrivals, | ||||
| 		validate, | ||||
| 		id: karlTheodorStr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: nearby
 | ||||
| 
 | ||||
| test('locations named "Nationaltheater"', co(function*(t) { | ||||
| test('locations named "Nationaltheater"', async (t) => { | ||||
| 	const nationaltheater = '624639' | ||||
| 	const locations = yield client.locations('Nationaltheater', { | ||||
| 	const locations = await client.locations('Nationaltheater', { | ||||
| 		results: 10 | ||||
| 	}) | ||||
| 
 | ||||
|  | @ -240,19 +239,19 @@ test('locations named "Nationaltheater"', co(function*(t) { | |||
| 	})) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('station Karl-Theodor-Straße', co(function* (t) { | ||||
| 	const s = yield client.station(karlTheodorStr) | ||||
| test('station Karl-Theodor-Straße', async (t) => { | ||||
| 	const s = await client.station(karlTheodorStr) | ||||
| 
 | ||||
| 	validate(t, s, ['stop', 'station'], 'station') | ||||
| 	t.equal(s.id, karlTheodorStr) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('radar', co(function* (t) { | ||||
| 	const vehicles = yield client.radar({ | ||||
| test('radar', async (t) => { | ||||
| 	const vehicles = await client.radar({ | ||||
| 		north: 48.145121, | ||||
| 		west: 11.543736, | ||||
| 		south: 48.138339, | ||||
|  | @ -263,10 +262,10 @@ test('radar', co(function* (t) { | |||
| 
 | ||||
| 	validate(t, vehicles, 'movements', 'vehicles') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('reachableFrom', co(function* (t) { | ||||
| 	yield testReachableFrom({ | ||||
| test('reachableFrom', async (t) => { | ||||
| 	await testReachableFrom({ | ||||
| 		test: t, | ||||
| 		reachableFrom: client.reachableFrom, | ||||
| 		address: poetschnerstr, | ||||
|  | @ -275,4 +274,4 @@ test('reachableFrom', co(function* (t) { | |||
| 		validate | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
|  |  | |||
							
								
								
									
										129
									
								
								test/vbb.js
									
										
									
									
									
								
							
							
						
						
									
										129
									
								
								test/vbb.js
									
										
									
									
									
								
							|  | @ -3,7 +3,6 @@ | |||
| const tapePromise = require('tape-promise').default | ||||
| const tape = require('tape') | ||||
| 
 | ||||
| const co = require('./lib/co') | ||||
| const createClient = require('..') | ||||
| const vbbProfile = require('../p/vbb') | ||||
| const products = require('../p/vbb/products') | ||||
|  | @ -49,8 +48,8 @@ const westhafen = '900000001201' | |||
| const wedding = '900000009104' | ||||
| const württembergallee = '900000026153' | ||||
| 
 | ||||
| test('journeys – Spichernstr. to Bismarckstr.', co(function* (t) { | ||||
| 	const journeys = yield client.journeys({ | ||||
| test('journeys – Spichernstr. to Bismarckstr.', async (t) => { | ||||
| 	const journeys = await client.journeys({ | ||||
| 		type: 'stop', | ||||
| 		id: spichernstr, | ||||
| 		name: 'U Spichernstr.' | ||||
|  | @ -60,7 +59,7 @@ test('journeys – Spichernstr. to Bismarckstr.', co(function* (t) { | |||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToStation({ | ||||
| 	await testJourneysStationToStation({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -70,10 +69,10 @@ test('journeys – Spichernstr. to Bismarckstr.', co(function* (t) { | |||
| 	// todo: find a journey where there ticket info is always available
 | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('journeys – only subway', co(function* (t) { | ||||
| 	const journeys = yield client.journeys(spichernstr, bismarckstr, { | ||||
| test('journeys – only subway', async (t) => { | ||||
| 	const journeys = await client.journeys(spichernstr, bismarckstr, { | ||||
| 		results: 20, | ||||
| 		departure: when, | ||||
| 		products: { | ||||
|  | @ -104,7 +103,7 @@ test('journeys – only subway', co(function* (t) { | |||
| 	} | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: journeys – with arrival time
 | ||||
| 
 | ||||
|  | @ -120,8 +119,8 @@ test('journeys – fails with no product', (t) => { | |||
| 	t.end() | ||||
| }) | ||||
| 
 | ||||
| test('earlier/later journeys', co(function* (t) { | ||||
| 	yield testEarlierLaterJourneys({ | ||||
| test('earlier/later journeys', async (t) => { | ||||
| 	await testEarlierLaterJourneys({ | ||||
| 		test: t, | ||||
| 		fetchJourneys: client.journeys, | ||||
| 		validate, | ||||
|  | @ -131,10 +130,10 @@ test('earlier/later journeys', co(function* (t) { | |||
| 	}) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('refreshJourney', co(function* (t) { | ||||
| 	yield testRefreshJourney({ | ||||
| test('refreshJourney', async (t) => { | ||||
| 	await testRefreshJourney({ | ||||
| 		test: t, | ||||
| 		fetchJourneys: client.journeys, | ||||
| 		refreshJourney: client.refreshJourney, | ||||
|  | @ -144,35 +143,35 @@ test('refreshJourney', co(function* (t) { | |||
| 		when | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('trip details', co(function* (t) { | ||||
| 	const journeys = yield client.journeys(spichernstr, amrumerStr, { | ||||
| test('trip details', async (t) => { | ||||
| 	const journeys = await client.journeys(spichernstr, amrumerStr, { | ||||
| 		results: 1, departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	const p = journeys[0].legs[0] | ||||
| 	t.ok(p.id, 'precondition failed') | ||||
| 	t.ok(p.line.name, 'precondition failed') | ||||
| 	const trip = yield client.trip(p.id, p.line.name, {when}) | ||||
| 	const trip = await client.trip(p.id, p.line.name, {when}) | ||||
| 
 | ||||
| 	validate(t, trip, 'journeyLeg', 'trip') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('journeys – station to address', co(function* (t) { | ||||
| test('journeys – station to address', async (t) => { | ||||
| 	const torfstr = { | ||||
| 		type: 'location', | ||||
| 		address: '13353 Berlin-Wedding, Torfstr. 17', | ||||
| 		latitude: 52.541797, | ||||
| 		longitude: 13.350042 | ||||
| 	} | ||||
| 	const journeys = yield client.journeys(spichernstr, torfstr, { | ||||
| 	const journeys = await client.journeys(spichernstr, torfstr, { | ||||
| 		results: 3, | ||||
| 		departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToAddress({ | ||||
| 	await testJourneysStationToAddress({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -180,9 +179,9 @@ test('journeys – station to address', co(function* (t) { | |||
| 		to: torfstr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('journeys – station to POI', co(function* (t) { | ||||
| test('journeys – station to POI', async (t) => { | ||||
| 	const atze = { | ||||
| 		type: 'location', | ||||
| 		id: '900980720', | ||||
|  | @ -190,12 +189,12 @@ test('journeys – station to POI', co(function* (t) { | |||
| 		latitude: 52.543333, | ||||
| 		longitude: 13.351686 | ||||
| 	} | ||||
| 	const journeys = yield client.journeys(spichernstr, atze, { | ||||
| 	const journeys = await client.journeys(spichernstr, atze, { | ||||
| 		results: 3, | ||||
| 		departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToPoi({ | ||||
| 	await testJourneysStationToPoi({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -203,46 +202,46 @@ test('journeys – station to POI', co(function* (t) { | |||
| 		to: atze | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('journeys: via works – with detour', co(function* (t) { | ||||
| test('journeys: via works – with detour', async (t) => { | ||||
| 	// Going from Westhafen to Wedding via Württembergalle without detour
 | ||||
| 	// is currently impossible. We check if the routing engine computes a detour.
 | ||||
| 	const journeys = yield client.journeys(westhafen, wedding, { | ||||
| 	const journeys = await client.journeys(westhafen, wedding, { | ||||
| 		via: württembergallee, | ||||
| 		results: 1, | ||||
| 		departure: when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysWithDetour({ | ||||
| 	await testJourneysWithDetour({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
| 		detourIds: [württembergallee] | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: without detour test
 | ||||
| 
 | ||||
| test('departures', co(function* (t) { | ||||
| 	const departures = yield client.departures(spichernstr, { | ||||
| test('departures', async (t) => { | ||||
| 	const departures = await client.departures(spichernstr, { | ||||
| 		duration: 5, when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testDepartures({ | ||||
| 	await testDepartures({ | ||||
| 		test: t, | ||||
| 		departures, | ||||
| 		validate, | ||||
| 		id: spichernstr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures with station object', co(function* (t) { | ||||
| 	const deps = yield client.departures({ | ||||
| test('departures with station object', async (t) => { | ||||
| 	const deps = await client.departures({ | ||||
| 		type: 'station', | ||||
| 		id: spichernstr, | ||||
| 		name: 'U Spichernstr', | ||||
|  | @ -255,10 +254,10 @@ test('departures with station object', co(function* (t) { | |||
| 
 | ||||
| 	validate(t, deps, 'departures', 'departures') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures at Spichernstr. in direction of Westhafen', co(function* (t) { | ||||
| 	yield testDeparturesInDirection({ | ||||
| test('departures at Spichernstr. in direction of Westhafen', async (t) => { | ||||
| 	await testDeparturesInDirection({ | ||||
| 		test: t, | ||||
| 		fetchDepartures: client.departures, | ||||
| 		fetchTrip: client.trip, | ||||
|  | @ -268,17 +267,17 @@ test('departures at Spichernstr. in direction of Westhafen', co(function* (t) { | |||
| 		validate | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures at 7-digit station', co(function* (t) { | ||||
| test('departures at 7-digit station', async (t) => { | ||||
| 	const eisenach = '8010097' // see derhuerst/vbb-hafas#22
 | ||||
| 	yield client.departures(eisenach, {when}) | ||||
| 	await client.departures(eisenach, {when}) | ||||
| 	t.pass('did not fail') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('departures without related stations', co(function* (t) { | ||||
| 	yield testDeparturesWithoutRelatedStations({ | ||||
| test('departures without related stations', async (t) => { | ||||
| 	await testDeparturesWithoutRelatedStations({ | ||||
| 		test: t, | ||||
| 		fetchDepartures: client.departures, | ||||
| 		id: '900000024101', // Charlottenburg
 | ||||
|  | @ -287,29 +286,29 @@ test('departures without related stations', co(function* (t) { | |||
| 		linesOfRelatedStations: ['U7'] | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('arrivals', co(function* (t) { | ||||
| 	const arrivals = yield client.arrivals(spichernstr, { | ||||
| test('arrivals', async (t) => { | ||||
| 	const arrivals = await client.arrivals(spichernstr, { | ||||
| 		duration: 5, when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testArrivals({ | ||||
| 	await testArrivals({ | ||||
| 		test: t, | ||||
| 		arrivals, | ||||
| 		validate, | ||||
| 		id: spichernstr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('nearby', co(function* (t) { | ||||
| test('nearby', async (t) => { | ||||
| 	const berlinerStr = '900000044201' | ||||
| 	const landhausstr = '900000043252' | ||||
| 
 | ||||
| 	// Berliner Str./Bundesallee
 | ||||
| 	const nearby = yield client.nearby({ | ||||
| 	const nearby = await client.nearby({ | ||||
| 		type: 'location', | ||||
| 		latitude: 52.4873452, | ||||
| 		longitude: 13.3310411 | ||||
|  | @ -328,10 +327,10 @@ test('nearby', co(function* (t) { | |||
| 	t.ok(nearby[1].distance < 200) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('locations', co(function* (t) { | ||||
| 	const locations = yield client.locations('Alexanderplatz', {results: 20}) | ||||
| test('locations', async (t) => { | ||||
| 	const locations = await client.locations('Alexanderplatz', {results: 20}) | ||||
| 
 | ||||
| 	validate(t, locations, 'locations', 'locations') | ||||
| 	t.ok(locations.length <= 20) | ||||
|  | @ -341,19 +340,19 @@ test('locations', co(function* (t) { | |||
| 	t.ok(locations.find(s => !s.name && s.address)) // addresses
 | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('station', co(function* (t) { | ||||
| 	const s = yield client.station(spichernstr) | ||||
| test('station', async (t) => { | ||||
| 	const s = await client.station(spichernstr) | ||||
| 
 | ||||
| 	validate(t, s, ['stop', 'station'], 'station') | ||||
| 	t.equal(s.id, spichernstr) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('radar', co(function* (t) { | ||||
| 	const vehicles = yield client.radar({ | ||||
| test('radar', async (t) => { | ||||
| 	const vehicles = await client.radar({ | ||||
| 		north: 52.52411, | ||||
| 		west: 13.41002, | ||||
| 		south: 52.51942, | ||||
|  | @ -364,9 +363,9 @@ test('radar', co(function* (t) { | |||
| 
 | ||||
| 	validate(t, vehicles, 'movements', 'vehicles') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test('reachableFrom', co(function* (t) { | ||||
| test('reachableFrom', async (t) => { | ||||
| 	const torfstr17 = { | ||||
| 		type: 'location', | ||||
| 		address: '13353 Berlin-Wedding, Torfstr. 17', | ||||
|  | @ -374,7 +373,7 @@ test('reachableFrom', co(function* (t) { | |||
| 		longitude: 13.350042 | ||||
| 	} | ||||
| 
 | ||||
| 	yield testReachableFrom({ | ||||
| 	await testReachableFrom({ | ||||
| 		test: t, | ||||
| 		reachableFrom: client.reachableFrom, | ||||
| 		address: torfstr17, | ||||
|  | @ -383,4 +382,4 @@ test('reachableFrom', co(function* (t) { | |||
| 		validate | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
|  |  | |||
							
								
								
									
										95
									
								
								test/vbn.js
									
										
									
									
									
								
							
							
						
						
									
										95
									
								
								test/vbn.js
									
										
									
									
									
								
							|  | @ -5,7 +5,6 @@ const tape = require('tape') | |||
| const isRoughlyEqual = require('is-roughly-equal') | ||||
| 
 | ||||
| const {createWhen} = require('./lib/util') | ||||
| const co = require('./lib/co') | ||||
| const createClient = require('..') | ||||
| const vbnProfile = require('../p/vbn') | ||||
| const products = require('../p/vbn/products') | ||||
|  | @ -40,14 +39,14 @@ const client = createClient(vbnProfile, 'public-transport/hafas-client:test') | |||
| const bremenHbf = '8000050' | ||||
| const bremerhavenHbf = '8000051' | ||||
| 
 | ||||
| test.only('journeys – Bremen Hbf to Bremerhaven Hbf', co(function* (t) { | ||||
| 	const journeys = yield client.journeys(bremenHbf, bremerhavenHbf, { | ||||
| test.only('journeys – Bremen Hbf to Bremerhaven Hbf', async (t) => { | ||||
| 	const journeys = await client.journeys(bremenHbf, bremerhavenHbf, { | ||||
| 		results: 3, | ||||
| 		departure: when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToStation({ | ||||
| 	await testJourneysStationToStation({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -55,7 +54,7 @@ test.only('journeys – Bremen Hbf to Bremerhaven Hbf', co(function* (t) { | |||
| 		toId: bremerhavenHbf | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: journeys, only one product
 | ||||
| 
 | ||||
|  | @ -71,7 +70,7 @@ test.skip('journeys – fails with no product', (t) => { | |||
| 	t.end() | ||||
| }) | ||||
| 
 | ||||
| test.skip('Magdeburg Hbf to 39104 Magdeburg, Sternstr. 10', co(function*(t) { | ||||
| test.skip('Magdeburg Hbf to 39104 Magdeburg, Sternstr. 10', async (t) => { | ||||
| 	const sternStr = { | ||||
| 		type: 'location', | ||||
| 		address: 'Magdeburg - Altenstadt, Sternstraße 10', | ||||
|  | @ -79,12 +78,12 @@ test.skip('Magdeburg Hbf to 39104 Magdeburg, Sternstr. 10', co(function*(t) { | |||
| 		longitude: 11.422332 | ||||
| 	} | ||||
| 
 | ||||
| 	const journeys = yield client.journeys(bremenHbf, sternStr, { | ||||
| 	const journeys = await client.journeys(bremenHbf, sternStr, { | ||||
| 		results: 3, | ||||
| 		departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToAddress({ | ||||
| 	await testJourneysStationToAddress({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -92,9 +91,9 @@ test.skip('Magdeburg Hbf to 39104 Magdeburg, Sternstr. 10', co(function*(t) { | |||
| 		to: sternStr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test.skip('Magdeburg Hbf to Kloster Unser Lieben Frauen', co(function*(t) { | ||||
| test.skip('Magdeburg Hbf to Kloster Unser Lieben Frauen', async (t) => { | ||||
| 	const kloster = { | ||||
| 		type: 'location', | ||||
| 		id: '970012223', | ||||
|  | @ -102,12 +101,12 @@ test.skip('Magdeburg Hbf to Kloster Unser Lieben Frauen', co(function*(t) { | |||
| 		latitude: 52.127601, | ||||
| 		longitude: 11.636437 | ||||
| 	} | ||||
| 	const journeys = yield client.journeys(bremenHbf, kloster, { | ||||
| 	const journeys = await client.journeys(bremenHbf, kloster, { | ||||
| 		results: 3, | ||||
| 		departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysStationToPoi({ | ||||
| 	await testJourneysStationToPoi({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
|  | @ -115,32 +114,32 @@ test.skip('Magdeburg Hbf to Kloster Unser Lieben Frauen', co(function*(t) { | |||
| 		to: kloster | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test.skip('journeys: via works – with detour', co(function* (t) { | ||||
| test.skip('journeys: via works – with detour', async (t) => { | ||||
| 	// Going from Magdeburg, Hasselbachplatz (Sternstr.) (Tram/Bus) to Stendal
 | ||||
| 	// via Dessau without detour is currently impossible. We check if the routing
 | ||||
| 	// engine computes a detour.
 | ||||
| 	const journeys = yield client.journeys(hasselbachplatzSternstrasse, stendal, { | ||||
| 	const journeys = await client.journeys(hasselbachplatzSternstrasse, stendal, { | ||||
| 		via: dessau, | ||||
| 		results: 1, | ||||
| 		departure: when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testJourneysWithDetour({ | ||||
| 	await testJourneysWithDetour({ | ||||
| 		test: t, | ||||
| 		journeys, | ||||
| 		validate, | ||||
| 		detourIds: [dessau] | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: without detour
 | ||||
| 
 | ||||
| test.skip('earlier/later journeys', co(function* (t) { | ||||
| 	yield testEarlierLaterJourneys({ | ||||
| test.skip('earlier/later journeys', async (t) => { | ||||
| 	await testEarlierLaterJourneys({ | ||||
| 		test: t, | ||||
| 		fetchJourneys: client.journeys, | ||||
| 		validate, | ||||
|  | @ -150,10 +149,10 @@ test.skip('earlier/later journeys', co(function* (t) { | |||
| 	}) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test.skip('refreshJourney', co(function* (t) { | ||||
| 	yield testRefreshJourney({ | ||||
| test.skip('refreshJourney', async (t) => { | ||||
| 	await testRefreshJourney({ | ||||
| 		test: t, | ||||
| 		fetchJourneys: client.journeys, | ||||
| 		refreshJourney: client.refreshJourney, | ||||
|  | @ -163,39 +162,39 @@ test.skip('refreshJourney', co(function* (t) { | |||
| 		when | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test.skip('trip details', co(function* (t) { | ||||
| 	const journeys = yield client.journeys(bremenHbf, bremerhavenHbf, { | ||||
| test.skip('trip details', async (t) => { | ||||
| 	const journeys = await client.journeys(bremenHbf, bremerhavenHbf, { | ||||
| 		results: 1, departure: when | ||||
| 	}) | ||||
| 
 | ||||
| 	const p = journeys[0].legs[0] | ||||
| 	t.ok(p.tripId, 'precondition failed') | ||||
| 	t.ok(p.line.name, 'precondition failed') | ||||
| 	const trip = yield client.trip(p.tripId, p.line.name, {when}) | ||||
| 	const trip = await client.trip(p.tripId, p.line.name, {when}) | ||||
| 
 | ||||
| 	validate(t, trip, 'journeyLeg', 'trip') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test.skip('departures at Magdeburg Leiterstr.', co(function*(t) { | ||||
| 	const departures = yield client.departures(leiterstr, { | ||||
| test.skip('departures at Magdeburg Leiterstr.', async (t) => { | ||||
| 	const departures = await client.departures(leiterstr, { | ||||
| 		duration: 5, when, | ||||
| 		stopovers: false | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testDepartures({ | ||||
| 	await testDepartures({ | ||||
| 		test: t, | ||||
| 		departures, | ||||
| 		validate, | ||||
| 		id: leiterstr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test.skip('departures with station object', co(function* (t) { | ||||
| 	const deps = yield client.departures({ | ||||
| test.skip('departures with station object', async (t) => { | ||||
| 	const deps = await client.departures({ | ||||
| 		type: 'station', | ||||
| 		id: bremenHbf, | ||||
| 		name: 'Magdeburg Hbf', | ||||
|  | @ -208,27 +207,27 @@ test.skip('departures with station object', co(function* (t) { | |||
| 
 | ||||
| 	validate(t, deps, 'departures', 'departures') | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test.skip('arrivals at Magdeburg Leiterstr.', co(function*(t) { | ||||
| 	const arrivals = yield client.arrivals(leiterstr, { | ||||
| test.skip('arrivals at Magdeburg Leiterstr.', async (t) => { | ||||
| 	const arrivals = await client.arrivals(leiterstr, { | ||||
| 		duration: 5, when, | ||||
| 		stopovers: true | ||||
| 	}) | ||||
| 
 | ||||
| 	yield testArrivals({ | ||||
| 	await testArrivals({ | ||||
| 		test: t, | ||||
| 		arrivals, | ||||
| 		validate, | ||||
| 		id: leiterstr | ||||
| 	}) | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| // todo: nearby
 | ||||
| 
 | ||||
| test.skip('locations named Magdeburg', co(function*(t) { | ||||
| 	const locations = yield client.locations('Magdeburg', { | ||||
| test.skip('locations named Magdeburg', async (t) => { | ||||
| 	const locations = await client.locations('Magdeburg', { | ||||
| 		results: 20 | ||||
| 	}) | ||||
| 
 | ||||
|  | @ -242,19 +241,19 @@ test.skip('locations named Magdeburg', co(function*(t) { | |||
| 	})) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test.skip('station Magdeburg-Buckau', co(function* (t) { | ||||
| 	const s = yield client.station(bremerhavenHbf) | ||||
| test.skip('station Magdeburg-Buckau', async (t) => { | ||||
| 	const s = await client.station(bremerhavenHbf) | ||||
| 
 | ||||
| 	validate(t, s, ['stop', 'station'], 'station') | ||||
| 	t.equal(s.id, bremerhavenHbf) | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
| 
 | ||||
| test.skip('radar', co(function* (t) { | ||||
| 	const vehicles = yield client.radar({ | ||||
| test.skip('radar', async (t) => { | ||||
| 	const vehicles = await client.radar({ | ||||
| 		north: 52.148364, | ||||
| 		west: 11.600826, | ||||
| 		south: 52.108486, | ||||
|  | @ -270,4 +269,4 @@ test.skip('radar', co(function* (t) { | |||
| 	validate(t, vehicles, 'movements', 'vehicles') | ||||
| 
 | ||||
| 	t.end() | ||||
| })) | ||||
| }) | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue