2024-02-06 22:58:49 +01:00
|
|
|
|
import tap from 'tap';
|
|
|
|
|
import isRoughlyEqual from 'is-roughly-equal';
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
import {createWhen} from './lib/util.js';
|
|
|
|
|
import {createClient} from '../../index.js';
|
|
|
|
|
import {profile as invgProfile} from '../../p/invg/index.js';
|
2022-05-07 16:17:37 +02:00
|
|
|
|
import {
|
|
|
|
|
createValidateJourneyLeg,
|
|
|
|
|
createValidateMovement,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
} 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 {testRefreshJourney} from './lib/refresh-journey.js';
|
|
|
|
|
import {journeysFailsWithNoProduct} from './lib/journeys-fails-with-no-product.js';
|
|
|
|
|
import {testDepartures} from './lib/departures.js';
|
|
|
|
|
import {testArrivals} from './lib/arrivals.js';
|
|
|
|
|
|
|
|
|
|
const T_MOCK = 1668495600 * 1000; // 2022-11-15T08:00:00+01:00
|
|
|
|
|
const when = createWhen(invgProfile.timezone, invgProfile.locale, T_MOCK);
|
2022-04-23 14:40:51 +02:00
|
|
|
|
|
2022-05-07 16:17:37 +02:00
|
|
|
|
const cfg = {
|
|
|
|
|
when,
|
|
|
|
|
products: invgProfile.products,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
};
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const _validateJourneyLeg = createValidateJourneyLeg(cfg);
|
2020-03-03 02:59:55 +01:00
|
|
|
|
const validateJourneyLeg = (val, leg, name = 'journeyLeg') => {
|
|
|
|
|
_validateJourneyLeg(val, {
|
|
|
|
|
...leg,
|
|
|
|
|
direction: leg.direction || 'foo',
|
2024-02-06 22:58:49 +01:00
|
|
|
|
}, name);
|
|
|
|
|
};
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const _validateMovement = createValidateMovement(cfg);
|
2020-03-03 02:59:55 +01:00
|
|
|
|
const validateMovement = (val, m, name = 'movement') => {
|
|
|
|
|
_validateMovement(val, {
|
|
|
|
|
...m,
|
|
|
|
|
direction: m.direction || 'foo',
|
2024-02-06 22:58:49 +01:00
|
|
|
|
}, name);
|
|
|
|
|
};
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
|
|
|
|
const validate = createValidate(cfg, {
|
|
|
|
|
journeyLeg: validateJourneyLeg,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
movement: validateMovement,
|
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const client = createClient(invgProfile, 'public-transport/hafas-client:test');
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const ingolstadtHbf = '8000183';
|
|
|
|
|
const telemannstr = '71802';
|
2020-03-03 02:59:55 +01:00
|
|
|
|
const uhlandstr1 = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
address: 'Ingolstadt, Uhlandstraße 1',
|
|
|
|
|
latitude: 48.775236,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
longitude: 11.441138,
|
|
|
|
|
};
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('journeys – Ingolstadt Hbf to Audi Parkplatz', async (t) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const telemannstr = '71801';
|
2020-03-03 02:59:55 +01:00
|
|
|
|
const res = await client.journeys(ingolstadtHbf, telemannstr, {
|
|
|
|
|
results: 4,
|
|
|
|
|
departure: when,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
stopovers: true,
|
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
|
|
|
|
await testJourneysStationToStation({
|
|
|
|
|
test: t,
|
|
|
|
|
res,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: ingolstadtHbf,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
toId: telemannstr,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
|
|
|
|
// todo: journeys, only one product
|
|
|
|
|
|
2021-12-29 18:53:50 +01:00
|
|
|
|
tap.test('journeys – fails with no product', async (t) => {
|
|
|
|
|
await journeysFailsWithNoProduct({
|
2020-03-03 02:59:55 +01:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
fromId: ingolstadtHbf,
|
|
|
|
|
toId: telemannstr,
|
|
|
|
|
when,
|
2022-05-07 16:17:37 +02:00
|
|
|
|
products: invgProfile.products,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('Ingolstadt Hbf to Uhlandstr. 1', async (t) => {
|
2020-03-03 02:59:55 +01:00
|
|
|
|
const res = await client.journeys(ingolstadtHbf, uhlandstr1, {
|
|
|
|
|
results: 3,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
departure: when,
|
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
|
|
|
|
await testJourneysStationToAddress({
|
|
|
|
|
test: t,
|
|
|
|
|
res,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: ingolstadtHbf,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
to: uhlandstr1,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('Ingolstadt Hbf to Städtisches Freibad', async (t) => {
|
2020-03-03 02:59:55 +01:00
|
|
|
|
const freibad = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
id: '980000591',
|
|
|
|
|
poi: true,
|
|
|
|
|
name: 'Ingolstadt, Städtisches Freibad (Sport)',
|
|
|
|
|
latitude: 48.761473,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
longitude: 11.418602,
|
|
|
|
|
};
|
2020-03-03 02:59:55 +01:00
|
|
|
|
const res = await client.journeys(ingolstadtHbf, freibad, {
|
|
|
|
|
results: 3,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
departure: when,
|
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
|
|
|
|
await testJourneysStationToPoi({
|
|
|
|
|
test: t,
|
|
|
|
|
res,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: ingolstadtHbf,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
to: freibad,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
|
|
|
|
// todo: via works – with detour
|
|
|
|
|
// todo: without detour
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('earlier/later journeys', async (t) => {
|
2020-03-03 02:59:55 +01:00
|
|
|
|
await testEarlierLaterJourneys({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: ingolstadtHbf,
|
2020-05-21 22:21:07 +02:00
|
|
|
|
toId: telemannstr,
|
|
|
|
|
when,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('refreshJourney', async (t) => {
|
2020-03-03 02:59:55 +01:00
|
|
|
|
await testRefreshJourney({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
refreshJourney: client.refreshJourney,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: ingolstadtHbf,
|
|
|
|
|
toId: telemannstr,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
when,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('trip details', async (t) => {
|
2020-03-03 02:59:55 +01:00
|
|
|
|
const {journeys} = await client.journeys(ingolstadtHbf, telemannstr, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
results: 1, departure: when,
|
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const p = journeys[0].legs.find(l => !l.walking);
|
|
|
|
|
t.ok(p.tripId, 'precondition failed');
|
|
|
|
|
t.ok(p.line.name, 'precondition failed');
|
2020-03-03 02:59:55 +01: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();
|
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('departures at Ingolstadt Hbf', async (t) => {
|
2020-03-03 02:59:55 +01:00
|
|
|
|
const ids = [
|
|
|
|
|
ingolstadtHbf, // station
|
|
|
|
|
'80301', // stop "Ingolstadt, Hauptbahnhof Stadtauswärts"
|
2021-08-24 00:43:20 +02:00
|
|
|
|
'80302', // stop "Ingolstadt, Hauptbahnhof Stadteinwärts"
|
|
|
|
|
'80303', // stop "Ingolstadt, Hauptbahnhof Stadtauswärts"
|
2024-02-06 22:58:49 +01:00
|
|
|
|
];
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.departures(ingolstadtHbf, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
duration: 10, when,
|
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2022-04-28 21:55:11 +02:00
|
|
|
|
await testDepartures({
|
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2022-04-28 21:55:11 +02:00
|
|
|
|
validate,
|
|
|
|
|
ids,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-03 02:59:55 +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({
|
2020-03-03 02:59:55 +01:00
|
|
|
|
type: 'station',
|
|
|
|
|
id: ingolstadtHbf,
|
|
|
|
|
name: 'Ingolstadt Hbf',
|
|
|
|
|
location: {
|
|
|
|
|
type: 'location',
|
|
|
|
|
latitude: 48.822834,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
longitude: 11.461148,
|
|
|
|
|
},
|
|
|
|
|
}, {when});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, res, 'departuresResponse', 'res');
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('arrivals at Ingolstadt Hbf', async (t) => {
|
2020-03-03 02:59:55 +01:00
|
|
|
|
const ids = [
|
|
|
|
|
ingolstadtHbf, // station
|
|
|
|
|
'80301', // stop "Ingolstadt, Hauptbahnhof Stadtauswärts"
|
2024-02-06 22:58:49 +01:00
|
|
|
|
'80302', // stop "Ingolstadt, Hauptbahnhof Stadteinwärts"
|
|
|
|
|
];
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.arrivals(ingolstadtHbf, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
duration: 10, when,
|
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2022-04-28 21:55:11 +02:00
|
|
|
|
await testArrivals({
|
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2022-04-28 21:55:11 +02:00
|
|
|
|
validate,
|
|
|
|
|
ids,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('nearby', async (t) => {
|
2020-03-03 02:59:55 +01:00
|
|
|
|
const nearby = await client.nearby({
|
|
|
|
|
type: 'location',
|
|
|
|
|
id: '990001921',
|
|
|
|
|
address: 'Ingolstadt, Rathausplatz 1',
|
|
|
|
|
latitude: 48.76292,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
longitude: 11.424624,
|
|
|
|
|
}, {distance: 500});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, nearby, 'locations', 'nearby');
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const rathausplatz = '60706';
|
|
|
|
|
const harderstr = '28402';
|
|
|
|
|
t.ok(nearby.find(l => l.id === rathausplatz));
|
|
|
|
|
t.ok(nearby.find(l => l.id === harderstr));
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('locations named "freibad"', async (t) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const freibadIngolstadt = '980000591';
|
2020-03-03 02:59:55 +01:00
|
|
|
|
const locations = await client.locations('freibad', {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
results: 5,
|
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, locations, 'locations', 'locations');
|
|
|
|
|
t.ok(locations.length <= 10);
|
2020-03-03 02:59:55 +01: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.id && s.name)); // POIs
|
2020-03-03 02:59:55 +01:00
|
|
|
|
t.ok(locations.some((l) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
return l.station && l.station.id === freibadIngolstadt || l.id === freibadIngolstadt;
|
|
|
|
|
}));
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('stop Ettinger Str.', async (t) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const ettingerStr = '18304';
|
|
|
|
|
const s = await client.stop(ettingerStr);
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, s, ['stop', 'station'], 'stop');
|
|
|
|
|
t.equal(s.id, ettingerStr);
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-03 02:59:55 +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({
|
2020-03-03 02:59:55 +01:00
|
|
|
|
north: 48.74453,
|
|
|
|
|
west: 11.42733,
|
|
|
|
|
south: 48.73453,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
east: 11.43733,
|
2020-03-03 02:59:55 +01:00
|
|
|
|
}, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
duration: 5 * 60, when, results: 10,
|
|
|
|
|
});
|
2020-03-03 02:59:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, res, 'radarResult', 'res');
|
|
|
|
|
t.end();
|
|
|
|
|
});
|