2024-02-06 22:58:49 +01:00
|
|
|
|
import tap from 'tap';
|
|
|
|
|
import isRoughlyEqual from 'is-roughly-equal';
|
2018-12-29 16:04: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 saarfahrplanProfile} from '../../p/saarfahrplan/index.js';
|
2022-05-07 16:17:37 +02:00
|
|
|
|
import {
|
|
|
|
|
createValidateStation,
|
|
|
|
|
createValidateStop,
|
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 {journeysFailsWithNoProduct} from './lib/journeys-fails-with-no-product.js';
|
|
|
|
|
import {testJourneysWithDetour} from './lib/journeys-with-detour.js';
|
|
|
|
|
import {testDepartures} from './lib/departures.js';
|
|
|
|
|
import {testDeparturesInDirection} from './lib/departures-in-direction.js';
|
|
|
|
|
|
|
|
|
|
const T_MOCK = 1671260400 * 1000; // 2022-12-17T08:00:00+01:00
|
|
|
|
|
const when = createWhen(saarfahrplanProfile.timezone, saarfahrplanProfile.locale, T_MOCK);
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
|
|
|
|
const cfg = {
|
|
|
|
|
when,
|
|
|
|
|
// stationCoordsOptional: false, @todo
|
2022-05-07 16:17:37 +02:00
|
|
|
|
products: saarfahrplanProfile.products,
|
2018-12-29 16:04:55 +01:00
|
|
|
|
minLatitude: 49,
|
|
|
|
|
maxLatitude: 49.6,
|
|
|
|
|
minLongitude: 6.1,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
maxLongitude: 7.5,
|
|
|
|
|
};
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
|
|
|
|
// @todo validateDirection: search list of stations for direction
|
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const validate = createValidate(cfg);
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
|
|
|
|
const assertValidPrice = (t, p) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.ok(p);
|
2018-12-29 16:04:55 +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);
|
2018-12-29 16:04:55 +01:00
|
|
|
|
}
|
|
|
|
|
if (p.hint !== null) {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.equal(typeof p.hint, 'string');
|
|
|
|
|
t.ok(p.hint);
|
2018-12-29 16:04:55 +01:00
|
|
|
|
}
|
2024-02-06 22:58:49 +01:00
|
|
|
|
};
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const client = createClient(saarfahrplanProfile, 'public-transport/hafas-client:test');
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const saarbrueckenHbf = '8000323';
|
2018-12-29 16:04:55 +01:00
|
|
|
|
// This seems to be the bus/tram stop. 🙄
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const hauptbahnhofSaarbruecken = '10600';
|
|
|
|
|
const saarlouisHbf = '8005247';
|
|
|
|
|
const metzVille = '8700019';
|
|
|
|
|
const saarbrueckenUhlandstr = '10609';
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
|
|
|
|
const thomasMannStr = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
address: 'Neunkirchen, Thomas-Mann-Straße 1',
|
|
|
|
|
latitude: 49.348307,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
longitude: 7.183613,
|
|
|
|
|
};
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
|
|
|
|
// @todo prices/tickets
|
|
|
|
|
// @todo journeys, only one product
|
|
|
|
|
|
2021-12-29 18:53:50 +01:00
|
|
|
|
tap.test('journeys – fails with no product', async (t) => {
|
|
|
|
|
await journeysFailsWithNoProduct({
|
2018-12-29 16:04:55 +01:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
fromId: saarbrueckenHbf,
|
|
|
|
|
toId: saarlouisHbf,
|
|
|
|
|
when,
|
2022-05-07 16:17:37 +02:00
|
|
|
|
products: saarfahrplanProfile.products,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('Saarbrücken Hbf to Neunkirchen, Thomas-Mann-Straße 1', async (t) => {
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(saarbrueckenHbf, thomasMannStr, {
|
2018-12-29 16:04:55 +01:00
|
|
|
|
results: 3,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
departure: when,
|
|
|
|
|
});
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToAddress({
|
2018-12-29 16:04:55 +01:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-12-29 16:04:55 +01:00
|
|
|
|
validate,
|
|
|
|
|
fromId: saarbrueckenHbf,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
to: thomasMannStr,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('Saarbrücken Hbf to Schlossberghöhlen', async (t) => {
|
2018-12-29 16:04:55 +01:00
|
|
|
|
const schlossberghoehlen = {
|
|
|
|
|
type: 'location',
|
2019-02-07 17:47:50 +01:00
|
|
|
|
id: '9000185',
|
|
|
|
|
poi: true,
|
2018-12-29 16:04:55 +01:00
|
|
|
|
name: 'Homburg, Schlossberghöhlen',
|
2019-02-07 17:47:50 +01:00
|
|
|
|
latitude: 49.32071,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
longitude: 7.343764,
|
|
|
|
|
};
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(saarbrueckenHbf, schlossberghoehlen, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
results: 3, departure: when,
|
|
|
|
|
});
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToPoi({
|
2018-12-29 16:04:55 +01:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-12-29 16:04:55 +01:00
|
|
|
|
validate,
|
|
|
|
|
fromId: saarbrueckenHbf,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
to: schlossberghoehlen,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2021-12-29 15:18:21 +01:00
|
|
|
|
tap.test('journeys: via works – with detour', async (t) => {
|
|
|
|
|
// Going from Lessingstr. to An der Trift via Steubenstr. without detour
|
2018-12-29 16:04:55 +01:00
|
|
|
|
// is currently impossible. We check if the routing engine computes a detour.
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const lessingstr = '10615';
|
|
|
|
|
const anDerTrift = '10801';
|
|
|
|
|
const steubenstr = '10051';
|
2021-12-29 15:18:21 +01:00
|
|
|
|
const res = await client.journeys(lessingstr, anDerTrift, {
|
|
|
|
|
via: steubenstr,
|
2018-12-29 16:04:55 +01:00
|
|
|
|
results: 1,
|
|
|
|
|
departure: when,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
stopovers: true,
|
|
|
|
|
});
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysWithDetour({
|
2018-12-29 16:04:55 +01:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-12-29 16:04:55 +01:00
|
|
|
|
validate,
|
2021-12-29 15:18:21 +01:00
|
|
|
|
detourIds: [steubenstr],
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2020-07-19 16:59:38 +02:00
|
|
|
|
// todo: journeys: via works – without detour
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('earlier/later journeys, Saarbrücken Hbf -> Saarlouis Hbf', async (t) => {
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testEarlierLaterJourneys({
|
2018-12-29 16:04:55 +01:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: saarbrueckenHbf,
|
|
|
|
|
toId: saarlouisHbf,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
when,
|
|
|
|
|
});
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-12-29 16:04:55 +01: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(saarlouisHbf, metzVille, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
results: 1, departure: when,
|
|
|
|
|
});
|
2018-12-29 16:04:55 +01: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-12-29 16:04: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();
|
|
|
|
|
});
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
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(saarbrueckenUhlandstr, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
duration: 5, when,
|
|
|
|
|
});
|
2018-12-29 16:04: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,
|
|
|
|
|
id: saarbrueckenUhlandstr,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('departures with stop object', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.departures({
|
2018-12-29 16:04:55 +01:00
|
|
|
|
type: 'stop',
|
2021-12-29 21:11:07 +01:00
|
|
|
|
id: saarbrueckenHbf,
|
2018-12-29 16:04:55 +01:00
|
|
|
|
name: 'Saarbrücken Hbf',
|
|
|
|
|
location: {
|
|
|
|
|
type: 'location',
|
|
|
|
|
latitude: 49.241066,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
longitude: 6.991019,
|
|
|
|
|
},
|
|
|
|
|
}, {when});
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, res, 'departuresResponse', 'res');
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('departures at Uhlandstr., Saarbrücken in direction of Landwehrplatz', async (t) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const saarbrueckenLandwehrplatz = '10606';
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testDeparturesInDirection({
|
2018-12-29 16:04:55 +01:00
|
|
|
|
test: t,
|
|
|
|
|
fetchDepartures: client.departures,
|
|
|
|
|
fetchTrip: client.trip,
|
|
|
|
|
id: saarbrueckenUhlandstr,
|
|
|
|
|
directionIds: [saarbrueckenLandwehrplatz],
|
|
|
|
|
when,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
|
|
|
|
// todo: arrivals
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('nearby Saarbrücken Hbf', async (t) => {
|
2018-11-21 19:07:37 +01:00
|
|
|
|
const nearby = await client.nearby({
|
2018-12-29 16:04:55 +01:00
|
|
|
|
type: 'location',
|
|
|
|
|
latitude: 49.241066,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
longitude: 6.991019,
|
2018-12-29 16:04:55 +01:00
|
|
|
|
}, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
results: 5, distance: 400,
|
|
|
|
|
});
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, nearby, 'locations', 'nearby');
|
|
|
|
|
t.equal(nearby.length, 5);
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const s = nearby[0];
|
|
|
|
|
t.equal(s.id, saarbrueckenHbf, 'id should be ' + saarbrueckenHbf);
|
|
|
|
|
t.equal(s.name, 'Saarbrücken Hbf');
|
|
|
|
|
t.ok(isRoughlyEqual(0.0005, s.location.latitude, 49.241066));
|
|
|
|
|
t.ok(isRoughlyEqual(0.0005, s.location.longitude, 6.991019));
|
|
|
|
|
t.ok(s.distance >= 0);
|
|
|
|
|
t.ok(s.distance <= 100);
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('locations named Saarbrücken', async (t) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const aufDerWerthBürgerpark = '10204';
|
2019-02-07 18:06:15 +01:00
|
|
|
|
const locations = await client.locations('bürgerpark', {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
results: 20,
|
|
|
|
|
});
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, locations, 'locations', 'locations');
|
|
|
|
|
t.ok(locations.length <= 20);
|
2018-12-29 16:04: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.poi)); // POIs
|
2018-12-29 16:04:55 +01:00
|
|
|
|
t.ok(locations.some((s) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
return s.station && s.station.id === aufDerWerthBürgerpark || s.id === aufDerWerthBürgerpark;
|
|
|
|
|
}));
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-12-29 16:04:55 +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(saarbrueckenUhlandstr);
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, s, ['stop', 'station'], 'stop');
|
|
|
|
|
t.equal(s.id, saarbrueckenUhlandstr);
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2018-12-29 16:04: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({
|
2018-12-29 16:04:55 +01:00
|
|
|
|
north: 49.27,
|
|
|
|
|
west: 6.97,
|
|
|
|
|
south: 49.22,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
east: 7.02,
|
2018-12-29 16:04:55 +01:00
|
|
|
|
}, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
duration: 5 * 60, when,
|
|
|
|
|
});
|
2018-12-29 16:04:55 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, res, 'radarResult', 'res');
|
|
|
|
|
t.end();
|
|
|
|
|
});
|