2024-02-06 22:58:49 +01:00
|
|
|
|
import tap from 'tap';
|
2020-03-11 22:07:56 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
import {createWhen} from './lib/util.js';
|
|
|
|
|
import {createClient} from '../../index.js';
|
|
|
|
|
import {profile as vbnProfile} from '../../p/vbn/index.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-11 22:07:56 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const T_MOCK = 1668495600 * 1000; // 2022-11-15T08:00:00+01:00
|
|
|
|
|
const when = createWhen(vbnProfile.timezone, vbnProfile.locale, T_MOCK);
|
2020-03-11 22:07:56 +01:00
|
|
|
|
|
|
|
|
|
const cfg = {
|
|
|
|
|
when,
|
|
|
|
|
stationCoordsOptional: false,
|
2022-05-07 16:17:37 +02:00
|
|
|
|
products: vbnProfile.products,
|
2020-03-11 22:07:56 +01:00
|
|
|
|
minLatitude: 51.817,
|
|
|
|
|
maxLatitude: 53.657,
|
|
|
|
|
minLongitude: 5.248,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
maxLongitude: 11.719,
|
|
|
|
|
};
|
2020-03-11 22:07:56 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const validate = createValidate(cfg);
|
2020-03-11 22:07:56 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const client = createClient(vbnProfile, 'public-transport/hafas-client:test');
|
2020-03-11 22:07:56 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const oldenburg = '8000291';
|
|
|
|
|
const bremenHumboldtstr = '9013973';
|
2020-03-11 22:07:56 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('journeys – Oldenburg to Bremen Humboldtstr.', async (t) => {
|
2020-03-11 22:07:56 +01:00
|
|
|
|
const res = await client.journeys(oldenburg, bremenHumboldtstr, {
|
|
|
|
|
results: 4,
|
|
|
|
|
departure: when,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
stopovers: true,
|
|
|
|
|
});
|
2020-03-11 22:07:56 +01:00
|
|
|
|
|
|
|
|
|
await testJourneysStationToStation({
|
|
|
|
|
test: t,
|
|
|
|
|
res,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: oldenburg,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
toId: bremenHumboldtstr,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-11 22:07:56 +01:00
|
|
|
|
|
|
|
|
|
// todo: via works – with detour
|
|
|
|
|
// todo: without detour
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('trip details', async (t) => {
|
2020-03-11 22:07:56 +01:00
|
|
|
|
const res = await client.journeys(oldenburg, bremenHumboldtstr, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
results: 1, departure: when,
|
|
|
|
|
});
|
2020-03-11 22:07:56 +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');
|
2020-03-11 22:07:56 +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();
|
|
|
|
|
});
|
2020-03-11 22:07:56 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('arrivals at Bremen Humboldtstr.', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.arrivals(bremenHumboldtstr, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
duration: 10, when,
|
|
|
|
|
});
|
2020-03-11 22:07:56 +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,
|
|
|
|
|
id: bremenHumboldtstr,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-11 22:07:56 +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-11 22:07:56 +01:00
|
|
|
|
north: 53.090516,
|
|
|
|
|
west: 8.750106,
|
|
|
|
|
south: 53.062859,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
east: 8.847423,
|
2020-03-11 22:07:56 +01:00
|
|
|
|
}, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
duration: 5 * 60, when, results: 10,
|
|
|
|
|
});
|
2020-03-11 22:07:56 +01:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, res, 'radarResult', 'res');
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-03-11 22:07:56 +01:00
|
|
|
|
|
2020-07-19 16:59:38 +02:00
|
|
|
|
// todo: fails with "HCI Service: location missing or invalid"
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('reachableFrom', async (t) => {
|
2020-03-11 22:07:56 +01:00
|
|
|
|
await testReachableFrom({
|
|
|
|
|
test: t,
|
|
|
|
|
reachableFrom: client.reachableFrom,
|
|
|
|
|
address: {
|
|
|
|
|
type: 'location',
|
2021-04-24 14:00:08 +02:00
|
|
|
|
id: '910001336',
|
2020-03-11 22:07:56 +01:00
|
|
|
|
name: 'Rathaus, Bremen',
|
|
|
|
|
poi: true,
|
|
|
|
|
latitude: 53.076053, longitude: 8.808008,
|
|
|
|
|
},
|
|
|
|
|
when,
|
|
|
|
|
maxDuration: 15,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate,
|
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|