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

266 lines
6.1 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 nvvProfile} from '../../p/nvv/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';
import {testJourneysWithDetour} from './lib/journeys-with-detour.js';
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o);
const T_MOCK = 1668495600 * 1000; // 2022-11-15T08:00:00+01:00
const when = createWhen(nvvProfile.timezone, nvvProfile.locale, T_MOCK);
2019-03-29 16:39:14 +01:00
const cfg = {
when,
stationCoordsOptional: false,
2022-05-07 16:17:37 +02:00
products: nvvProfile.products,
2019-03-29 16:39:14 +01:00
minLatitude: 48,
minLongitude: 8,
maxLatitude: 53,
maxLongitude: 14,
};
const validate = createValidate(cfg, {});
2019-03-29 16:39:14 +01:00
const client = createClient(nvvProfile, 'public-transport/hafas-client:test');
2019-03-29 16:39:14 +01:00
const scheidemannplatz = '2200073';
const auestadion = '2200042';
const weigelstr = '2200056';
const friedrichsplatz = '2200006';
2019-03-29 16:39:14 +01:00
2021-05-20 16:42:43 +01:00
tap.test('journeys  Kassel Scheidemannplatz to Kassel Auestadion', async (t) => {
2019-03-29 16:39:14 +01:00
const res = await client.journeys(scheidemannplatz, auestadion, {
results: 4,
departure: when,
stopovers: true,
});
2019-03-29 16:39:14 +01:00
await testJourneysStationToStation({
test: t,
res,
validate,
fromId: scheidemannplatz,
toId: auestadion,
});
t.end();
});
2019-03-29 16:39:14 +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({
2019-03-29 16:39:14 +01:00
test: t,
fetchJourneys: client.journeys,
fromId: scheidemannplatz,
toId: auestadion,
when,
2022-05-07 16:17:37 +02:00
products: nvvProfile.products,
});
t.end();
});
2019-03-29 16:39:14 +01:00
2021-05-20 16:42:43 +01:00
tap.test('Kassel Scheidemannplatz to Heckerstraße 2', async (t) => {
2019-03-29 16:39:14 +01:00
const heckerstr2 = {
type: 'location',
id: '990100251',
address: 'Kassel, Heckerstraße 2',
latitude: 51.308108,
longitude: 9.475152,
};
2019-03-29 16:39:14 +01:00
const res = await client.journeys(scheidemannplatz, heckerstr2, {
results: 3,
departure: when,
});
2019-03-29 16:39:14 +01:00
await testJourneysStationToAddress({
test: t,
res,
validate,
fromId: scheidemannplatz,
to: heckerstr2,
});
t.end();
});
2019-03-29 16:39:14 +01:00
2021-05-20 16:42:43 +01:00
tap.test('Kassel Scheidemannplatz to Grimmwelt', async (t) => {
2019-03-29 16:39:14 +01:00
const grimmwelt = {
type: 'location',
id: '1500490',
2019-03-29 16:39:14 +01:00
poi: true,
name: 'Grimmwelt Kassel',
latitude: 51.309313,
longitude: 9.489283,
};
2019-03-29 16:39:14 +01:00
const res = await client.journeys(scheidemannplatz, grimmwelt, {
results: 3,
departure: when,
});
2019-03-29 16:39:14 +01:00
await testJourneysStationToPoi({
test: t,
res,
validate,
fromId: scheidemannplatz,
to: grimmwelt,
});
t.end();
});
2019-03-29 16:39:14 +01:00
2021-05-20 16:42:43 +01:00
tap.test('journeys: via works with detour', async (t) => {
2019-03-29 16:39:14 +01:00
// Going from Scheidemannplatz to Rathaus/Fünffensterstr. via Kassel Wilhelmshöhe
// implies a detour. We check if the routing engine computes a detour.
const rathausFünffensterstr = '2200436';
const wilhelmshöhe = '2200007';
2019-03-29 16:39:14 +01:00
const res = await client.journeys(scheidemannplatz, rathausFünffensterstr, {
via: wilhelmshöhe,
results: 1,
departure: when,
stopovers: true,
});
2019-03-29 16:39:14 +01:00
await testJourneysWithDetour({
test: t,
res,
validate,
detourIds: [wilhelmshöhe],
});
t.end();
});
2019-03-29 16:39:14 +01:00
// todo: without detour
2021-05-20 16:42:43 +01:00
tap.test('earlier/later journeys', async (t) => {
2019-03-29 16:39:14 +01:00
await testEarlierLaterJourneys({
test: t,
fetchJourneys: client.journeys,
validate,
fromId: scheidemannplatz,
toId: auestadion,
when,
});
2019-03-29 16:39:14 +01:00
t.end();
});
2019-03-29 16:39:14 +01:00
2021-05-20 16:42:43 +01:00
tap.test('trip details', async (t) => {
2019-03-29 16:39:14 +01:00
const res = await client.journeys(scheidemannplatz, auestadion, {
results: 1, departure: when,
});
2019-03-29 16:39:14 +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');
2019-03-29 16:39:14 +01:00
const tripRes = await client.trip(p.tripId, {when});
validate(t, tripRes, 'tripResult', 'res');
t.end();
});
2019-03-29 16:39:14 +01:00
2021-05-20 16:42:43 +01:00
tap.test('departures at Kassel Auestadion.', async (t) => {
const res = await client.departures(auestadion, {
2019-03-29 16:39:14 +01:00
duration: 11, when,
});
2019-03-29 16:39:14 +01:00
await testDepartures({
test: t,
res,
2019-03-29 16:39:14 +01:00
validate,
id: auestadion,
});
t.end();
});
2019-03-29 16:39:14 +01:00
2021-05-20 16:42:43 +01:00
tap.test('departures with station object', async (t) => {
const res = await client.departures({
2019-03-29 16:39:14 +01:00
type: 'station',
id: auestadion,
name: 'Kassel Auestadion',
location: {
type: 'location',
latitude: 1.23,
longitude: 2.34,
},
}, {when});
2019-03-29 16:39:14 +01:00
validate(t, res, 'departuresResponse', 'res');
t.end();
});
2019-03-29 16:39:14 +01:00
2021-05-20 16:42:43 +01:00
tap.test('departures at Auestadion in direction of Friedrichsplatz', async (t) => {
2019-03-29 16:39:14 +01:00
await testDeparturesInDirection({
test: t,
fetchDepartures: client.departures,
fetchTrip: client.trip,
id: weigelstr,
directionIds: [friedrichsplatz],
when,
validate,
});
t.end();
});
2019-03-29 16:39:14 +01:00
2021-05-20 16:42:43 +01:00
tap.test('arrivals at Kassel Weigelstr.', async (t) => {
const res = await client.arrivals(weigelstr, {
duration: 5, when,
});
2019-03-29 16:39:14 +01:00
await testArrivals({
test: t,
res,
2019-03-29 16:39:14 +01:00
validate,
id: weigelstr,
});
t.end();
});
2019-03-29 16:39:14 +01:00
// todo: nearby
2021-05-20 16:42:43 +01:00
tap.test('locations named Auestadion', async (t) => {
const locations = await client.locations('auestadion', {results: 10});
2019-03-29 16:39:14 +01:00
validate(t, locations, 'locations', 'locations');
t.ok(locations.length <= 10);
2019-03-29 16:39:14 +01:00
t.ok(locations.find(s => s.type === 'stop' || s.type === 'station'));
t.ok(locations.find(s => s.poi)); // POIs
t.ok(locations.some(l => l.station && l.station.id === auestadion || l.id === auestadion));
2019-03-29 16:39:14 +01:00
t.end();
});
2019-03-29 16:39:14 +01:00
2021-05-20 16:42:43 +01:00
tap.test('station Auestadion', async (t) => {
const s = await client.stop(auestadion);
2019-03-29 16:39:14 +01:00
validate(t, s, ['stop', 'station'], 'station');
t.equal(s.id, auestadion);
2019-03-29 16:39:14 +01:00
t.end();
});
2019-03-29 16:39:14 +01:00
2021-05-20 16:42:43 +01:00
tap.test('radar', async (t) => {
const res = await client.radar({
2019-03-29 16:39:14 +01:00
north: 51.320153,
west: 9.458359,
south: 51.304304,
east: 9.493672,
2019-03-29 16:39:14 +01:00
}, {
duration: 5 * 60, when, results: 10,
});
2019-03-29 16:39:14 +01:00
validate(t, res, 'radarResult', 'res');
2019-03-29 16:39:14 +01:00
t.end();
});