db-vendo-client/test/e2e/vrn.js

229 lines
5.2 KiB
JavaScript
Raw Normal View History

import tap from 'tap';
import isRoughlyEqual from 'is-roughly-equal';
import {createWhen} from './lib/util.js';
import {createClient} from '../../index.js';
import {profile as vrnProfile} from '../../p/vrn/index.js';
import {createValidateFptfWith as createValidate} from './lib/validate-fptf-with.js';
import {testJourneysStationToStation} from './lib/journeys-station-to-station.js';
import {journeysFailsWithNoProduct} from './lib/journeys-fails-with-no-product.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 {testDepartures} from './lib/departures.js';
import {testDeparturesInDirection} from './lib/departures-in-direction.js';
import {testArrivals} from './lib/arrivals.js';
const T_MOCK = 1668495600 * 1000; // 2022-11-15T08:00:00+01:00
const when = createWhen(vrnProfile.timezone, vrnProfile.locale, T_MOCK);
2020-11-26 14:19:52 +01:00
const cfg = {
when,
// stationCoordsOptional: false,
2022-05-07 16:17:37 +02:00
products: vrnProfile.products,
2020-11-26 14:19:52 +01:00
minLatitude: 48.462,
minLongitude: 6.163,
maxLatitude: 50.440,
maxLongitude: 10.701,
};
2020-11-26 14:19:52 +01:00
const validate = createValidate(cfg, {});
2020-11-26 14:19:52 +01:00
const client = createClient(vrnProfile, 'public-transport/hafas-client:test');
2020-11-26 14:19:52 +01:00
const ludwigshafen = '8000236';
const meckesheim = '8003932';
2020-11-26 14:19:52 +01:00
2021-05-20 16:42:43 +01:00
tap.test('journeys  Ludwigshafen to Meckesheim', async (t) => {
2020-11-26 14:19:52 +01:00
const res = await client.journeys(ludwigshafen, meckesheim, {
results: 4,
departure: when,
stopovers: true,
});
2020-11-26 14:19:52 +01:00
await testJourneysStationToStation({
test: t,
res,
validate,
fromId: ludwigshafen,
toId: meckesheim,
});
t.end();
});
2020-11-26 14:19:52 +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-11-26 14:19:52 +01:00
test: t,
fetchJourneys: client.journeys,
fromId: ludwigshafen,
toId: meckesheim,
when,
2022-05-07 16:17:37 +02:00
products: vrnProfile.products,
});
t.end();
});
2020-11-26 14:19:52 +01:00
2021-05-20 16:42:43 +01:00
tap.test('Ludwigshafen to Pestalozzistr. 2, Ludwigshafen', async (t) => {
2020-11-26 14:19:52 +01:00
const pestalozzistr2 = {
type: 'location',
id: '980787337',
address: 'Ludwigshafen am Rhein - Mitte, Pestalozzistraße 2',
latitude: 49.474336, longitude: 8.441779,
};
2020-11-26 14:19:52 +01:00
const res = await client.journeys(ludwigshafen, pestalozzistr2, {
results: 3,
departure: when,
});
2020-11-26 14:19:52 +01:00
await testJourneysStationToAddress({
test: t,
res,
validate,
fromId: ludwigshafen,
to: pestalozzistr2,
});
t.end();
});
2020-11-26 14:19:52 +01:00
2021-05-20 16:42:43 +01:00
tap.test('Ludwigshafen to Südwest-Stadion', async (t) => {
2020-11-26 14:19:52 +01:00
const südweststadion = {
type: 'location',
id: '991664983',
poi: true,
name: 'Ludwigshafen am Rhein, Südwest-Stadion (Sport)',
latitude: 49.469248, longitude: 8.440691,
};
2020-11-26 14:19:52 +01:00
const res = await client.journeys(ludwigshafen, südweststadion, {
results: 3,
departure: when,
});
2020-11-26 14:19:52 +01:00
await testJourneysStationToPoi({
test: t,
res,
validate,
fromId: ludwigshafen,
to: südweststadion,
});
t.end();
});
2020-11-26 14:19:52 +01:00
// todo: via works with detour
// todo: via works without detour
2021-05-20 16:42:43 +01:00
tap.test('earlier/later journeys', async (t) => {
2020-11-26 14:19:52 +01:00
await testEarlierLaterJourneys({
test: t,
fetchJourneys: client.journeys,
validate,
fromId: ludwigshafen,
toId: meckesheim,
when,
});
2020-11-26 14:19:52 +01:00
t.end();
});
2020-11-26 14:19:52 +01:00
2021-05-20 16:42:43 +01:00
tap.test('trip details', async (t) => {
2020-11-26 14:19:52 +01:00
const res = await client.journeys(ludwigshafen, meckesheim, {
results: 1, departure: when,
});
2020-11-26 14:19:52 +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');
2020-11-26 14:19:52 +01:00
const tripRes = await client.trip(p.tripId, {when});
validate(t, tripRes, 'tripResult', 'res');
t.end();
});
2020-11-26 14:19:52 +01:00
2021-05-20 16:42:43 +01:00
tap.test('departures at Meckesheim', async (t) => {
const res = await client.departures(meckesheim, {
2020-11-26 14:19:52 +01:00
duration: 3 * 60, when,
});
2020-11-26 14:19:52 +01:00
await testDepartures({
test: t,
res,
2020-11-26 14:19:52 +01:00
validate,
id: meckesheim,
});
t.end();
});
2020-11-26 14:19:52 +01:00
2021-05-20 16:42:43 +01:00
tap.test('departures at Meckesheim in direction of Reilsheim', async (t) => {
const reilsheim = '8005015';
2020-11-26 14:19:52 +01:00
await testDeparturesInDirection({
test: t,
fetchDepartures: client.departures,
fetchTrip: client.trip,
id: meckesheim,
directionIds: [reilsheim],
when, duration: 30 * 60,
2020-11-26 14:19:52 +01:00
validate,
});
t.end();
});
2020-11-26 14:19:52 +01:00
2021-05-20 16:42:43 +01:00
tap.test('arrivals at Meckesheim', async (t) => {
const res = await client.arrivals(meckesheim, {
duration: 3 * 60, when,
});
2020-11-26 14:19:52 +01:00
await testArrivals({
test: t,
res,
2020-11-26 14:19:52 +01:00
validate,
id: meckesheim,
});
t.end();
});
2020-11-26 14:19:52 +01:00
// todo: nearby
2021-05-20 16:42:43 +01:00
tap.test('locations named Ebertpark', async (t) => {
const ebertpark = '506453';
2020-11-26 14:19:52 +01:00
const locations = await client.locations('Ebertpark', {
results: 20,
});
2020-11-26 14:19:52 +01:00
validate(t, locations, 'locations', 'locations');
t.ok(locations.length <= 20);
2020-11-26 14:19:52 +01:00
t.ok(locations.find(s => s.type === 'stop' || s.type === 'station'));
t.ok(locations.find(s => s.poi)); // POIs
2020-11-26 14:19:52 +01:00
t.ok(locations.some((l) => {
return l.station && l.station.id === ebertpark || l.id === ebertpark;
}));
2020-11-26 14:19:52 +01:00
t.end();
});
2020-11-26 14:19:52 +01:00
tap.skip('station Meckesheim', async (t) => {
const s = await client.stop(meckesheim);
2020-11-26 14:19:52 +01:00
validate(t, s, ['stop', 'station'], 'station');
t.equal(s.id, meckesheim);
2020-11-26 14:19:52 +01:00
t.end();
});
2020-11-26 14:19:52 +01:00
2021-05-20 16:42:43 +01:00
tap.test('radar', async (t) => {
const res = await client.radar({
2020-11-26 14:19:52 +01:00
north: 49.4940,
west: 8.4560,
south: 49.4774,
east: 8.4834,
}, {
duration: 5 * 60, when, results: 10,
});
2020-11-26 14:19:52 +01:00
validate(t, res, 'radarResult', 'res');
t.end();
});