2024-02-06 22:58:49 +01:00
|
|
|
|
import tap from 'tap';
|
2020-03-10 23:48:01 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
import {createWhen} from './lib/util.js';
|
|
|
|
|
import {createClient} from '../../index.js';
|
|
|
|
|
import {profile as rsagProfile} from '../../p/rsag/index.js';
|
|
|
|
|
import {createValidateFptfWith as createValidate} from './lib/validate-fptf-with.js';
|
|
|
|
|
import {testJourneysStationToStation} from './lib/journeys-station-to-station.js';
|
|
|
|
|
import {testEarlierLaterJourneys} from './lib/earlier-later-journeys.js';
|
|
|
|
|
import {testRefreshJourney} from './lib/refresh-journey.js';
|
|
|
|
|
import {testArrivals} from './lib/arrivals.js';
|
|
|
|
|
import {testReachableFrom} from './lib/reachable-from.js';
|
2020-03-10 23:48:01 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const T_MOCK = 1671260400 * 1000; // 2022-12-17T08:00:00+01:00
|
|
|
|
|
const when = createWhen(rsagProfile.timezone, rsagProfile.locale, T_MOCK);
|
2020-03-10 23:48:01 +01:00
|
|
|
|
|
|
|
|
|
const cfg = {
|
|
|
|
|
when,
|
|
|
|
|
// stationCoordsOptional: false,
|
2022-05-07 16:17:37 +02:00
|
|
|
|
products: rsagProfile.products,
|
2020-03-10 23:48:01 +01:00
|
|
|
|
minLatitude: 52.299,
|
|
|
|
|
maxLatitude: 54.862,
|
|
|
|
|
minLongitude: 9.121,
|
|
|
|
|
maxLongitude: 14.824,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
};
|
2020-03-10 23:48:01 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const validate = createValidate(cfg);
|
2020-03-10 23:48:01 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const client = createClient(rsagProfile, 'public-transport/hafas-client:test');
|
2020-03-10 23:48:01 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const sternwarte = '704956';
|
|
|
|
|
const sternwarte2 = '708539';
|
|
|
|
|
const weißesKreuz = '708573';
|
2020-03-10 23:48:01 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('journeys – Platz der Jugend to Weißes Kreuz', async (t) => {
|
2020-03-10 23:48:01 +01:00
|
|
|
|
const res = await client.journeys(sternwarte, weißesKreuz, {
|
|
|
|
|
results: 4,
|
|
|
|
|
departure: when,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
stopovers: true,
|
|
|
|
|
});
|
2020-03-10 23:48:01 +01:00
|
|
|
|
|
|
|
|
|
await testJourneysStationToStation({
|
|
|
|
|
test: t,
|
|
|
|
|
res,
|
|
|
|
|
validate,
|
2020-05-22 01:36:04 +02:00
|
|
|
|
fromIds: [sternwarte, sternwarte2],
|
|
|
|
|
toId: weißesKreuz,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-10 23:48:01 +01:00
|
|
|
|
|
|
|
|
|
// todo: journeys, walkingSpeed
|
|
|
|
|
// todo: via works – with detour
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('earlier/later journeys', async (t) => {
|
2020-03-10 23:48:01 +01:00
|
|
|
|
await testEarlierLaterJourneys({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: sternwarte,
|
|
|
|
|
toId: weißesKreuz,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
when,
|
|
|
|
|
});
|
2020-03-10 23:48:01 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-10 23:48:01 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('refreshJourney', async (t) => {
|
2020-03-10 23:48:01 +01:00
|
|
|
|
await testRefreshJourney({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
refreshJourney: client.refreshJourney,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: sternwarte,
|
|
|
|
|
toId: weißesKreuz,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
when,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-10 23:48:01 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('arrivals at Platz der Jugend', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.arrivals(sternwarte, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
duration: 30, when,
|
|
|
|
|
});
|
2020-03-10 23:48:01 +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: [
|
|
|
|
|
sternwarte,
|
|
|
|
|
'708539', // Rostock Sternwarte
|
|
|
|
|
],
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-10 23:48:01 +01:00
|
|
|
|
|
|
|
|
|
// todo: nearby
|
|
|
|
|
|
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-10 23:48:01 +01:00
|
|
|
|
north: 54.116968,
|
|
|
|
|
west: 12.029738,
|
|
|
|
|
south: 54.060517,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
east: 12.203261,
|
2020-03-10 23:48:01 +01:00
|
|
|
|
}, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
duration: 5 * 60, when, results: 10,
|
|
|
|
|
});
|
2020-03-10 23:48:01 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, res, 'radarResult', 'res');
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-10 23:48:01 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('reachableFrom', async (t) => {
|
2020-03-10 23:48:01 +01:00
|
|
|
|
await testReachableFrom({
|
|
|
|
|
test: t,
|
|
|
|
|
reachableFrom: client.reachableFrom,
|
|
|
|
|
address: {
|
|
|
|
|
type: 'location',
|
|
|
|
|
id: '990004158',
|
|
|
|
|
address: 'Rostock - Stadtmitte, Pläterstraße 2',
|
2024-02-06 22:58:49 +01:00
|
|
|
|
latitude: 54.091285, longitude: 12.13648,
|
2020-03-10 23:48:01 +01:00
|
|
|
|
},
|
|
|
|
|
when,
|
|
|
|
|
maxDuration: 15,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|