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

129 lines
2.7 KiB
JavaScript
Raw Normal View History

2022-05-07 16:17:37 +02:00
import tap from 'tap'
2020-03-10 23:48:01 +01:00
2022-05-07 16:17:37 +02:00
import {createWhen} from './lib/util.js'
import {createClient} from '../../index.js'
import {profile as rsagProfile} from '../../p/rsag/index.js'
import {createValidateFptfWith as createValidate} from './lib/validate-fptf-with.js'
import {testJourneysStationToStation} from './lib/journeys-station-to-station.js'
import {testEarlierLaterJourneys} from './lib/earlier-later-journeys.js'
import {testRefreshJourney} from './lib/refresh-journey.js'
import {testArrivals} from './lib/arrivals.js'
import {testReachableFrom} from './lib/reachable-from.js'
2020-03-10 23:48:01 +01:00
const T_MOCK = 1641897000 * 1000 // 2022-01-11T11:30:00+01
const when = createWhen(rsagProfile.timezone, rsagProfile.locale, T_MOCK)
2020-03-10 23:48:01 +01:00
const cfg = {
when,
// stationCoordsOptional: false,
2022-05-07 16:17:37 +02:00
products: rsagProfile.products,
2020-03-10 23:48:01 +01:00
minLatitude: 52.299,
maxLatitude: 54.862,
minLongitude: 9.121,
maxLongitude: 14.824,
}
const validate = createValidate(cfg)
const client = createClient(rsagProfile, 'public-transport/hafas-client:test')
const sternwarte = '704956'
const sternwarte2 = '708539'
const weißesKreuz = '708573'
2021-05-20 16:42:43 +01:00
tap.test('journeys  Platz der Jugend to Weißes Kreuz', async (t) => {
2020-03-10 23:48:01 +01:00
const res = await client.journeys(sternwarte, weißesKreuz, {
results: 4,
departure: when,
stopovers: true
})
await testJourneysStationToStation({
test: t,
res,
validate,
fromIds: [sternwarte, sternwarte2],
toId: weißesKreuz,
2020-03-10 23:48:01 +01:00
})
t.end()
})
// todo: journeys, walkingSpeed
// todo: via works with detour
2021-05-20 16:42:43 +01:00
tap.test('earlier/later journeys', async (t) => {
2020-03-10 23:48:01 +01:00
await testEarlierLaterJourneys({
test: t,
fetchJourneys: client.journeys,
validate,
fromId: sternwarte,
toId: weißesKreuz,
when
})
t.end()
})
2021-05-20 16:42:43 +01:00
tap.test('refreshJourney', async (t) => {
2020-03-10 23:48:01 +01:00
await testRefreshJourney({
test: t,
fetchJourneys: client.journeys,
refreshJourney: client.refreshJourney,
validate,
fromId: sternwarte,
toId: weißesKreuz,
when
})
t.end()
})
2021-05-20 16:42:43 +01:00
tap.test('arrivals at Platz der Jugend', async (t) => {
const res = await client.arrivals(sternwarte, {
2020-03-10 23:48:01 +01:00
duration: 30, when
})
await testArrivals({
test: t,
res,
validate,
ids: [
sternwarte,
'708539', // Rostock Sternwarte
],
})
2020-03-10 23:48:01 +01:00
t.end()
})
// todo: nearby
2021-05-20 16:42:43 +01:00
tap.test('radar', async (t) => {
const res = await client.radar({
2020-03-10 23:48:01 +01:00
north: 54.116968,
west: 12.029738,
south: 54.060517,
east: 12.203261
}, {
duration: 5 * 60, when, results: 10
})
validate(t, res, 'radarResult', 'res')
2020-03-10 23:48:01 +01:00
t.end()
})
2021-05-20 16:42:43 +01:00
tap.test('reachableFrom', async (t) => {
2020-03-10 23:48:01 +01:00
await testReachableFrom({
test: t,
reachableFrom: client.reachableFrom,
address: {
type: 'location',
id: '990004158',
address: 'Rostock - Stadtmitte, Pläterstraße 2',
latitude: 54.091285, longitude: 12.13648
},
when,
maxDuration: 15,
validate
})
t.end()
})