db-vendo-client/test/e2e/vbb.js

407 lines
8.9 KiB
JavaScript
Raw Normal View History

'use strict'
2019-08-30 18:31:39 +02:00
const createClient = require('../..')
const vbbProfile = require('../../p/vbb')
const products = require('../../p/vbb/products')
const {
2018-07-28 13:43:58 +02:00
cfg,
validateStation,
validateLine,
validateJourneyLeg,
validateDeparture,
validateMovement
} = require('./lib/vbb-bvg-validators')
2018-04-18 23:56:11 +02:00
const createValidate = require('./lib/validate-fptf-with')
2020-05-21 19:04:22 +02:00
const {test} = require('./lib/util')
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
const testJourneysWalkingSpeed = require('./lib/journeys-walking-speed')
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
const testRefreshJourney = require('./lib/refresh-journey')
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
2018-04-24 16:58:17 +02:00
const testDepartures = require('./lib/departures')
const testDeparturesInDirection = require('./lib/departures-in-direction')
const testDeparturesWithoutRelatedStations = require('./lib/departures-without-related-stations')
const testArrivals = require('./lib/arrivals')
2018-05-13 00:34:26 +02:00
const testJourneysWithDetour = require('./lib/journeys-with-detour')
const testReachableFrom = require('./lib/reachable-from')
2018-07-28 13:43:58 +02:00
const when = cfg.when
2018-04-18 23:56:11 +02:00
const validate = createValidate(cfg, {
station: validateStation,
line: validateLine,
journeyLeg: validateJourneyLeg,
departure: validateDeparture,
movement: validateMovement
})
2018-07-19 21:55:54 +02:00
const client = createClient(vbbProfile, 'public-transport/hafas-client:test')
2017-11-20 01:05:48 +01:00
const amrumerStr = '900000009101'
const spichernstr = '900000042101'
const bismarckstr = '900000024201'
2018-04-18 23:56:11 +02:00
const westhafen = '900000001201'
const wedding = '900000009104'
const württembergallee = '900000026153'
2017-11-20 01:05:48 +01:00
2018-11-21 19:07:37 +01:00
test('journeys  Spichernstr. to Bismarckstr.', async (t) => {
const res = await client.journeys({
type: 'stop',
id: spichernstr,
name: 'U Spichernstr.'
}, bismarckstr, {
results: 4,
2018-05-31 13:42:54 +02:00
departure: when,
stopovers: true
})
2017-11-14 02:59:17 +01:00
2018-11-21 19:07:37 +01:00
await testJourneysStationToStation({
test: t,
res,
validate,
fromId: spichernstr,
toId: bismarckstr
})
// todo: find a journey where there ticket info is always available
2017-11-14 02:59:17 +01:00
t.end()
2018-11-21 19:07:37 +01:00
})
2018-11-21 19:07:37 +01:00
test('journeys  only subway', async (t) => {
const res = await client.journeys(spichernstr, bismarckstr, {
2018-05-31 13:42:54 +02:00
results: 20,
departure: when,
products: {
suburban: false,
subway: true,
tram: false,
bus: false,
ferry: false,
express: false,
regional: false
}
})
2017-11-14 02:59:17 +01:00
validate(t, res, 'journeysResult', 'res')
t.ok(res.journeys.length > 1)
for (let i = 0; i < res.journeys.length; i++) {
const journey = res.journeys[i]
2018-04-18 23:56:11 +02:00
for (let j = 0; j < journey.legs.length; j++) {
const leg = journey.legs[j]
2017-11-14 02:59:17 +01:00
const name = `res.journeys[${i}].legs[${i}].line`
if (leg.line) {
2018-04-18 23:56:11 +02:00
t.equal(leg.line.mode, 'train', name + '.mode is invalid')
t.equal(leg.line.product, 'subway', name + '.product is invalid')
}
2018-04-18 23:56:11 +02:00
t.ok(journey.legs.some(l => l.line), name + '.legs has no subway leg')
}
2017-11-14 02:59:17 +01:00
}
2018-04-18 23:56:11 +02:00
2017-11-14 02:59:17 +01:00
t.end()
2018-11-21 19:07:37 +01:00
})
2018-08-17 21:52:40 +02:00
// todo: journeys  with arrival time
2018-04-18 23:56:11 +02:00
test('journeys  fails with no product', (t) => {
journeysFailsWithNoProduct({
test: t,
fetchJourneys: client.journeys,
fromId: spichernstr,
toId: bismarckstr,
2018-05-24 12:13:24 +02:00
when,
products
2018-05-24 12:13:24 +02:00
})
t.end()
2018-04-18 23:56:11 +02:00
})
2018-05-24 12:13:24 +02:00
test('journeys: walkingSpeed', async (t) => {
const havelchaussee = {
type: 'location',
address: 'Havelchaussee',
latitude: 52.443576,
longitude: 13.198973
}
const wannsee = '900000053301'
await testJourneysWalkingSpeed({
test: t,
journeys: client.journeys,
validate,
from: havelchaussee,
to: wannsee,
when,
products: {bus: false},
minTimeDifference: 5 * 60 * 1000
})
})
2018-11-21 19:07:37 +01:00
test('earlier/later journeys', async (t) => {
await testEarlierLaterJourneys({
test: t,
fetchJourneys: client.journeys,
validate,
fromId: spichernstr,
toId: bismarckstr,
when
})
2018-03-04 19:54:21 +01:00
t.end()
2018-11-21 19:07:37 +01:00
})
2018-03-04 19:54:21 +01:00
2018-11-21 19:07:37 +01:00
test('refreshJourney', async (t) => {
await testRefreshJourney({
test: t,
fetchJourneys: client.journeys,
refreshJourney: client.refreshJourney,
validate,
fromId: spichernstr,
toId: bismarckstr,
when
2018-03-04 19:54:21 +01:00
})
t.end()
2018-11-21 19:07:37 +01:00
})
2018-03-04 19:54:21 +01:00
2018-11-21 19:07:37 +01:00
test('trip details', async (t) => {
const res = await client.journeys(spichernstr, amrumerStr, {
2018-05-28 20:35:01 +02:00
results: 1, departure: when
})
const p = res.journeys[0].legs.find(l => !l.walking)
t.ok(p.tripId, 'precondition failed')
2017-11-14 02:59:17 +01:00
t.ok(p.line.name, 'precondition failed')
const trip = await client.trip(p.tripId, p.line.name, {when})
2017-11-14 02:59:17 +01:00
validate(t, trip, 'trip', 'trip')
2017-11-14 02:59:17 +01:00
t.end()
2018-11-21 19:07:37 +01:00
})
2018-11-21 19:07:37 +01:00
test('journeys  station to address', async (t) => {
const torfstr = {
type: 'location',
address: '13353 Berlin-Wedding, Torfstr. 17',
latitude: 52.541797,
longitude: 13.350042
}
const res = await client.journeys(spichernstr, torfstr, {
2018-05-31 13:42:54 +02:00
results: 3,
departure: when
})
2017-11-14 02:59:17 +01:00
2018-11-21 19:07:37 +01:00
await testJourneysStationToAddress({
test: t,
res,
validate,
fromId: spichernstr,
to: torfstr
})
2017-11-14 02:59:17 +01:00
t.end()
2018-11-21 19:07:37 +01:00
})
2018-11-21 19:07:37 +01:00
test('journeys  station to POI', async (t) => {
const atze = {
type: 'location',
id: '900980720',
2019-02-07 17:47:50 +01:00
poi: true,
name: 'Berlin, Atze Musiktheater für Kinder',
latitude: 52.543333,
longitude: 13.351686
}
const res = await client.journeys(spichernstr, atze, {
2018-05-31 13:42:54 +02:00
results: 3,
departure: when
})
2017-11-14 02:59:17 +01:00
2018-11-21 19:07:37 +01:00
await testJourneysStationToPoi({
test: t,
res,
validate,
fromId: spichernstr,
to: atze
})
2017-11-14 02:59:17 +01:00
t.end()
2018-11-21 19:07:37 +01:00
})
2018-11-21 19:07:37 +01:00
test('journeys: via works with detour', async (t) => {
2018-03-16 14:30:49 +01:00
// Going from Westhafen to Wedding via Württembergalle without detour
2018-03-16 14:34:37 +01:00
// is currently impossible. We check if the routing engine computes a detour.
const res = await client.journeys(westhafen, wedding, {
via: württembergallee,
results: 1,
2018-05-28 20:35:01 +02:00
departure: when,
stopovers: true
})
2018-11-21 19:07:37 +01:00
await testJourneysWithDetour({
2018-05-13 00:34:26 +02:00
test: t,
res,
2018-05-13 00:34:26 +02:00
validate,
detourIds: [württembergallee]
})
t.end()
2018-11-21 19:07:37 +01:00
})
// todo: without detour test
2018-11-21 19:07:37 +01:00
test('departures', async (t) => {
const departures = await client.departures(spichernstr, {
duration: 5, when,
stopovers: true
2018-04-24 16:58:17 +02:00
})
2018-04-18 23:56:11 +02:00
2018-11-21 19:07:37 +01:00
await testDepartures({
2018-04-24 16:58:17 +02:00
test: t,
departures,
validate,
id: spichernstr
})
2017-11-14 02:59:17 +01:00
t.end()
2018-11-21 19:07:37 +01:00
})
2018-11-21 19:07:37 +01:00
test('departures with station object', async (t) => {
const deps = await client.departures({
type: 'station',
id: spichernstr,
name: 'U Spichernstr',
location: {
type: 'location',
latitude: 1.23,
longitude: 2.34
}
}, {when})
2018-04-18 23:56:11 +02:00
validate(t, deps, 'departures', 'departures')
t.end()
2018-11-21 19:07:37 +01:00
})
2018-11-21 19:07:37 +01:00
test('departures at Spichernstr. in direction of Westhafen', async (t) => {
await testDeparturesInDirection({
test: t,
fetchDepartures: client.departures,
fetchTrip: client.trip,
id: spichernstr,
directionIds: [westhafen],
when,
validate
})
t.end()
2018-11-21 19:07:37 +01:00
})
2018-11-21 19:07:37 +01:00
test('departures at 7-digit station', async (t) => {
const eisenach = '8010097' // see derhuerst/vbb-hafas#22
2018-11-21 19:07:37 +01:00
await client.departures(eisenach, {when})
2017-11-14 02:59:17 +01:00
t.pass('did not fail')
t.end()
2018-11-21 19:07:37 +01:00
})
2017-11-14 02:59:17 +01:00
2018-11-21 19:07:37 +01:00
test('departures without related stations', async (t) => {
await testDeparturesWithoutRelatedStations({
test: t,
fetchDepartures: client.departures,
id: '900000024101', // Charlottenburg
when,
products: {bus: false, suburban: false, regional: false},
linesOfRelatedStations: ['U7']
})
2017-11-14 02:59:17 +01:00
t.end()
2018-11-21 19:07:37 +01:00
})
2018-11-21 19:07:37 +01:00
test('arrivals', async (t) => {
const arrivals = await client.arrivals(spichernstr, {
duration: 5, when,
stopovers: true
})
2018-11-21 19:07:37 +01:00
await testArrivals({
test: t,
arrivals,
validate,
id: spichernstr
})
t.end()
2018-11-21 19:07:37 +01:00
})
2018-11-21 19:07:37 +01:00
test('nearby', async (t) => {
const berlinerStr = '900000044201'
const landhausstr = '900000043252'
2017-11-14 02:59:17 +01:00
// Berliner Str./Bundesallee
2018-11-21 19:07:37 +01:00
const nearby = await client.nearby({
2018-01-05 14:53:03 +01:00
type: 'location',
latitude: 52.4873452,
longitude: 13.3310411
}, {distance: 200})
2018-04-18 23:56:11 +02:00
validate(t, nearby, 'locations', 'nearby')
2018-04-18 23:56:11 +02:00
t.equal(nearby[0].id, berlinerStr)
2017-11-14 02:59:17 +01:00
t.equal(nearby[0].name, 'U Berliner Str.')
t.ok(nearby[0].distance > 0)
t.ok(nearby[0].distance < 100)
2018-04-18 23:56:11 +02:00
t.equal(nearby[1].id, landhausstr)
2017-11-14 02:59:17 +01:00
t.equal(nearby[1].name, 'Landhausstr.')
t.ok(nearby[1].distance > 100)
t.ok(nearby[1].distance < 200)
t.end()
2018-11-21 19:07:37 +01:00
})
2018-11-21 19:07:37 +01:00
test('locations', async (t) => {
const locations = await client.locations('Alexanderplatz', {results: 20})
2017-11-14 02:59:17 +01:00
2018-04-18 23:56:11 +02:00
validate(t, locations, 'locations', 'locations')
2018-02-15 17:31:43 +01:00
t.ok(locations.length <= 20)
2018-04-18 23:56:11 +02:00
2018-07-11 13:25:22 +02:00
t.ok(locations.find(s => s.type === 'stop' || s.type === 'station'))
2019-02-07 17:47:50 +01:00
t.ok(locations.find(s => s.poi)) // POIs
2017-12-11 19:53:26 +01:00
t.ok(locations.find(s => !s.name && s.address)) // addresses
2017-11-14 02:59:17 +01:00
t.end()
2018-11-21 19:07:37 +01:00
})
test('stop', async (t) => {
const s = await client.stop(spichernstr)
2018-01-26 17:08:07 +01:00
validate(t, s, ['stop', 'station'], 'stop')
2018-04-18 23:56:11 +02:00
t.equal(s.id, spichernstr)
2018-01-26 17:08:07 +01:00
t.end()
2018-11-21 19:07:37 +01:00
})
2018-01-26 17:08:07 +01:00
2018-11-21 19:07:37 +01:00
test('radar', async (t) => {
const vehicles = await client.radar({
north: 52.52411,
west: 13.41002,
south: 52.51942,
east: 13.41709
}, {
2017-11-14 02:59:17 +01:00
duration: 5 * 60, when
})
2018-04-18 23:56:11 +02:00
validate(t, vehicles, 'movements', 'vehicles')
2017-11-14 02:59:17 +01:00
t.end()
2018-11-21 19:07:37 +01:00
})
2018-11-21 19:07:37 +01:00
test('reachableFrom', async (t) => {
const torfstr17 = {
type: 'location',
address: '13353 Berlin-Wedding, Torfstr. 17',
latitude: 52.541797,
longitude: 13.350042
}
2018-11-21 19:07:37 +01:00
await testReachableFrom({
test: t,
reachableFrom: client.reachableFrom,
address: torfstr17,
when,
maxDuration: 15,
validate
})
t.end()
2018-11-21 19:07:37 +01:00
})