mirror of
				https://github.com/public-transport/db-vendo-client.git
				synced 2025-11-04 10:06:32 +02:00 
			
		
		
		
	fix ÖBB tests ✅
This commit is contained in:
		
							parent
							
								
									c6e558be21
								
							
						
					
					
						commit
						aced74078a
					
				
					 3 changed files with 58 additions and 3 deletions
				
			
		| 
						 | 
					@ -49,7 +49,7 @@
 | 
				
			||||||
		"tap-spec": "^4.1.1",
 | 
							"tap-spec": "^4.1.1",
 | 
				
			||||||
		"tape": "^4.8.0",
 | 
							"tape": "^4.8.0",
 | 
				
			||||||
		"tape-promise": "^2.0.1",
 | 
							"tape-promise": "^2.0.1",
 | 
				
			||||||
		"validate-fptf": "^1.0.2",
 | 
							"validate-fptf": "^1.2.0",
 | 
				
			||||||
		"vbb-stations-autocomplete": "^2.11.0"
 | 
							"vbb-stations-autocomplete": "^2.11.0"
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	"scripts": {
 | 
						"scripts": {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										21
									
								
								test/oebb.js
									
										
									
									
									
								
							
							
						
						
									
										21
									
								
								test/oebb.js
									
										
									
									
									
								
							| 
						 | 
					@ -6,6 +6,9 @@ const tapePromise = require('tape-promise').default
 | 
				
			||||||
const tape = require('tape')
 | 
					const tape = require('tape')
 | 
				
			||||||
const co = require('co')
 | 
					const co = require('co')
 | 
				
			||||||
const isRoughlyEqual = require('is-roughly-equal')
 | 
					const isRoughlyEqual = require('is-roughly-equal')
 | 
				
			||||||
 | 
					const validateFptf = require('validate-fptf')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const validateLineWithoutMode = require('./validate-line-without-mode')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const createClient = require('..')
 | 
					const createClient = require('..')
 | 
				
			||||||
const oebbProfile = require('../p/oebb')
 | 
					const oebbProfile = require('../p/oebb')
 | 
				
			||||||
| 
						 | 
					@ -15,7 +18,6 @@ const {
 | 
				
			||||||
	assertValidPoi,
 | 
						assertValidPoi,
 | 
				
			||||||
	assertValidAddress,
 | 
						assertValidAddress,
 | 
				
			||||||
	assertValidLocation,
 | 
						assertValidLocation,
 | 
				
			||||||
	assertValidLine,
 | 
					 | 
				
			||||||
	assertValidStopover,
 | 
						assertValidStopover,
 | 
				
			||||||
	hour, createWhen, assertValidWhen
 | 
						hour, createWhen, assertValidWhen
 | 
				
			||||||
} = require('./util.js')
 | 
					} = require('./util.js')
 | 
				
			||||||
| 
						 | 
					@ -91,6 +93,20 @@ const assertValidPrice = (t, p) => {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// todo: fix this upstream
 | 
				
			||||||
 | 
					// see https://github.com/derhuerst/hafas-client/blob/c6e558be217667f1bcdac4a605898eb75ea80374/p/oebb/products.js#L71
 | 
				
			||||||
 | 
					const assertValidLine = (t, l) => { // with optional mode
 | 
				
			||||||
 | 
						const validators = Object.assign({}, validateFptf.defaultValidators, {
 | 
				
			||||||
 | 
							line: validateLineWithoutMode
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						const recurse = validateFptf.createRecurse(validators)
 | 
				
			||||||
 | 
						try {
 | 
				
			||||||
 | 
							recurse(['line'], l, 'line')
 | 
				
			||||||
 | 
						} catch (err) {
 | 
				
			||||||
 | 
							t.ifError(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const test = tapePromise(tape)
 | 
					const test = tapePromise(tape)
 | 
				
			||||||
const client = createClient(oebbProfile)
 | 
					const client = createClient(oebbProfile)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -285,10 +301,11 @@ test('departures at Salzburg Hbf', co.wrap(function* (t) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
test('nearby Salzburg Hbf', co.wrap(function* (t) {
 | 
					test('nearby Salzburg Hbf', co.wrap(function* (t) {
 | 
				
			||||||
	const salzburgHbfPosition = {
 | 
						const salzburgHbfPosition = {
 | 
				
			||||||
 | 
							type: 'location',
 | 
				
			||||||
		longitude: 13.045604,
 | 
							longitude: 13.045604,
 | 
				
			||||||
		latitude: 47.812851
 | 
							latitude: 47.812851
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	const nearby = yield client.nearby(salzburgHbfPosition.latitude, salzburgHbfPosition.longitude, {
 | 
						const nearby = yield client.nearby(salzburgHbfPosition, {
 | 
				
			||||||
		results: 2, distance: 400
 | 
							results: 2, distance: 400
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										38
									
								
								test/validate-line-without-mode.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								test/validate-line-without-mode.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,38 @@
 | 
				
			||||||
 | 
					'use strict'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const a = require('assert')
 | 
				
			||||||
 | 
					const is = require('@sindresorhus/is')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const validateItem = require('validate-fptf/lib/item')
 | 
				
			||||||
 | 
					const validateReference = require('validate-fptf/lib/reference')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// todo: this is copied code, DRY this up!
 | 
				
			||||||
 | 
					// see https://github.com/public-transport/validate-fptf/blob/373b4847ec9668c4a9ec9b0dbd50f8a70ffbe127/line.js
 | 
				
			||||||
 | 
					const validateLineWithoutMode = (validate, line, name) => {
 | 
				
			||||||
 | 
						validateItem(line, name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						a.strictEqual(line.type, 'line', name + '.type must be `line`')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateReference(line.id, name + '.id')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						a.strictEqual(typeof line.name, 'string', name + '.name must be a string')
 | 
				
			||||||
 | 
						a.ok(line.name.length > 0, name + '.name can\'t be empty')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// skipping line validation here
 | 
				
			||||||
 | 
						// see https://github.com/derhuerst/hafas-client/issues/8#issuecomment-355839965
 | 
				
			||||||
 | 
						if (is.undefined(line.mode) || is.null(line.mode)) {
 | 
				
			||||||
 | 
							console.error(`ÖBB: Missing \`mode\` for line ${line.name} (at ${name}).`)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!is.undefined(line.subMode)) {
 | 
				
			||||||
 | 
						a.fail(name + '.subMode is reserved an should not be used for now')
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// todo: routes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!is.null(line.operator) && !is.undefined(line.operator)) {
 | 
				
			||||||
 | 
							validate(['operator'], line.operator, name + '.operator')
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module.exports = validateLineWithoutMode
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue