2018-07-28 13:43:58 +02:00
|
|
|
|
// todo: DRY with vbb tests
|
2022-05-07 16:17:37 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
import tap from 'tap';
|
|
|
|
|
|
|
|
|
|
import isRoughlyEqual from 'is-roughly-equal';
|
|
|
|
|
import {DateTime} from 'luxon';
|
|
|
|
|
import flatMap from 'lodash/flatMap.js';
|
|
|
|
|
|
|
|
|
|
import {createWhen} from './lib/util.js';
|
|
|
|
|
import {createClient} from '../../index.js';
|
|
|
|
|
import {profile as bvgProfile} from '../../p/bvg/index.js';
|
|
|
|
|
import {createValidateFptfWith as createValidate} from './lib/validate-fptf-with.js';
|
|
|
|
|
import {createVbbBvgValidators} from './lib/vbb-bvg-validators.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 {testJourneysWalkingSpeed} from './lib/journeys-walking-speed.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 {testRemarks} from './lib/remarks.js';
|
|
|
|
|
import {testLines} from './lib/lines.js';
|
|
|
|
|
|
2024-09-25 21:42:23 +02:00
|
|
|
|
const T_MOCK = 1731394800 * 1000; // 2024-11-12T08:00:00+01:00
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const when = createWhen(bvgProfile.timezone, bvgProfile.locale, T_MOCK);
|
2022-04-27 09:46:19 +02:00
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
cfg,
|
|
|
|
|
validateStation,
|
|
|
|
|
validateJourneyLeg,
|
|
|
|
|
validateDeparture,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validateMovement,
|
2022-05-07 16:17:37 +02:00
|
|
|
|
} = createVbbBvgValidators({
|
2022-04-27 09:46:19 +02:00
|
|
|
|
when,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
|
|
|
|
const validate = createValidate(cfg, {
|
|
|
|
|
station: validateStation,
|
|
|
|
|
journeyLeg: validateJourneyLeg,
|
|
|
|
|
departure: validateDeparture,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
movement: validateMovement,
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const client = createClient(bvgProfile, 'public-transport/hafas-client:test');
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const amrumerStr = '900009101';
|
|
|
|
|
const spichernstr = '900042101';
|
|
|
|
|
const bismarckstr = '900024201';
|
|
|
|
|
const westhafen = '900001201';
|
|
|
|
|
const wedding = '900009104';
|
|
|
|
|
const württembergallee = '900026153';
|
|
|
|
|
const tiergarten = '900003103';
|
|
|
|
|
const jannowitzbrücke = '900100004';
|
2018-12-02 21:24:21 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const hour = 60 * 60 * 1000;
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('journeys – Spichernstr. to Bismarckstr.', async (t) => {
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(spichernstr, bismarckstr, {
|
2019-02-01 15:35:18 +01:00
|
|
|
|
results: 4,
|
2018-07-28 13:43:58 +02:00
|
|
|
|
departure: when,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
stopovers: true,
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToStation({
|
2018-07-28 13:43:58 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-07-28 13:43:58 +02:00
|
|
|
|
validate,
|
|
|
|
|
fromId: spichernstr,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
toId: bismarckstr,
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
// todo: find a journey where there ticket info is always available
|
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('journeys – only subway', async (t) => {
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(spichernstr, bismarckstr, {
|
2018-07-28 13:43:58 +02:00
|
|
|
|
results: 20,
|
|
|
|
|
departure: when,
|
|
|
|
|
products: {
|
|
|
|
|
suburban: false,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
subway: true,
|
|
|
|
|
tram: false,
|
|
|
|
|
bus: false,
|
|
|
|
|
ferry: false,
|
|
|
|
|
express: false,
|
|
|
|
|
regional: false,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
validate(t, res, 'journeysResult', 'res');
|
|
|
|
|
|
|
|
|
|
t.ok(res.journeys.length > 1);
|
2019-01-16 21:41:17 +08:00
|
|
|
|
for (let i = 0; i < res.journeys.length; i++) {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const journey = res.journeys[i];
|
2018-07-28 13:43:58 +02:00
|
|
|
|
for (let j = 0; j < journey.legs.length; j++) {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const leg = journey.legs[j];
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const name = `res.journeys[${i}].legs[${j}].line`;
|
2018-07-28 13:43:58 +02:00
|
|
|
|
if (leg.line) {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.equal(leg.line.mode, 'train', name + '.mode is invalid');
|
|
|
|
|
t.equal(leg.line.product, 'subway', name + '.product is invalid');
|
2018-07-28 13:43:58 +02:00
|
|
|
|
}
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.ok(journey.legs.some(l => l.line), name + '.legs has no subway leg');
|
2018-07-28 13:43:58 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2021-12-29 18:53:50 +01:00
|
|
|
|
tap.test('journeys – fails with no product', async (t) => {
|
|
|
|
|
await journeysFailsWithNoProduct({
|
2018-07-28 13:43:58 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
fromId: spichernstr,
|
|
|
|
|
toId: bismarckstr,
|
|
|
|
|
when,
|
2022-05-07 16:17:37 +02:00
|
|
|
|
products: bvgProfile.products,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2020-05-22 01:36:04 +02:00
|
|
|
|
// BerlKönig for public use is suspended during COVID-19.
|
2022-04-27 09:50:24 +02:00
|
|
|
|
tap.skip('journeys – BerlKönig', async (t) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const when = DateTime
|
|
|
|
|
.fromMillis(Date.now(), {
|
|
|
|
|
zone: 'Europe/Berlin',
|
|
|
|
|
locale: 'de-De',
|
|
|
|
|
})
|
|
|
|
|
.startOf('day')
|
|
|
|
|
.plus({days: 1, hours: 18})
|
|
|
|
|
.toISO();
|
2018-10-28 17:55:52 +01:00
|
|
|
|
|
|
|
|
|
const {journeys} = await client.journeys({
|
|
|
|
|
type: 'location',
|
|
|
|
|
address: '12101 Berlin-Tempelhof, Peter-Str.r-Weg 1',
|
|
|
|
|
latitude: 52.476283,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
longitude: 13.384947,
|
2018-10-28 17:55:52 +01:00
|
|
|
|
}, {
|
|
|
|
|
type: 'location',
|
|
|
|
|
id: '900981505',
|
|
|
|
|
poi: true,
|
|
|
|
|
name: 'Berlin, Tempelhofer Park Eingang Oderstr.',
|
|
|
|
|
latitude: 52.476688,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
longitude: 13.41872,
|
2018-10-28 17:55:52 +01:00
|
|
|
|
}, {
|
|
|
|
|
berlkoenig: true,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
departure: when,
|
|
|
|
|
});
|
2018-10-28 17:55:52 +01:00
|
|
|
|
|
|
|
|
|
const withBerlkoenig = flatMap(journeys, j => j.legs)
|
2024-02-06 22:58:49 +01:00
|
|
|
|
.find(l => l.line && l.line.product === 'berlkoenig');
|
|
|
|
|
t.ok(withBerlkoenig, 'journey with BerlKönig not found');
|
2018-10-28 17:55:52 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.ok(withBerlkoenig.line);
|
|
|
|
|
t.equal(withBerlkoenig.line.public, true);
|
|
|
|
|
t.equal(withBerlkoenig.line.mode, 'taxi');
|
|
|
|
|
t.equal(withBerlkoenig.line.product, 'berlkoenig');
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-10-28 17:55:52 +01:00
|
|
|
|
|
2018-10-29 22:11:08 +01:00
|
|
|
|
// todo: opt.walkingSpeed doesn't seem to work right now
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.skip('journeys: walkingSpeed', async (t) => {
|
2018-10-29 22:11:08 +01:00
|
|
|
|
const havelchaussee = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
address: 'Havelchaussee',
|
|
|
|
|
latitude: 52.443576,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
longitude: 13.198973,
|
|
|
|
|
};
|
|
|
|
|
const wannsee = '900053301';
|
2018-10-29 22:11:08 +01:00
|
|
|
|
|
|
|
|
|
await testJourneysWalkingSpeed({
|
|
|
|
|
test: t,
|
|
|
|
|
journeys: client.journeys,
|
|
|
|
|
validate,
|
|
|
|
|
from: havelchaussee,
|
|
|
|
|
to: wannsee,
|
|
|
|
|
products: {bus: false},
|
2024-02-06 22:58:49 +01:00
|
|
|
|
minTimeDifference: 5 * 60 * 1000,
|
|
|
|
|
});
|
|
|
|
|
});
|
2018-10-29 22:11:08 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('earlier/later journeys', async (t) => {
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testEarlierLaterJourneys({
|
2018-07-28 13:43:58 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: spichernstr,
|
2018-11-20 18:38:48 +01:00
|
|
|
|
toId: bismarckstr,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
when,
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02: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: tiergarten,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
toId: jannowitzbrücke,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2022-11-18 18:01:33 +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-28 13:43:58 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
refreshJourney: client.refreshJourney,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: spichernstr,
|
|
|
|
|
toId: bismarckstr,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
when,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-07-28 13:43:58 +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(spichernstr, amrumerStr, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
results: 1, departure: when,
|
|
|
|
|
});
|
2018-07-28 13:43:58 +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');
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const tripRes = await client.trip(p.tripId, {when});
|
2021-12-29 21:23:28 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, tripRes, 'tripResult', 'res');
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('journeys – station to address', async (t) => {
|
2018-07-28 13:43:58 +02:00
|
|
|
|
const torfstr = {
|
|
|
|
|
type: 'location',
|
2024-09-25 21:42:23 +02:00
|
|
|
|
address: '13353 Berlin-Wedding, Torfstraße 17',
|
2018-07-28 13:43:58 +02:00
|
|
|
|
latitude: 52.541797,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
longitude: 13.350042,
|
|
|
|
|
};
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(spichernstr, torfstr, {
|
2018-07-28 13:43:58 +02:00
|
|
|
|
results: 3,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
departure: when,
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToAddress({
|
2018-07-28 13:43:58 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-07-28 13:43:58 +02:00
|
|
|
|
validate,
|
|
|
|
|
fromId: spichernstr,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
to: torfstr,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('journeys – station to POI', async (t) => {
|
2018-07-28 13:43:58 +02:00
|
|
|
|
const atze = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
id: '900980720',
|
2019-02-07 17:47:50 +01:00
|
|
|
|
poi: true,
|
2018-07-28 13:43:58 +02:00
|
|
|
|
name: 'Berlin, Atze Musiktheater für Kinder',
|
|
|
|
|
latitude: 52.543333,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
longitude: 13.351686,
|
|
|
|
|
};
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(spichernstr, atze, {
|
2018-07-28 13:43:58 +02:00
|
|
|
|
results: 3,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
departure: when,
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToPoi({
|
2018-07-28 13:43:58 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-07-28 13:43:58 +02:00
|
|
|
|
validate,
|
|
|
|
|
fromId: spichernstr,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
to: atze,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('journeys: via works – with detour', async (t) => {
|
2018-07-28 13:43:58 +02:00
|
|
|
|
// Going from Westhafen to Wedding via Württembergalle without detour
|
|
|
|
|
// 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-07-28 13:43:58 +02:00
|
|
|
|
via: württembergallee,
|
|
|
|
|
results: 1,
|
|
|
|
|
departure: when,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
stopovers: true,
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysWithDetour({
|
2018-07-28 13:43:58 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-07-28 13:43:58 +02:00
|
|
|
|
validate,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
detourIds: [württembergallee],
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
|
|
|
|
// todo: without detour test
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('departures', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.departures(spichernstr, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
duration: 5, when,
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testDepartures({
|
2018-07-28 13:43:58 +02:00
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2018-07-28 13:43:58 +02:00
|
|
|
|
validate,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
id: spichernstr,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02: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-07-28 13:43:58 +02:00
|
|
|
|
type: 'station',
|
|
|
|
|
id: spichernstr,
|
|
|
|
|
name: 'U Spichernstr',
|
|
|
|
|
location: {
|
|
|
|
|
type: 'location',
|
|
|
|
|
latitude: 1.23,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
longitude: 2.34,
|
|
|
|
|
},
|
|
|
|
|
}, {when});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, res, 'departuresResponse', 'res');
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('departures at Spichernstr. in direction of Westhafen', async (t) => {
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testDeparturesInDirection({
|
2018-07-28 13:43:58 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchDepartures: client.departures,
|
|
|
|
|
fetchTrip: client.trip,
|
|
|
|
|
id: spichernstr,
|
|
|
|
|
directionIds: [westhafen],
|
|
|
|
|
when,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('departures at 7-digit station', async (t) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const eisenach = '8010097'; // see derhuerst/vbb-hafas#22
|
|
|
|
|
await client.departures(eisenach, {when});
|
|
|
|
|
t.pass('did not fail');
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('arrivals', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.arrivals(spichernstr, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
duration: 5, when,
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testArrivals({
|
2018-07-28 13:43:58 +02:00
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2018-07-28 13:43:58 +02:00
|
|
|
|
validate,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
id: spichernstr,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('nearby', async (t) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const berlinerStr = '900044201';
|
|
|
|
|
const landhausstr = '900043252';
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
|
|
|
|
// Berliner Str./Bundesallee
|
2018-11-21 19:07:37 +01:00
|
|
|
|
const nearby = await client.nearby({
|
2018-07-28 13:43:58 +02:00
|
|
|
|
type: 'location',
|
|
|
|
|
latitude: 52.4873452,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
longitude: 13.3310411,
|
2021-10-19 00:35:45 +02:00
|
|
|
|
}, {
|
|
|
|
|
// Even though HAFAS reports Landhausstr. to be 179m, we have to pass way more here. 🙄
|
|
|
|
|
distance: 600,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, nearby, 'locations', 'nearby');
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.equal(nearby[0].id, berlinerStr);
|
|
|
|
|
t.equal(nearby[0].name, 'U Berliner Str. (Berlin)');
|
|
|
|
|
t.ok(nearby[0].distance > 0);
|
|
|
|
|
t.ok(nearby[0].distance < 100);
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const res = nearby.find(s => s.id === landhausstr);
|
|
|
|
|
t.ok(res, `Landhausstr. ${landhausstr} is not among the nearby stops`);
|
|
|
|
|
t.equal(nearby[1].name, 'Landhausstr. (Berlin)');
|
|
|
|
|
t.ok(nearby[1].distance > 100);
|
|
|
|
|
t.ok(nearby[1].distance < 200);
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('locations', async (t) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const locations = await client.locations('Alexanderplatz', {results: 20});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, locations, 'locations', 'locations');
|
|
|
|
|
t.ok(locations.length <= 20);
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.ok(locations.find(s => s.type === 'stop' || s.type === 'station'));
|
|
|
|
|
t.ok(locations.find(s => s.poi)); // POIs
|
|
|
|
|
t.ok(locations.find(s => !s.name && s.address)); // addresses
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02: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(spichernstr);
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, s, ['stop', 'station'], 'stop');
|
|
|
|
|
t.equal(s.id, spichernstr);
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02: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({
|
2018-07-28 13:43:58 +02:00
|
|
|
|
north: 52.52411,
|
|
|
|
|
west: 13.41002,
|
|
|
|
|
south: 52.51942,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
east: 13.41709,
|
2018-07-28 13:43:58 +02:00
|
|
|
|
}, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
duration: 5 * 60, when,
|
|
|
|
|
});
|
2018-07-28 13:43:58 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, res, 'radarResult', 'res');
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-08-27 12:04:14 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('reachableFrom', async (t) => {
|
2018-08-27 12:04:14 +02:00
|
|
|
|
const torfstr17 = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
address: '13353 Berlin-Wedding, Torfstr. 17',
|
|
|
|
|
latitude: 52.541797,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
longitude: 13.350042,
|
|
|
|
|
};
|
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();
|
|
|
|
|
});
|
2021-12-29 21:25:49 +01:00
|
|
|
|
|
|
|
|
|
tap.test('remarks', async (t) => {
|
|
|
|
|
await testRemarks({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchRemarks: client.remarks,
|
|
|
|
|
when,
|
|
|
|
|
validate,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2021-12-29 21:26:12 +01:00
|
|
|
|
|
|
|
|
|
tap.test('lines', async (t) => {
|
|
|
|
|
await testLines({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchLines: client.lines,
|
|
|
|
|
validate,
|
|
|
|
|
query: 'M10',
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|