adapt tests to 98a051b

This commit is contained in:
Jannis R 2018-07-11 13:25:22 +02:00 committed by Jannis Redmann
parent 59fee11216
commit 951c21eecc
13 changed files with 104 additions and 54 deletions

View file

@ -317,6 +317,9 @@ test('locations named Jungfernheide', co(function* (t) {
t.ok(locations.length <= 10)
t.ok(locations.some((l) => {
// todo: trim IDs
if (l.station) {
if (l.station.id === '008011167' || l.station.id === jungfernheide) return true
}
return l.id === '008011167' || l.id === jungfernheide
}), 'Jungfernheide not found')
@ -326,7 +329,7 @@ test('locations named Jungfernheide', co(function* (t) {
test('station', co(function* (t) {
const s = yield client.station(regensburgHbf)
validate(t, s, 'station', 'station')
validate(t, s, ['stop', 'station'], 'station')
t.equal(s.id, regensburgHbf)
t.end()

View file

@ -235,13 +235,14 @@ test('locations named Magdeburg', co(function*(t) {
validate(t, locations, 'locations', 'locations')
t.ok(locations.length <= 20)
t.ok(locations.find(s => s.type === 'station'))
t.ok(locations.find(s => s.type === 'stop' || s.type === 'station'))
t.ok(locations.find(s => s.id && s.name)) // POIs
t.ok(locations.some((loc) => {
return (
loc.id === '008010224' || // todo: trim IDs
loc.id === magdeburgHbf
)
t.ok(locations.some((l) => {
// todo: trim IDs
if (l.station) {
if (l.station.id === '008010224' || l.station.id === magdeburgHbf) return true
}
return l.id === '008010224' || l.id === magdeburgHbf
}))
t.end()
@ -250,7 +251,7 @@ test('locations named Magdeburg', co(function*(t) {
test('station Magdeburg-Buckau', co(function* (t) {
const s = yield client.station(magdeburgBuckau)
validate(t, s, 'station', 'station')
validate(t, s, ['stop', 'station'], 'station')
t.equal(s.id, magdeburgBuckau)
t.end()

View file

@ -8,10 +8,14 @@ const testArrivals = co(function* (cfg) {
validate(t, arrs, 'arrivals', 'arrivals')
t.ok(arrs.length > 0, 'must be >0 arrivals')
for (let i = 0; i < arrs.length; i++) {
const dep = arrs[i]
const name = `arrs[${i}]`
let station = arrs[i].station
let name = `arrs[${i}].station`
if (station.station) {
station = station.station
name += '.station'
}
t.equal(dep.station.id, id, name + '.station.id is invalid')
t.equal(station.id, id, name + '.id is invalid')
}
// todo: move into arrivals validator

View file

@ -28,9 +28,10 @@ const testDeparturesInDirection = co(function* (cfg) {
const trip = yield fetchTrip(dep.tripId, line, {
when, stopovers: true
})
t.ok(trip.stopovers.some(st => {
return st.stop && directionIds.includes(st.stop.id)
}), `trip ${dep.tripId} of ${name} has no stopover at ${directionIds}`)
t.ok(trip.stopovers.some(st => (
st.stop.station && directionIds.includes(st.stop.station.id) ||
directionIds.includes(st.stop.id)
)), `trip ${dep.tripId} of ${name} has no stopover at ${directionIds}`)
}
})

View file

@ -8,10 +8,14 @@ const testDepartures = co(function* (cfg) {
validate(t, deps, 'departures', 'departures')
t.ok(deps.length > 0, 'must be >0 departures')
for (let i = 0; i < deps.length; i++) {
const dep = deps[i]
const name = `deps[${i}]`
let station = deps[i].station
let name = `deps[${i}].station`
if (station.station) {
station = station.station
name += '.station'
}
t.equal(dep.station.id, id, name + '.station.id is invalid')
t.equal(station.id, id, name + '.id is invalid')
}
// todo: move into deps validator

View file

@ -13,17 +13,26 @@ const testJourneysStationToPoi = co(function* (cfg) {
for (let i = 0; i < journeys.length; i++) {
const j = journeys[i]
const firstLeg = j.legs[0]
t.strictEqual(firstLeg.origin.id, fromId)
let o = j.legs[0].origin
let oN = `journeys[0].legs[0].destination`
if (o.station) {
o = o.station
oN += '.station'
}
t.strictEqual(o.id, fromId)
const d = j.legs[j.legs.length - 1].destination
const n = `journeys[0].legs[${i}].destination`
let d = j.legs[j.legs.length - 1].destination
let dN = `journeys[${i}].legs[${j.legs.length - 1}].destination`
if (d.station) {
d = d.station
dN += '.station'
}
t.strictEqual(d.type, 'location', n + '.type is invalid')
t.strictEqual(d.id, id, n + '.id is invalid')
t.strictEqual(d.name, name, n + '.name is invalid')
t.ok(isRoughlyEqual(.0001, d.latitude, latitude), n + '.latitude is invalid')
t.ok(isRoughlyEqual(.0001, d.longitude, longitude), n + '.longitude is invalid')
t.strictEqual(d.type, 'location', dN + '.type is invalid')
t.strictEqual(d.id, id, dN + '.id is invalid')
t.strictEqual(d.name, name, dN + '.name is invalid')
t.ok(isRoughlyEqual(.0001, d.latitude, latitude), dN + '.latitude is invalid')
t.ok(isRoughlyEqual(.0001, d.longitude, longitude), dN + '.longitude is invalid')
}
})

View file

@ -10,10 +10,12 @@ const testJourneysStationToStation = co(function* (cfg) {
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)
let origin = j.legs[0].origin
if (origin.station) origin = origin.station
let dest = j.legs[j.legs.length - 1].destination
if (dest.station) dest = dest.station
t.strictEqual(origin.id, fromId)
t.strictEqual(dest.id, toId)
}
})

View file

@ -11,9 +11,10 @@ const testJourneysWithDetour = co(function* (cfg) {
validate(t, journeys, 'journeys', 'journeys')
const leg = journeys[0].legs.some((leg) => {
return leg.stopovers && leg.stopovers.some((stopover) => {
return detourIds.includes(stopover.stop.id)
})
return leg.stopovers && leg.stopovers.some((st) => (
st.stop.station && detourIds.includes(st.stop.station.id) ||
detourIds.includes(st.stop.id)
))
})
t.ok(leg, detourIds.join('/') + ' is not being passed')
})

View file

@ -32,6 +32,16 @@ const createValidateStation = (cfg) => {
return validateStation
}
const validateStop = (val, s, name = 'stop') => {
// HAFAS doesn't always return the station of a stop. We mock it here
// to silence `validate-fptf`.
const station = Object.assign({}, s)
station.type = 'station'
s = Object.assign({station}, s)
defaultValidators.stop(val, s, name)
}
const validatePoi = (val, poi, name = 'location') => {
defaultValidators.location(val, poi, name)
val.ref(val, poi.id, name + '.id')
@ -46,7 +56,8 @@ const validateAddress = (val, addr, name = 'location') => {
const validateLocation = (val, loc, name = 'location') => {
a.ok(isObj(loc), name + ' must be an object')
if (loc.type === 'station') val.station(val, loc, name)
if (loc.type === 'stop') val.stop(val, loc, name)
else if (loc.type === 'station') val.station(val, loc, name)
else if ('id' in loc) validatePoi(val, loc, name)
else if (!('name' in loc) && ('address' in loc)) {
validateAddress(val, loc, name)
@ -120,7 +131,7 @@ const createValidateStopover = (cfg) => {
a.ok(s.formerScheduledDeparturePlatform, msg + 'not be empty')
}
val.station(val, s.stop, name + '.stop')
anyOf(['stop', 'station'], val, s.stop, name + '.stop')
}
return validateStopover
}
@ -251,7 +262,7 @@ const createValidateArrivalOrDeparture = (cfg) => {
a.ok(dep.tripId, name + '.tripId must not be empty')
a.strictEqual(typeof dep.trip, 'number', name + '.trip must be a number')
val.station(val, dep.station, name + '.station')
anyOf(['stop', 'station'], val, dep.station, name + '.station')
assertValidWhen(dep.when, cfg.when, name)
if (dep.delay !== null) {
@ -315,8 +326,8 @@ const validateMovement = (val, m, name = 'movement') => {
const fName = name + `.frames[${i}]`
a.ok(isObj(f), fName + ' must be an object')
anyOf(['location', 'station'], val, f.origin, fName + '.origin')
anyOf(['location', 'station'], val, f.destination, fName + '.destination')
anyOf(['location', 'stop', 'station'], val, f.origin, fName + '.origin')
anyOf(['location', 'stop', 'station'], val, f.destination, fName + '.destination')
a.strictEqual(typeof f.t, 'number', fName + '.frames must be a number')
}
@ -333,6 +344,7 @@ const validateMovements = (val, ms, name = 'movements') => {
module.exports = {
station: createValidateStation,
stop: () => validateStop,
location: () => validateLocation,
locations: () => validateLocations,
poi: () => validatePoi,

View file

@ -164,7 +164,8 @@ test('Husum to Lübeck Hbf with stopover at Kiel Hbf', co(function* (t) {
const leg = journeys[0].legs.some((leg) => {
return leg.stopovers && leg.stopovers.some((stopover) => {
return stopover.stop.id === kielHbf
const s = stopover.stop
return s.station && s.station.id === kielHbf || s.id === kielHbf
})
})
t.ok(leg, 'Kiel Hbf is not being passed')
@ -293,9 +294,9 @@ test('locations named Kiel', co(function* (t) {
validate(t, locations, 'locations', 'locations')
t.ok(locations.length <= 20)
t.ok(locations.find(s => s.type === 'station'))
t.ok(locations.find(s => s.type === 'stop' || s.type === 'station'))
t.ok(locations.find(s => s.id && s.name)) // POIs
t.ok(locations.some(l => l.id === kielHbf))
t.ok(locations.some(l => l.station && s.station.id === kielHbf || l.id === kielHbf))
t.end()
}))
@ -303,7 +304,7 @@ test('locations named Kiel', co(function* (t) {
test('station', co(function* (t) {
const s = yield client.station(kielHbf)
validate(t, s, 'station', 'station')
validate(t, s, ['stop', 'station'], 'station')
t.equal(s.id, kielHbf)
t.end()

View file

@ -11,7 +11,8 @@ const createClient = require('..')
const oebbProfile = require('../p/oebb')
const products = require('../p/oebb/products')
const {
station: createValidateStation
station: createValidateStation,
stop: validateStop
} = require('./lib/validators')
const createValidate = require('./lib/validate-fptf-with')
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
@ -314,9 +315,15 @@ test('locations named Salzburg', co(function* (t) {
validate(t, locations, 'locations', 'locations')
t.ok(locations.length <= 20)
t.ok(locations.find(s => s.type === 'station'))
t.ok(locations.find(s => s.type === 'stop' || s.type === 'station'))
t.ok(locations.find(s => s.id && s.name)) // POIs
t.ok(locations.some(s => s.id === '008100002' || s.id === '8100002'))
t.ok(locations.some((s) => {
// todo: trim IDs
if (s.station) {
if (s.station.id === '008100002' || s.station.id === '8100002') return true
}
return s.id === '008100002' || s.id === '8100002'
}))
t.end()
}))
@ -329,12 +336,16 @@ test('station', co(function* (t) {
const allProducts = products.reduce((acc, p) => (acc[p.id] = true, acc), {})
const validateStation = createValidateStation(cfg)
const validate = createValidate(cfg, {
stop: (validate, s, name) => {
const withFakeProducts = Object.assign({products: allProducts}, s)
validateStop(validate, withFakeProducts, name)
},
station: (validate, s, name) => {
const withFakeProducts = Object.assign({products: allProducts}, s)
validateStation(validate, withFakeProducts, name)
}
})
validate(t, loc, 'station', 'station')
validate(t, loc, ['stop', 'station'], 'station')
t.equal(loc.id, wienRenngasse)

View file

@ -377,7 +377,7 @@ test('locations', co(function* (t) {
validate(t, locations, 'locations', 'locations')
t.ok(locations.length <= 20)
t.ok(locations.find(s => s.type === 'station'))
t.ok(locations.find(s => s.type === 'stop' || s.type === 'station'))
t.ok(locations.find(s => s.id && s.name)) // POIs
t.ok(locations.find(s => !s.name && s.address)) // addresses
@ -387,7 +387,7 @@ test('locations', co(function* (t) {
test('station', co(function* (t) {
const s = yield client.station(spichernstr)
validate(t, s, 'station', 'station')
validate(t, s, ['stop', 'station'], 'station')
t.equal(s.id, spichernstr)
t.end()

View file

@ -214,13 +214,14 @@ test.skip('locations named Magdeburg', co(function*(t) {
validate(t, locations, 'locations', 'locations')
t.ok(locations.length <= 20)
t.ok(locations.find(s => s.type === 'station'))
t.ok(locations.find(s => s.type === 'stop' || s.type === 'station'))
t.ok(locations.find(s => s.id && s.name)) // POIs
t.ok(locations.some((loc) => {
return (
loc.id === '008010224' || // todo: trim IDs
loc.id === bremenHbf
)
// todo: trim IDs
if (l.station) {
if (l.station.id === '008010224' || l.station.id === bremenHbf) return true
}
return l.id === '008010224' || l.id === bremenHbf
}))
t.end()
@ -229,7 +230,7 @@ test.skip('locations named Magdeburg', co(function*(t) {
test.skip('station Magdeburg-Buckau', co(function* (t) {
const s = yield client.station(bremerhavenHbf)
validate(t, s, 'station', 'station')
validate(t, s, ['stop', 'station'], 'station')
t.equal(s.id, bremerhavenHbf)
t.end()