2024-02-06 22:58:49 +01:00
|
|
|
|
import tap from 'tap';
|
|
|
|
|
import isRoughlyEqual from 'is-roughly-equal';
|
|
|
|
|
import maxBy from 'lodash/maxBy.js';
|
|
|
|
|
import flatMap from 'lodash/flatMap.js';
|
|
|
|
|
import last from 'lodash/last.js';
|
|
|
|
|
|
|
|
|
|
import {createWhen} from './lib/util.js';
|
|
|
|
|
import {createClient} from '../../index.js';
|
|
|
|
|
import {profile as dbProfile} from '../../p/db/index.js';
|
|
|
|
|
import {routingModes} from '../../p/db/routing-modes.js';
|
2022-05-07 16:17:37 +02:00
|
|
|
|
import {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
createValidateStation,
|
|
|
|
|
createValidateTrip,
|
|
|
|
|
} from './lib/validators.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 {testLegCycleAlternatives} from './lib/leg-cycle-alternatives.js';
|
|
|
|
|
import {testRefreshJourney} from './lib/refresh-journey.js';
|
|
|
|
|
import {journeysFailsWithNoProduct} from './lib/journeys-fails-with-no-product.js';
|
|
|
|
|
import {testDepartures} from './lib/departures.js';
|
|
|
|
|
import {testDeparturesInDirection} from './lib/departures-in-direction.js';
|
|
|
|
|
import {testArrivals} from './lib/arrivals.js';
|
|
|
|
|
import {testJourneysWithDetour} from './lib/journeys-with-detour.js';
|
|
|
|
|
import {testReachableFrom} from './lib/reachable-from.js';
|
|
|
|
|
import {testServerInfo} from './lib/server-info.js';
|
|
|
|
|
|
|
|
|
|
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o);
|
|
|
|
|
const minute = 60 * 1000;
|
|
|
|
|
|
|
|
|
|
const T_MOCK = 1696921200 * 1000; // 2023-10-10T08:00:00+01:00
|
|
|
|
|
const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK);
|
2017-12-28 22:57:22 +01:00
|
|
|
|
|
2018-04-19 14:55:17 +02:00
|
|
|
|
const cfg = {
|
|
|
|
|
when,
|
|
|
|
|
stationCoordsOptional: false,
|
2022-05-07 16:17:37 +02:00
|
|
|
|
products: dbProfile.products,
|
2019-02-15 14:53:01 +01:00
|
|
|
|
minLatitude: 46.673100,
|
|
|
|
|
maxLatitude: 55.030671,
|
|
|
|
|
minLongitude: 6.896517,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
maxLongitude: 16.180237,
|
|
|
|
|
};
|
2017-12-11 14:41:28 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const validate = createValidate(cfg);
|
2017-11-12 21:23:29 +01:00
|
|
|
|
|
2017-12-11 16:06:37 +01:00
|
|
|
|
const assertValidPrice = (t, p) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.ok(p);
|
2017-12-11 16:06:37 +01:00
|
|
|
|
if (p.amount !== null) {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.equal(typeof p.amount, 'number');
|
|
|
|
|
t.ok(p.amount > 0);
|
2017-12-11 16:06:37 +01:00
|
|
|
|
}
|
|
|
|
|
if (p.hint !== null) {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.equal(typeof p.hint, 'string');
|
|
|
|
|
t.ok(p.hint);
|
2017-12-11 16:06:37 +01:00
|
|
|
|
}
|
2024-02-06 22:58:49 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const client = createClient(dbProfile, 'public-transport/hafas-client:test');
|
|
|
|
|
|
|
|
|
|
const berlinHbf = '8011160';
|
|
|
|
|
const münchenHbf = '8000261';
|
|
|
|
|
const jungfernheide = '8011167';
|
|
|
|
|
const blnSchwedterStr = '732652';
|
|
|
|
|
const westhafen = '8089116';
|
|
|
|
|
const wedding = '8089131';
|
|
|
|
|
const württembergallee = '731084';
|
|
|
|
|
const regensburgHbf = '8000309';
|
|
|
|
|
const blnOstbahnhof = '8010255';
|
|
|
|
|
const blnTiergarten = '8089091';
|
|
|
|
|
const blnJannowitzbrücke = '8089019';
|
|
|
|
|
const potsdamHbf = '8012666';
|
|
|
|
|
const berlinSüdkreuz = '8011113';
|
|
|
|
|
const kölnHbf = '8000207';
|
2018-03-04 20:12:38 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.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, {
|
2019-02-01 15:35:18 +01:00
|
|
|
|
results: 4,
|
2018-06-13 20:39:33 +02:00
|
|
|
|
departure: when,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
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,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
toId: münchenHbf,
|
|
|
|
|
});
|
2018-04-23 13:56:00 +02:00
|
|
|
|
// 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) {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
if (journey.price) {
|
|
|
|
|
assertValidPrice(t, journey.price);
|
|
|
|
|
}
|
2017-11-12 21:03:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
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
|
|
|
|
|
2021-12-29 18:53:50 +01:00
|
|
|
|
tap.test('journeys – fails with no product', async (t) => {
|
|
|
|
|
await journeysFailsWithNoProduct({
|
2018-04-25 13:07:31 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
fromId: blnSchwedterStr,
|
|
|
|
|
toId: münchenHbf,
|
|
|
|
|
when,
|
2022-05-07 16:17:37 +02:00
|
|
|
|
products: dbProfile.products,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-04-19 14:55:17 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.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,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
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,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
departure: when,
|
|
|
|
|
});
|
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,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
to: torfstr,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2017-11-12 21:03:24 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => {
|
2018-04-24 16:10:56 +02:00
|
|
|
|
const atze = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
id: '991598902',
|
2019-02-07 17:47:50 +01:00
|
|
|
|
poi: true,
|
2021-08-24 00:43:20 +02:00
|
|
|
|
name: 'Berlin, Atze Musiktheater für Kinder (Kultur und U',
|
2018-04-24 16:10:56 +02:00
|
|
|
|
latitude: 52.542417,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
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,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
departure: when,
|
|
|
|
|
});
|
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,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
to: atze,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2017-11-12 21:03:24 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.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,
|
2024-02-06 22:58:49 +01: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,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
detourIds: [württembergallee],
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-03-06 02:47:05 +01:00
|
|
|
|
|
2018-10-29 22:11:08 +01:00
|
|
|
|
// todo: walkingSpeed "Berlin - Charlottenburg, Hallerstraße" -> jungfernheide
|
2018-04-25 13:24:27 +02:00
|
|
|
|
// todo: without detour
|
|
|
|
|
|
2023-07-18 21:55:11 +02:00
|
|
|
|
tap.test('journeys – all routing modes work', async (t) => {
|
|
|
|
|
for (const mode in routingModes) {
|
|
|
|
|
await client.journeys(berlinHbf, münchenHbf, {
|
|
|
|
|
results: 1,
|
|
|
|
|
departure: when,
|
|
|
|
|
routingMode: mode,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
2023-07-18 21:55:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2023-07-18 21:55:11 +02:00
|
|
|
|
|
2022-11-09 21:17:32 +01:00
|
|
|
|
// todo: with the DB endpoint, earlierRef/laterRef is missing queries many days in the future
|
|
|
|
|
tap.skip('earlier/later journeys, Jungfernheide -> München Hbf', async (t) => {
|
2018-11-21 19:07:37 +01:00
|
|
|
|
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,
|
2022-11-09 21:17:32 +01:00
|
|
|
|
when,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
2018-03-04 20:12:38 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-03-04 20:12:38 +01:00
|
|
|
|
|
2022-11-18 18:01:33 +01:00
|
|
|
|
if (!process.env.VCR_MODE) {
|
|
|
|
|
tap.test('journeys – leg cycle & alternatives', async (t) => {
|
|
|
|
|
await testLegCycleAlternatives({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
fromId: blnTiergarten,
|
|
|
|
|
toId: blnJannowitzbrücke,
|
|
|
|
|
when,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2022-11-18 18:01:33 +01:00
|
|
|
|
}
|
2018-12-02 22:15:09 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('refreshJourney', async (t) => {
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testRefreshJourney({
|
2018-07-24 18:16:46 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
refreshJourney: client.refreshJourney,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: jungfernheide,
|
|
|
|
|
toId: münchenHbf,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
when,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-07-24 18:16:46 +02:00
|
|
|
|
|
2021-05-04 00:55:00 +02:00
|
|
|
|
tap.skip('journeysFromTrip – U Mehringdamm to U Naturkundemuseum, reroute to Spittelmarkt.', async (t) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const blnMehringdamm = '730939';
|
|
|
|
|
const blnStadtmitte = '732541';
|
|
|
|
|
const blnNaturkundemuseum = '732539';
|
|
|
|
|
const blnSpittelmarkt = '732543';
|
|
|
|
|
|
|
|
|
|
const isU6Leg = leg => leg.line && leg.line.name
|
|
|
|
|
&& leg.line.name.toUpperCase()
|
|
|
|
|
.replace(/\s+/g, '') === 'U6';
|
|
|
|
|
|
2018-10-08 20:16:20 +02:00
|
|
|
|
const sameStopOrStation = (stopA) => (stopB) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
if (stopA.id && stopB.id && stopA.id === stopB.id) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
const statA = stopA.stat && stopA.stat.id || NaN;
|
|
|
|
|
const statB = stopB.stat && stopB.stat.id || NaN;
|
|
|
|
|
return statA === statB || stopA.id === statB || stopB.id === statA;
|
|
|
|
|
};
|
|
|
|
|
const departureOf = st => Number(new Date(st.departure || st.scheduledDeparture));
|
|
|
|
|
const arrivalOf = st => Number(new Date(st.arrival || st.scheduledArrival));
|
2018-10-08 20:16:20 +02:00
|
|
|
|
|
|
|
|
|
// `journeysFromTrip` only supports queries *right now*, so we can't use `when` as in all
|
|
|
|
|
// other tests. To make the test less brittle, we pick a connection that is served all night. 🙄
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const when = new Date();
|
|
|
|
|
const validate = createValidate({...cfg, when});
|
2018-10-08 20:16:20 +02:00
|
|
|
|
|
|
|
|
|
const findTripBetween = async (stopAId, stopBId, products = {}) => {
|
|
|
|
|
const {journeys} = await client.journeys(stopAId, stopBId, {
|
|
|
|
|
departure: new Date(when - 10 * minute),
|
|
|
|
|
transfers: 0, products,
|
|
|
|
|
results: 8, stopovers: false, remarks: false,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
2018-10-08 20:16:20 +02:00
|
|
|
|
for (const j of journeys) {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const l = j.legs.find(isU6Leg);
|
|
|
|
|
if (!l) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2021-12-29 21:33:42 +01:00
|
|
|
|
const t = await client.trip(l.tripId, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
stopovers: true, remarks: false,
|
|
|
|
|
});
|
2018-10-08 20:16:20 +02:00
|
|
|
|
|
2022-04-28 22:17:49 +02:00
|
|
|
|
const pastStopovers = t.stopovers
|
2024-02-06 22:58:49 +01:00
|
|
|
|
.filter(st => departureOf(st) < Date.now()); // todo: <= ?
|
2022-04-28 22:17:49 +02:00
|
|
|
|
const hasStoppedAtA = pastStopovers
|
2024-02-06 22:58:49 +01:00
|
|
|
|
.find(sameStopOrStation({id: stopAId}));
|
2018-10-08 20:16:20 +02:00
|
|
|
|
const willStopAtB = t.stopovers
|
2024-02-06 22:58:49 +01:00
|
|
|
|
.filter(st => arrivalOf(st) > Date.now()) // todo: >= ?
|
|
|
|
|
.find(sameStopOrStation({id: stopBId}));
|
2018-10-08 20:16:20 +02:00
|
|
|
|
|
|
|
|
|
if (hasStoppedAtA && willStopAtB) {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const prevStopover = maxBy(pastStopovers, departureOf);
|
|
|
|
|
return {trip: t, prevStopover};
|
2018-10-08 20:16:20 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-06 22:58:49 +01:00
|
|
|
|
return {trip: null, prevStopover: null};
|
|
|
|
|
};
|
2018-10-08 20:16:20 +02:00
|
|
|
|
|
|
|
|
|
// Find a vehicle from U Mehringdamm to U Stadtmitte (to the north) that is currently
|
|
|
|
|
// between these two stations.
|
|
|
|
|
const {trip, prevStopover} = await findTripBetween(blnMehringdamm, blnStadtmitte, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
regionalExpress: false, regional: false, suburban: false,
|
|
|
|
|
});
|
|
|
|
|
t.ok(trip, 'precondition failed: trip not found');
|
|
|
|
|
t.ok(prevStopover, 'precondition failed: previous stopover missing');
|
2018-10-08 20:16:20 +02:00
|
|
|
|
|
|
|
|
|
// todo: "Error: Suche aus dem Zug: Vor Abfahrt des Zuges"
|
|
|
|
|
const newJourneys = await client.journeysFromTrip(trip.id, prevStopover, blnSpittelmarkt, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
results: 3, stopovers: true, remarks: false,
|
|
|
|
|
});
|
2018-10-08 20:16:20 +02:00
|
|
|
|
|
|
|
|
|
// Validate with fake prices.
|
|
|
|
|
const withFakePrice = (j) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const clone = Object.assign({}, j);
|
|
|
|
|
clone.price = {amount: 123, currency: 'EUR'};
|
|
|
|
|
return clone;
|
|
|
|
|
};
|
2022-04-28 22:17:49 +02:00
|
|
|
|
// todo: there is no such validator!
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, newJourneys.map(withFakePrice), 'journeysFromTrip', 'newJourneys');
|
2018-10-08 20:16:20 +02:00
|
|
|
|
|
|
|
|
|
for (let i = 0; i < newJourneys.length; i++) {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const j = newJourneys[i];
|
|
|
|
|
const n = `newJourneys[${i}]`;
|
2018-10-08 20:16:20 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const legOnTrip = j.legs.find(l => l.tripId === trip.id);
|
|
|
|
|
t.ok(legOnTrip, n + ': leg with trip ID not found');
|
|
|
|
|
t.equal(last(legOnTrip.stopovers).stop.id, blnStadtmitte);
|
2018-10-08 20:16:20 +02:00
|
|
|
|
}
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
2018-10-08 20:16:20 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('trip details', async (t) => {
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(berlinHbf, münchenHbf, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
results: 1, departure: when,
|
|
|
|
|
});
|
2018-04-19 14:55:17 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
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:23:28 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const tripRes = await client.trip(p.tripId, {when});
|
2018-04-19 14:55:17 +02:00
|
|
|
|
|
2018-05-30 15:51:58 +02:00
|
|
|
|
const validate = createValidate(cfg, {
|
2022-04-28 23:30:49 +02:00
|
|
|
|
trip: (cfg) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const validateTrip = createValidateTrip(cfg);
|
2022-04-28 23:30:49 +02:00
|
|
|
|
const validateTripWithFakeDirection = (val, trip, name) => {
|
|
|
|
|
validateTrip(val, {
|
|
|
|
|
...trip,
|
|
|
|
|
direction: trip.direction || 'foo', // todo, see #49
|
2024-02-06 22:58:49 +01:00
|
|
|
|
}, name);
|
|
|
|
|
};
|
|
|
|
|
return validateTripWithFakeDirection;
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
validate(t, tripRes, 'tripResult', 'tripRes');
|
2018-05-30 15:51:58 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-04-19 14:55:17 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('departures at Berlin Schwedter Str.', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.departures(blnSchwedterStr, {
|
2018-12-28 21:17:03 +01:00
|
|
|
|
duration: 5, when,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
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,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2018-04-24 16:58:17 +02:00
|
|
|
|
validate,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
id: blnSchwedterStr,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2017-11-12 21:03:24 +01:00
|
|
|
|
|
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({
|
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,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
longitude: 2.34,
|
|
|
|
|
},
|
|
|
|
|
}, {when});
|
2018-01-04 16:19:42 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, res, 'departuresResponse', 'res');
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-01-04 16:19:42 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('departures at Berlin Hbf in direction of Berlin Ostbahnhof', async (t) => {
|
2018-11-21 19:07:37 +01:00
|
|
|
|
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,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-07-07 21:26:40 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('arrivals at Berlin Schwedter Str.', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.arrivals(blnSchwedterStr, {
|
2018-12-28 21:17:03 +01:00
|
|
|
|
duration: 5, when,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
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,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2018-06-26 17:30:46 +02:00
|
|
|
|
validate,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
id: blnSchwedterStr,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-06-26 17:30:46 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('nearby Berlin Jungfernheide', async (t) => {
|
2018-11-21 19:07:37 +01:00
|
|
|
|
const nearby = await client.nearby({
|
2018-01-05 14:53:03 +01:00
|
|
|
|
type: 'location',
|
|
|
|
|
latitude: 52.530273,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
longitude: 13.299433,
|
2018-01-05 14:53:03 +01:00
|
|
|
|
}, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
results: 2, distance: 400,
|
|
|
|
|
});
|
2017-11-12 21:03:24 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, nearby, 'locations', 'nearby');
|
2018-04-19 14:55:17 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.equal(nearby.length, 2);
|
2017-11-12 21:03:24 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const s0 = nearby[0];
|
|
|
|
|
t.equal(s0.id, jungfernheide);
|
|
|
|
|
t.equal(s0.name, 'Berlin Jungfernheide');
|
|
|
|
|
t.ok(isRoughlyEqual(0.0005, s0.location.latitude, 52.530408));
|
|
|
|
|
t.ok(isRoughlyEqual(0.0005, s0.location.longitude, 13.299424));
|
|
|
|
|
t.ok(s0.distance >= 0);
|
|
|
|
|
t.ok(s0.distance <= 100);
|
2017-12-11 19:53:26 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2017-11-12 21:03:24 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('locations named Jungfernheide', async (t) => {
|
2018-11-21 19:07:37 +01:00
|
|
|
|
const locations = await client.locations('Jungfernheide', {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
results: 10,
|
|
|
|
|
});
|
2017-11-12 21:03:24 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, locations, 'locations', 'locations');
|
|
|
|
|
t.ok(locations.length <= 10);
|
2018-04-19 14:55:17 +02:00
|
|
|
|
t.ok(locations.some((l) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
return l.station && l.station.id === jungfernheide || l.id === jungfernheide;
|
|
|
|
|
}), 'Jungfernheide not found');
|
2017-11-12 21:03:24 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-01-26 17:08:07 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('stop', async (t) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const s = await client.stop(regensburgHbf);
|
2018-01-26 17:08:07 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, s, ['stop', 'station'], 'stop');
|
|
|
|
|
t.equal(s.id, regensburgHbf);
|
2018-01-26 17:40:14 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-08-27 12:04:14 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('line with additionalName', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const {departures} = await client.departures(potsdamHbf, {
|
2020-05-21 22:21:07 +02:00
|
|
|
|
when,
|
2019-01-09 10:51:46 +01:00
|
|
|
|
duration: 12 * 60, // 12 minutes
|
2024-02-06 22:58:49 +01:00
|
|
|
|
products: {bus: false, suburban: false, tram: false},
|
|
|
|
|
});
|
|
|
|
|
t.ok(departures.some(d => d.line && d.line.additionalName));
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2019-01-09 10:51:46 +01:00
|
|
|
|
|
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({
|
2019-07-20 12:47:32 +02:00
|
|
|
|
north: 52.52411,
|
|
|
|
|
west: 13.41002,
|
|
|
|
|
south: 52.51942,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
east: 13.41709,
|
2019-07-20 12:47:32 +02:00
|
|
|
|
}, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
duration: 5 * 60, when,
|
|
|
|
|
});
|
2019-07-20 12:47:32 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, res, 'radarResult', 'res');
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2019-07-20 12:47:32 +02:00
|
|
|
|
|
2024-02-22 13:25:44 +01:00
|
|
|
|
tap.test('radar works across the antimeridian', async (t) => {
|
|
|
|
|
await client.radar({
|
|
|
|
|
north: -8,
|
|
|
|
|
west: 179,
|
|
|
|
|
south: -10,
|
|
|
|
|
east: -179,
|
|
|
|
|
}, {
|
|
|
|
|
// todo: update `when`, re-record all fixtures, remove this special handling
|
|
|
|
|
when: process.env.VCR_MODE ? '2024-02-22T16:00+01:00' : when,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
|
|
|
|
|
2021-12-29 15:18:21 +01:00
|
|
|
|
tap.test('reachableFrom', {timeout: 20 * 1000}, async (t) => {
|
2018-08-27 12:04:14 +02:00
|
|
|
|
const torfstr17 = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
address: 'Torfstraße 17',
|
|
|
|
|
latitude: 52.5416823,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
longitude: 13.3491223,
|
|
|
|
|
};
|
2018-08-27 12:04:14 +02:00
|
|
|
|
|
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,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-09 19:47:29 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('serverInfo works', async (t) => {
|
2020-03-09 19:47:29 +01:00
|
|
|
|
await testServerInfo({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchServerInfo: client.serverInfo,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
|
|
|
|
});
|