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

162 lines
3.7 KiB
JavaScript
Raw Permalink Normal View History

import tap from 'tap';
2022-05-07 16:17:37 +02:00
import {createWhen} from './lib/util.js';
import {createClient} from '../../index.js';
import {profile as pkpProfile} from '../../p/pkp/index.js';
2022-05-07 16:17:37 +02:00
import {
createValidateLine,
createValidateJourneyLeg,
createValidateMovement,
} from './lib/validators.js';
import {createValidateFptfWith as createValidate} from './lib/validate-fptf-with.js';
import {testJourneysStationToStation} from './lib/journeys-station-to-station.js';
import {testArrivals} from './lib/arrivals.js';
import {testReachableFrom} from './lib/reachable-from.js';
2020-03-12 18:21:16 +01:00
const T_MOCK = 1671260400 * 1000; // 2022-12-17T08:00:00+01:00
const when = createWhen(pkpProfile.timezone, pkpProfile.locale, T_MOCK);
2020-03-12 18:21:16 +01:00
const cfg = {
when,
stationCoordsOptional: false,
2022-05-07 16:17:37 +02:00
products: pkpProfile.products,
2020-03-12 18:21:16 +01:00
minLatitude: 40,
maxLatitude: 65,
minLongitude: 10,
maxLongitude: 30,
};
2020-03-12 18:21:16 +01:00
const _validateLine = createValidateLine(cfg);
2020-03-12 18:21:16 +01:00
const validateLine = (validate, l, name) => {
if (!l.direction) {
l = Object.assign({}, l, {direction: 'foo'});
}
_validateLine(validate, l, name);
};
2020-03-12 18:21:16 +01:00
const _validateJourneyLeg = createValidateJourneyLeg(cfg);
2020-03-12 18:21:16 +01:00
const validateJourneyLeg = (validate, l, name) => {
if (!l.direction) {
l = Object.assign({}, l, {direction: 'foo'});
}
_validateJourneyLeg(validate, l, name);
};
2020-03-12 18:21:16 +01:00
const _validateMovement = createValidateMovement(cfg);
2020-03-12 18:21:16 +01:00
const validateMovement = (val, m, name) => {
if (!m.direction) {
m = Object.assign({}, m, {direction: 'foo'});
}
_validateMovement(val, m, name);
};
2020-03-12 18:21:16 +01:00
const validate = createValidate(cfg, {
line: validateLine,
journeyLeg: validateJourneyLeg,
movement: validateMovement,
});
2020-03-12 18:21:16 +01:00
const client = createClient(pkpProfile, 'public-transport/hafas-client:test');
2020-03-12 18:21:16 +01:00
const wrocławGł = '5100069';
const krakówGł = '5100028';
2020-03-12 18:21:16 +01:00
const dworcowa100 = {
type: 'location',
address: 'Bydgoszcz, Dworcowa 100',
latitude: 53.1336648,
longitude: 17.9908571,
};
2020-03-12 18:21:16 +01:00
const filharmonia = {
type: 'location',
id: '980013218',
latitude: 54.351487,
longitude: 18.659548,
name: 'Gdańsk, Filharmonia',
poi: true,
};
2020-03-12 18:21:16 +01:00
2021-05-20 16:42:43 +01:00
tap.skip('journeys Wrocław Główny to Kraków Główny', async (t) => {
2020-03-12 18:21:16 +01:00
const res = await client.journeys(wrocławGł, krakówGł, {
results: 4,
departure: when,
stopovers: true,
});
2020-03-12 18:21:16 +01:00
await testJourneysStationToStation({
test: t,
res,
validate,
fromId: wrocławGł,
toId: krakówGł,
});
t.end();
});
2020-03-12 18:21:16 +01:00
// todo: via works with detour
// todo: without detour
2021-05-20 16:42:43 +01:00
tap.skip('trip details', async (t) => {
2020-03-12 18:21:16 +01:00
const res = await client.journeys(wrocławGł, krakówGł, {
results: 1, departure: when,
});
2020-03-12 18:21:16 +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-03-12 18:21:16 +01:00
const tripRes = await client.trip(p.tripId, {when});
validate(t, tripRes, 'tripResult', 'res');
t.end();
});
2020-03-12 18:21:16 +01:00
2021-05-20 16:42:43 +01:00
tap.skip('arrivals at Kraków Główny', async (t) => {
2020-03-12 18:21:16 +01:00
const arrivals = await client.arrivals(krakówGł, {
duration: 10, when,
});
2020-03-12 18:21:16 +01:00
await testArrivals({
test: t,
arrivals,
id: krakówGł,
validate,
});
t.end();
});
2020-03-12 18:21:16 +01:00
2021-05-20 16:42:43 +01:00
tap.skip('nearby', async (t) => {
const nearby = await client.nearby(dworcowa100, {distance: 500});
2020-03-12 18:21:16 +01:00
validate(t, nearby, 'locations', 'nearby');
2020-03-12 18:21:16 +01:00
const bydgoszczGł = '5100005';
t.ok(nearby.find(l => l.id === bydgoszczGł));
2020-03-12 18:21:16 +01:00
t.end();
});
2020-03-12 18:21:16 +01:00
2021-05-20 16:42:43 +01:00
tap.skip('radar', async (t) => {
const res = await client.radar({
2020-03-12 18:21:16 +01:00
north: 48.74453,
west: 11.42733,
south: 48.73453,
east: 11.43733,
2020-03-12 18:21:16 +01:00
}, {
duration: 5 * 60, when, results: 10,
});
2020-03-12 18:21:16 +01:00
validate(t, res, 'radarResult', 'res');
t.end();
});
2020-03-12 18:21:16 +01:00
2021-05-20 16:42:43 +01:00
tap.skip('reachableFrom', async (t) => {
2020-03-12 18:21:16 +01:00
await testReachableFrom({
test: t,
reachableFrom: client.reachableFrom,
address: dworcowa100,
when,
maxDuration: 20,
validate,
});
t.end();
});