2022-05-07 16:17:37 +02:00
|
|
|
|
import tap from 'tap'
|
2020-03-18 03:15:59 +01:00
|
|
|
|
|
2022-05-07 16:17:37 +02:00
|
|
|
|
import {createWhen} from './lib/util.js'
|
|
|
|
|
import {createClient} from '../../index.js'
|
|
|
|
|
import {profile as sncbProfile} from '../../p/sncb/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-18 03:15:59 +01:00
|
|
|
|
|
2022-05-03 17:16:17 +02:00
|
|
|
|
const T_MOCK = 1657618200 * 1000 // 2022-07-12T11:30+02:00
|
2022-04-23 14:40:51 +02:00
|
|
|
|
const when = createWhen(sncbProfile.timezone, sncbProfile.locale, T_MOCK)
|
2020-03-18 03:15:59 +01:00
|
|
|
|
|
|
|
|
|
const cfg = {
|
|
|
|
|
when,
|
|
|
|
|
stationCoordsOptional: false,
|
2022-05-07 16:17:37 +02:00
|
|
|
|
products: sncbProfile.products,
|
2020-03-18 03:15:59 +01:00
|
|
|
|
minLatitude: 46.513,
|
|
|
|
|
maxLatitude: 54.521,
|
|
|
|
|
minLongitude: -1.423,
|
|
|
|
|
maxLongitude: 15.26
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const validate = createValidate(cfg)
|
|
|
|
|
|
|
|
|
|
const client = createClient(sncbProfile, 'public-transport/hafas-client:test')
|
|
|
|
|
|
|
|
|
|
const gentStPieters = '8892007'
|
|
|
|
|
const bruxellesMidi = '8814001'
|
|
|
|
|
const gentPaddenhoek = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
address: 'Gent, Paddenhoek',
|
2021-12-29 15:18:21 +01:00
|
|
|
|
latitude: 51.051691, longitude: 3.724914,
|
2020-03-18 03:15:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('journeys – Gent Sant Pieters to Bruxelles Midi', async (t) => {
|
2020-03-18 03:15:59 +01:00
|
|
|
|
const res = await client.journeys(gentStPieters, bruxellesMidi, {
|
|
|
|
|
results: 4,
|
|
|
|
|
departure: when,
|
|
|
|
|
stopovers: true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await testJourneysStationToStation({
|
|
|
|
|
test: t,
|
|
|
|
|
res,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: gentStPieters,
|
|
|
|
|
toId: bruxellesMidi
|
|
|
|
|
})
|
|
|
|
|
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-18 03:15:59 +01:00
|
|
|
|
const res = await client.journeys(gentStPieters, bruxellesMidi, {
|
|
|
|
|
results: 1, departure: when
|
|
|
|
|
})
|
|
|
|
|
|
2020-04-09 14:53:28 +02:00
|
|
|
|
const p = res.journeys[0].legs.find(l => !l.walking)
|
2020-03-18 03:15:59 +01:00
|
|
|
|
t.ok(p.tripId, 'precondition failed')
|
|
|
|
|
t.ok(p.line.name, 'precondition failed')
|
|
|
|
|
|
2021-12-29 21:33:42 +01:00
|
|
|
|
const tripRes = await client.trip(p.tripId, {when})
|
2021-12-29 21:23:28 +01:00
|
|
|
|
|
|
|
|
|
validate(t, tripRes, 'tripResult', 'res')
|
2020-03-18 03:15:59 +01:00
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('arrivals at Bruxelles Midi', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.arrivals(bruxellesMidi, {
|
2020-03-18 03:15:59 +01:00
|
|
|
|
duration: 10, when
|
|
|
|
|
})
|
|
|
|
|
|
2022-04-28 21:55:11 +02:00
|
|
|
|
await testArrivals({
|
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2022-04-28 21:55:11 +02:00
|
|
|
|
validate,
|
|
|
|
|
id: bruxellesMidi,
|
|
|
|
|
})
|
2020-03-18 03:15:59 +01:00
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// todo: nearby
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('radar', async (t) => {
|
2021-12-29 21:24:07 +01:00
|
|
|
|
const res = await client.radar({
|
2020-03-18 03:15:59 +01:00
|
|
|
|
north: 51.065,
|
|
|
|
|
west: 3.688,
|
|
|
|
|
south: 51.04,
|
|
|
|
|
east: 3.748
|
|
|
|
|
}, {
|
|
|
|
|
duration: 5 * 60, when, results: 10
|
|
|
|
|
})
|
|
|
|
|
|
2021-12-29 21:24:07 +01:00
|
|
|
|
validate(t, res, 'radarResult', 'res')
|
2020-03-18 03:15:59 +01:00
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2022-11-09 21:22:49 +01:00
|
|
|
|
tap.test('reachableFrom', async (t) => {
|
2020-03-18 03:15:59 +01:00
|
|
|
|
await testReachableFrom({
|
|
|
|
|
test: t,
|
|
|
|
|
reachableFrom: client.reachableFrom,
|
|
|
|
|
address: gentPaddenhoek,
|
|
|
|
|
when,
|
|
|
|
|
maxDuration: 15,
|
|
|
|
|
validate
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|