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

158 lines
3.6 KiB
JavaScript
Raw Normal View History

2020-03-12 18:21:16 +01:00
'use strict'
2021-05-20 16:42:43 +01:00
const tap = require('tap')
2020-03-12 18:21:16 +01:00
const { createWhen } = require('./lib/util')
const createClient = require('../..')
const pkpProfile = require('../../p/pkp')
const products = require('../../p/pkp/products')
const {
line: createValidateLine,
journeyLeg: createValidateJourneyLeg,
movement: _validateMovement
} = require('./lib/validators')
const createValidate = require('./lib/validate-fptf-with')
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
const testArrivals = require('./lib/arrivals')
const testReachableFrom = require('./lib/reachable-from')
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,
products,
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)
}
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, p.line.name, {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()
})