2020-03-11 22:58:12 +01:00
|
|
|
|
'use strict'
|
|
|
|
|
|
|
|
|
|
const {createWhen} = require('./lib/util')
|
|
|
|
|
const createClient = require('../..')
|
|
|
|
|
const rmvProfile = require('../../p/rmv')
|
|
|
|
|
const products = require('../../p/rmv/products')
|
|
|
|
|
const createValidate = require('./lib/validate-fptf-with')
|
2020-05-21 19:04:22 +02:00
|
|
|
|
const {test} = require('./lib/util')
|
2020-03-11 22:58:12 +01:00
|
|
|
|
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
|
|
|
|
const testRefreshJourney = require('./lib/refresh-journey')
|
|
|
|
|
const testArrivals = require('./lib/arrivals')
|
|
|
|
|
const testReachableFrom = require('./lib/reachable-from')
|
|
|
|
|
|
|
|
|
|
const when = createWhen(rmvProfile.timezone, rmvProfile.locale)
|
|
|
|
|
|
|
|
|
|
const cfg = {
|
|
|
|
|
when,
|
|
|
|
|
stationCoordsOptional: false,
|
|
|
|
|
products,
|
|
|
|
|
minLatitude: 47,
|
|
|
|
|
maxLatitude: 54,
|
|
|
|
|
minLongitude: 6,
|
|
|
|
|
maxLongitude: 11,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const validate = createValidate(cfg)
|
|
|
|
|
|
|
|
|
|
const client = createClient(rmvProfile, 'public-transport/hafas-client:test')
|
|
|
|
|
|
|
|
|
|
const frankfurtOstendstr = '3000525'
|
|
|
|
|
const wiesbadenHbf = '3006907'
|
|
|
|
|
|
|
|
|
|
test('journeys – Frankfurt Ostendstr. to Wiesbaden Hbf', async (t) => {
|
|
|
|
|
const res = await client.journeys(frankfurtOstendstr, wiesbadenHbf, {
|
|
|
|
|
results: 4,
|
|
|
|
|
departure: when,
|
|
|
|
|
stopovers: true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await testJourneysStationToStation({
|
|
|
|
|
test: t,
|
|
|
|
|
res,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: frankfurtOstendstr,
|
|
|
|
|
toId: wiesbadenHbf
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// todo: via works – with detour
|
|
|
|
|
// todo: without detour
|
|
|
|
|
|
|
|
|
|
test('trip details', async (t) => {
|
|
|
|
|
const res = await client.journeys(frankfurtOstendstr, wiesbadenHbf, {
|
|
|
|
|
results: 1, departure: when
|
|
|
|
|
})
|
|
|
|
|
|
2020-04-09 14:53:28 +02:00
|
|
|
|
const p = res.journeys[0].legs.find(l => !l.walking)
|
2020-03-11 22:58:12 +01:00
|
|
|
|
t.ok(p.tripId, 'precondition failed')
|
|
|
|
|
t.ok(p.line.name, 'precondition failed')
|
|
|
|
|
const trip = await client.trip(p.tripId, p.line.name, {when})
|
|
|
|
|
|
|
|
|
|
validate(t, trip, 'trip', 'trip')
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('arrivals at Wiesbaden Hbf', async (t) => {
|
|
|
|
|
const arrivals = await client.arrivals(wiesbadenHbf, {
|
|
|
|
|
duration: 10, when
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
validate(t, arrivals, 'arrivals', 'arrivals')
|
|
|
|
|
t.ok(arrivals.length > 0, 'must be >0 arrivals')
|
|
|
|
|
t.deepEqual(arrivals, arrivals.sort((a, b) => t.when > b.when))
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// todo: nearby
|
|
|
|
|
|
|
|
|
|
test('radar', async (t) => {
|
|
|
|
|
const vehicles = await client.radar({
|
|
|
|
|
north: 53.090516,
|
|
|
|
|
west: 8.750106,
|
|
|
|
|
south: 53.062859,
|
|
|
|
|
east: 8.847423
|
|
|
|
|
}, {
|
|
|
|
|
duration: 5 * 60, when, results: 10
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
validate(t, vehicles, 'movements', 'vehicles')
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2020-05-22 01:36:04 +02:00
|
|
|
|
// todo: always fails with `LOCATION` ("location/stop not found")
|
|
|
|
|
test.skip('reachableFrom', async (t) => {
|
2020-03-11 22:58:12 +01:00
|
|
|
|
await testReachableFrom({
|
|
|
|
|
test: t,
|
|
|
|
|
reachableFrom: client.reachableFrom,
|
|
|
|
|
address: {
|
|
|
|
|
type: 'location',
|
2020-05-22 01:36:04 +02:00
|
|
|
|
id: '9001709',
|
|
|
|
|
name: 'Frankfurt (Main) Musterschule',
|
2020-03-11 22:58:12 +01:00
|
|
|
|
poi: true,
|
2020-05-22 01:36:04 +02:00
|
|
|
|
latitude: 50.122027, longitude: 8.68536,
|
2020-03-11 22:58:12 +01:00
|
|
|
|
},
|
|
|
|
|
when,
|
|
|
|
|
maxDuration: 15,
|
|
|
|
|
validate
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|