mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
make tests more reliable 💚
This commit is contained in:
parent
f6a7be0652
commit
1eeb0d7bd7
7 changed files with 46 additions and 34 deletions
26
test/cmta.js
26
test/cmta.js
|
@ -9,7 +9,6 @@ const co = require('./lib/co')
|
||||||
const createClient = require('..')
|
const createClient = require('..')
|
||||||
const cmtaProfile = require('../p/cmta')
|
const cmtaProfile = require('../p/cmta')
|
||||||
const products = require('../p/cmta/products')
|
const products = require('../p/cmta/products')
|
||||||
const {movement: _validateMovement} = 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 testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
||||||
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
|
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
|
||||||
|
@ -27,27 +26,14 @@ const when = createWhen(cmtaProfile.timezone, cmtaProfile.locale)
|
||||||
const cfg = {
|
const cfg = {
|
||||||
when,
|
when,
|
||||||
stationCoordsOptional: false,
|
stationCoordsOptional: false,
|
||||||
products
|
products,
|
||||||
|
minLatitude: 26,
|
||||||
|
maxLatitude: 33,
|
||||||
|
minLongitude: -100,
|
||||||
|
maxLongitude: -95
|
||||||
}
|
}
|
||||||
|
|
||||||
const validateMovement = (val, m, name = 'movement') => {
|
const validate = createValidate(cfg)
|
||||||
// todo: fix this upstream
|
|
||||||
const withFakeLocation = Object.assign({}, m)
|
|
||||||
withFakeLocation.location = Object.assign({}, m.location, {
|
|
||||||
latitude: 50,
|
|
||||||
longitude: 12
|
|
||||||
})
|
|
||||||
_validateMovement(val, withFakeLocation, name)
|
|
||||||
|
|
||||||
assert.ok(m.location.latitude <= 33, name + '.location.latitude is too small')
|
|
||||||
assert.ok(m.location.latitude >= 26, name + '.location.latitude is too large')
|
|
||||||
assert.ok(m.location.longitude >= -100, name + '.location.longitude is too small')
|
|
||||||
assert.ok(m.location.longitude <= -95, name + '.location.longitude is too small')
|
|
||||||
}
|
|
||||||
|
|
||||||
const validate = createValidate(cfg, {
|
|
||||||
movement: validateMovement
|
|
||||||
})
|
|
||||||
|
|
||||||
const test = tapePromise(tape)
|
const test = tapePromise(tape)
|
||||||
const client = createClient(cmtaProfile, 'public-transport/hafas-client:test')
|
const client = createClient(cmtaProfile, 'public-transport/hafas-client:test')
|
||||||
|
|
|
@ -37,7 +37,11 @@ const when = createWhen('Europe/Berlin', 'de-DE')
|
||||||
const cfg = {
|
const cfg = {
|
||||||
when,
|
when,
|
||||||
stationCoordsOptional: false,
|
stationCoordsOptional: false,
|
||||||
products
|
products,
|
||||||
|
minLatitude: 46.673100,
|
||||||
|
maxLatitude: 55.030671,
|
||||||
|
minLongitude: 6.896517,
|
||||||
|
maxLongitude: 16.180237
|
||||||
}
|
}
|
||||||
|
|
||||||
const _validateStation = createValidateStation(cfg)
|
const _validateStation = createValidateStation(cfg)
|
||||||
|
|
13
test/insa.js
13
test/insa.js
|
@ -27,7 +27,11 @@ const when = createWhen('Europe/Berlin', 'de-DE')
|
||||||
const cfg = {
|
const cfg = {
|
||||||
when,
|
when,
|
||||||
stationCoordsOptional: false,
|
stationCoordsOptional: false,
|
||||||
products
|
products,
|
||||||
|
minLatitude: 50.7,
|
||||||
|
maxLatitude: 53.2,
|
||||||
|
minLongitude: 10.25,
|
||||||
|
maxLongitude: 13.4
|
||||||
}
|
}
|
||||||
|
|
||||||
const validate = createValidate(cfg, {})
|
const validate = createValidate(cfg, {})
|
||||||
|
@ -230,7 +234,8 @@ test('arrivals at Magdeburg Leiterstr.', co(function*(t) {
|
||||||
// todo: nearby
|
// todo: nearby
|
||||||
|
|
||||||
test('locations named Magdeburg', co(function*(t) {
|
test('locations named Magdeburg', co(function*(t) {
|
||||||
const locations = yield client.locations('Magdeburg', {
|
const nordpark = '7480'
|
||||||
|
const locations = yield client.locations('nordpark', {
|
||||||
results: 20
|
results: 20
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -242,9 +247,9 @@ test('locations named Magdeburg', co(function*(t) {
|
||||||
t.ok(locations.some((l) => {
|
t.ok(locations.some((l) => {
|
||||||
// todo: trim IDs
|
// todo: trim IDs
|
||||||
if (l.station) {
|
if (l.station) {
|
||||||
if (l.station.id === '008010224' || l.station.id === magdeburgHbf) return true
|
if (l.station.id === '000007480' || l.station.id === nordpark) return true
|
||||||
}
|
}
|
||||||
return l.id === '008010224' || l.id === magdeburgHbf
|
return l.id === '000007480' || l.id === nordpark
|
||||||
}))
|
}))
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
|
|
|
@ -30,7 +30,11 @@ const when = createWhen('Europe/Berlin', 'de-DE')
|
||||||
const cfg = {
|
const cfg = {
|
||||||
when,
|
when,
|
||||||
stationCoordsOptional: false,
|
stationCoordsOptional: false,
|
||||||
products
|
products,
|
||||||
|
maxLatitude: 55.15,
|
||||||
|
minLongitude: 7.5,
|
||||||
|
minLatitude: 53.15,
|
||||||
|
maxLongitude: 11.6
|
||||||
}
|
}
|
||||||
|
|
||||||
const _validateLine = createValidateLine(cfg)
|
const _validateLine = createValidateLine(cfg)
|
||||||
|
@ -300,17 +304,18 @@ test('nearby Kiel Hbf', co(function* (t) {
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
test('locations named Kiel', co(function* (t) {
|
test('locations named "Kiel Rathaus"', co(function* (t) {
|
||||||
const locations = yield client.locations('Kiel', {
|
const kielRathaus = '9049200'
|
||||||
results: 20
|
const locations = yield client.locations('Kiel Rathaus', {
|
||||||
|
results: 15
|
||||||
})
|
})
|
||||||
|
|
||||||
validate(t, locations, 'locations', 'locations')
|
validate(t, locations, 'locations', 'locations')
|
||||||
t.ok(locations.length <= 20)
|
t.ok(locations.length <= 15)
|
||||||
|
|
||||||
t.ok(locations.find(l => l.type === 'stop' || l.type === 'station'))
|
t.ok(locations.find(l => l.type === 'stop' || l.type === 'station'))
|
||||||
t.ok(locations.find(l => l.id && l.name)) // POIs
|
t.ok(locations.find(l => l.id && l.name)) // POIs
|
||||||
t.ok(locations.some(l => l.station && l.station.id === kielHbf || l.id === kielHbf))
|
t.ok(locations.some(l => l.station && l.station.id === kielRathaus || l.id === kielRathaus))
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -29,7 +29,11 @@ const when = createWhen('Europe/Vienna', 'de-AT')
|
||||||
const cfg = {
|
const cfg = {
|
||||||
when,
|
when,
|
||||||
stationCoordsOptional: false,
|
stationCoordsOptional: false,
|
||||||
products
|
products,
|
||||||
|
minLatitude: 45.992803,
|
||||||
|
maxLatitude: 49.453517,
|
||||||
|
minLongitude: 8.787557,
|
||||||
|
maxLongitude: 17.491275
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo validateDirection: search list of stations for direction
|
// todo validateDirection: search list of stations for direction
|
||||||
|
|
|
@ -27,7 +27,11 @@ const when = createWhen(sMunichProfile.timezone, sMunichProfile.locale)
|
||||||
const cfg = {
|
const cfg = {
|
||||||
when,
|
when,
|
||||||
stationCoordsOptional: false,
|
stationCoordsOptional: false,
|
||||||
products
|
products,
|
||||||
|
minLatitude: 48,
|
||||||
|
maxLatitude: 48.3,
|
||||||
|
minLongitude: 11.3,
|
||||||
|
maxLongitude: 11.8
|
||||||
}
|
}
|
||||||
|
|
||||||
const validateMovement = (val, m, name = 'movement') => {
|
const validateMovement = (val, m, name = 'movement') => {
|
||||||
|
|
|
@ -25,7 +25,11 @@ const when = createWhen('Europe/Berlin', 'de-DE')
|
||||||
const cfg = {
|
const cfg = {
|
||||||
when,
|
when,
|
||||||
stationCoordsOptional: false,
|
stationCoordsOptional: false,
|
||||||
products
|
products,
|
||||||
|
minLatitude: 52.559311,
|
||||||
|
maxLatitude: 53.948075,
|
||||||
|
minLongitude: 7.622917,
|
||||||
|
maxLongitude: 9.984605
|
||||||
}
|
}
|
||||||
|
|
||||||
const validate = createValidate(cfg, {})
|
const validate = createValidate(cfg, {})
|
||||||
|
|
Loading…
Add table
Reference in a new issue