db-vendo-client/test/e2e/lib/departures-in-direction.js

37 lines
833 B
JavaScript
Raw Normal View History

'use strict'
2018-11-21 19:07:37 +01:00
const testDeparturesInDirection = async (cfg) => {
const {
test: t,
fetchDepartures,
fetchTrip,
id,
directionIds,
when,
validate
} = cfg
2018-11-21 19:07:37 +01:00
const deps = await fetchDepartures(id, {
direction: directionIds[0],
when
})
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}]`
const line = dep.line && dep.line.name
2018-11-21 19:07:37 +01:00
const trip = await fetchTrip(dep.tripId, line, {
when, stopovers: true
})
2018-07-11 13:25:22 +02:00
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.join('/')}`)
}
2018-11-21 19:07:37 +01:00
}
module.exports = testDeparturesInDirection