db-vendo-client/test/e2e/pkp.js

156 lines
3.6 KiB
JavaScript
Raw Normal View History

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 pkpProfile} from '../../p/pkp/index.js'
import {
createValidateLine,
createValidateJourneyLeg,
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 {testArrivals} from './lib/arrivals.js'
import {testReachableFrom} from './lib/reachable-from.js'
2020-03-12 18:21:16 +01:00
const T_MOCK = 1641897000 * 1000 // 2022-01-11T11:30:00+01
const when = createWhen(pkpProfile.timezone, pkpProfile.locale, T_MOCK)
2020-03-12 18:21:16 +01:00
const cfg = {
when,
stationCoordsOptional: false,
2022-05-07 16:17:37 +02:00
products: pkpProfile.products,
2020-03-12 18:21:16 +01:00
minLatitude: 40,
maxLatitude: 65,
minLongitude: 10,
maxLongitude: 30,
}
const _validateLine = createValidateLine(cfg)
const validateLine = (validate, l, name) => {
if (!l.direction) l = Object.assign({}, l, { direction: 'foo' })
_validateLine(validate, l, name)
}
const _validateJourneyLeg = createValidateJourneyLeg(cfg)
const validateJourneyLeg = (validate, l, name) => {
if (!l.direction) l = Object.assign({}, l, { direction: 'foo' })
_validateJourneyLeg(validate, l, name)
}
2022-05-07 16:17:37 +02:00
const _validateMovement = createValidateMovement(cfg)
2020-03-12 18:21:16 +01:00
const validateMovement = (val, m, name) => {
if (!m.direction) m = Object.assign({}, m, { direction: 'foo' })
_validateMovement(val, m, name)
}
const validate = createValidate(cfg, {
line: validateLine,
journeyLeg: validateJourneyLeg,
movement: validateMovement
})
const client = createClient(pkpProfile, 'public-transport/hafas-client:test')
const wrocławGł = '5100069'
const krakówGł = '5100028'
const dworcowa100 = {
type: 'location',
address: 'Bydgoszcz, Dworcowa 100',
latitude: 53.1336648,
longitude: 17.9908571
}
const filharmonia = {
type: 'location',
id: '980013218',
latitude: 54.351487,
longitude: 18.659548,
name: 'Gdańsk, Filharmonia',
poi: true
}
2021-05-20 16:42:43 +01:00
tap.skip('journeys Wrocław Główny to Kraków Główny', async (t) => {
2020-03-12 18:21:16 +01:00
const res = await client.journeys(wrocławGł, krakówGł, {
results: 4,
departure: when,
stopovers: true
})
await testJourneysStationToStation({
test: t,
res,
validate,
fromId: wrocławGł,
toId: krakówGł
})
t.end()
})
// todo: via works with detour
// todo: without detour
2021-05-20 16:42:43 +01:00
tap.skip('trip details', async (t) => {
2020-03-12 18:21:16 +01:00
const res = await client.journeys(wrocławGł, krakówGł, {
results: 1, departure: when
})
const p = res.journeys[0].legs.find(l => !l.walking)
2020-03-12 18:21:16 +01:00
t.ok(p.tripId, 'precondition failed')
t.ok(p.line.name, 'precondition failed')
const tripRes = await client.trip(p.tripId, {when})
validate(t, tripRes, 'tripResult', 'res')
2020-03-12 18:21:16 +01:00
t.end()
})
2021-05-20 16:42:43 +01:00
tap.skip('arrivals at Kraków Główny', async (t) => {
2020-03-12 18:21:16 +01:00
const arrivals = await client.arrivals(krakówGł, {
duration: 10, when
})
await testArrivals({
test: t,
arrivals,
id: krakówGł,
validate
})
t.end()
})
2021-05-20 16:42:43 +01:00
tap.skip('nearby', async (t) => {
2020-03-12 18:21:16 +01:00
const nearby = await client.nearby(dworcowa100, { distance: 500 })
validate(t, nearby, 'locations', 'nearby')
const bydgoszczGł = '5100005'
t.ok(nearby.find(l => l.id === bydgoszczGł))
t.end()
})
2021-05-20 16:42:43 +01:00
tap.skip('radar', async (t) => {
const res = await client.radar({
2020-03-12 18:21:16 +01:00
north: 48.74453,
west: 11.42733,
south: 48.73453,
east: 11.43733
}, {
duration: 5 * 60, when, results: 10
})
validate(t, res, 'radarResult', 'res')
2020-03-12 18:21:16 +01:00
t.end()
})
2021-05-20 16:42:43 +01:00
tap.skip('reachableFrom', async (t) => {
2020-03-12 18:21:16 +01:00
await testReachableFrom({
test: t,
reachableFrom: client.reachableFrom,
address: dworcowa100,
when,
maxDuration: 20,
validate
})
t.end()
})