2024-02-06 22:58:49 +01:00
|
|
|
|
import tap from 'tap';
|
|
|
|
|
import assert from 'assert';
|
|
|
|
|
|
|
|
|
|
import {createWhen} from './lib/util.js';
|
|
|
|
|
import {createClient} from '../../index.js';
|
|
|
|
|
import {profile as rejseplanenProfile} from '../../p/rejseplanen/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 {testEarlierLaterJourneys} from './lib/earlier-later-journeys.js';
|
|
|
|
|
import {testDepartures} from './lib/departures.js';
|
|
|
|
|
import {testArrivals} from './lib/arrivals.js';
|
|
|
|
|
|
|
|
|
|
const T_MOCK = 1671260400 * 1000; // 2022-12-17T08:00:00+01:00
|
|
|
|
|
const when = createWhen(rejseplanenProfile.timezone, rejseplanenProfile.locale, T_MOCK);
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
|
|
|
|
const validate = createValidate({
|
|
|
|
|
when,
|
2022-05-07 16:17:37 +02:00
|
|
|
|
products: rejseplanenProfile.products,
|
2020-06-30 22:05:30 +02:00
|
|
|
|
minLatitude: 52.7,
|
|
|
|
|
maxLatitude: 58.85,
|
|
|
|
|
minLongitude: 5.8,
|
|
|
|
|
maxLongitude: 15.7,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
}, {});
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const client = createClient(rejseplanenProfile, 'public-transport/hafas-client:test');
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const næstved = '8600810';
|
|
|
|
|
const randers = '8600040';
|
|
|
|
|
const aalborg = '8600020';
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('journeys – Næstved to Aalborg', async (t) => {
|
2020-06-30 22:05:30 +02:00
|
|
|
|
const res = await client.journeys(næstved, aalborg, {
|
|
|
|
|
results: 4,
|
|
|
|
|
departure: when,
|
|
|
|
|
stopovers: true,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
|
|
|
|
await testJourneysStationToStation({
|
|
|
|
|
test: t,
|
|
|
|
|
res,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: næstved,
|
|
|
|
|
toId: aalborg,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-06-30 22:05:30 +02: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-06-30 22:05:30 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
fromId: næstved,
|
|
|
|
|
toId: aalborg,
|
|
|
|
|
when,
|
2022-05-07 16:17:37 +02:00
|
|
|
|
products: rejseplanenProfile.products,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('Randers to Møllegade 3, København', async (t) => {
|
2020-06-30 22:05:30 +02:00
|
|
|
|
const møllegade3 = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
id: '901011579',
|
|
|
|
|
address: 'Møllegade 3, 2200 København N, Københavns Kommune',
|
|
|
|
|
latitude: 55.69052, longitude: 12.555494,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
};
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
|
|
|
|
const res = await client.journeys(randers, møllegade3, {
|
|
|
|
|
results: 3,
|
|
|
|
|
departure: when,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
|
|
|
|
await testJourneysStationToAddress({
|
|
|
|
|
test: t,
|
|
|
|
|
res,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: randers,
|
|
|
|
|
to: møllegade3,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
|
|
|
|
// todo: journeys: via works – with detour
|
|
|
|
|
// todo: without detour
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('earlier/later journeys', async (t) => {
|
2020-06-30 22:05:30 +02:00
|
|
|
|
await testEarlierLaterJourneys({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: randers,
|
|
|
|
|
toId: næstved,
|
|
|
|
|
when,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('trip', async (t) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const {journeys} = await client.journeys(aalborg, næstved, {
|
2020-06-30 22:05:30 +02:00
|
|
|
|
results: 1, departure: when,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const p = journeys[0].legs.find(l => !l.walking);
|
|
|
|
|
t.ok(p.tripId, 'precondition failed');
|
|
|
|
|
t.ok(p.line.name, 'precondition failed');
|
2020-06-30 22:05:30 +02: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-06-30 22:05:30 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('departures at Næstved.', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.departures(næstved, {
|
2020-06-30 22:05:30 +02:00
|
|
|
|
duration: 20, when,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
|
|
|
|
await testDepartures({
|
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2020-06-30 22:05:30 +02:00
|
|
|
|
validate,
|
2021-08-24 00:43:20 +02:00
|
|
|
|
ids: [
|
|
|
|
|
næstved,
|
|
|
|
|
'8650810', // Næstved St. (togbus)
|
|
|
|
|
'8651810', // Næstved St. (togbus)
|
|
|
|
|
],
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('arrivals at Næstved.', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.arrivals(næstved, {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
duration: 20, when,
|
|
|
|
|
});
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
|
|
|
|
await testArrivals({
|
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2020-06-30 22:05:30 +02:00
|
|
|
|
validate,
|
2021-08-24 00:43:20 +02:00
|
|
|
|
ids: [
|
|
|
|
|
næstved,
|
|
|
|
|
'8650810', // Næstved St. (togbus)
|
|
|
|
|
'8651810', // Næstved St. (togbus)
|
|
|
|
|
],
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
|
|
|
|
// todo: nearby
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('locations named "næstved"', async (t) => {
|
2020-06-30 22:05:30 +02:00
|
|
|
|
const locations = await client.locations('næstved', {
|
|
|
|
|
results: 20,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, locations, 'locations', 'locations');
|
|
|
|
|
t.ok(locations.length <= 20);
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.ok(locations.find(s => s.type === 'stop' || s.type === 'station'));
|
|
|
|
|
t.ok(locations.find(s => s.poi));
|
2020-06-30 22:05:30 +02:00
|
|
|
|
t.ok(locations.some((loc) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
if (loc.station && loc.station.id === næstved) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return loc.id === næstved;
|
|
|
|
|
}));
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('stop Næstved', async (t) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
|
const s = await client.stop(næstved);
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, s, ['stop', 'station'], 'stop');
|
|
|
|
|
t.equal(s.id, næstved);
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
t.end();
|
|
|
|
|
});
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
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-06-30 22:05:30 +02:00
|
|
|
|
north: 55.695,
|
|
|
|
|
west: 12.498,
|
|
|
|
|
south: 55.639,
|
|
|
|
|
east: 12.621,
|
|
|
|
|
}, {
|
|
|
|
|
duration: 5 * 60, when, results: 10,
|
2024-02-06 22:58:49 +01:00
|
|
|
|
});
|
2020-06-30 22:05:30 +02:00
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
|
validate(t, res, 'radarResult', 'res');
|
|
|
|
|
t.end();
|
|
|
|
|
});
|