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

113 lines
2.5 KiB
JavaScript
Raw Normal View History

2022-05-07 16:17:37 +02:00
import tap from 'tap'
2020-03-11 22:58:12 +01:00
2022-05-07 16:17:37 +02:00
import {createWhen} from './lib/util.js'
import {createClient} from '../../index.js'
import {profile as rmvProfile} from '../../p/rmv/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'
2020-03-11 22:58:12 +01:00
const T_MOCK = 1668495600 * 1000 // 2022-11-15T08:00:00+01:00
const when = createWhen(rmvProfile.timezone, rmvProfile.locale, T_MOCK)
2020-03-11 22:58:12 +01:00
const cfg = {
when,
stationCoordsOptional: false,
2022-05-07 16:17:37 +02:00
products: rmvProfile.products,
2020-03-11 22:58:12 +01:00
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'
2021-05-20 16:42:43 +01:00
tap.test('journeys  Frankfurt Ostendstr. to Wiesbaden Hbf', async (t) => {
2020-03-11 22:58:12 +01:00
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
2021-05-20 16:42:43 +01:00
tap.test('trip details', async (t) => {
2020-03-11 22:58:12 +01:00
const res = await client.journeys(frankfurtOstendstr, wiesbadenHbf, {
results: 1, departure: when
})
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 tripRes = await client.trip(p.tripId, {when})
validate(t, tripRes, 'tripResult', 'res')
2020-03-11 22:58:12 +01:00
t.end()
})
2021-05-20 16:42:43 +01:00
tap.test('arrivals at Wiesbaden Hbf', async (t) => {
const res = await client.arrivals(wiesbadenHbf, {
2020-03-11 22:58:12 +01:00
duration: 10, when
})
await testArrivals({
test: t,
res,
validate,
id: wiesbadenHbf,
})
2020-03-11 22:58:12 +01:00
t.end()
})
// todo: nearby
tap.test('radar', async (t) => {
const res = await client.radar({
2020-03-11 22:58:12 +01:00
north: 53.090516,
west: 8.750106,
south: 53.062859,
east: 8.847423
}, {
duration: 5 * 60, when, results: 10
})
validate(t, res, 'radarResult', 'res')
2020-03-11 22:58:12 +01:00
t.end()
})
2021-05-20 16:42:43 +01:00
tap.test('reachableFrom', async (t) => {
2020-03-11 22:58:12 +01:00
await testReachableFrom({
test: t,
reachableFrom: client.reachableFrom,
address: {
type: 'location',
id: '9001709',
name: 'Frankfurt (Main) Musterschule',
2020-03-11 22:58:12 +01:00
poi: true,
latitude: 50.122027, longitude: 8.68536,
2020-03-11 22:58:12 +01:00
},
when,
maxDuration: 15,
validate
})
t.end()
})