2022-05-07 16:17:37 +02:00
|
|
|
|
import tap from 'tap'
|
|
|
|
|
import isRoughlyEqual from 'is-roughly-equal'
|
2018-02-26 23:23:00 +01:00
|
|
|
|
|
2022-05-07 16:17:37 +02:00
|
|
|
|
import {createWhen} from './lib/util.js'
|
|
|
|
|
import {createClient} from '../../index.js'
|
|
|
|
|
import {profile as insaProfile} from '../../p/insa/index.js'
|
|
|
|
|
import {
|
|
|
|
|
createValidateMovement,
|
|
|
|
|
createValidateJourneyLeg,
|
|
|
|
|
} from './lib/validators.js'
|
|
|
|
|
import {createValidateFptfWith as createValidate} from './lib/validate-fptf-with.js'
|
|
|
|
|
import {testJourneysStationToStation} from './lib/journeys-station-to-station.js'
|
|
|
|
|
import {testJourneysStationToAddress} from './lib/journeys-station-to-address.js'
|
|
|
|
|
import {testJourneysStationToPoi} from './lib/journeys-station-to-poi.js'
|
|
|
|
|
import {testEarlierLaterJourneys} from './lib/earlier-later-journeys.js'
|
|
|
|
|
import {journeysFailsWithNoProduct} from './lib/journeys-fails-with-no-product.js'
|
|
|
|
|
import {testDepartures} from './lib/departures.js'
|
|
|
|
|
import {testDeparturesInDirection} from './lib/departures-in-direction.js'
|
|
|
|
|
import {testArrivals} from './lib/arrivals.js'
|
|
|
|
|
import {testJourneysWithDetour} from './lib/journeys-with-detour.js'
|
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
|
|
|
|
|
2022-04-28 21:55:37 +02:00
|
|
|
|
const T_MOCK = 1652175000 * 1000 // 2022-05-10T11:30+02:00
|
2022-04-23 14:40:51 +02:00
|
|
|
|
const when = createWhen(insaProfile.timezone, insaProfile.locale, T_MOCK)
|
2018-02-26 23:23:00 +01:00
|
|
|
|
|
2018-04-19 16:00:14 +02:00
|
|
|
|
const cfg = {
|
|
|
|
|
when,
|
|
|
|
|
stationCoordsOptional: false,
|
2022-05-07 16:17:37 +02:00
|
|
|
|
products: insaProfile.products,
|
2019-02-15 14:53:01 +01:00
|
|
|
|
minLatitude: 50.7,
|
|
|
|
|
maxLatitude: 53.2,
|
2022-11-09 18:25:04 +01:00
|
|
|
|
minLongitude: 9, // considering e.g. IC 245
|
2019-02-15 14:53:01 +01:00
|
|
|
|
maxLongitude: 13.4
|
2018-03-12 22:43:50 +01:00
|
|
|
|
}
|
2018-02-26 23:23:00 +01:00
|
|
|
|
|
2020-05-22 01:36:04 +02:00
|
|
|
|
const withFakeDirection = (validate) => (val, item, name) => {
|
|
|
|
|
validate(val, {
|
|
|
|
|
...item,
|
|
|
|
|
direction: item.direction === null ? 'foo' : item.direction,
|
|
|
|
|
}, name)
|
|
|
|
|
}
|
|
|
|
|
const validators = {
|
|
|
|
|
movement: withFakeDirection(createValidateMovement(cfg)),
|
|
|
|
|
journeyLeg: withFakeDirection(createValidateJourneyLeg(cfg)),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const validate = createValidate(cfg, validators)
|
2018-02-26 23:23:00 +01:00
|
|
|
|
|
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'
|
2022-04-28 21:55:37 +02:00
|
|
|
|
const spielhagenstr = '7336'
|
2021-12-29 15:18:21 +01:00
|
|
|
|
const hasselbachplatz = '90443'
|
2019-01-16 22:05:21 +08:00
|
|
|
|
const stendal = '8010334'
|
|
|
|
|
const dessau = '8010077'
|
2018-07-07 21:26:40 +02:00
|
|
|
|
const universitaet = '19686'
|
2018-04-19 16:00:14 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('journeys – Magdeburg Hbf to Magdeburg-Buckau', async (t) => {
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(magdeburgHbf, magdeburgBuckau, {
|
2019-02-01 15:35:18 +01:00
|
|
|
|
results: 4,
|
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-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToStation({
|
2018-04-23 13:56:00 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-04-23 13:56:00 +02:00
|
|
|
|
validate,
|
|
|
|
|
fromId: magdeburgHbf,
|
|
|
|
|
toId: magdeburgBuckau
|
|
|
|
|
})
|
2018-03-12 22:43:50 +01:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-12 22:43:50 +01:00
|
|
|
|
|
2018-04-19 16:00:14 +02:00
|
|
|
|
// todo: journeys, only one product
|
2018-04-25 13:07:31 +02:00
|
|
|
|
|
2021-12-29 18:53:50 +01:00
|
|
|
|
tap.test('journeys – fails with no product', async (t) => {
|
|
|
|
|
await journeysFailsWithNoProduct({
|
2018-04-25 13:07:31 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
fromId: magdeburgHbf,
|
|
|
|
|
toId: magdeburgBuckau,
|
|
|
|
|
when,
|
2022-05-07 16:17:37 +02:00
|
|
|
|
products: insaProfile.products,
|
2018-04-25 13:07:31 +02:00
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
2018-04-19 16:00:14 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('Magdeburg Hbf to 39104 Magdeburg, Sternstr. 10', async (t) => {
|
2018-03-12 22:43:50 +01:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await 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-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToAddress({
|
2018-04-24 15:42:53 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-04-24 15:42:53 +02:00
|
|
|
|
validate,
|
|
|
|
|
fromId: magdeburgHbf,
|
|
|
|
|
to: sternStr
|
|
|
|
|
})
|
2018-03-12 22:43:50 +01:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-12 22:43:50 +01:00
|
|
|
|
|
2022-11-09 21:17:32 +01:00
|
|
|
|
tap.test('Magdeburg Hbf to Kloster Unser Lieben Frauen', async (t) => {
|
2018-03-12 22:43:50 +01:00
|
|
|
|
const kloster = {
|
|
|
|
|
type: 'location',
|
2018-04-19 16:00:14 +02:00
|
|
|
|
id: '970012223',
|
2019-02-07 17:47:50 +01:00
|
|
|
|
poi: true,
|
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
|
|
|
|
}
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await 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
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToPoi({
|
2018-04-24 16:10:56 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-04-24 16:10:56 +02:00
|
|
|
|
validate,
|
|
|
|
|
fromId: magdeburgHbf,
|
|
|
|
|
to: kloster
|
2018-02-26 23:23:00 +01:00
|
|
|
|
})
|
2018-03-12 22:43:50 +01:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-12 22:43:50 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('journeys: via works – with detour', async (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.
|
2021-12-29 15:18:21 +01:00
|
|
|
|
const res = await client.journeys(hasselbachplatz, 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-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysWithDetour({
|
2018-05-13 00:34:26 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-05-13 00:34:26 +02:00
|
|
|
|
validate,
|
2019-01-16 22:05:21 +08:00
|
|
|
|
detourIds: [dessau]
|
2018-04-19 16:00:14 +02:00
|
|
|
|
})
|
2018-03-16 15:32:19 +01:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-16 15:32:19 +01:00
|
|
|
|
|
2018-04-25 13:24:27 +02:00
|
|
|
|
// todo: without detour
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('earlier/later journeys', async (t) => {
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testEarlierLaterJourneys({
|
2018-04-24 15:24:59 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: magdeburgHbf,
|
2018-11-20 18:38:48 +01:00
|
|
|
|
toId: magdeburgBuckau,
|
|
|
|
|
when
|
2018-04-19 16:00:14 +02:00
|
|
|
|
})
|
2018-03-12 22:43:50 +01:00
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-12 22:43:50 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('trip details', async (t) => {
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(magdeburgHbf, magdeburgBuckau, {
|
2018-05-31 13:42:54 +02:00
|
|
|
|
results: 1, departure: when
|
2018-03-13 21:04:42 +01:00
|
|
|
|
})
|
|
|
|
|
|
2020-04-09 14:53:28 +02:00
|
|
|
|
const p = res.journeys[0].legs.find(l => !l.walking)
|
2018-11-22 00:17:28 +01:00
|
|
|
|
t.ok(p.tripId, 'precondition failed')
|
2018-04-19 16:00:14 +02:00
|
|
|
|
t.ok(p.line.name, 'precondition failed')
|
2018-03-13 21:04:42 +01:00
|
|
|
|
|
2021-12-29 21:33:42 +01:00
|
|
|
|
const tripRes = await client.trip(p.tripId, {when})
|
2021-12-29 21:23:28 +01:00
|
|
|
|
|
|
|
|
|
validate(t, tripRes, 'tripResult', 'res')
|
2018-04-19 16:00:14 +02:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-13 21:04:42 +01:00
|
|
|
|
|
2022-04-28 21:55:37 +02:00
|
|
|
|
tap.test('departures at Magdeburg Universität', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.departures(universitaet, {
|
2022-04-28 21:55:37 +02:00
|
|
|
|
duration: 30, when,
|
2018-04-19 16:00:14 +02:00
|
|
|
|
})
|
2018-03-13 21:04:42 +01:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testDepartures({
|
2018-04-24 16:58:17 +02:00
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2018-04-24 16:58:17 +02:00
|
|
|
|
validate,
|
2022-04-28 21:55:37 +02:00
|
|
|
|
id: universitaet
|
2018-04-24 16:58:17 +02:00
|
|
|
|
})
|
2018-03-13 21:04:42 +01:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-13 21:04:42 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('departures with station object', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.departures({
|
2022-04-28 21:55:37 +02:00
|
|
|
|
type: 'stop',
|
|
|
|
|
id: universitaet,
|
|
|
|
|
name: 'Universität',
|
2018-04-19 16:00:14 +02:00
|
|
|
|
location: {
|
|
|
|
|
type: 'location',
|
|
|
|
|
latitude: 1.23,
|
|
|
|
|
longitude: 2.34
|
|
|
|
|
}
|
2022-04-28 21:55:37 +02:00
|
|
|
|
}, {
|
|
|
|
|
duration: 30, when,
|
|
|
|
|
})
|
2018-04-19 16:00:14 +02:00
|
|
|
|
|
2021-12-29 21:11:07 +01:00
|
|
|
|
validate(t, res, 'departuresResponse', 'res')
|
2018-04-19 16:00:14 +02:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-04-19 16:00:14 +02:00
|
|
|
|
|
2022-04-28 21:55:37 +02:00
|
|
|
|
// todo: deps empty, wrong loc ID?
|
|
|
|
|
tap.test('departures at Universität in direction of Spielhagenstr.', async (t) => {
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testDeparturesInDirection({
|
2018-07-07 21:26:40 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchDepartures: client.departures,
|
|
|
|
|
fetchTrip: client.trip,
|
2022-04-28 21:55:37 +02:00
|
|
|
|
id: universitaet,
|
|
|
|
|
directionIds: [spielhagenstr],
|
2018-07-07 21:26:40 +02:00
|
|
|
|
when,
|
|
|
|
|
validate
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-07-07 21:26:40 +02:00
|
|
|
|
|
2022-04-28 21:55:37 +02:00
|
|
|
|
tap.test('arrivals at Magdeburg Universität', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.arrivals(universitaet, {
|
2022-04-28 21:55:37 +02:00
|
|
|
|
duration: 30, when
|
2018-06-26 17:30:46 +02:00
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testArrivals({
|
2018-06-26 17:30:46 +02:00
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2018-06-26 17:30:46 +02:00
|
|
|
|
validate,
|
2022-04-28 21:55:37 +02:00
|
|
|
|
id: universitaet
|
2018-06-26 17:30:46 +02:00
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-06-26 17:30:46 +02:00
|
|
|
|
|
2018-04-19 16:00:14 +02:00
|
|
|
|
// todo: nearby
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('locations named Magdeburg', async (t) => {
|
2019-02-15 14:53:01 +01:00
|
|
|
|
const nordpark = '7480'
|
2018-11-21 19:07:37 +01:00
|
|
|
|
const locations = await client.locations('nordpark', {
|
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'))
|
2019-02-07 17:47:50 +01:00
|
|
|
|
t.ok(locations.find(s => s.poi)) // POIs
|
2018-07-11 13:25:22 +02:00
|
|
|
|
t.ok(locations.some((l) => {
|
2019-01-16 22:05:21 +08:00
|
|
|
|
return l.station && l.station.id === nordpark || l.id === nordpark
|
2018-04-19 16:00:14 +02:00
|
|
|
|
}))
|
2018-03-12 22:43:50 +01:00
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-12 22:43:50 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('station Magdeburg-Buckau', async (t) => {
|
2018-11-21 19:55:37 +01:00
|
|
|
|
const s = await client.stop(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-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-13 21:06:27 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('radar', async (t) => {
|
2021-12-29 21:24:07 +01:00
|
|
|
|
const res = await client.radar({
|
2018-04-19 16:00:14 +02:00
|
|
|
|
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
|
|
|
|
|
})
|
2020-05-22 01:36:04 +02:00
|
|
|
|
const validate = createValidate(customCfg, validators)
|
2021-12-29 21:24:07 +01:00
|
|
|
|
validate(t, res, 'radarResult', 'res')
|
2018-03-13 21:06:27 +01:00
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|