mirror of
				https://github.com/public-transport/db-vendo-client.git
				synced 2025-10-31 16:16:32 +02:00 
			
		
		
		
	journeys from station to station test: use helper fn
This commit is contained in:
		
							parent
							
								
									279dfa4f8f
								
							
						
					
					
						commit
						63e303b6f8
					
				
					 6 changed files with 84 additions and 48 deletions
				
			
		
							
								
								
									
										17
									
								
								test/db.js
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								test/db.js
									
										
									
									
									
								
							|  | @ -15,6 +15,7 @@ const { | ||||||
| 	station: createValidateStation | 	station: createValidateStation | ||||||
| } = require('./lib/validators') | } = require('./lib/validators') | ||||||
| const createValidate = require('./lib/validate-fptf-with') | const createValidate = require('./lib/validate-fptf-with') | ||||||
|  | const testJourneysStationToStation = require('./lib/journeys-station-to-station') | ||||||
| 
 | 
 | ||||||
| const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o) | const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o) | ||||||
| 
 | 
 | ||||||
|  | @ -60,18 +61,26 @@ const client = createClient(dbProfile) | ||||||
| const berlinHbf = '8011160' | const berlinHbf = '8011160' | ||||||
| const münchenHbf = '8000261' | const münchenHbf = '8000261' | ||||||
| const jungfernheide = '8011167' | const jungfernheide = '8011167' | ||||||
|  | const blnSchwedterStr = '732652' | ||||||
| const atze = '991598902' | const atze = '991598902' | ||||||
| const westhafen = '008089116' | const westhafen = '008089116' | ||||||
| const wedding = '008089131' | const wedding = '008089131' | ||||||
| const württembergallee = '731084' | const württembergallee = '731084' | ||||||
| const regensburgHbf = '8000309' | const regensburgHbf = '8000309' | ||||||
| 
 | 
 | ||||||
| test('Berlin Jungfernheide to München Hbf', co(function* (t) { | test('journeys – Berlin Schwedter Str. to München Hbf', co(function* (t) { | ||||||
| 	const journeys = yield client.journeys(jungfernheide, münchenHbf, { | 	const journeys = yield client.journeys(blnSchwedterStr, münchenHbf, { | ||||||
| 		when, passedStations: true | 		results: 3, when, passedStations: true | ||||||
| 	}) | 	}) | ||||||
| 
 | 
 | ||||||
| 	validate(t, journeys, 'journeys', 'journeys') | 	yield testJourneysStationToStation({ | ||||||
|  | 		test: t, | ||||||
|  | 		journeys, | ||||||
|  | 		validate, | ||||||
|  | 		fromId: blnSchwedterStr, | ||||||
|  | 		toId: münchenHbf | ||||||
|  | 	}) | ||||||
|  | 	// todo: find a journey where there pricing info is always available
 | ||||||
| 	for (let journey of journeys) { | 	for (let journey of journeys) { | ||||||
| 		if (journey.price) assertValidPrice(t, journey.price) | 		if (journey.price) assertValidPrice(t, journey.price) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
							
								
								
									
										21
									
								
								test/insa.js
									
										
									
									
									
								
							
							
						
						
									
										21
									
								
								test/insa.js
									
										
									
									
									
								
							|  | @ -10,6 +10,7 @@ const createClient = require('..') | ||||||
| const insaProfile = require('../p/insa') | const insaProfile = require('../p/insa') | ||||||
| const products = require('../p/insa/products') | const products = require('../p/insa/products') | ||||||
| const createValidate = require('./lib/validate-fptf-with') | const createValidate = require('./lib/validate-fptf-with') | ||||||
|  | const testJourneysStationToStation = require('./lib/journeys-station-to-station') | ||||||
| 
 | 
 | ||||||
| const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o) | const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o) | ||||||
| 
 | 
 | ||||||
|  | @ -32,20 +33,18 @@ const hasselbachplatzSternstrasse = '000006545' | ||||||
| const stendal = '008010334' | const stendal = '008010334' | ||||||
| const dessau = '008010077' | const dessau = '008010077' | ||||||
| 
 | 
 | ||||||
| test('Magdeburg Hbf to Magdeburg-Buckau', co(function*(t) { | test('journeys – Magdeburg Hbf to Magdeburg-Buckau', co(function* (t) { | ||||||
| 	const journeys = yield client.journeys(magdeburgHbf, magdeburgBuckau, { | 	const journeys = yield client.journeys(magdeburgHbf, magdeburgBuckau, { | ||||||
| 		when, | 		results: 3, when, passedStations: true | ||||||
| 		passedStations: true |  | ||||||
| 	}) | 	}) | ||||||
| 
 | 
 | ||||||
| 	validate(t, journeys, 'journeys', 'journeys') | 	yield testJourneysStationToStation({ | ||||||
| 
 | 		test: t, | ||||||
| 	for (let j of journeys) { | 		journeys, | ||||||
| 		const firstLeg = j.legs[0] | 		validate, | ||||||
| 		const lastLeg = j.legs[j.legs.length - 1] | 		fromId: magdeburgHbf, | ||||||
| 		t.strictEqual(firstLeg.origin.id, magdeburgHbf) | 		toId: magdeburgBuckau | ||||||
| 		t.strictEqual(lastLeg.destination.id, magdeburgBuckau) | 	}) | ||||||
| 	} |  | ||||||
| 	t.end() | 	t.end() | ||||||
| })) | })) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										20
									
								
								test/lib/journeys-station-to-station.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								test/lib/journeys-station-to-station.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,20 @@ | ||||||
|  | 'use strict' | ||||||
|  | 
 | ||||||
|  | const co = require('./co') | ||||||
|  | 
 | ||||||
|  | const testJourneysStationToStation = co(function* (cfg) { | ||||||
|  | 	const {test: t, journeys, validate, fromId, toId} = cfg | ||||||
|  | 
 | ||||||
|  | 	validate(t, journeys, 'journeys', 'journeys') | ||||||
|  | 	t.strictEqual(journeys.length, 3) | ||||||
|  | 	for (let i = 0; i < journeys.length; i++) { | ||||||
|  | 		const j = journeys[i] | ||||||
|  | 
 | ||||||
|  | 		const firstLeg = j.legs[0] | ||||||
|  | 		const lastLeg = j.legs[j.legs.length - 1] | ||||||
|  | 		t.strictEqual(firstLeg.origin.id, fromId) | ||||||
|  | 		t.strictEqual(lastLeg.destination.id, toId) | ||||||
|  | 	} | ||||||
|  | }) | ||||||
|  | 
 | ||||||
|  | module.exports = testJourneysStationToStation | ||||||
|  | @ -14,6 +14,7 @@ const { | ||||||
| 	station: createValidateStation | 	station: createValidateStation | ||||||
| } = require('./lib/validators') | } = require('./lib/validators') | ||||||
| const createValidate = require('./lib/validate-fptf-with') | const createValidate = require('./lib/validate-fptf-with') | ||||||
|  | const testJourneysStationToStation = require('./lib/journeys-station-to-station') | ||||||
| 
 | 
 | ||||||
| const when = createWhen('Europe/Berlin', 'de-DE') | const when = createWhen('Europe/Berlin', 'de-DE') | ||||||
| 
 | 
 | ||||||
|  | @ -60,24 +61,25 @@ const luebeckHbf = '8000237' | ||||||
| const husum = '8000181' | const husum = '8000181' | ||||||
| const schleswig = '8005362' | const schleswig = '8005362' | ||||||
| 
 | 
 | ||||||
| test('Kiel Hbf to Flensburg', co(function* (t) { | test('journeys – Kiel Hbf to Flensburg', co(function* (t) { | ||||||
| 	const journeys = yield client.journeys(kielHbf, flensburg, { | 	const journeys = yield client.journeys(kielHbf, flensburg, { | ||||||
| 		when, passedStations: true, results: 3 | 		results: 3, when, passedStations: true | ||||||
|  | 	}) | ||||||
|  | 
 | ||||||
|  | 	yield testJourneysStationToStation({ | ||||||
|  | 		test: t, | ||||||
|  | 		journeys, | ||||||
|  | 		validate, | ||||||
|  | 		fromId: kielHbf, | ||||||
|  | 		toId: flensburg | ||||||
| 	}) | 	}) | ||||||
| 
 | 
 | ||||||
| 	validate(t, journeys, 'journeys', 'journeys') |  | ||||||
| 	t.strictEqual(journeys.length, 3) |  | ||||||
| 	for (let i = 0; i < journeys.length; i++) { | 	for (let i = 0; i < journeys.length; i++) { | ||||||
| 		const j = journeys[i] | 		const j = journeys[i] | ||||||
| 
 |  | ||||||
| 		const firstLeg = j.legs[0] |  | ||||||
| 		const lastLeg = j.legs[j.legs.length - 1] |  | ||||||
| 		t.strictEqual(firstLeg.origin.id, kielHbf) |  | ||||||
| 		t.strictEqual(lastLeg.destination.id, flensburg) |  | ||||||
| 
 |  | ||||||
| 		// todo: find a journey where there pricing info is always available
 | 		// todo: find a journey where there pricing info is always available
 | ||||||
| 		if (j.price) assertValidPrice(t, j.price) | 		if (j.price) assertValidPrice(t, j.price, `journeys[${i}].price`) | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
| 	t.end() | 	t.end() | ||||||
| })) | })) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										24
									
								
								test/oebb.js
									
										
									
									
									
								
							
							
						
						
									
										24
									
								
								test/oebb.js
									
										
									
									
									
								
							|  | @ -14,6 +14,7 @@ const { | ||||||
| 	station: createValidateStation | 	station: createValidateStation | ||||||
| } = require('./lib/validators') | } = require('./lib/validators') | ||||||
| const createValidate = require('./lib/validate-fptf-with') | const createValidate = require('./lib/validate-fptf-with') | ||||||
|  | const testJourneysStationToStation = require('./lib/journeys-station-to-station') | ||||||
| 
 | 
 | ||||||
| const when = createWhen('Europe/Vienna', 'de-AT') | const when = createWhen('Europe/Vienna', 'de-AT') | ||||||
| 
 | 
 | ||||||
|  | @ -45,20 +46,29 @@ const test = tapePromise(tape) | ||||||
| const client = createClient(oebbProfile) | const client = createClient(oebbProfile) | ||||||
| 
 | 
 | ||||||
| const salzburgHbf = '8100002' | const salzburgHbf = '8100002' | ||||||
| const wienWestbahnhof = '1291501' | const wienFickeystr = '911014' | ||||||
| const wien = '1190100' | const wien = '1190100' | ||||||
|  | const wienWestbahnhof = '1291501' | ||||||
| const klagenfurtHbf = '8100085' | const klagenfurtHbf = '8100085' | ||||||
| const muenchenHbf = '8000261' | const muenchenHbf = '8000261' | ||||||
| const wienRenngasse = '1390186' | const wienRenngasse = '1390186' | ||||||
| 
 | 
 | ||||||
| test('Salzburg Hbf to Wien Westbahnhof', co(function* (t) { | test('journeys – Salzburg Hbf to Wien Westbahnhof', co(function* (t) { | ||||||
| 	const journeys = yield client.journeys(salzburgHbf, wienWestbahnhof, { | 	const journeys = yield client.journeys(salzburgHbf, wienFickeystr, { | ||||||
| 		when, passedStations: true | 		results: 3, when, passedStations: true | ||||||
| 	}) | 	}) | ||||||
| 
 | 
 | ||||||
| 	validate(t, journeys, 'journeys', 'journeys') | 	yield testJourneysStationToStation({ | ||||||
| 	for (let journey of journeys) { | 		test: t, | ||||||
| 		if (journey.price) assertValidPrice(t, journey.price) | 		journeys, | ||||||
|  | 		validate, | ||||||
|  | 		fromId: salzburgHbf, | ||||||
|  | 		toId: wienFickeystr | ||||||
|  | 	}) | ||||||
|  | 
 | ||||||
|  | 	for (let i = 0; i < journeys.length; i++) { | ||||||
|  | 		const j = journeys[i] | ||||||
|  | 		if (j.price) assertValidPrice(t, j.price, `journeys[${i}].price`) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	t.end() | 	t.end() | ||||||
|  |  | ||||||
							
								
								
									
										26
									
								
								test/vbb.js
									
										
									
									
									
								
							
							
						
						
									
										26
									
								
								test/vbb.js
									
										
									
									
									
								
							|  | @ -20,8 +20,7 @@ const { | ||||||
| 	movement: _validateMovement | 	movement: _validateMovement | ||||||
| } = require('./lib/validators') | } = require('./lib/validators') | ||||||
| const createValidate = require('./lib/validate-fptf-with') | const createValidate = require('./lib/validate-fptf-with') | ||||||
| 
 | const testJourneysStationToStation = require('./lib/journeys-station-to-station') | ||||||
| const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o) |  | ||||||
| 
 | 
 | ||||||
| const when = createWhen('Europe/Berlin', 'de-DE') | const when = createWhen('Europe/Berlin', 'de-DE') | ||||||
| 
 | 
 | ||||||
|  | @ -106,23 +105,20 @@ const württembergallee = '900000026153' | ||||||
| const berlinerStr = '900000044201' | const berlinerStr = '900000044201' | ||||||
| const landhausstr = '900000043252' | const landhausstr = '900000043252' | ||||||
| 
 | 
 | ||||||
| test('journeys – station to station', co(function* (t) { | test('journeys – Spichernstr. to Bismarckstr.', co(function* (t) { | ||||||
| 	const journeys = yield client.journeys(spichernstr, amrumerStr, { | 	const journeys = yield client.journeys(spichernstr, bismarckstr, { | ||||||
| 		results: 3, when, passedStations: true | 		results: 3, when, passedStations: true | ||||||
| 	}) | 	}) | ||||||
| 
 | 
 | ||||||
| 	validate(t, journeys, 'journeys', 'journeys') | 	yield testJourneysStationToStation({ | ||||||
| 	t.strictEqual(journeys.length, 3) | 		test: t, | ||||||
| 	for (let i = 0; i < journeys.length; i++) { | 		journeys, | ||||||
| 		const j = journeys[i] | 		validate, | ||||||
| 
 | 		fromId: spichernstr, | ||||||
| 		const firstLeg = j.legs[0] | 		toId: bismarckstr | ||||||
| 		const lastLeg = j.legs[j.legs.length - 1] | 	}) | ||||||
| 		t.strictEqual(firstLeg.origin.id, spichernstr) |  | ||||||
| 		t.strictEqual(lastLeg.destination.id, amrumerStr) |  | ||||||
| 
 |  | ||||||
| 	// todo: find a journey where there ticket info is always available
 | 	// todo: find a journey where there ticket info is always available
 | ||||||
| 	} | 
 | ||||||
| 	t.end() | 	t.end() | ||||||
| })) | })) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue