2022-05-07 16:17:37 +02:00
|
|
|
|
import tap from 'tap'
|
|
|
|
|
import isRoughlyEqual from 'is-roughly-equal'
|
2020-07-20 18:21:38 +02:00
|
|
|
|
|
2022-05-07 16:17:37 +02:00
|
|
|
|
import {createWhen} from './lib/util.js'
|
|
|
|
|
import {createClient} from '../../index.js'
|
|
|
|
|
import {profile as zvvProfile} from '../../p/zvv/index.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 {testDepartures} from './lib/departures.js'
|
|
|
|
|
import {testDeparturesInDirection} from './lib/departures-in-direction.js'
|
|
|
|
|
import {testArrivals} from './lib/arrivals.js'
|
2020-07-20 18:21:38 +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(zvvProfile.timezone, zvvProfile.locale, T_MOCK)
|
2020-07-20 18:21:38 +02:00
|
|
|
|
|
|
|
|
|
const validate = createValidate({
|
|
|
|
|
when,
|
2022-05-07 16:17:37 +02:00
|
|
|
|
products: zvvProfile.products,
|
2020-07-20 18:21:38 +02:00
|
|
|
|
maxLatitude: 47.75,
|
|
|
|
|
minLongitude: 7.38,
|
|
|
|
|
minLatitude: 46.99,
|
|
|
|
|
maxLongitude: 9.71,
|
|
|
|
|
}, {})
|
|
|
|
|
|
|
|
|
|
const client = createClient(zvvProfile, 'public-transport/hafas-client:test')
|
|
|
|
|
|
|
|
|
|
const bürkliplatz = '8591105'
|
|
|
|
|
const ethUniversitätsspital = '8591123'
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('journeys – Bürkliplatz to ETH/Universitätsspital', async (t) => {
|
2020-07-20 18:21:38 +02:00
|
|
|
|
const res = await client.journeys(bürkliplatz, ethUniversitätsspital, {
|
|
|
|
|
results: 4,
|
|
|
|
|
departure: when,
|
|
|
|
|
stopovers: true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await testJourneysStationToStation({
|
|
|
|
|
test: t,
|
|
|
|
|
res,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: bürkliplatz,
|
|
|
|
|
toId: ethUniversitätsspital
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('earlier/later journeys', async (t) => {
|
2020-07-20 18:21:38 +02:00
|
|
|
|
await testEarlierLaterJourneys({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: bürkliplatz,
|
|
|
|
|
toId: ethUniversitätsspital,
|
|
|
|
|
when
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('trip details', async (t) => {
|
2020-07-20 18:21:38 +02:00
|
|
|
|
const res = await client.journeys(bürkliplatz, ethUniversitätsspital, {
|
|
|
|
|
results: 1, departure: when
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const p = res.journeys[0].legs.find(l => !l.walking)
|
|
|
|
|
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-07-20 18:21:38 +02:00
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-12-29 15:18:21 +01:00
|
|
|
|
tap.test('departures at ETH/Universitätsspital', async (t) => { // todo
|
|
|
|
|
const polyterrasseETH = '8503500'
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.departures(ethUniversitätsspital, {
|
2020-07-20 18:21:38 +02:00
|
|
|
|
duration: 5, when,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await testDepartures({
|
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2020-07-20 18:21:38 +02:00
|
|
|
|
validate,
|
2021-12-29 15:18:21 +01:00
|
|
|
|
ids: [ethUniversitätsspital, polyterrasseETH],
|
2020-07-20 18:21:38 +02:00
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// todo: departures in direction
|
|
|
|
|
// todo: nearby
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('locations named Rennweg', async (t) => {
|
2020-07-20 18:21:38 +02:00
|
|
|
|
const rennweg = '8591316'
|
|
|
|
|
const locations = await client.locations('Rennweg', {
|
|
|
|
|
results: 20,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
validate(t, locations, 'locations', 'locations')
|
|
|
|
|
t.ok(locations.length <= 20)
|
|
|
|
|
|
|
|
|
|
t.ok(locations.find(s => s.type === 'stop' || s.type === 'station'))
|
|
|
|
|
t.ok(locations.some((l) => {
|
|
|
|
|
return l.station && l.station.id === rennweg || l.id === rennweg
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
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({
|
2020-07-20 18:21:38 +02:00
|
|
|
|
north: 47.387,
|
|
|
|
|
west: 8.514,
|
|
|
|
|
south: 47.356,
|
|
|
|
|
east: 8.568,
|
|
|
|
|
}, {
|
|
|
|
|
duration: 5 * 60, when, results: 10,
|
|
|
|
|
})
|
|
|
|
|
|
2021-12-29 21:24:07 +01:00
|
|
|
|
validate(t, res, 'radarResult', 'res')
|
2020-07-20 18:21:38 +02:00
|
|
|
|
t.end()
|
|
|
|
|
})
|