2022-05-07 16:17:37 +02:00
|
|
|
|
import tap from 'tap'
|
|
|
|
|
|
|
|
|
|
import {createWhen} from './lib/util.js'
|
|
|
|
|
import {createClient} from '../../index.js'
|
|
|
|
|
import {profile as sMunichProfile} from '../../p/sbahn-muenchen/index.js'
|
|
|
|
|
import {createValidateMovement as _createValidateMovement} 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 {testRefreshJourney} from './lib/refresh-journey.js'
|
|
|
|
|
import {journeysFailsWithNoProduct} from './lib/journeys-fails-with-no-product.js'
|
|
|
|
|
import {testDepartures} from './lib/departures.js'
|
|
|
|
|
import {testArrivals} from './lib/arrivals.js'
|
|
|
|
|
import {testJourneysWithDetour} from './lib/journeys-with-detour.js'
|
|
|
|
|
import {testReachableFrom} from './lib/reachable-from.js'
|
2018-09-07 20:23:48 +02:00
|
|
|
|
|
2022-05-03 17:16:17 +02:00
|
|
|
|
const T_MOCK = 1657618200 * 1000 // 2022-07-12T11:30+02:00
|
2022-04-23 14:40:51 +02:00
|
|
|
|
const when = createWhen(sMunichProfile.timezone, sMunichProfile.locale, T_MOCK)
|
2018-09-07 20:23:48 +02:00
|
|
|
|
|
|
|
|
|
const cfg = {
|
|
|
|
|
when,
|
|
|
|
|
stationCoordsOptional: false,
|
2022-05-07 16:17:37 +02:00
|
|
|
|
products: sMunichProfile.products,
|
2019-02-15 14:53:01 +01:00
|
|
|
|
minLatitude: 48,
|
|
|
|
|
maxLatitude: 48.3,
|
|
|
|
|
minLongitude: 11.3,
|
|
|
|
|
maxLongitude: 11.8
|
2018-09-07 20:23:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-07 16:17:37 +02:00
|
|
|
|
const _validateMovement = _createValidateMovement(cfg)
|
2018-09-07 20:23:48 +02:00
|
|
|
|
const validateMovement = (val, m, name = 'movement') => {
|
|
|
|
|
const dummyStopA = {type: 'stop', id: '123'}
|
|
|
|
|
const dummyStopB = {type: 'stop', id: '321'}
|
|
|
|
|
|
|
|
|
|
const withFakeFrame = Object.assign({}, m)
|
|
|
|
|
if (!m.frames.length) {
|
|
|
|
|
withFakeFrame.frames = [
|
|
|
|
|
{t: 5, origin: dummyStopA, destination: dummyStopB}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
_validateMovement(val, withFakeFrame, name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const validate = createValidate(cfg, {
|
|
|
|
|
movement: validateMovement
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const client = createClient(sMunichProfile, 'public-transport/hafas-client:test')
|
|
|
|
|
|
|
|
|
|
const mittersendling = '8004154'
|
2022-11-09 21:17:32 +01:00
|
|
|
|
const karlTheodorStr = '638842' // Karl-Theodor-Straße
|
|
|
|
|
const lehel = '624826'
|
2018-09-07 20:23:48 +02:00
|
|
|
|
const poetschnerstr = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
address: 'Pötschnerstraße 3, Neuhausen',
|
|
|
|
|
latitude: 48.152499,
|
|
|
|
|
longitude: 11.531695
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('journeys – Mittersendling to Karl-Theodor-Straße', async (t) => {
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(mittersendling, karlTheodorStr, {
|
2019-02-01 15:35:18 +01:00
|
|
|
|
results: 4,
|
2018-09-07 20:23:48 +02:00
|
|
|
|
departure: when,
|
|
|
|
|
stopovers: true
|
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToStation({
|
2018-09-07 20:23:48 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-09-07 20:23:48 +02:00
|
|
|
|
validate,
|
|
|
|
|
fromId: mittersendling,
|
|
|
|
|
toId: karlTheodorStr
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-09-07 20:23:48 +02:00
|
|
|
|
|
|
|
|
|
// todo: journeys, only one product
|
|
|
|
|
|
2021-12-29 18:53:50 +01:00
|
|
|
|
tap.test('journeys – fails with no product', async (t) => {
|
|
|
|
|
await journeysFailsWithNoProduct({
|
2018-09-07 20:23:48 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
fromId: mittersendling,
|
|
|
|
|
toId: karlTheodorStr,
|
|
|
|
|
when,
|
2022-05-07 16:17:37 +02:00
|
|
|
|
products: sMunichProfile.products,
|
2018-09-07 20:23:48 +02:00
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('Karl-Theodor-Straße to Pötschnerstraße 3, Neuhausen', async (t) => {
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(karlTheodorStr, poetschnerstr, {
|
2018-09-07 20:23:48 +02:00
|
|
|
|
results: 3,
|
|
|
|
|
departure: when
|
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToAddress({
|
2018-09-07 20:23:48 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-09-07 20:23:48 +02:00
|
|
|
|
validate,
|
|
|
|
|
fromId: karlTheodorStr,
|
|
|
|
|
to: poetschnerstr
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-09-07 20:23:48 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('Karl-Theodor-Straße to Hofbräuhaus', async (t) => {
|
2018-09-07 20:23:48 +02:00
|
|
|
|
const hofbraeuhaus = {
|
|
|
|
|
type: 'location',
|
2021-08-24 00:43:20 +02:00
|
|
|
|
id: '970008829',
|
2019-02-07 17:47:50 +01:00
|
|
|
|
poi: true,
|
2021-08-24 00:43:20 +02:00
|
|
|
|
name: 'München, Hofbräuhaus München',
|
2018-09-07 20:23:48 +02:00
|
|
|
|
latitude: 48.137739,
|
|
|
|
|
longitude: 11.579823
|
|
|
|
|
}
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(karlTheodorStr, hofbraeuhaus, {
|
2018-09-07 20:23:48 +02:00
|
|
|
|
results: 3,
|
|
|
|
|
departure: when
|
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToPoi({
|
2018-09-07 20:23:48 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-09-07 20:23:48 +02:00
|
|
|
|
validate,
|
|
|
|
|
fromId: karlTheodorStr,
|
|
|
|
|
to: hofbraeuhaus
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-09-07 20:23:48 +02:00
|
|
|
|
|
2018-10-29 22:11:08 +01:00
|
|
|
|
// todo: walkingSpeed "München - Freimann, Gyßlingstraße 78" -> lehel
|
2018-09-07 20:23:48 +02:00
|
|
|
|
// todo: via works – with detour
|
|
|
|
|
// 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-09-07 20:23:48 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: mittersendling,
|
2018-11-20 18:38:48 +01:00
|
|
|
|
toId: karlTheodorStr,
|
|
|
|
|
when
|
2018-09-07 20:23:48 +02:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-09-07 20:23:48 +02:00
|
|
|
|
|
2022-11-09 21:17:32 +01:00
|
|
|
|
// todo: for some reason, a leg is missing in the journey returned by refreshJourney()
|
|
|
|
|
tap.skip('refreshJourney', async (t) => {
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testRefreshJourney({
|
2018-09-07 20:23:48 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
refreshJourney: client.refreshJourney,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: mittersendling,
|
|
|
|
|
toId: karlTheodorStr,
|
|
|
|
|
when
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-09-07 20:23:48 +02: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(mittersendling, karlTheodorStr, {
|
2018-09-07 20:23:48 +02:00
|
|
|
|
results: 1, departure: when
|
|
|
|
|
})
|
|
|
|
|
|
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-09-07 20:23:48 +02:00
|
|
|
|
t.ok(p.line.name, 'precondition failed')
|
|
|
|
|
|
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-09-07 20:23:48 +02:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-09-07 20:23:48 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('departures at Dietlindenstraße', async (t) => {
|
2020-05-22 01:36:04 +02:00
|
|
|
|
const dietlindenstr = '624391'
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.departures(dietlindenstr, {
|
2018-12-28 21:17:03 +01:00
|
|
|
|
duration: 10, when,
|
2018-09-07 20:23:48 +02:00
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testDepartures({
|
2018-09-07 20:23:48 +02:00
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2018-09-07 20:23:48 +02:00
|
|
|
|
validate,
|
2020-05-22 01:36:04 +02:00
|
|
|
|
id: dietlindenstr
|
2018-09-07 20:23:48 +02:00
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-09-07 20:23:48 +02: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({
|
2018-09-07 20:23:48 +02:00
|
|
|
|
type: 'station',
|
|
|
|
|
id: mittersendling,
|
|
|
|
|
name: 'Mittersendling',
|
|
|
|
|
location: {
|
|
|
|
|
type: 'location',
|
|
|
|
|
latitude: 48.107418,
|
|
|
|
|
longitude: 11.536306
|
|
|
|
|
}
|
|
|
|
|
}, {when})
|
|
|
|
|
|
2021-12-29 21:11:07 +01:00
|
|
|
|
validate(t, res, 'departuresResponse', 'res')
|
2018-09-07 20:23:48 +02:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-09-07 20:23:48 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('arrivals at Karl-Theodor-Straße', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.arrivals(karlTheodorStr, {
|
2018-12-28 21:17:03 +01:00
|
|
|
|
duration: 10, when,
|
2018-09-07 20:23:48 +02:00
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testArrivals({
|
2018-09-07 20:23:48 +02:00
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2018-09-07 20:23:48 +02:00
|
|
|
|
validate,
|
|
|
|
|
id: karlTheodorStr
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-09-07 20:23:48 +02:00
|
|
|
|
|
|
|
|
|
// todo: nearby
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('locations named "Nationaltheater"', async (t) => {
|
2018-09-07 20:23:48 +02:00
|
|
|
|
const nationaltheater = '624639'
|
2018-11-21 19:07:37 +01:00
|
|
|
|
const locations = await client.locations('Nationaltheater', {
|
2018-09-07 20:23:48 +02:00
|
|
|
|
results: 10
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
validate(t, locations, 'locations', 'locations')
|
|
|
|
|
t.ok(locations.length <= 10)
|
|
|
|
|
|
|
|
|
|
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-09-07 20:23:48 +02:00
|
|
|
|
t.ok(locations.some((l) => {
|
2019-01-16 22:05:21 +08:00
|
|
|
|
return l.station && l.station.id === nationaltheater || l.id === nationaltheater
|
2018-09-07 20:23:48 +02:00
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-09-07 20:23:48 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('station Karl-Theodor-Straße', async (t) => {
|
2018-11-21 19:55:37 +01:00
|
|
|
|
const s = await client.stop(karlTheodorStr)
|
2018-09-07 20:23:48 +02:00
|
|
|
|
|
|
|
|
|
validate(t, s, ['stop', 'station'], 'station')
|
|
|
|
|
t.equal(s.id, karlTheodorStr)
|
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-09-07 20:23:48 +02: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-09-07 20:23:48 +02:00
|
|
|
|
north: 48.145121,
|
|
|
|
|
west: 11.543736,
|
|
|
|
|
south: 48.138339,
|
|
|
|
|
east: 11.553776
|
|
|
|
|
}, {
|
|
|
|
|
duration: 5 * 60, when, results: 10
|
|
|
|
|
})
|
|
|
|
|
|
2021-12-29 21:24:07 +01:00
|
|
|
|
validate(t, res, 'radarResult', 'res')
|
2018-09-07 20:23:48 +02:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-09-07 20:23:48 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('reachableFrom', async (t) => {
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testReachableFrom({
|
2018-09-07 20:23:48 +02:00
|
|
|
|
test: t,
|
|
|
|
|
reachableFrom: client.reachableFrom,
|
|
|
|
|
address: poetschnerstr,
|
|
|
|
|
when,
|
|
|
|
|
maxDuration: 15,
|
|
|
|
|
validate
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|