2018-07-09 19:46:13 +02:00
|
|
|
|
'use strict'
|
|
|
|
|
|
|
|
|
|
const tapePromise = require('tape-promise').default
|
|
|
|
|
const tape = require('tape')
|
|
|
|
|
const isRoughlyEqual = require('is-roughly-equal')
|
|
|
|
|
|
|
|
|
|
const {createWhen} = require('./lib/util')
|
2019-08-30 18:31:39 +02:00
|
|
|
|
const createClient = require('../..')
|
|
|
|
|
const vbnProfile = require('../../p/vbn')
|
|
|
|
|
const products = require('../../p/vbn/products')
|
2018-07-09 19:46:13 +02:00
|
|
|
|
const createValidate = require('./lib/validate-fptf-with')
|
|
|
|
|
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 testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
2018-07-24 18:16:46 +02:00
|
|
|
|
const testRefreshJourney = require('./lib/refresh-journey')
|
2018-07-09 19:46:13 +02:00
|
|
|
|
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
|
|
|
|
const testDepartures = require('./lib/departures')
|
|
|
|
|
const testArrivals = require('./lib/arrivals')
|
|
|
|
|
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
|
|
|
|
|
|
|
|
|
const when = createWhen('Europe/Berlin', 'de-DE')
|
|
|
|
|
|
|
|
|
|
const cfg = {
|
|
|
|
|
when,
|
|
|
|
|
stationCoordsOptional: false,
|
2019-02-15 14:53:01 +01:00
|
|
|
|
products,
|
|
|
|
|
minLatitude: 52.559311,
|
|
|
|
|
maxLatitude: 53.948075,
|
|
|
|
|
minLongitude: 7.622917,
|
|
|
|
|
maxLongitude: 9.984605
|
2018-07-09 19:46:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const validate = createValidate(cfg, {})
|
|
|
|
|
|
|
|
|
|
const test = tapePromise(tape)
|
2018-07-19 21:55:54 +02:00
|
|
|
|
const client = createClient(vbnProfile, 'public-transport/hafas-client:test')
|
2018-07-09 19:46:13 +02:00
|
|
|
|
|
|
|
|
|
const bremenHbf = '8000050'
|
|
|
|
|
const bremerhavenHbf = '8000051'
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test.only('journeys – Bremen Hbf to Bremerhaven Hbf', async (t) => {
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(bremenHbf, bremerhavenHbf, {
|
2019-02-01 15:35:18 +01:00
|
|
|
|
results: 4,
|
2018-07-09 19:46:13 +02:00
|
|
|
|
departure: when,
|
|
|
|
|
stopovers: true
|
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToStation({
|
2018-07-09 19:46:13 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-07-09 19:46:13 +02:00
|
|
|
|
validate,
|
|
|
|
|
fromId: bremenHbf,
|
|
|
|
|
toId: bremerhavenHbf
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-07-09 19:46:13 +02:00
|
|
|
|
|
|
|
|
|
// todo: journeys, only one product
|
|
|
|
|
|
|
|
|
|
test.skip('journeys – fails with no product', (t) => {
|
|
|
|
|
journeysFailsWithNoProduct({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
fromId: bremenHbf,
|
|
|
|
|
toId: bremerhavenHbf,
|
|
|
|
|
when,
|
|
|
|
|
products
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test.skip('Magdeburg Hbf to 39104 Magdeburg, Sternstr. 10', async (t) => {
|
2018-07-09 19:46:13 +02:00
|
|
|
|
const sternStr = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
address: 'Magdeburg - Altenstadt, Sternstraße 10',
|
|
|
|
|
latitude: 52.118414,
|
|
|
|
|
longitude: 11.422332
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(bremenHbf, sternStr, {
|
2018-07-09 19:46:13 +02:00
|
|
|
|
results: 3,
|
|
|
|
|
departure: when
|
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToAddress({
|
2018-07-09 19:46:13 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-07-09 19:46:13 +02:00
|
|
|
|
validate,
|
|
|
|
|
fromId: bremenHbf,
|
|
|
|
|
to: sternStr
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-07-09 19:46:13 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test.skip('Magdeburg Hbf to Kloster Unser Lieben Frauen', async (t) => {
|
2018-07-09 19:46:13 +02:00
|
|
|
|
const kloster = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
id: '970012223',
|
2019-02-07 17:47:50 +01:00
|
|
|
|
poi: true,
|
2018-07-09 19:46:13 +02:00
|
|
|
|
name: 'Magdeburg, Kloster Unser Lieben Frauen (Denkmal)',
|
|
|
|
|
latitude: 52.127601,
|
|
|
|
|
longitude: 11.636437
|
|
|
|
|
}
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(bremenHbf, kloster, {
|
2018-07-09 19:46:13 +02:00
|
|
|
|
results: 3,
|
|
|
|
|
departure: when
|
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToPoi({
|
2018-07-09 19:46:13 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-07-09 19:46:13 +02:00
|
|
|
|
validate,
|
|
|
|
|
fromId: bremenHbf,
|
|
|
|
|
to: kloster
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-07-09 19:46:13 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test.skip('journeys: via works – with detour', async (t) => {
|
2018-07-09 19:46:13 +02:00
|
|
|
|
// Going from Magdeburg, Hasselbachplatz (Sternstr.) (Tram/Bus) to Stendal
|
|
|
|
|
// via Dessau without detour is currently impossible. We check if the routing
|
|
|
|
|
// engine computes a detour.
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(hasselbachplatzSternstrasse, stendal, {
|
2018-07-09 19:46:13 +02:00
|
|
|
|
via: dessau,
|
|
|
|
|
results: 1,
|
|
|
|
|
departure: when,
|
|
|
|
|
stopovers: true
|
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysWithDetour({
|
2018-07-09 19:46:13 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-07-09 19:46:13 +02:00
|
|
|
|
validate,
|
2019-01-16 22:05:21 +08:00
|
|
|
|
detourIds: [dessau]
|
2018-07-09 19:46:13 +02:00
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-07-09 19:46:13 +02:00
|
|
|
|
|
|
|
|
|
// todo: without detour
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test.skip('earlier/later journeys', async (t) => {
|
|
|
|
|
await testEarlierLaterJourneys({
|
2018-07-09 19:46:13 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: bremenHbf,
|
2018-11-20 18:38:48 +01:00
|
|
|
|
toId: bremerhavenHbf,
|
|
|
|
|
when
|
2018-07-09 19:46:13 +02:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-07-09 19:46:13 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test.skip('refreshJourney', async (t) => {
|
|
|
|
|
await testRefreshJourney({
|
2018-07-24 18:16:46 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
refreshJourney: client.refreshJourney,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: bremenHbf,
|
|
|
|
|
toId: bremerhavenHbf,
|
|
|
|
|
when
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-07-24 18:16:46 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test.skip('trip details', async (t) => {
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(bremenHbf, bremerhavenHbf, {
|
2018-07-09 19:46:13 +02:00
|
|
|
|
results: 1, departure: when
|
|
|
|
|
})
|
|
|
|
|
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const p = res.journeys[0].legs[0]
|
2018-07-09 19:46:13 +02:00
|
|
|
|
t.ok(p.tripId, 'precondition failed')
|
|
|
|
|
t.ok(p.line.name, 'precondition failed')
|
2018-11-21 19:07:37 +01:00
|
|
|
|
const trip = await client.trip(p.tripId, p.line.name, {when})
|
2018-07-09 19:46:13 +02:00
|
|
|
|
|
2018-11-22 00:15:59 +01:00
|
|
|
|
validate(t, trip, 'trip', 'trip')
|
2018-07-09 19:46:13 +02:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-07-09 19:46:13 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test.skip('departures at Magdeburg Leiterstr.', async (t) => {
|
|
|
|
|
const departures = await client.departures(leiterstr, {
|
2018-12-28 21:17:03 +01:00
|
|
|
|
duration: 5, when,
|
2018-11-21 19:07:37 +01:00
|
|
|
|
stopovers: true
|
2018-07-09 19:46:13 +02:00
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testDepartures({
|
2018-07-09 19:46:13 +02:00
|
|
|
|
test: t,
|
|
|
|
|
departures,
|
|
|
|
|
validate,
|
|
|
|
|
id: leiterstr
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-07-09 19:46:13 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test.skip('departures with station object', async (t) => {
|
|
|
|
|
const deps = await client.departures({
|
2018-07-09 19:46:13 +02:00
|
|
|
|
type: 'station',
|
|
|
|
|
id: bremenHbf,
|
|
|
|
|
name: 'Magdeburg Hbf',
|
|
|
|
|
location: {
|
|
|
|
|
type: 'location',
|
|
|
|
|
latitude: 1.23,
|
|
|
|
|
longitude: 2.34
|
|
|
|
|
}
|
|
|
|
|
}, {when})
|
|
|
|
|
|
|
|
|
|
validate(t, deps, 'departures', 'departures')
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-07-09 19:46:13 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test.skip('arrivals at Magdeburg Leiterstr.', async (t) => {
|
|
|
|
|
const arrivals = await client.arrivals(leiterstr, {
|
2018-12-28 21:17:03 +01:00
|
|
|
|
duration: 5, when,
|
|
|
|
|
stopovers: true
|
2018-07-09 19:46:13 +02:00
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testArrivals({
|
2018-07-09 19:46:13 +02:00
|
|
|
|
test: t,
|
|
|
|
|
arrivals,
|
|
|
|
|
validate,
|
|
|
|
|
id: leiterstr
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-07-09 19:46:13 +02:00
|
|
|
|
|
|
|
|
|
// todo: nearby
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test.skip('locations named Magdeburg', async (t) => {
|
|
|
|
|
const locations = await client.locations('Magdeburg', {
|
2018-07-09 19:46:13 +02:00
|
|
|
|
results: 20
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
validate(t, locations, 'locations', 'locations')
|
|
|
|
|
t.ok(locations.length <= 20)
|
|
|
|
|
|
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
|
2018-11-13 20:34:12 +01:00
|
|
|
|
t.ok(locations.some((l) => {
|
2019-01-16 22:05:21 +08:00
|
|
|
|
return l.station && l.station.id === bremenHbf || l.id === bremenHbf
|
2018-07-09 19:46:13 +02:00
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-07-09 19:46:13 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test.skip('station Magdeburg-Buckau', async (t) => {
|
2018-11-21 19:55:37 +01:00
|
|
|
|
const s = await client.stop(bremerhavenHbf)
|
2018-07-09 19:46:13 +02:00
|
|
|
|
|
2018-07-11 13:25:22 +02:00
|
|
|
|
validate(t, s, ['stop', 'station'], 'station')
|
2018-07-09 19:46:13 +02:00
|
|
|
|
t.equal(s.id, bremerhavenHbf)
|
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-07-09 19:46:13 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test.skip('radar', async (t) => {
|
|
|
|
|
const vehicles = await client.radar({
|
2018-07-09 19:46:13 +02:00
|
|
|
|
north: 52.148364,
|
|
|
|
|
west: 11.600826,
|
|
|
|
|
south: 52.108486,
|
|
|
|
|
east: 11.651451
|
|
|
|
|
}, {
|
|
|
|
|
duration: 5 * 60, when, results: 10
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const customCfg = Object.assign({}, cfg, {
|
|
|
|
|
stationCoordsOptional: true, // see #28
|
|
|
|
|
})
|
|
|
|
|
const validate = createValidate(customCfg, {})
|
|
|
|
|
validate(t, vehicles, 'movements', 'vehicles')
|
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|