2022-05-07 16:17:37 +02:00
|
|
|
|
import tap from 'tap'
|
|
|
|
|
|
|
|
|
|
import {createWhen} from './lib/util.js'
|
|
|
|
|
import {createClient} from '../../index.js'
|
|
|
|
|
import {profile as mobilNrwProfile} from '../../p/mobil-nrw/index.js'
|
|
|
|
|
import {createValidateFptfWith as createValidate} from './lib/validate-fptf-with.js'
|
|
|
|
|
import {testJourneysStationToStation} from './lib/journeys-station-to-station.js'
|
|
|
|
|
import {testJourneysStationToAddress} from './lib/journeys-station-to-address.js'
|
|
|
|
|
import {testJourneysStationToPoi} from './lib/journeys-station-to-poi.js'
|
|
|
|
|
import {testEarlierLaterJourneys} from './lib/earlier-later-journeys.js'
|
|
|
|
|
import {testRefreshJourney} from './lib/refresh-journey.js'
|
|
|
|
|
import {testDepartures} from './lib/departures.js'
|
|
|
|
|
import {testArrivals} from './lib/arrivals.js'
|
|
|
|
|
import {testReachableFrom} from './lib/reachable-from.js'
|
2021-01-10 20:44:33 +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(mobilNrwProfile.timezone, mobilNrwProfile.locale, T_MOCK)
|
2021-01-10 20:44:33 +01:00
|
|
|
|
|
|
|
|
|
const cfg = {
|
|
|
|
|
when,
|
|
|
|
|
stationCoordsOptional: false,
|
2022-05-07 16:17:37 +02:00
|
|
|
|
products: mobilNrwProfile.products,
|
2021-01-10 20:44:33 +01:00
|
|
|
|
minLatitude: 48.089,
|
|
|
|
|
minLongitude: 1.659,
|
|
|
|
|
maxLatitude: 53.531,
|
|
|
|
|
maxLongitude: 14.689,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const validate = createValidate(cfg)
|
|
|
|
|
|
|
|
|
|
const client = createClient(mobilNrwProfile, 'public-transport/hafas-client:test')
|
|
|
|
|
|
|
|
|
|
const soest = '8000076'
|
|
|
|
|
const aachenHbf = '8000001'
|
|
|
|
|
const dortmundStadtgarten = '655672'
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('journeys – Soest to Aachen Hbf', async (t) => {
|
2021-01-10 20:44:33 +01:00
|
|
|
|
const res = await client.journeys(soest, aachenHbf, {
|
|
|
|
|
results: 4,
|
|
|
|
|
departure: when,
|
|
|
|
|
stopovers: true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await testJourneysStationToStation({
|
|
|
|
|
test: t,
|
|
|
|
|
res,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: soest,
|
|
|
|
|
toId: aachenHbf
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// todo: journeys, only one product
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('Aachen Hbf to Schillingstr. 3, Dortmund', async (t) => {
|
2021-01-10 20:44:33 +01:00
|
|
|
|
const schillingstr3 = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
id: '980288407',
|
|
|
|
|
address: 'Dortmund - Mitte, Schillingstraße 3',
|
|
|
|
|
latitude: 51.504891,
|
|
|
|
|
longitude: 7.457802,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const res = await client.journeys(aachenHbf, schillingstr3, {
|
|
|
|
|
results: 3,
|
|
|
|
|
departure: when
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await testJourneysStationToAddress({
|
|
|
|
|
test: t,
|
|
|
|
|
res,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: aachenHbf,
|
|
|
|
|
to: schillingstr3
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('Aachen Hbf to Sportanlage Schulzentrum, Dortmund', async (t) => {
|
2021-01-10 20:44:33 +01:00
|
|
|
|
const sportanlage = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
id: '991557725',
|
|
|
|
|
poi: true,
|
|
|
|
|
name: 'Dortmund, Sportanlage Schulzentrum (Grünanlagen)',
|
|
|
|
|
latitude: 51.491201,
|
|
|
|
|
longitude: 7.562859,
|
|
|
|
|
}
|
|
|
|
|
const res = await client.journeys(aachenHbf, sportanlage, {
|
|
|
|
|
results: 3,
|
|
|
|
|
departure: when
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await testJourneysStationToPoi({
|
|
|
|
|
test: t,
|
|
|
|
|
res,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: aachenHbf,
|
|
|
|
|
to: sportanlage
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// todo: walkingSpeed "2107 MELRIDGE PL" -> 000002148
|
|
|
|
|
// todo: via works – with detour
|
|
|
|
|
// todo: without detour
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('earlier/later journeys', async (t) => {
|
2021-01-10 20:44:33 +01:00
|
|
|
|
await testEarlierLaterJourneys({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: soest,
|
|
|
|
|
toId: aachenHbf,
|
|
|
|
|
when
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('refreshJourney', async (t) => {
|
2021-01-10 20:44:33 +01:00
|
|
|
|
await testRefreshJourney({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
refreshJourney: client.refreshJourney,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: soest,
|
|
|
|
|
toId: aachenHbf,
|
|
|
|
|
when
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('trip details', async (t) => {
|
2021-01-10 20:44:33 +01:00
|
|
|
|
const res = await client.journeys(soest, aachenHbf, {
|
|
|
|
|
results: 1, departure: when
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const p = res.journeys[0].legs.find(l => !l.walking)
|
|
|
|
|
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')
|
2021-01-10 20:44:33 +01:00
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('departures at Soest', async (t) => {
|
2021-08-24 00:43:20 +02:00
|
|
|
|
const ids = [
|
|
|
|
|
soest,
|
|
|
|
|
'906135', // Bahnhof, Soest
|
|
|
|
|
'904812', // Bahnhof/Brüdertor, Soest
|
|
|
|
|
'902737', // Bahnhof E, Soest
|
|
|
|
|
]
|
|
|
|
|
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.departures(soest, {
|
2021-01-10 20:44:33 +01:00
|
|
|
|
duration: 10, when,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await testDepartures({
|
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2021-01-10 20:44:33 +01:00
|
|
|
|
validate,
|
2021-08-24 00:43:20 +02:00
|
|
|
|
ids,
|
2021-01-10 20:44:33 +01:00
|
|
|
|
})
|
|
|
|
|
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({
|
2021-01-10 20:44:33 +01:00
|
|
|
|
type: 'station',
|
|
|
|
|
id: soest,
|
|
|
|
|
name: 'Magdeburg Hbf',
|
|
|
|
|
location: {
|
|
|
|
|
type: 'location',
|
|
|
|
|
latitude: 1.23,
|
|
|
|
|
longitude: 2.34
|
|
|
|
|
}
|
|
|
|
|
}, {when})
|
|
|
|
|
|
2021-12-29 21:11:07 +01:00
|
|
|
|
validate(t, res, 'departuresResponse', 'res')
|
2021-01-10 20:44:33 +01:00
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('arrivals at Soest', async (t) => {
|
2021-08-24 00:43:20 +02:00
|
|
|
|
const ids = [
|
|
|
|
|
soest,
|
|
|
|
|
'906135', // Bahnhof, Soest
|
|
|
|
|
'904812', // Bahnhof/Brüdertor, Soest
|
|
|
|
|
'902737', // Bahnhof E, Soest
|
|
|
|
|
]
|
|
|
|
|
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.arrivals(soest, {
|
2021-01-10 20:44:33 +01:00
|
|
|
|
duration: 10, when,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await testArrivals({
|
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2021-01-10 20:44:33 +01:00
|
|
|
|
validate,
|
2021-08-24 00:43:20 +02:00
|
|
|
|
ids,
|
2021-01-10 20:44:33 +01:00
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// todo: nearby
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('locations named "stadtgarten dortmund"', async (t) => {
|
2021-01-10 20:44:33 +01:00
|
|
|
|
const locations = await client.locations('stadtgarten dortmund', {
|
|
|
|
|
results: 10,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
validate(t, locations, 'locations', 'locations')
|
|
|
|
|
t.ok(locations.length <= 10)
|
|
|
|
|
|
|
|
|
|
t.ok(locations.find(s => s.type === 'stop' || s.type === 'station'))
|
|
|
|
|
t.ok(locations.find(s => s.poi)) // POIs
|
|
|
|
|
t.ok(locations.some((l) => {
|
|
|
|
|
return l.station && l.station.id === dortmundStadtgarten || l.id === dortmundStadtgarten
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('station Aachen Hbf', async (t) => {
|
2021-01-10 20:44:33 +01:00
|
|
|
|
const s = await client.stop(aachenHbf)
|
|
|
|
|
|
|
|
|
|
validate(t, s, ['stop', 'station'], 'station')
|
|
|
|
|
t.equal(s.id, aachenHbf)
|
|
|
|
|
|
|
|
|
|
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({
|
2021-01-10 20:44:33 +01:00
|
|
|
|
north: 51.4358,
|
|
|
|
|
west: 6.7625,
|
|
|
|
|
south: 51.4214,
|
|
|
|
|
east: 6.7900,
|
|
|
|
|
}, {
|
|
|
|
|
duration: 5 * 60, when, results: 10,
|
|
|
|
|
})
|
|
|
|
|
|
2021-12-29 21:24:07 +01:00
|
|
|
|
validate(t, res, 'radarResult', 'res')
|
2021-01-10 20:44:33 +01:00
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('reachableFrom', async (t) => {
|
2021-01-10 20:44:33 +01:00
|
|
|
|
await testReachableFrom({
|
|
|
|
|
test: t,
|
|
|
|
|
reachableFrom: client.reachableFrom,
|
|
|
|
|
address: {
|
|
|
|
|
type: 'location',
|
|
|
|
|
id: '980301639',
|
|
|
|
|
latitude: 51.387609,
|
|
|
|
|
longitude: 6.684019,
|
|
|
|
|
address: 'Duisburg, Am Mühlenberg 1',
|
|
|
|
|
},
|
|
|
|
|
when,
|
|
|
|
|
maxDuration: 15,
|
|
|
|
|
validate
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|