2020-02-07 03:10:29 +01:00
|
|
|
|
'use strict'
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
const tap = require('tap')
|
2020-02-07 03:10:29 +01:00
|
|
|
|
const isRoughlyEqual = require('is-roughly-equal')
|
|
|
|
|
|
|
|
|
|
const {createWhen} = require('./lib/util')
|
|
|
|
|
const createClient = require('../..')
|
|
|
|
|
const vsnProfile = require('../../p/vsn')
|
|
|
|
|
const products = require('../../p/vsn/products')
|
|
|
|
|
const createValidate = require('./lib/validate-fptf-with')
|
|
|
|
|
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
|
|
|
|
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
|
|
|
|
|
const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
|
|
|
|
|
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
|
|
|
|
const testDepartures = require('./lib/departures')
|
|
|
|
|
const testArrivals = require('./lib/arrivals')
|
|
|
|
|
|
2022-05-03 17:16:17 +02:00
|
|
|
|
const T_MOCK = 1652175000 * 1000 // 2022-05-10T11:30+02:00
|
2022-04-23 14:40:51 +02:00
|
|
|
|
const when = createWhen(vsnProfile.timezone, vsnProfile.locale, T_MOCK)
|
2020-02-07 03:10:29 +01:00
|
|
|
|
|
|
|
|
|
const cfg = {
|
|
|
|
|
when,
|
|
|
|
|
products,
|
2020-07-19 16:59:38 +02:00
|
|
|
|
minLatitude: 50,
|
|
|
|
|
maxLatitude: 54.5,
|
|
|
|
|
minLongitude: 6.5,
|
|
|
|
|
maxLongitude: 11.5,
|
2020-02-07 03:10:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const validate = createValidate(cfg)
|
|
|
|
|
|
|
|
|
|
const client = createClient(vsnProfile, 'public-transport/hafas-client:test')
|
|
|
|
|
|
|
|
|
|
const kornmarkt = '9033977'
|
|
|
|
|
const jugendherberge = '9033961'
|
|
|
|
|
const ewaldstrasse = '9033896'
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('journeys – Kornmarkt to Ewaldstraße', async (t) => {
|
2020-02-07 03:10:29 +01:00
|
|
|
|
const res = await client.journeys(kornmarkt, ewaldstrasse, {
|
|
|
|
|
results: 4,
|
|
|
|
|
departure: when,
|
|
|
|
|
stopovers: true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await testJourneysStationToStation({
|
|
|
|
|
test: t,
|
|
|
|
|
res,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: kornmarkt,
|
|
|
|
|
toId: ewaldstrasse
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('Ewaldstraße to 37083 Göttingen, Schulweg 22', async (t) => {
|
2020-02-07 03:10:29 +01:00
|
|
|
|
const schulweg = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
address: '37083 Göttingen, Schulweg 22',
|
|
|
|
|
latitude: 51.51579,
|
|
|
|
|
longitude: 9.945382
|
|
|
|
|
}
|
|
|
|
|
const res = await client.journeys(ewaldstrasse, schulweg, {
|
|
|
|
|
results: 3,
|
|
|
|
|
departure: when
|
|
|
|
|
})
|
|
|
|
|
await testJourneysStationToAddress({
|
|
|
|
|
test: t,
|
|
|
|
|
res,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: ewaldstrasse,
|
|
|
|
|
to: schulweg
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('earlier/later journeys', async (t) => {
|
2020-02-07 03:10:29 +01:00
|
|
|
|
await testEarlierLaterJourneys({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: ewaldstrasse,
|
2020-05-21 22:21:07 +02:00
|
|
|
|
toId: kornmarkt,
|
|
|
|
|
when
|
2020-02-07 03:10:29 +01:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('trip', async (t) => {
|
2020-02-07 03:10:29 +01:00
|
|
|
|
const { journeys } = await client.journeys(jugendherberge, kornmarkt, {
|
|
|
|
|
results: 1, departure: when
|
|
|
|
|
})
|
|
|
|
|
|
2020-04-09 14:53:28 +02:00
|
|
|
|
const p = journeys[0].legs.find(l => !l.walking)
|
2020-02-07 03:10:29 +01:00
|
|
|
|
t.ok(p.tripId, 'precondition failed')
|
|
|
|
|
t.ok(p.line.name, 'precondition failed')
|
|
|
|
|
|
2021-12-29 21:23:28 +01:00
|
|
|
|
const tripRes = await client.trip(p.tripId, p.line.name, {when})
|
|
|
|
|
|
|
|
|
|
validate(t, tripRes, 'tripResult', 'res')
|
2020-02-07 03:10:29 +01:00
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('departures at Kornmarkt.', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.departures(kornmarkt, {
|
2020-02-07 03:10:29 +01:00
|
|
|
|
duration: 20, when
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await testDepartures({
|
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2020-02-07 03:10:29 +01:00
|
|
|
|
validate,
|
|
|
|
|
id: kornmarkt
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('arrivals at Kornmarkt.', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.arrivals(kornmarkt, {
|
2020-02-07 03:10:29 +01:00
|
|
|
|
duration: 20, when
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await testArrivals({
|
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2020-02-07 03:10:29 +01:00
|
|
|
|
validate,
|
|
|
|
|
id: kornmarkt
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('departures with station object', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.departures({
|
2020-02-07 03:10:29 +01:00
|
|
|
|
type: 'station',
|
|
|
|
|
id: kornmarkt,
|
|
|
|
|
name: 'Kornmarkt',
|
|
|
|
|
location: {
|
|
|
|
|
type: 'location',
|
|
|
|
|
latitude: 51.727914,
|
|
|
|
|
longitude: 10.250606
|
|
|
|
|
}
|
|
|
|
|
}, {when})
|
|
|
|
|
|
2021-12-29 21:11:07 +01:00
|
|
|
|
validate(t, res, 'departuresResponse', 'res')
|
2020-02-07 03:10:29 +01:00
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('locations named Botanischer Garten', async (t) => {
|
2020-05-22 01:36:04 +02:00
|
|
|
|
const locations = await client.locations('Botanischer Garten', {
|
2020-02-07 03:10:29 +01:00
|
|
|
|
results: 20
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
validate(t, locations, 'locations', 'locations')
|
|
|
|
|
t.ok(locations.length <= 20)
|
|
|
|
|
|
|
|
|
|
t.ok(locations.find(s => s.type === 'stop' || s.type === 'station'))
|
|
|
|
|
t.ok(locations.find(s => s.poi))
|
|
|
|
|
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('stop Jugendherberge', async (t) => {
|
2020-02-07 03:10:29 +01:00
|
|
|
|
const s = await client.stop(jugendherberge)
|
|
|
|
|
|
|
|
|
|
validate(t, s, ['stop', 'station'], 'stop')
|
|
|
|
|
t.equal(s.id, jugendherberge)
|
|
|
|
|
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
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-02-07 03:10:29 +01:00
|
|
|
|
north: 52,
|
|
|
|
|
west: 9.8,
|
|
|
|
|
south: 51.51,
|
|
|
|
|
east: 10
|
|
|
|
|
}, {
|
|
|
|
|
duration: 5 * 60, when, results: 10
|
|
|
|
|
})
|
2021-12-29 21:24:07 +01:00
|
|
|
|
validate(t, res, 'radarResult', 'res')
|
2020-02-07 03:10:29 +01:00
|
|
|
|
t.end()
|
|
|
|
|
})
|