mirror of
				https://github.com/public-transport/db-vendo-client.git
				synced 2025-11-04 10:06:32 +02:00 
			
		
		
		
	journeys detour tests: use helper fn
This commit is contained in:
		
							parent
							
								
									5cea7e47e4
								
							
						
					
					
						commit
						2ca7e64fd5
					
				
					 5 changed files with 45 additions and 38 deletions
				
			
		
							
								
								
									
										14
									
								
								test/db.js
									
										
									
									
									
								
							
							
						
						
									
										14
									
								
								test/db.js
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -21,6 +21,7 @@ const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
 | 
			
		|||
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
 | 
			
		||||
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
 | 
			
		||||
const testDepartures = require('./lib/departures')
 | 
			
		||||
const testJourneysWithDetour = require('./lib/journeys-with-detour')
 | 
			
		||||
 | 
			
		||||
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -159,15 +160,12 @@ test('journeys: via works – with detour', co(function* (t) {
 | 
			
		|||
		passedStations: true
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	validate(t, journeys, 'journeys', 'journeys')
 | 
			
		||||
 | 
			
		||||
	const leg = journeys[0].legs.some((leg) => {
 | 
			
		||||
		return leg.passed && leg.passed.some((passed) => {
 | 
			
		||||
			return passed.station.id === württembergallee
 | 
			
		||||
		})
 | 
			
		||||
	yield testJourneysWithDetour({
 | 
			
		||||
		test: t,
 | 
			
		||||
		journeys,
 | 
			
		||||
		validate,
 | 
			
		||||
		detourIds: [württembergallee]
 | 
			
		||||
	})
 | 
			
		||||
	t.ok(leg, 'Württembergalle is not being passed')
 | 
			
		||||
 | 
			
		||||
	t.end()
 | 
			
		||||
}))
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										17
									
								
								test/insa.js
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								test/insa.js
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -16,6 +16,7 @@ const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
 | 
			
		|||
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
 | 
			
		||||
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
 | 
			
		||||
const testDepartures = require('./lib/departures')
 | 
			
		||||
const testJourneysWithDetour = require('./lib/journeys-with-detour')
 | 
			
		||||
 | 
			
		||||
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -123,18 +124,12 @@ test('journeys: via works – with detour', co(function* (t) {
 | 
			
		|||
		passedStations: true
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	validate(t, journeys, 'journeys', 'journeys')
 | 
			
		||||
 | 
			
		||||
	const leg = journeys[0].legs.some((leg) => {
 | 
			
		||||
		return leg.passed && leg.passed.some((passed) => {
 | 
			
		||||
			return (
 | 
			
		||||
				passed.station.id === '8010077' || // todo: trim IDs
 | 
			
		||||
				passed.station.id === dessau
 | 
			
		||||
			)
 | 
			
		||||
		})
 | 
			
		||||
	yield testJourneysWithDetour({
 | 
			
		||||
		test: t,
 | 
			
		||||
		journeys,
 | 
			
		||||
		validate,
 | 
			
		||||
		detourIds: ['8010077', dessau] // todo: trim IDs
 | 
			
		||||
	})
 | 
			
		||||
	t.ok(leg, 'Dessau is not being passed')
 | 
			
		||||
 | 
			
		||||
	t.end()
 | 
			
		||||
}))
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										21
									
								
								test/lib/journeys-with-detour.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								test/lib/journeys-with-detour.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,21 @@
 | 
			
		|||
'use strict'
 | 
			
		||||
 | 
			
		||||
const co = require('./co')
 | 
			
		||||
 | 
			
		||||
const testJourneysWithDetour = co(function* (cfg) {
 | 
			
		||||
	const {test: t, journeys, validate, detourIds} = cfg
 | 
			
		||||
 | 
			
		||||
	// We assume that going from A to B via C *without* detour is currently
 | 
			
		||||
	// impossible. We check if the routing engine computes a detour.
 | 
			
		||||
 | 
			
		||||
	validate(t, journeys, 'journeys', 'journeys')
 | 
			
		||||
 | 
			
		||||
	const leg = journeys[0].legs.some((leg) => {
 | 
			
		||||
		return leg.passed && leg.passed.some((passed) => {
 | 
			
		||||
			return detourIds.includes(passed.station.id)
 | 
			
		||||
		})
 | 
			
		||||
	})
 | 
			
		||||
	t.ok(leg, detourIds.join('/') + ' is not being passed')
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
module.exports = testJourneysWithDetour
 | 
			
		||||
							
								
								
									
										17
									
								
								test/oebb.js
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								test/oebb.js
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -20,6 +20,7 @@ const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
 | 
			
		|||
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
 | 
			
		||||
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
 | 
			
		||||
const testDepartures = require('./lib/departures')
 | 
			
		||||
const testJourneysWithDetour = require('./lib/journeys-with-detour')
 | 
			
		||||
 | 
			
		||||
const when = createWhen('Europe/Vienna', 'de-AT')
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -150,18 +151,12 @@ test('journeys: via works – with detour', co(function* (t) {
 | 
			
		|||
		passedStations: true
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	validate(t, journeys, 'journeys', 'journeys')
 | 
			
		||||
 | 
			
		||||
	const leg = journeys[0].legs.some((leg) => {
 | 
			
		||||
		return leg.passed && leg.passed.some((passed) => {
 | 
			
		||||
			return (
 | 
			
		||||
				passed.station.id === donauinsel ||
 | 
			
		||||
				passed.station.id === donauinselPassed
 | 
			
		||||
			)
 | 
			
		||||
		})
 | 
			
		||||
	yield testJourneysWithDetour({
 | 
			
		||||
		test: t,
 | 
			
		||||
		journeys,
 | 
			
		||||
		validate,
 | 
			
		||||
		detourIds: [donauinsel, donauinselPassed]
 | 
			
		||||
	})
 | 
			
		||||
	t.ok(leg, 'Donauinsel is not being passed')
 | 
			
		||||
 | 
			
		||||
	t.end()
 | 
			
		||||
}))
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										14
									
								
								test/vbb.js
									
										
									
									
									
								
							
							
						
						
									
										14
									
								
								test/vbb.js
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -26,6 +26,7 @@ const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
 | 
			
		|||
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
 | 
			
		||||
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
 | 
			
		||||
const testDepartures = require('./lib/departures')
 | 
			
		||||
const testJourneysWithDetour = require('./lib/journeys-with-detour')
 | 
			
		||||
 | 
			
		||||
const when = createWhen('Europe/Berlin', 'de-DE')
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -251,15 +252,12 @@ test('journeys: via works – with detour', co(function* (t) {
 | 
			
		|||
		passedStations: true
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	validate(t, journeys, 'journeys', 'journeys')
 | 
			
		||||
 | 
			
		||||
	const leg = journeys[0].legs.some((leg) => {
 | 
			
		||||
		return leg.passed && leg.passed.some((passed) => {
 | 
			
		||||
			return passed.station.id === württembergallee
 | 
			
		||||
		})
 | 
			
		||||
	yield testJourneysWithDetour({
 | 
			
		||||
		test: t,
 | 
			
		||||
		journeys,
 | 
			
		||||
		validate,
 | 
			
		||||
		detourIds: [württembergallee]
 | 
			
		||||
	})
 | 
			
		||||
	t.ok(leg, 'Württembergalle is not being passed')
 | 
			
		||||
 | 
			
		||||
	t.end()
 | 
			
		||||
}))
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue