2022-05-07 16:17:37 +02:00
|
|
|
|
import tap from 'tap'
|
2020-03-23 00:44:35 +01:00
|
|
|
|
|
2022-05-07 16:17:37 +02:00
|
|
|
|
import {createWhen} from './lib/util.js'
|
|
|
|
|
import {createClient} from '../../index.js'
|
|
|
|
|
import {profile as svvProfile} from '../../p/svv/index.js'
|
|
|
|
|
import {createValidateFptfWith as createValidate} from './lib/validate-fptf-with.js'
|
|
|
|
|
import {testJourneysStationToStation} from './lib/journeys-station-to-station.js'
|
|
|
|
|
import {testArrivals} from './lib/arrivals.js'
|
|
|
|
|
import {testReachableFrom} from './lib/reachable-from.js'
|
|
|
|
|
import {testServerInfo} from './lib/server-info.js'
|
2020-03-23 00:44:35 +01:00
|
|
|
|
|
2022-11-09 21:21:55 +01:00
|
|
|
|
const T_MOCK = 1671260400 * 1000 // 2022-12-17T08:00:00+01:00
|
2022-04-23 14:40:51 +02:00
|
|
|
|
const when = createWhen(svvProfile.timezone, svvProfile.locale, T_MOCK)
|
2020-03-23 00:44:35 +01:00
|
|
|
|
|
|
|
|
|
const cfg = {
|
|
|
|
|
when,
|
|
|
|
|
stationCoordsOptional: false,
|
2022-05-07 16:17:37 +02:00
|
|
|
|
products: svvProfile.products,
|
2020-03-23 00:44:35 +01:00
|
|
|
|
minLatitude: 45.742,
|
|
|
|
|
maxLatitude: 49.41,
|
|
|
|
|
minLongitude: 8.177,
|
|
|
|
|
maxLongitude: 18.448,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const validate = createValidate(cfg)
|
|
|
|
|
|
|
|
|
|
const client = createClient(svvProfile, 'public-transport/hafas-client:test')
|
|
|
|
|
|
|
|
|
|
const sam = '455086100'
|
|
|
|
|
const volksgarten = '455082100'
|
|
|
|
|
const zillnerstr2 = {
|
|
|
|
|
type: 'location',
|
2020-07-19 16:59:38 +02:00
|
|
|
|
id: '980133209',
|
2020-03-23 00:44:35 +01:00
|
|
|
|
address: 'Zillnerstraße 2, 5020 Salzburg',
|
|
|
|
|
latitude: 47.801434, longitude: 13.031006,
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('journeys – Sam to Volksgarten', async (t) => {
|
2020-03-23 00:44:35 +01:00
|
|
|
|
const res = await client.journeys(sam, volksgarten, {
|
|
|
|
|
results: 4,
|
|
|
|
|
departure: when,
|
|
|
|
|
stopovers: true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await testJourneysStationToStation({
|
|
|
|
|
test: t,
|
|
|
|
|
res,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: sam,
|
|
|
|
|
toId: volksgarten
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// todo: via works – with detour
|
|
|
|
|
// todo: without detour
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('trip details', async (t) => {
|
2020-03-23 00:44:35 +01:00
|
|
|
|
const res = await client.journeys(sam, volksgarten, {
|
|
|
|
|
results: 1, departure: when
|
|
|
|
|
})
|
|
|
|
|
|
2020-04-09 14:53:28 +02:00
|
|
|
|
const p = res.journeys[0].legs.find(l => !l.walking)
|
2020-03-23 00:44:35 +01:00
|
|
|
|
t.ok(p.tripId, 'precondition failed')
|
|
|
|
|
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')
|
2020-03-23 00:44:35 +01:00
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('arrivals at Volksgarten', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.arrivals(volksgarten, {
|
2020-03-23 00:44:35 +01:00
|
|
|
|
duration: 10, when
|
|
|
|
|
})
|
|
|
|
|
|
2022-04-28 21:55:11 +02:00
|
|
|
|
await testArrivals({
|
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2022-04-28 21:55:11 +02:00
|
|
|
|
validate,
|
|
|
|
|
id: volksgarten,
|
|
|
|
|
})
|
2020-03-23 00:44:35 +01:00
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// todo: nearby
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('reachableFrom', async (t) => {
|
2020-03-23 00:44:35 +01:00
|
|
|
|
await testReachableFrom({
|
|
|
|
|
test: t,
|
|
|
|
|
reachableFrom: client.reachableFrom,
|
|
|
|
|
address: zillnerstr2,
|
|
|
|
|
when,
|
|
|
|
|
maxDuration: 15,
|
|
|
|
|
validate
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
2020-03-09 19:47:29 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('serverInfo works', async (t) => {
|
2020-03-09 19:47:29 +01:00
|
|
|
|
await testServerInfo({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchServerInfo: client.serverInfo,
|
|
|
|
|
})
|
|
|
|
|
})
|