2017-11-12 21:03:24 +01:00
|
|
|
|
'use strict'
|
|
|
|
|
|
2018-04-19 14:55:17 +02:00
|
|
|
|
const stations = require('db-stations/full.json')
|
|
|
|
|
const a = require('assert')
|
2017-11-12 21:03:24 +01:00
|
|
|
|
const tapePromise = require('tape-promise').default
|
|
|
|
|
const tape = require('tape')
|
|
|
|
|
const isRoughlyEqual = require('is-roughly-equal')
|
|
|
|
|
|
2018-04-19 14:55:17 +02:00
|
|
|
|
const {createWhen} = require('./lib/util')
|
2017-11-12 21:03:24 +01:00
|
|
|
|
const createClient = require('..')
|
2017-11-12 23:51:39 +01:00
|
|
|
|
const dbProfile = require('../p/db')
|
2018-04-19 14:55:17 +02:00
|
|
|
|
const products = require('../p/db/products')
|
2017-11-12 21:03:24 +01:00
|
|
|
|
const {
|
2018-05-30 15:51:58 +02:00
|
|
|
|
station: createValidateStation,
|
2018-11-22 00:15:59 +01:00
|
|
|
|
trip: createValidateTrip
|
2018-04-19 14:55:17 +02:00
|
|
|
|
} = require('./lib/validators')
|
|
|
|
|
const createValidate = require('./lib/validate-fptf-with')
|
2018-04-23 13:56:00 +02:00
|
|
|
|
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
2018-04-24 15:42:53 +02:00
|
|
|
|
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
|
2018-04-24 16:10:56 +02:00
|
|
|
|
const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
|
2018-04-24 15:24:59 +02:00
|
|
|
|
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
2018-12-02 22:15:09 +01:00
|
|
|
|
const testLegCycleAlternatives = require('./lib/leg-cycle-alternatives')
|
2018-07-24 18:16:46 +02:00
|
|
|
|
const testRefreshJourney = require('./lib/refresh-journey')
|
2018-04-25 13:07:31 +02:00
|
|
|
|
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
2018-04-24 16:58:17 +02:00
|
|
|
|
const testDepartures = require('./lib/departures')
|
2018-07-07 21:26:40 +02:00
|
|
|
|
const testDeparturesInDirection = require('./lib/departures-in-direction')
|
2018-07-10 22:33:52 +02:00
|
|
|
|
const testDeparturesWithoutRelatedStations = require('./lib/departures-without-related-stations')
|
2018-06-26 17:30:46 +02:00
|
|
|
|
const testArrivals = require('./lib/arrivals')
|
2018-05-13 00:34:26 +02:00
|
|
|
|
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
2018-08-27 12:04:14 +02:00
|
|
|
|
const testReachableFrom = require('./lib/reachable-from')
|
2018-04-19 14:55:17 +02:00
|
|
|
|
|
|
|
|
|
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
|
2017-11-12 21:03:24 +01:00
|
|
|
|
|
2017-12-28 22:57:22 +01:00
|
|
|
|
const when = createWhen('Europe/Berlin', 'de-DE')
|
|
|
|
|
|
2018-04-19 14:55:17 +02:00
|
|
|
|
const cfg = {
|
|
|
|
|
when,
|
|
|
|
|
stationCoordsOptional: false,
|
2019-02-15 14:53:01 +01:00
|
|
|
|
products,
|
|
|
|
|
minLatitude: 46.673100,
|
|
|
|
|
maxLatitude: 55.030671,
|
|
|
|
|
minLongitude: 6.896517,
|
|
|
|
|
maxLongitude: 16.180237
|
2017-12-11 14:41:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-19 14:55:17 +02:00
|
|
|
|
const _validateStation = createValidateStation(cfg)
|
|
|
|
|
const validateStation = (validate, s, name) => {
|
|
|
|
|
_validateStation(validate, s, name)
|
|
|
|
|
const match = stations.some(station => (
|
|
|
|
|
station.id === s.id ||
|
|
|
|
|
(station.additionalIds && station.additionalIds.includes(s.id))
|
|
|
|
|
))
|
|
|
|
|
if (!match) {
|
|
|
|
|
console.error(name + `.id: unknown ID "${s.id}"`)
|
|
|
|
|
}
|
2017-11-12 21:23:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-19 14:55:17 +02:00
|
|
|
|
const validate = createValidate(cfg, {
|
|
|
|
|
station: validateStation
|
|
|
|
|
})
|
2017-11-12 21:23:29 +01:00
|
|
|
|
|
2017-12-11 16:06:37 +01:00
|
|
|
|
const assertValidPrice = (t, p) => {
|
|
|
|
|
t.ok(p)
|
|
|
|
|
if (p.amount !== null) {
|
|
|
|
|
t.equal(typeof p.amount, 'number')
|
|
|
|
|
t.ok(p.amount > 0)
|
|
|
|
|
}
|
|
|
|
|
if (p.hint !== null) {
|
|
|
|
|
t.equal(typeof p.hint, 'string')
|
|
|
|
|
t.ok(p.hint)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-12 21:03:24 +01:00
|
|
|
|
const test = tapePromise(tape)
|
2018-07-19 21:55:54 +02:00
|
|
|
|
const client = createClient(dbProfile, 'public-transport/hafas-client:test')
|
2017-11-12 21:03:24 +01:00
|
|
|
|
|
2018-03-04 20:12:38 +01:00
|
|
|
|
const berlinHbf = '8011160'
|
|
|
|
|
const münchenHbf = '8000261'
|
2018-04-19 14:55:17 +02:00
|
|
|
|
const jungfernheide = '8011167'
|
2018-04-23 13:56:00 +02:00
|
|
|
|
const blnSchwedterStr = '732652'
|
2019-01-16 22:05:21 +08:00
|
|
|
|
const westhafen = '8089116'
|
|
|
|
|
const wedding = '8089131'
|
2018-04-19 14:55:17 +02:00
|
|
|
|
const württembergallee = '731084'
|
2018-03-04 20:12:38 +01:00
|
|
|
|
const regensburgHbf = '8000309'
|
2018-07-07 21:26:40 +02:00
|
|
|
|
const blnOstbahnhof = '8010255'
|
2018-12-02 22:15:09 +01:00
|
|
|
|
const blnTiergarten = '8089091'
|
|
|
|
|
const blnJannowitzbrücke = '8089019'
|
2019-01-09 10:51:46 +01:00
|
|
|
|
const potsdamHbf = '8012666'
|
2018-03-04 20:12:38 +01:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('journeys – Berlin Schwedter Str. to München Hbf', async (t) => {
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(blnSchwedterStr, münchenHbf, {
|
2018-06-13 20:39:33 +02:00
|
|
|
|
results: 3,
|
|
|
|
|
departure: when,
|
|
|
|
|
stopovers: true
|
2017-11-12 21:03:24 +01:00
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToStation({
|
2018-04-23 13:56:00 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-04-23 13:56:00 +02:00
|
|
|
|
validate,
|
|
|
|
|
fromId: blnSchwedterStr,
|
|
|
|
|
toId: münchenHbf
|
|
|
|
|
})
|
|
|
|
|
// todo: find a journey where there pricing info is always available
|
2019-01-16 21:41:17 +08:00
|
|
|
|
for (let journey of res.journeys) {
|
2017-12-11 16:06:37 +01:00
|
|
|
|
if (journey.price) assertValidPrice(t, journey.price)
|
2017-11-12 21:03:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2017-11-12 21:03:24 +01:00
|
|
|
|
|
2018-04-19 14:55:17 +02:00
|
|
|
|
// todo: journeys, only one product
|
2018-04-25 13:07:31 +02:00
|
|
|
|
|
|
|
|
|
test('journeys – fails with no product', (t) => {
|
|
|
|
|
journeysFailsWithNoProduct({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
fromId: blnSchwedterStr,
|
|
|
|
|
toId: münchenHbf,
|
|
|
|
|
when,
|
|
|
|
|
products
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
2018-04-19 14:55:17 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('Berlin Schwedter Str. to Torfstraße 17', async (t) => {
|
2018-04-24 15:42:53 +02:00
|
|
|
|
const torfstr = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
address: 'Torfstraße 17',
|
|
|
|
|
latitude: 52.5416823,
|
|
|
|
|
longitude: 13.3491223
|
|
|
|
|
}
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(blnSchwedterStr, torfstr, {
|
2018-05-31 13:42:54 +02:00
|
|
|
|
results: 3,
|
|
|
|
|
departure: when
|
2018-04-24 15:42:53 +02:00
|
|
|
|
})
|
2017-11-12 21:03:24 +01:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToAddress({
|
2018-04-24 15:42:53 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-04-24 15:42:53 +02:00
|
|
|
|
validate,
|
|
|
|
|
fromId: blnSchwedterStr,
|
|
|
|
|
to: torfstr
|
|
|
|
|
})
|
2017-11-12 21:03:24 +01:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2017-11-12 21:03:24 +01:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => {
|
2018-04-24 16:10:56 +02:00
|
|
|
|
const atze = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
id: '991598902',
|
|
|
|
|
name: 'ATZE Musiktheater',
|
|
|
|
|
latitude: 52.542417,
|
|
|
|
|
longitude: 13.350437
|
|
|
|
|
}
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(blnSchwedterStr, atze, {
|
2018-05-31 13:42:54 +02:00
|
|
|
|
results: 3,
|
|
|
|
|
departure: when
|
2018-04-24 16:10:56 +02:00
|
|
|
|
})
|
2017-11-12 21:03:24 +01:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToPoi({
|
2018-04-24 16:10:56 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-04-24 16:10:56 +02:00
|
|
|
|
validate,
|
|
|
|
|
fromId: blnSchwedterStr,
|
|
|
|
|
to: atze
|
|
|
|
|
})
|
2017-11-12 21:03:24 +01:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2017-11-12 21:03:24 +01:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('journeys: via works – with detour', async (t) => {
|
2018-03-16 14:30:49 +01:00
|
|
|
|
// Going from Westhafen to Wedding via Württembergalle without detour
|
2018-03-16 14:34:37 +01:00
|
|
|
|
// is currently impossible. We check if the routing engine computes a detour.
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(westhafen, wedding, {
|
2018-03-06 02:47:05 +01:00
|
|
|
|
via: württembergallee,
|
|
|
|
|
results: 1,
|
2018-05-28 20:35:01 +02:00
|
|
|
|
departure: when,
|
2018-06-13 20:39:33 +02:00
|
|
|
|
stopovers: true
|
2018-01-19 16:58:39 +01:00
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysWithDetour({
|
2018-05-13 00:34:26 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-05-13 00:34:26 +02:00
|
|
|
|
validate,
|
|
|
|
|
detourIds: [württembergallee]
|
2018-03-06 02:47:05 +01:00
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-06 02:47:05 +01:00
|
|
|
|
|
2018-04-25 13:24:27 +02:00
|
|
|
|
// todo: without detour
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('earlier/later journeys, Jungfernheide -> München Hbf', async (t) => {
|
|
|
|
|
await testEarlierLaterJourneys({
|
2018-04-24 15:24:59 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: jungfernheide,
|
2018-11-20 18:38:48 +01:00
|
|
|
|
toId: münchenHbf,
|
|
|
|
|
when
|
2018-03-04 20:12:38 +01:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-04 20:12:38 +01:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test.skip('journeys – leg cycle & alternatives', async (t) => {
|
|
|
|
|
await testLegCycleAlternatives({
|
2018-12-02 22:15:09 +01:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
fromId: blnTiergarten,
|
|
|
|
|
toId: blnJannowitzbrücke
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-12-02 22:15:09 +01:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('refreshJourney', async (t) => {
|
|
|
|
|
await testRefreshJourney({
|
2018-07-24 18:16:46 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
refreshJourney: client.refreshJourney,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: jungfernheide,
|
|
|
|
|
toId: münchenHbf,
|
|
|
|
|
when
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-07-24 18:16:46 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('trip details', async (t) => {
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(berlinHbf, münchenHbf, {
|
2018-05-31 13:42:54 +02:00
|
|
|
|
results: 1, departure: when
|
2018-04-19 14:55:17 +02:00
|
|
|
|
})
|
|
|
|
|
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const p = res.journeys[0].legs[0]
|
2018-11-22 00:17:28 +01:00
|
|
|
|
t.ok(p.tripId, 'precondition failed')
|
2018-04-19 14:55:17 +02:00
|
|
|
|
t.ok(p.line.name, 'precondition failed')
|
2018-11-22 00:17:28 +01:00
|
|
|
|
const trip = await client.trip(p.tripId, p.line.name, {when})
|
2018-04-19 14:55:17 +02:00
|
|
|
|
|
2018-11-22 00:15:59 +01:00
|
|
|
|
const validateTrip = createValidateTrip(cfg)
|
2018-05-30 15:51:58 +02:00
|
|
|
|
const validate = createValidate(cfg, {
|
2018-11-22 00:15:59 +01:00
|
|
|
|
trip: (validate, trip, name) => {
|
|
|
|
|
trip = Object.assign({}, trip)
|
|
|
|
|
if (!trip.direction) trip.direction = 'foo' // todo, see #49
|
|
|
|
|
validateTrip(validate, trip, name)
|
2018-05-30 15:51:58 +02:00
|
|
|
|
}
|
|
|
|
|
})
|
2018-11-22 00:15:59 +01:00
|
|
|
|
validate(t, trip, 'trip', 'trip')
|
2018-05-30 15:51:58 +02:00
|
|
|
|
|
2018-04-19 14:55:17 +02:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-04-19 14:55:17 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('departures at Berlin Schwedter Str.', async (t) => {
|
|
|
|
|
const departures = await client.departures(blnSchwedterStr, {
|
2018-12-28 21:17:03 +01:00
|
|
|
|
duration: 5, when,
|
|
|
|
|
stopovers: true
|
2017-11-12 21:03:24 +01:00
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testDepartures({
|
2018-04-24 16:58:17 +02:00
|
|
|
|
test: t,
|
|
|
|
|
departures,
|
|
|
|
|
validate,
|
|
|
|
|
id: blnSchwedterStr
|
|
|
|
|
})
|
2017-11-12 21:03:24 +01:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2017-11-12 21:03:24 +01:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('departures with station object', async (t) => {
|
|
|
|
|
const deps = await client.departures({
|
2018-01-04 16:19:42 +01:00
|
|
|
|
type: 'station',
|
2018-04-19 14:55:17 +02:00
|
|
|
|
id: jungfernheide,
|
2018-01-04 16:19:42 +01:00
|
|
|
|
name: 'Berlin Jungfernheide',
|
|
|
|
|
location: {
|
|
|
|
|
type: 'location',
|
|
|
|
|
latitude: 1.23,
|
|
|
|
|
longitude: 2.34
|
|
|
|
|
}
|
|
|
|
|
}, {when})
|
|
|
|
|
|
2018-04-19 14:55:17 +02:00
|
|
|
|
validate(t, deps, 'departures', 'departures')
|
2018-01-04 16:19:42 +01:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-01-04 16:19:42 +01:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('departures at Berlin Hbf in direction of Berlin Ostbahnhof', async (t) => {
|
|
|
|
|
await testDeparturesInDirection({
|
2018-07-07 21:26:40 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchDepartures: client.departures,
|
|
|
|
|
fetchTrip: client.trip,
|
|
|
|
|
id: berlinHbf,
|
|
|
|
|
directionIds: [blnOstbahnhof, '8089185', '732676'],
|
|
|
|
|
when,
|
|
|
|
|
validate
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-07-07 21:26:40 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('departures without related stations', async (t) => {
|
|
|
|
|
await testDeparturesWithoutRelatedStations({
|
2018-07-10 22:33:52 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchDepartures: client.departures,
|
|
|
|
|
id: '8089051', // Berlin Yorckstr. (S1)
|
|
|
|
|
when,
|
|
|
|
|
products: {bus: false},
|
|
|
|
|
linesOfRelatedStations: ['S 2', 'S 25', 'S 26', 'U 7']
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-07-10 22:33:52 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('arrivals at Berlin Schwedter Str.', async (t) => {
|
|
|
|
|
const arrivals = await client.arrivals(blnSchwedterStr, {
|
2018-12-28 21:17:03 +01:00
|
|
|
|
duration: 5, when,
|
|
|
|
|
stopovers: true
|
2018-06-26 17:30:46 +02:00
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testArrivals({
|
2018-06-26 17:30:46 +02:00
|
|
|
|
test: t,
|
|
|
|
|
arrivals,
|
|
|
|
|
validate,
|
|
|
|
|
id: blnSchwedterStr
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-06-26 17:30:46 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('nearby Berlin Jungfernheide', async (t) => {
|
|
|
|
|
const nearby = await client.nearby({
|
2018-01-05 14:53:03 +01:00
|
|
|
|
type: 'location',
|
|
|
|
|
latitude: 52.530273,
|
|
|
|
|
longitude: 13.299433
|
|
|
|
|
}, {
|
2017-11-12 21:03:24 +01:00
|
|
|
|
results: 2, distance: 400
|
|
|
|
|
})
|
|
|
|
|
|
2018-04-19 14:55:17 +02:00
|
|
|
|
validate(t, nearby, 'locations', 'nearby')
|
|
|
|
|
|
2017-11-12 21:03:24 +01:00
|
|
|
|
t.equal(nearby.length, 2)
|
|
|
|
|
|
2018-04-19 14:55:17 +02:00
|
|
|
|
const s0 = nearby[0]
|
2019-01-16 22:05:21 +08:00
|
|
|
|
t.equal(s0.id, jungfernheide)
|
2018-04-19 14:55:17 +02:00
|
|
|
|
t.equal(s0.name, 'Berlin Jungfernheide')
|
2018-05-13 01:03:10 +02:00
|
|
|
|
t.ok(isRoughlyEqual(.0005, s0.location.latitude, 52.530408))
|
|
|
|
|
t.ok(isRoughlyEqual(.0005, s0.location.longitude, 13.299424))
|
2018-04-19 14:55:17 +02:00
|
|
|
|
t.ok(s0.distance >= 0)
|
|
|
|
|
t.ok(s0.distance <= 100)
|
2017-12-11 19:53:26 +01:00
|
|
|
|
|
2017-11-12 21:03:24 +01:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2017-11-12 21:03:24 +01:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('locations named Jungfernheide', async (t) => {
|
|
|
|
|
const locations = await client.locations('Jungfernheide', {
|
2017-11-12 21:03:24 +01:00
|
|
|
|
results: 10
|
|
|
|
|
})
|
|
|
|
|
|
2018-04-19 14:55:17 +02:00
|
|
|
|
validate(t, locations, 'locations', 'locations')
|
2017-11-12 21:03:24 +01:00
|
|
|
|
t.ok(locations.length <= 10)
|
2018-04-19 14:55:17 +02:00
|
|
|
|
t.ok(locations.some((l) => {
|
2019-01-16 22:05:21 +08:00
|
|
|
|
return l.station && l.station.id === jungfernheide || l.id === jungfernheide
|
2018-04-19 14:55:17 +02:00
|
|
|
|
}), 'Jungfernheide not found')
|
2017-11-12 21:03:24 +01:00
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-01-26 17:08:07 +01:00
|
|
|
|
|
2018-11-21 19:55:37 +01:00
|
|
|
|
test('stop', async (t) => {
|
|
|
|
|
const s = await client.stop(regensburgHbf)
|
2018-01-26 17:08:07 +01:00
|
|
|
|
|
2018-11-21 19:55:37 +01:00
|
|
|
|
validate(t, s, ['stop', 'station'], 'stop')
|
2018-04-19 14:55:17 +02:00
|
|
|
|
t.equal(s.id, regensburgHbf)
|
2018-01-26 17:40:14 +01:00
|
|
|
|
|
2018-01-26 17:08:07 +01:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-08-27 12:04:14 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('line with additionalName', async (t) => {
|
|
|
|
|
const departures = await client.departures(potsdamHbf, {
|
2019-01-09 10:51:46 +01:00
|
|
|
|
duration: 12 * 60, // 12 minutes
|
|
|
|
|
products: {bus: false, suburban: false, tram: false}
|
|
|
|
|
})
|
|
|
|
|
t.ok(departures.some(d => d.line && d.line.additionalName))
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2019-01-09 10:51:46 +01:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('reachableFrom', async (t) => {
|
2018-08-27 12:04:14 +02:00
|
|
|
|
const torfstr17 = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
address: 'Torfstraße 17',
|
|
|
|
|
latitude: 52.5416823,
|
|
|
|
|
longitude: 13.3491223
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testReachableFrom({
|
2018-08-27 12:04:14 +02:00
|
|
|
|
test: t,
|
|
|
|
|
reachableFrom: client.reachableFrom,
|
2018-08-27 12:06:14 +02:00
|
|
|
|
address: torfstr17,
|
2018-08-27 12:04:14 +02:00
|
|
|
|
when,
|
|
|
|
|
maxDuration: 15,
|
|
|
|
|
validate
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|