2018-03-12 22:43:50 +01:00
|
|
|
|
'use strict'
|
2018-02-26 23:23:00 +01:00
|
|
|
|
|
2018-03-12 22:43:50 +01:00
|
|
|
|
const tapePromise = require('tape-promise').default
|
|
|
|
|
const tape = require('tape')
|
|
|
|
|
const isRoughlyEqual = require('is-roughly-equal')
|
2018-02-26 23:23:00 +01:00
|
|
|
|
|
2018-04-19 16:00:14 +02:00
|
|
|
|
const {createWhen} = require('./lib/util')
|
2018-04-18 16:15:24 +02:00
|
|
|
|
const co = require('./lib/co')
|
2018-03-12 22:43:50 +01:00
|
|
|
|
const createClient = require('..')
|
|
|
|
|
const insaProfile = require('../p/insa')
|
2018-04-19 16:00:14 +02:00
|
|
|
|
const products = require('../p/insa/products')
|
|
|
|
|
const createValidate = require('./lib/validate-fptf-with')
|
2018-04-23 13:56:00 +02:00
|
|
|
|
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
2018-04-24 15:42:53 +02:00
|
|
|
|
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
|
2018-04-24 16:10:56 +02:00
|
|
|
|
const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
|
2018-04-24 15:24:59 +02:00
|
|
|
|
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
2018-04-25 13:07:31 +02:00
|
|
|
|
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
2018-04-24 16:58:17 +02:00
|
|
|
|
const testDepartures = require('./lib/departures')
|
2018-07-07 21:26:40 +02:00
|
|
|
|
const testDeparturesInDirection = require('./lib/departures-in-direction')
|
2018-06-26 17:30:46 +02:00
|
|
|
|
const testArrivals = require('./lib/arrivals')
|
2018-05-13 00:34:26 +02:00
|
|
|
|
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
2018-02-26 23:23:00 +01:00
|
|
|
|
|
2018-04-19 16:00:14 +02:00
|
|
|
|
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
|
2018-02-26 23:23:00 +01:00
|
|
|
|
|
2018-04-19 16:00:14 +02:00
|
|
|
|
const when = createWhen('Europe/Berlin', 'de-DE')
|
2018-02-26 23:23:00 +01:00
|
|
|
|
|
2018-04-19 16:00:14 +02:00
|
|
|
|
const cfg = {
|
|
|
|
|
when,
|
|
|
|
|
stationCoordsOptional: false,
|
|
|
|
|
products
|
2018-03-12 22:43:50 +01:00
|
|
|
|
}
|
2018-02-26 23:23:00 +01:00
|
|
|
|
|
2018-04-19 16:00:14 +02:00
|
|
|
|
const validate = createValidate(cfg, {})
|
2018-02-26 23:23:00 +01:00
|
|
|
|
|
2018-03-12 22:43:50 +01:00
|
|
|
|
const test = tapePromise(tape)
|
2018-07-19 21:55:54 +02:00
|
|
|
|
const client = createClient(insaProfile, 'public-transport/hafas-client:test')
|
2018-03-12 22:43:50 +01:00
|
|
|
|
|
2018-04-19 16:00:14 +02:00
|
|
|
|
const magdeburgHbf = '8010224'
|
|
|
|
|
const magdeburgBuckau = '8013456'
|
2018-04-24 16:58:17 +02:00
|
|
|
|
const leiterstr = '7464'
|
2018-04-19 16:00:14 +02:00
|
|
|
|
const hasselbachplatzSternstrasse = '000006545'
|
|
|
|
|
const stendal = '008010334'
|
|
|
|
|
const dessau = '008010077'
|
2018-07-07 21:26:40 +02:00
|
|
|
|
const universitaet = '19686'
|
2018-04-19 16:00:14 +02:00
|
|
|
|
|
2018-04-23 13:56:00 +02:00
|
|
|
|
test('journeys – Magdeburg Hbf to Magdeburg-Buckau', co(function* (t) {
|
2018-03-12 22:43:50 +01:00
|
|
|
|
const journeys = yield client.journeys(magdeburgHbf, magdeburgBuckau, {
|
2018-05-31 13:42:54 +02:00
|
|
|
|
results: 3,
|
2018-05-28 20:35:01 +02:00
|
|
|
|
departure: when,
|
2018-06-13 20:39:33 +02:00
|
|
|
|
stopovers: true
|
2018-02-26 23:23:00 +01:00
|
|
|
|
})
|
2018-03-12 22:43:50 +01:00
|
|
|
|
|
2018-04-23 13:56:00 +02:00
|
|
|
|
yield testJourneysStationToStation({
|
|
|
|
|
test: t,
|
|
|
|
|
journeys,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: magdeburgHbf,
|
|
|
|
|
toId: magdeburgBuckau
|
|
|
|
|
})
|
2018-03-12 22:43:50 +01:00
|
|
|
|
t.end()
|
|
|
|
|
}))
|
|
|
|
|
|
2018-04-19 16:00:14 +02:00
|
|
|
|
// todo: journeys, only one product
|
2018-04-25 13:07:31 +02:00
|
|
|
|
|
|
|
|
|
test('journeys – fails with no product', (t) => {
|
|
|
|
|
journeysFailsWithNoProduct({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
fromId: magdeburgHbf,
|
|
|
|
|
toId: magdeburgBuckau,
|
|
|
|
|
when,
|
|
|
|
|
products
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
2018-04-19 16:00:14 +02:00
|
|
|
|
|
2018-03-12 22:43:50 +01:00
|
|
|
|
test('Magdeburg Hbf to 39104 Magdeburg, Sternstr. 10', co(function*(t) {
|
|
|
|
|
const sternStr = {
|
|
|
|
|
type: 'location',
|
2018-04-24 15:42:53 +02:00
|
|
|
|
address: 'Magdeburg - Altenstadt, Sternstraße 10',
|
2018-03-13 02:28:51 +01:00
|
|
|
|
latitude: 52.118414,
|
2018-04-24 15:42:53 +02:00
|
|
|
|
longitude: 11.422332
|
2018-03-12 22:43:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const journeys = yield client.journeys(magdeburgHbf, sternStr, {
|
2018-05-31 13:42:54 +02:00
|
|
|
|
results: 3,
|
2018-05-28 20:35:01 +02:00
|
|
|
|
departure: when
|
2018-02-26 23:23:00 +01:00
|
|
|
|
})
|
2018-03-12 22:43:50 +01:00
|
|
|
|
|
2018-04-24 15:42:53 +02:00
|
|
|
|
yield testJourneysStationToAddress({
|
|
|
|
|
test: t,
|
|
|
|
|
journeys,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: magdeburgHbf,
|
|
|
|
|
to: sternStr
|
|
|
|
|
})
|
2018-03-12 22:43:50 +01:00
|
|
|
|
t.end()
|
|
|
|
|
}))
|
|
|
|
|
|
2018-04-24 16:10:56 +02:00
|
|
|
|
test('Magdeburg Hbf to Kloster Unser Lieben Frauen', co(function*(t) {
|
2018-03-12 22:43:50 +01:00
|
|
|
|
const kloster = {
|
|
|
|
|
type: 'location',
|
2018-04-19 16:00:14 +02:00
|
|
|
|
id: '970012223',
|
2018-03-12 22:43:50 +01:00
|
|
|
|
name: 'Magdeburg, Kloster Unser Lieben Frauen (Denkmal)',
|
2018-04-19 16:00:14 +02:00
|
|
|
|
latitude: 52.127601,
|
|
|
|
|
longitude: 11.636437
|
2018-03-12 22:43:50 +01:00
|
|
|
|
}
|
2018-04-19 16:00:14 +02:00
|
|
|
|
const journeys = yield client.journeys(magdeburgHbf, kloster, {
|
2018-05-31 13:42:54 +02:00
|
|
|
|
results: 3,
|
2018-05-28 20:35:01 +02:00
|
|
|
|
departure: when
|
2018-04-24 16:10:56 +02:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
yield testJourneysStationToPoi({
|
|
|
|
|
test: t,
|
|
|
|
|
journeys,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: magdeburgHbf,
|
|
|
|
|
to: kloster
|
2018-02-26 23:23:00 +01:00
|
|
|
|
})
|
2018-03-12 22:43:50 +01:00
|
|
|
|
t.end()
|
|
|
|
|
}))
|
|
|
|
|
|
2018-03-16 15:32:19 +01:00
|
|
|
|
test('journeys: via works – with detour', co(function* (t) {
|
2018-04-19 16:00:14 +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.
|
|
|
|
|
const journeys = yield client.journeys(hasselbachplatzSternstrasse, stendal, {
|
2018-03-16 15:32:19 +01:00
|
|
|
|
via: dessau,
|
2018-03-12 22:43:50 +01:00
|
|
|
|
results: 1,
|
2018-05-28 20:35:01 +02:00
|
|
|
|
departure: when,
|
2018-06-13 20:39:33 +02:00
|
|
|
|
stopovers: true
|
2018-03-16 15:32:19 +01:00
|
|
|
|
})
|
|
|
|
|
|
2018-05-13 00:34:26 +02:00
|
|
|
|
yield testJourneysWithDetour({
|
|
|
|
|
test: t,
|
|
|
|
|
journeys,
|
|
|
|
|
validate,
|
|
|
|
|
detourIds: ['8010077', dessau] // todo: trim IDs
|
2018-04-19 16:00:14 +02:00
|
|
|
|
})
|
2018-03-16 15:32:19 +01:00
|
|
|
|
t.end()
|
|
|
|
|
}))
|
|
|
|
|
|
2018-04-25 13:24:27 +02:00
|
|
|
|
// todo: without detour
|
|
|
|
|
|
2018-04-19 16:00:14 +02:00
|
|
|
|
test('earlier/later journeys', co(function* (t) {
|
2018-04-24 15:24:59 +02:00
|
|
|
|
yield testEarlierLaterJourneys({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: magdeburgHbf,
|
|
|
|
|
toId: magdeburgBuckau
|
2018-04-19 16:00:14 +02:00
|
|
|
|
})
|
2018-03-12 22:43:50 +01:00
|
|
|
|
|
|
|
|
|
t.end()
|
|
|
|
|
}))
|
|
|
|
|
|
2018-06-29 14:58:43 +02:00
|
|
|
|
test('trip details', co(function* (t) {
|
2018-04-19 16:00:14 +02:00
|
|
|
|
const journeys = yield client.journeys(magdeburgHbf, magdeburgBuckau, {
|
2018-05-31 13:42:54 +02:00
|
|
|
|
results: 1, departure: when
|
2018-03-13 21:04:42 +01:00
|
|
|
|
})
|
|
|
|
|
|
2018-04-19 16:00:14 +02:00
|
|
|
|
const p = journeys[0].legs[0]
|
|
|
|
|
t.ok(p.id, 'precondition failed')
|
|
|
|
|
t.ok(p.line.name, 'precondition failed')
|
2018-06-29 14:58:43 +02:00
|
|
|
|
const trip = yield client.trip(p.id, p.line.name, {when})
|
2018-03-13 21:04:42 +01:00
|
|
|
|
|
2018-06-29 14:58:43 +02:00
|
|
|
|
validate(t, trip, 'journeyLeg', 'trip')
|
2018-04-19 16:00:14 +02:00
|
|
|
|
t.end()
|
|
|
|
|
}))
|
2018-03-13 21:04:42 +01:00
|
|
|
|
|
2018-04-24 16:58:17 +02:00
|
|
|
|
test('departures at Magdeburg Leiterstr.', co(function*(t) {
|
|
|
|
|
const departures = yield client.departures(leiterstr, {
|
|
|
|
|
duration: 5, when
|
2018-04-19 16:00:14 +02:00
|
|
|
|
})
|
2018-03-13 21:04:42 +01:00
|
|
|
|
|
2018-04-24 16:58:17 +02:00
|
|
|
|
yield testDepartures({
|
|
|
|
|
test: t,
|
|
|
|
|
departures,
|
|
|
|
|
validate,
|
|
|
|
|
id: leiterstr
|
|
|
|
|
})
|
2018-03-13 21:04:42 +01:00
|
|
|
|
t.end()
|
|
|
|
|
}))
|
|
|
|
|
|
2018-04-19 16:00:14 +02:00
|
|
|
|
test('departures with station object', co(function* (t) {
|
|
|
|
|
const deps = yield client.departures({
|
|
|
|
|
type: 'station',
|
|
|
|
|
id: magdeburgHbf,
|
|
|
|
|
name: 'Magdeburg Hbf',
|
|
|
|
|
location: {
|
|
|
|
|
type: 'location',
|
|
|
|
|
latitude: 1.23,
|
|
|
|
|
longitude: 2.34
|
|
|
|
|
}
|
|
|
|
|
}, {when})
|
|
|
|
|
|
|
|
|
|
validate(t, deps, 'departures', 'departures')
|
|
|
|
|
t.end()
|
|
|
|
|
}))
|
|
|
|
|
|
2018-07-07 21:26:40 +02:00
|
|
|
|
test('departures at Leiterstr in direction of Universität', co(function* (t) {
|
|
|
|
|
yield testDeparturesInDirection({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchDepartures: client.departures,
|
|
|
|
|
fetchTrip: client.trip,
|
|
|
|
|
id: leiterstr,
|
|
|
|
|
directionIds: [universitaet],
|
|
|
|
|
when,
|
|
|
|
|
validate
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
}))
|
|
|
|
|
|
2018-06-26 17:30:46 +02:00
|
|
|
|
test('arrivals at Magdeburg Leiterstr.', co(function*(t) {
|
|
|
|
|
const arrivals = yield client.arrivals(leiterstr, {
|
|
|
|
|
duration: 5, when
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
yield testArrivals({
|
|
|
|
|
test: t,
|
|
|
|
|
arrivals,
|
|
|
|
|
validate,
|
|
|
|
|
id: leiterstr
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
}))
|
|
|
|
|
|
2018-04-19 16:00:14 +02:00
|
|
|
|
// todo: nearby
|
|
|
|
|
|
2018-03-12 22:43:50 +01:00
|
|
|
|
test('locations named Magdeburg', co(function*(t) {
|
|
|
|
|
const locations = yield client.locations('Magdeburg', {
|
2018-04-19 16:00:14 +02:00
|
|
|
|
results: 20
|
2018-02-26 23:23:00 +01:00
|
|
|
|
})
|
2018-03-12 22:43:50 +01:00
|
|
|
|
|
2018-04-19 16:00:14 +02:00
|
|
|
|
validate(t, locations, 'locations', 'locations')
|
|
|
|
|
t.ok(locations.length <= 20)
|
2018-03-12 22:43:50 +01:00
|
|
|
|
|
2018-07-11 13:25:22 +02:00
|
|
|
|
t.ok(locations.find(s => s.type === 'stop' || s.type === 'station'))
|
2018-04-19 16:00:14 +02:00
|
|
|
|
t.ok(locations.find(s => s.id && s.name)) // POIs
|
2018-07-11 13:25:22 +02:00
|
|
|
|
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
|
2018-04-19 16:00:14 +02:00
|
|
|
|
}))
|
2018-03-12 22:43:50 +01:00
|
|
|
|
|
|
|
|
|
t.end()
|
|
|
|
|
}))
|
|
|
|
|
|
2018-06-10 14:57:51 +02:00
|
|
|
|
test('station Magdeburg-Buckau', co(function* (t) {
|
|
|
|
|
const s = yield client.station(magdeburgBuckau)
|
2018-03-12 22:43:50 +01:00
|
|
|
|
|
2018-07-11 13:25:22 +02:00
|
|
|
|
validate(t, s, ['stop', 'station'], 'station')
|
2018-04-19 16:00:14 +02:00
|
|
|
|
t.equal(s.id, magdeburgBuckau)
|
2018-03-12 22:43:50 +01:00
|
|
|
|
|
|
|
|
|
t.end()
|
|
|
|
|
}))
|
2018-03-13 21:06:27 +01:00
|
|
|
|
|
|
|
|
|
test('radar', co(function* (t) {
|
2018-04-19 16:00:14 +02:00
|
|
|
|
const vehicles = yield client.radar({
|
|
|
|
|
north: 52.148364,
|
|
|
|
|
west: 11.600826,
|
|
|
|
|
south: 52.108486,
|
|
|
|
|
east: 11.651451
|
|
|
|
|
}, {
|
2018-03-13 21:06:27 +01:00
|
|
|
|
duration: 5 * 60, when, results: 10
|
|
|
|
|
})
|
|
|
|
|
|
2018-04-19 16:00:14 +02:00
|
|
|
|
const customCfg = Object.assign({}, cfg, {
|
|
|
|
|
stationCoordsOptional: true, // see #28
|
|
|
|
|
})
|
|
|
|
|
const validate = createValidate(customCfg, {})
|
|
|
|
|
validate(t, vehicles, 'movements', 'vehicles')
|
2018-03-13 21:06:27 +01:00
|
|
|
|
|
|
|
|
|
t.end()
|
|
|
|
|
}))
|