improve line details (fahrtNr, name, id), add tests

This commit is contained in:
Traines 2025-01-10 18:55:14 +00:00
parent a624e62172
commit 63bc542b1c
13 changed files with 1193 additions and 24 deletions

View file

@ -322,7 +322,7 @@ const createClient = (profile, userAgent, opt = {}) => {
const {res} = await profile.request({profile, opt}, userAgent, req);
const ctx = {profile, opt, common, res};
const trip = profile.parseTrip(ctx, res);
const trip = profile.parseTrip(ctx, res, id);
return {
trip,

View file

@ -2,12 +2,12 @@ import slugg from 'slugg';
const parseLine = (ctx, p) => {
const profile = ctx.profile;
const fahrtNr = p.verkehrsmittel?.nummer || p.transport?.number || p.train?.no || ((p.risZuglaufId || '') + '_').split('_')[1] || p.verkehrsmittelNummer || ((p.mitteltext || '') + ' ').split(' ')[1];
const fahrtNr = p.verkehrsmittel?.nummer || p.transport?.number || p.train?.no || ((p.risZuglaufId || '') + '_').split('_')[1] || p.verkehrsmittelNummer || ((p.mitteltext || '') + ' ').split(' ')[1] || ((p.zugName || '') + ' ').split(' ')[1];
const res = {
type: 'line',
id: slugg(p.verkehrsmittel?.langText || p.transport?.journeyDescription || p.train && p.train.category + ' ' + p.train.lineName + ' ' + p.train.no || p.langtext || p.mitteltext), // TODO terrible
id: slugg(p.verkehrsmittel?.langText || p.transport?.journeyDescription || p.risZuglaufId || p.train && p.train.category + ' ' + p.train.lineName + ' ' + p.train.no || p.langtext || p.mitteltext || p.zugName), // TODO terrible
fahrtNr: String(fahrtNr),
name: p.verkehrsmittel?.langText || p.verkehrsmittel?.name || p.zugName || p.transport?.journeyDescription || p.train && p.train.category + ' ' + p.train.lineName || p.langtext || p.mitteltext,
name: p.verkehrsmittel?.langText || p.verkehrsmittel?.name || p.zugName || p.transport && p.transport.category + ' ' + p.transport.line || p.train && p.train.category + ' ' + p.train.lineName || p.mitteltext || p.langtext,
public: true,
};

View file

@ -1,9 +1,9 @@
const parseTrip = (ctx, t) => { // t = raw trip
const parseTrip = (ctx, t, id) => { // t = raw trip
const {profile} = ctx;
// pretend the trip is a leg in a journey
const trip = profile.parseJourneyLeg(ctx, t);
trip.id = trip.tripId; // TODO journeyId
trip.id = trip.tripId || id; // TODO journeyId
delete trip.tripId;
delete trip.reachable;
trip.cancelled = profile.parseCancelled(t);

View file

@ -31,8 +31,8 @@ Depending on the configured profile, db-vendo-client will use multiple different
| tickets | only for `refreshJourney()` | only for `refreshJourney()`, mutually exclusive with polylines |
| polylines | only for `trip()` | only for `refreshJourney()/trip()`, mutually exclusive with tickets |
| trip ids used | HAFAS trip ids for journeys, RIS trip ids for boards (static on train splits?) | HAFAS trip ids |
| line.id/fahrtNr used | unreliable/route id for journeys, actual fahrtNr for boards | unreliable/route id |
| adminCode/operator | adminCode only for boards | only for `journeys()` |
| line.id/fahrtNr used | unreliable/route id for journeys/`trip()`, actual fahrtNr for boards | actual fahrtNr for journeys, unreliable/route id for boards and `trip()` |
| adminCode/operator | adminCode only for boards | only for journeys |
| `stop()` | ❌ | ✅ |
| assumed backend API stability | less stable | more stable |

28
test/db-trip.js Normal file
View file

@ -0,0 +1,28 @@
// todo: use import assertions once they're supported by Node.js & ESLint
// https://github.com/tc39/proposal-import-assertions
import {createRequire} from 'module';
const require = createRequire(import.meta.url);
import tap from 'tap';
import {createClient} from '../index.js';
import {profile as rawProfile} from '../p/db/index.js';
const res = require('./fixtures/db-trip.json');
import {dbTrip as expected} from './fixtures/db-trip.js';
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
const {profile} = client;
const opt = {
stopovers: true,
remarks: true,
products: {},
};
tap.test('parses a trip correctly (DB)', (t) => {
const ctx = {profile, opt, common: null, res};
const trip = profile.parseTrip(ctx, res, 'foo');
t.same(trip, expected.trip);
t.end();
});

30
test/dbnav-trip.js Normal file
View file

@ -0,0 +1,30 @@
// todo: use import assertions once they're supported by Node.js & ESLint
// https://github.com/tc39/proposal-import-assertions
import {createRequire} from 'module';
const require = createRequire(import.meta.url);
import tap from 'tap';
import {createClient} from '../index.js';
import {profile as rawProfile} from '../p/dbnav/index.js';
const res = require('./fixtures/dbnav-trip.json');
import {dbTrip as expected} from './fixtures/dbnav-trip.js';
const client = createClient(rawProfile, 'public-transport/hafas-client:test', {enrichStations: false});
const {profile} = client;
const opt = {
stopovers: true,
remarks: true,
products: {},
};
tap.test('parses a trip correctly (DBnav)', (t) => {
const ctx = {profile, opt, common: null, res};
const trip = profile.parseTrip(ctx, res, 'foo');
t.same(trip, expected.trip);
// console.log(JSON.stringify(trip, function(k, v) { return v === undefined ? "undefined" : v; }));
t.end();
});

View file

@ -17,7 +17,7 @@ const dbArrivals = [
type: 'line',
id: 's-42-42323',
fahrtNr: '42323',
name: 'S 42 (42323)',
name: 'S 42',
public: true,
productName: 'S',
mode: 'train',
@ -62,7 +62,7 @@ const dbArrivals = [
type: 'line',
id: 'u-7-15421',
fahrtNr: '15421',
name: 'U 7 (15421)',
name: 'U 7',
public: true,
productName: 'U',
mode: 'train',
@ -113,7 +113,7 @@ const dbArrivals = [
type: 'line',
id: 'bus-m21-93424',
fahrtNr: '93424',
name: 'Bus M21 (93424)',
name: 'Bus M21',
public: true,
productName: 'Bus',
mode: 'bus',
@ -164,7 +164,7 @@ const dbArrivals = [
type: 'line',
id: 's-41-41254',
fahrtNr: '41254',
name: 'S 41 (41254)',
name: 'S 41',
public: true,
productName: 'S',
mode: 'train',
@ -209,7 +209,7 @@ const dbArrivals = [
type: 'line',
id: 'u-7-15422',
fahrtNr: '15422',
name: 'U 7 (15422)',
name: 'U 7',
public: true,
productName: 'U',
mode: 'train',
@ -260,7 +260,7 @@ const dbArrivals = [
type: 'line',
id: 's-42-42325',
fahrtNr: '42325',
name: 'S 42 (42325)',
name: 'S 42',
public: true,
productName: 'S',
mode: 'train',
@ -305,7 +305,7 @@ const dbArrivals = [
type: 'line',
id: 'u-7-15752',
fahrtNr: '15752',
name: 'U 7 (15752)',
name: 'U 7',
public: true,
productName: 'U',
mode: 'train',

474
test/fixtures/db-trip.js vendored Normal file
View file

@ -0,0 +1,474 @@
const dbTrip = {
trip: {
id: 'foo',
origin: {
type: 'station',
id: '8004168',
name: 'München Flughafen Terminal',
location: {
type: 'location',
id: '8004168',
latitude: 48.353732,
longitude: 11.785973,
},
},
destination: {
type: 'station',
id: '8000284',
name: 'Nürnberg Hbf',
location: {
type: 'location',
id: '8000284',
latitude: 49.445615,
longitude: 11.082989,
},
},
departure: '2025-01-17T15:16:00+01:00',
plannedDeparture: '2025-01-17T15:16:00+01:00',
departureDelay: null,
arrival: '2025-01-17T17:49:00+01:00',
plannedArrival: '2025-01-17T17:49:00+01:00',
arrivalDelay: null,
line: {
type: 'line',
id: 'ag-84100',
fahrtNr: '84100',
name: 'ag 84100',
productName: undefined,
product: undefined,
mode: undefined,
public: true,
operator: null,
},
direction: null,
arrivalPlatform: '13',
plannedArrivalPlatform: '13',
departurePlatform: '1',
plannedDeparturePlatform: '1',
stopovers: [
{
stop: {
type: 'station',
id: '8004168',
name: 'München Flughafen Terminal',
location: {
type: 'location',
id: '8004168',
latitude: 48.353732,
longitude: 11.785973,
},
},
arrival: null,
plannedArrival: null,
arrivalDelay: null,
arrivalPlatform: '1',
arrivalPrognosisType: null,
plannedArrivalPlatform: '1',
departure: '2025-01-17T15:16:00+01:00',
plannedDeparture: '2025-01-17T15:16:00+01:00',
departureDelay: null,
departurePlatform: '1',
departurePrognosisType: null,
plannedDeparturePlatform: '1',
remarks: [],
},
{
stop: {
type: 'station',
id: '8004167',
name: 'München Flughafen Besucherpark',
location: {
type: 'location',
id: '8004167',
latitude: 48.352095,
longitude: 11.764183,
},
},
arrival: '2025-01-17T15:18:00+01:00',
plannedArrival: '2025-01-17T15:18:00+01:00',
arrivalDelay: null,
arrivalPlatform: '1',
arrivalPrognosisType: null,
plannedArrivalPlatform: '1',
departure: '2025-01-17T15:18:00+01:00',
plannedDeparture: '2025-01-17T15:18:00+01:00',
departureDelay: null,
departurePlatform: '1',
departurePrognosisType: null,
plannedDeparturePlatform: '1',
remarks: [],
},
{
stop: {
type: 'station',
id: '8002078',
name: 'Freising',
location: {
type: 'location',
id: '8002078',
latitude: 48.395199,
longitude: 11.744542,
},
},
arrival: '2025-01-17T15:28:00+01:00',
plannedArrival: '2025-01-17T15:28:00+01:00',
arrivalDelay: null,
arrivalPlatform: '4',
arrivalPrognosisType: null,
plannedArrivalPlatform: '4',
departure: '2025-01-17T15:29:00+01:00',
plannedDeparture: '2025-01-17T15:29:00+01:00',
departureDelay: null,
departurePlatform: '4',
departurePrognosisType: null,
plannedDeparturePlatform: '4',
remarks: [],
},
{
stop: {
type: 'station',
id: '8004084',
name: 'Moosburg',
location: {
type: 'location',
id: '8004084',
latitude: 48.470331,
longitude: 11.930385,
},
},
arrival: '2025-01-17T15:37:00+01:00',
plannedArrival: '2025-01-17T15:37:00+01:00',
arrivalDelay: null,
arrivalPlatform: '1',
arrivalPrognosisType: null,
plannedArrivalPlatform: '1',
departure: '2025-01-17T15:38:00+01:00',
plannedDeparture: '2025-01-17T15:38:00+01:00',
departureDelay: null,
departurePlatform: '1',
departurePrognosisType: null,
plannedDeparturePlatform: '1',
remarks: [],
},
{
stop: {
type: 'station',
id: '8000217',
name: 'Landshut(Bay)Hbf',
location: {
type: 'location',
id: '8000217',
latitude: 48.547494,
longitude: 12.135932,
},
},
arrival: '2025-01-17T15:50:00+01:00',
plannedArrival: '2025-01-17T15:50:00+01:00',
arrivalDelay: null,
arrivalPlatform: '5',
arrivalPrognosisType: null,
plannedArrivalPlatform: '5',
departure: '2025-01-17T15:53:00+01:00',
plannedDeparture: '2025-01-17T15:53:00+01:00',
departureDelay: null,
departurePlatform: '5',
departurePrognosisType: null,
plannedDeparturePlatform: '5',
remarks: [],
},
{
stop: {
type: 'station',
id: '8001835',
name: 'Ergoldsbach',
location: {
type: 'location',
id: '8001835',
latitude: 48.693865,
longitude: 12.201877,
},
},
arrival: '2025-01-17T16:05:00+01:00',
plannedArrival: '2025-01-17T16:05:00+01:00',
arrivalDelay: null,
arrivalPlatform: '1',
arrivalPrognosisType: null,
plannedArrivalPlatform: '1',
departure: '2025-01-17T16:06:00+01:00',
plannedDeparture: '2025-01-17T16:06:00+01:00',
departureDelay: null,
departurePlatform: '1',
departurePrognosisType: null,
plannedDeparturePlatform: '1',
remarks: [],
},
{
stop: {
type: 'station',
id: '8000688',
name: 'Neufahrn(Niederbay)',
location: {
type: 'location',
id: '8000688',
latitude: 48.729885,
longitude: 12.19046,
},
},
arrival: '2025-01-17T16:09:00+01:00',
plannedArrival: '2025-01-17T16:09:00+01:00',
arrivalDelay: null,
arrivalPlatform: '2',
arrivalPrognosisType: null,
plannedArrivalPlatform: '2',
departure: '2025-01-17T16:10:00+01:00',
plannedDeparture: '2025-01-17T16:10:00+01:00',
departureDelay: null,
departurePlatform: '2',
departurePrognosisType: null,
plannedDeparturePlatform: '2',
remarks: [],
},
{
stop: {
type: 'station',
id: '8001679',
name: 'Eggmühl',
location: {
type: 'location',
id: '8001679',
latitude: 48.836497,
longitude: 12.18219,
},
},
arrival: '2025-01-17T16:19:00+01:00',
plannedArrival: '2025-01-17T16:19:00+01:00',
arrivalDelay: null,
arrivalPlatform: '3',
arrivalPrognosisType: null,
plannedArrivalPlatform: '3',
departure: '2025-01-17T16:20:00+01:00',
plannedDeparture: '2025-01-17T16:20:00+01:00',
departureDelay: null,
departurePlatform: '3',
departurePrognosisType: null,
plannedDeparturePlatform: '3',
remarks: [],
},
{
stop: {
type: 'station',
id: '8002506',
name: 'Hagelstadt',
location: {
type: 'location',
id: '8002506',
latitude: 48.895862,
longitude: 12.21483,
},
},
arrival: '2025-01-17T16:25:00+01:00',
plannedArrival: '2025-01-17T16:25:00+01:00',
arrivalDelay: null,
arrivalPlatform: '2',
arrivalPrognosisType: null,
plannedArrivalPlatform: '2',
departure: '2025-01-17T16:26:00+01:00',
plannedDeparture: '2025-01-17T16:26:00+01:00',
departureDelay: null,
departurePlatform: '2',
departurePrognosisType: null,
plannedDeparturePlatform: '2',
remarks: [],
},
{
stop: {
type: 'station',
id: '8003357',
name: 'Köfering',
location: {
type: 'location',
id: '8003357',
latitude: 48.93172,
longitude: 12.208753,
},
},
arrival: '2025-01-17T16:29:00+01:00',
plannedArrival: '2025-01-17T16:29:00+01:00',
arrivalDelay: null,
arrivalPlatform: '2',
arrivalPrognosisType: null,
plannedArrivalPlatform: '2',
departure: '2025-01-17T16:30:00+01:00',
plannedDeparture: '2025-01-17T16:30:00+01:00',
departureDelay: null,
departurePlatform: '2',
departurePrognosisType: null,
plannedDeparturePlatform: '2',
remarks: [],
},
{
stop: {
type: 'station',
id: '8004592',
name: 'Obertraubling',
location: {
type: 'location',
id: '8004592',
latitude: 48.967533,
longitude: 12.169992,
},
},
arrival: '2025-01-17T16:33:00+01:00',
plannedArrival: '2025-01-17T16:33:00+01:00',
arrivalDelay: null,
arrivalPlatform: '2',
arrivalPrognosisType: null,
plannedArrivalPlatform: '2',
departure: '2025-01-17T16:34:00+01:00',
plannedDeparture: '2025-01-17T16:34:00+01:00',
departureDelay: null,
departurePlatform: '2',
departurePrognosisType: null,
plannedDeparturePlatform: '2',
remarks: [],
},
{
stop: {
type: 'station',
id: '8000309',
name: 'Regensburg Hbf',
location: {
type: 'location',
id: '8000309',
latitude: 49.01167,
longitude: 12.099615,
},
},
arrival: '2025-01-17T16:41:00+01:00',
plannedArrival: '2025-01-17T16:41:00+01:00',
arrivalDelay: null,
arrivalPlatform: '5',
arrivalPrognosisType: null,
plannedArrivalPlatform: '5',
departure: '2025-01-17T16:45:00+01:00',
plannedDeparture: '2025-01-17T16:45:00+01:00',
departureDelay: null,
departurePlatform: '5',
departurePrognosisType: null,
plannedDeparturePlatform: '5',
remarks: [],
},
{
stop: {
type: 'station',
id: '8000882',
name: 'Beratzhausen',
location: {
type: 'location',
id: '8000882',
latitude: 49.092843,
longitude: 11.807853,
},
},
arrival: '2025-01-17T17:02:00+01:00',
plannedArrival: '2025-01-17T17:02:00+01:00',
arrivalDelay: null,
arrivalPlatform: '2',
arrivalPrognosisType: null,
plannedArrivalPlatform: '2',
departure: '2025-01-17T17:02:00+01:00',
plannedDeparture: '2025-01-17T17:02:00+01:00',
departureDelay: null,
departurePlatform: '2',
departurePrognosisType: null,
plannedDeparturePlatform: '2',
remarks: [],
},
{
stop: {
type: 'station',
id: '8004755',
name: 'Parsberg',
location: {
type: 'location',
id: '8004755',
latitude: 49.164352,
longitude: 11.723354,
},
},
arrival: '2025-01-17T17:08:00+01:00',
plannedArrival: '2025-01-17T17:08:00+01:00',
arrivalDelay: null,
arrivalPlatform: '2',
arrivalPrognosisType: null,
plannedArrivalPlatform: '2',
departure: '2025-01-17T17:09:00+01:00',
plannedDeparture: '2025-01-17T17:09:00+01:00',
departureDelay: null,
departurePlatform: '2',
departurePrognosisType: null,
plannedDeparturePlatform: '2',
remarks: [],
},
{
stop: {
type: 'station',
id: '8004305',
name: 'Neumarkt(Oberpf)',
location: {
type: 'location',
id: '8004305',
latitude: 49.27322,
longitude: 11.456986,
},
},
arrival: '2025-01-17T17:25:00+01:00',
plannedArrival: '2025-01-17T17:25:00+01:00',
arrivalDelay: null,
arrivalPlatform: '1',
arrivalPrognosisType: null,
plannedArrivalPlatform: '1',
departure: '2025-01-17T17:26:00+01:00',
plannedDeparture: '2025-01-17T17:26:00+01:00',
departureDelay: null,
departurePlatform: '1',
departurePrognosisType: null,
plannedDeparturePlatform: '1',
remarks: [],
},
{
stop: {
type: 'station',
id: '8000284',
name: 'Nürnberg Hbf',
location: {
type: 'location',
id: '8000284',
latitude: 49.445615,
longitude: 11.082989,
},
},
arrival: '2025-01-17T17:49:00+01:00',
plannedArrival: '2025-01-17T17:49:00+01:00',
arrivalDelay: null,
arrivalPlatform: '13',
arrivalPrognosisType: null,
plannedArrivalPlatform: '13',
departure: null,
plannedDeparture: null,
departureDelay: null,
departurePlatform: '13',
departurePrognosisType: null,
plannedDeparturePlatform: '13',
remarks: [],
},
],
remarks: [],
cancelled: false,
},
realtimeDataUpdatedAt: null,
};
export {
dbTrip,
};

1
test/fixtures/db-trip.json vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -34,9 +34,9 @@ const dbNavJourney = {
tripId: '2|#VN#1#ST#1735585219#PI#1#ZI#888642#TA#1#DA#30125#1S#8000105#1T#1756#LS#8000007#LT#1921#PU#81#RT#1#CA#DPN#ZE#29266#ZB#RB 29266#PC#3#FR#8000105#FT#1756#TO#8000007#TT#1921#',
line: {
type: 'line',
id: 'rb-31-29266',
id: 'rb-29266',
fahrtNr: '29266',
name: 'RB 31 (29266)',
name: 'RB 31',
public: true,
productName: 'RB',
mode: 'train',

529
test/fixtures/dbnav-trip.js vendored Normal file
View file

@ -0,0 +1,529 @@
const dbTrip = {
trip: {
id: 'foo',
origin: {
type: 'station',
id: '8004168',
name: 'München Flughafen Terminal',
location: {
type: 'location',
id: '8004168',
latitude: 48.353733,
longitude: 11.785973,
},
},
destination: {
type: 'station',
id: '8000284',
name: 'Nürnberg Hbf',
location: {
type: 'location',
id: '8000284',
latitude: 49.445435,
longitude: 11.08227,
},
},
departure: '2025-01-17T15:16:00+01:00',
plannedDeparture: '2025-01-17T15:16:00+01:00',
departureDelay: null,
arrival: '2025-01-17T17:49:00+01:00',
plannedArrival: '2025-01-17T17:49:00+01:00',
arrivalDelay: null,
line: {
type: 'line',
id: 'ag-re22',
fahrtNr: '84100',
name: 'ag RE22',
public: true,
productName: 'ag',
mode: 'train',
product: 'regional',
operator: {
type: 'operator',
id: 'agilis',
name: 'agilis',
},
},
direction: 'Nürnberg Hbf',
arrivalPlatform: '13',
plannedArrivalPlatform: '13',
departurePlatform: '1',
plannedDeparturePlatform: '1',
stopovers: [
{
stop: {
type: 'station',
id: '8004168',
name: 'München Flughafen Terminal',
location: {
type: 'location',
id: '8004168',
latitude: 48.353733,
longitude: 11.785973,
},
},
arrival: null,
plannedArrival: null,
arrivalDelay: null,
arrivalPlatform: '1',
arrivalPrognosisType: null,
plannedArrivalPlatform: '1',
departure: '2025-01-17T15:16:00+01:00',
plannedDeparture: '2025-01-17T15:16:00+01:00',
departureDelay: null,
departurePlatform: '1',
departurePrognosisType: null,
plannedDeparturePlatform: '1',
remarks: [
{
code: 'text.journeystop.product.or.direction.changes.stop.message',
summary: 'As ag 84100 heading towards Nürnberg Hbf from here',
text: 'As ag 84100 heading towards Nürnberg Hbf from here',
type: 'hint',
},
],
},
{
stop: {
type: 'station',
id: '8004167',
name: 'München Flughafen Besucherpark',
location: {
type: 'location',
id: '8004167',
latitude: 48.352097,
longitude: 11.764174,
},
},
arrival: '2025-01-17T15:18:00+01:00',
plannedArrival: '2025-01-17T15:18:00+01:00',
arrivalDelay: null,
arrivalPlatform: '1',
arrivalPrognosisType: null,
plannedArrivalPlatform: '1',
departure: '2025-01-17T15:18:00+01:00',
plannedDeparture: '2025-01-17T15:18:00+01:00',
departureDelay: null,
departurePlatform: '1',
departurePrognosisType: null,
plannedDeparturePlatform: '1',
remarks: [],
},
{
stop: {
type: 'station',
id: '8002078',
name: 'Freising',
location: {
type: 'location',
id: '8002078',
latitude: 48.39498,
longitude: 11.744551,
},
},
arrival: '2025-01-17T15:28:00+01:00',
plannedArrival: '2025-01-17T15:28:00+01:00',
arrivalDelay: null,
arrivalPlatform: '4',
arrivalPrognosisType: null,
plannedArrivalPlatform: '4',
departure: '2025-01-17T15:29:00+01:00',
plannedDeparture: '2025-01-17T15:29:00+01:00',
departureDelay: null,
departurePlatform: '4',
departurePrognosisType: null,
plannedDeparturePlatform: '4',
remarks: [],
},
{
stop: {
type: 'station',
id: '8004084',
name: 'Moosburg',
location: {
type: 'location',
id: '8004084',
latitude: 48.46998,
longitude: 11.930492,
},
},
arrival: '2025-01-17T15:37:00+01:00',
plannedArrival: '2025-01-17T15:37:00+01:00',
arrivalDelay: null,
arrivalPlatform: '1',
arrivalPrognosisType: null,
plannedArrivalPlatform: '1',
departure: '2025-01-17T15:38:00+01:00',
plannedDeparture: '2025-01-17T15:38:00+01:00',
departureDelay: null,
departurePlatform: '1',
departurePrognosisType: null,
plannedDeparturePlatform: '1',
remarks: [],
},
{
stop: {
type: 'station',
id: '8000217',
name: 'Landshut(Bay)Hbf',
location: {
type: 'location',
id: '8000217',
latitude: 48.547512,
longitude: 12.135878,
},
},
arrival: '2025-01-17T15:50:00+01:00',
plannedArrival: '2025-01-17T15:50:00+01:00',
arrivalDelay: null,
arrivalPlatform: '5',
arrivalPrognosisType: null,
plannedArrivalPlatform: '5',
departure: '2025-01-17T15:53:00+01:00',
plannedDeparture: '2025-01-17T15:53:00+01:00',
departureDelay: null,
departurePlatform: '5',
departurePrognosisType: null,
plannedDeparturePlatform: '5',
remarks: [],
},
{
stop: {
type: 'station',
id: '8001835',
name: 'Ergoldsbach',
location: {
type: 'location',
id: '8001835',
latitude: 48.69383,
longitude: 12.201877,
},
},
arrival: '2025-01-17T16:05:00+01:00',
plannedArrival: '2025-01-17T16:05:00+01:00',
arrivalDelay: null,
arrivalPlatform: '1',
arrivalPrognosisType: null,
plannedArrivalPlatform: '1',
departure: '2025-01-17T16:06:00+01:00',
plannedDeparture: '2025-01-17T16:06:00+01:00',
departureDelay: null,
departurePlatform: '1',
departurePrognosisType: null,
plannedDeparturePlatform: '1',
remarks: [],
},
{
stop: {
type: 'station',
id: '8000688',
name: 'Neufahrn(Niederbay)',
location: {
type: 'location',
id: '8000688',
latitude: 48.729866,
longitude: 12.19046,
},
},
arrival: '2025-01-17T16:09:00+01:00',
plannedArrival: '2025-01-17T16:09:00+01:00',
arrivalDelay: null,
arrivalPlatform: '2',
arrivalPrognosisType: null,
plannedArrivalPlatform: '2',
departure: '2025-01-17T16:10:00+01:00',
plannedDeparture: '2025-01-17T16:10:00+01:00',
departureDelay: null,
departurePlatform: '2',
departurePrognosisType: null,
plannedDeparturePlatform: '2',
remarks: [],
},
{
stop: {
type: 'station',
id: '8001679',
name: 'Eggmühl',
location: {
type: 'location',
id: '8001679',
latitude: 48.8365,
longitude: 12.182217,
},
},
arrival: '2025-01-17T16:19:00+01:00',
plannedArrival: '2025-01-17T16:19:00+01:00',
arrivalDelay: null,
arrivalPlatform: '3',
arrivalPrognosisType: null,
plannedArrivalPlatform: '3',
departure: '2025-01-17T16:20:00+01:00',
plannedDeparture: '2025-01-17T16:20:00+01:00',
departureDelay: null,
departurePlatform: '3',
departurePrognosisType: null,
plannedDeparturePlatform: '3',
remarks: [],
},
{
stop: {
type: 'station',
id: '8002506',
name: 'Hagelstadt',
location: {
type: 'location',
id: '8002506',
latitude: 48.896034,
longitude: 12.214812,
},
},
arrival: '2025-01-17T16:25:00+01:00',
plannedArrival: '2025-01-17T16:25:00+01:00',
arrivalDelay: null,
arrivalPlatform: '2',
arrivalPrognosisType: null,
plannedArrivalPlatform: '2',
departure: '2025-01-17T16:26:00+01:00',
plannedDeparture: '2025-01-17T16:26:00+01:00',
departureDelay: null,
departurePlatform: '2',
departurePrognosisType: null,
plannedDeparturePlatform: '2',
remarks: [],
},
{
stop: {
type: 'station',
id: '8003357',
name: 'Köfering',
location: {
type: 'location',
id: '8003357',
latitude: 48.931694,
longitude: 12.208736,
},
},
arrival: '2025-01-17T16:29:00+01:00',
plannedArrival: '2025-01-17T16:29:00+01:00',
arrivalDelay: null,
arrivalPlatform: '2',
arrivalPrognosisType: null,
plannedArrivalPlatform: '2',
departure: '2025-01-17T16:30:00+01:00',
plannedDeparture: '2025-01-17T16:30:00+01:00',
departureDelay: null,
departurePlatform: '2',
departurePrognosisType: null,
plannedDeparturePlatform: '2',
remarks: [],
},
{
stop: {
type: 'station',
id: '8004592',
name: 'Obertraubling',
location: {
type: 'location',
id: '8004592',
latitude: 48.967514,
longitude: 12.169974,
},
},
arrival: '2025-01-17T16:33:00+01:00',
plannedArrival: '2025-01-17T16:33:00+01:00',
arrivalDelay: null,
arrivalPlatform: '2',
arrivalPrognosisType: null,
plannedArrivalPlatform: '2',
departure: '2025-01-17T16:34:00+01:00',
plannedDeparture: '2025-01-17T16:34:00+01:00',
departureDelay: null,
departurePlatform: '2',
departurePrognosisType: null,
plannedDeparturePlatform: '2',
remarks: [],
},
{
stop: {
type: 'station',
id: '8000309',
name: 'Regensburg Hbf',
location: {
type: 'location',
id: '8000309',
latitude: 49.01175,
longitude: 12.099669,
},
},
arrival: '2025-01-17T16:41:00+01:00',
plannedArrival: '2025-01-17T16:41:00+01:00',
arrivalDelay: null,
arrivalPlatform: '5',
arrivalPrognosisType: null,
plannedArrivalPlatform: '5',
departure: '2025-01-17T16:45:00+01:00',
plannedDeparture: '2025-01-17T16:45:00+01:00',
departureDelay: null,
departurePlatform: '5',
departurePrognosisType: null,
plannedDeparturePlatform: '5',
remarks: [
{
code: 'text.journeystop.product.or.direction.changes.stop.message',
summary: 'As ag 63070 heading towards Nürnberg Hbf from here',
text: 'As ag 63070 heading towards Nürnberg Hbf from here',
type: 'hint',
},
],
},
{
stop: {
type: 'station',
id: '8000882',
name: 'Beratzhausen',
location: {
type: 'location',
id: '8000882',
latitude: 49.09251,
longitude: 11.808527,
},
},
arrival: '2025-01-17T17:02:00+01:00',
plannedArrival: '2025-01-17T17:02:00+01:00',
arrivalDelay: null,
arrivalPlatform: '2',
arrivalPrognosisType: null,
plannedArrivalPlatform: '2',
departure: '2025-01-17T17:02:00+01:00',
plannedDeparture: '2025-01-17T17:02:00+01:00',
departureDelay: null,
departurePlatform: '2',
departurePrognosisType: null,
plannedDeparturePlatform: '2',
remarks: [],
},
{
stop: {
type: 'station',
id: '8004755',
name: 'Parsberg',
location: {
type: 'location',
id: '8004755',
latitude: 49.16416,
longitude: 11.724136,
},
},
arrival: '2025-01-17T17:08:00+01:00',
plannedArrival: '2025-01-17T17:08:00+01:00',
arrivalDelay: null,
arrivalPlatform: '2',
arrivalPrognosisType: null,
plannedArrivalPlatform: '2',
departure: '2025-01-17T17:09:00+01:00',
plannedDeparture: '2025-01-17T17:09:00+01:00',
departureDelay: null,
departurePlatform: '2',
departurePrognosisType: null,
plannedDeparturePlatform: '2',
remarks: [],
},
{
stop: {
type: 'station',
id: '8004305',
name: 'Neumarkt(Oberpf)',
location: {
type: 'location',
id: '8004305',
latitude: 49.273193,
longitude: 11.456986,
},
},
arrival: '2025-01-17T17:25:00+01:00',
plannedArrival: '2025-01-17T17:25:00+01:00',
arrivalDelay: null,
arrivalPlatform: '1',
arrivalPrognosisType: null,
plannedArrivalPlatform: '1',
departure: '2025-01-17T17:26:00+01:00',
plannedDeparture: '2025-01-17T17:26:00+01:00',
departureDelay: null,
departurePlatform: '1',
departurePrognosisType: null,
plannedDeparturePlatform: '1',
remarks: [],
},
{
stop: {
type: 'station',
id: '8000284',
name: 'Nürnberg Hbf',
location: {
type: 'location',
id: '8000284',
latitude: 49.445435,
longitude: 11.08227,
},
},
arrival: '2025-01-17T17:49:00+01:00',
plannedArrival: '2025-01-17T17:49:00+01:00',
arrivalDelay: null,
arrivalPlatform: '13',
arrivalPrognosisType: null,
plannedArrivalPlatform: '13',
departure: null,
plannedDeparture: null,
departureDelay: null,
departurePlatform: '13',
departurePrognosisType: null,
plannedDeparturePlatform: '13',
remarks: [],
},
],
remarks: [
{
code: 'ZR',
summary: 'vertraglicher Beförderer DB Regio (München Flughafen Terminal - Regensburg Hbf)',
text: 'vertraglicher Beförderer DB Regio (München Flughafen Terminal - Regensburg Hbf)',
type: 'hint',
},
{
text: 'Number of bicycles conveyed limited',
type: 'hint',
code: 'bicycle-conveyance',
summary: 'bicycles conveyed',
},
{
code: 'EA',
summary: 'Behindertengerechte Ausstattung',
text: 'Behindertengerechte Ausstattung',
type: 'hint',
},
{
text: 'power sockets for laptop',
type: 'hint',
code: 'power-sockets',
summary: 'power sockets available',
},
{
text: 'air conditioning',
type: 'hint',
code: 'air-conditioned',
summary: 'air-conditioned vehicle',
},
{
text: 'Wifi available',
type: 'hint',
code: 'wifi',
summary: 'WiFi available',
},
],
cancelled: false,
},
realtimeDataUpdatedAt: null,
};
export {
dbTrip,
};

1
test/fixtures/dbnav-trip.json vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -12,7 +12,7 @@ const ctx = {
profile,
};
tap.test('parses ICE leg correctly', (t) => {
tap.test('parses db ICE leg correctly', (t) => {
const input = {
journeyId: 'foo',
verkehrsmittel: {
@ -53,7 +53,7 @@ tap.test('parses ICE leg correctly', (t) => {
});
tap.test('parses Bus trip correctly', (t) => {
tap.test('parses db Bus trip correctly', (t) => {
const input = {
reisetag: '2024-12-07',
regulaereVerkehrstage: 'not every day',
@ -70,8 +70,8 @@ tap.test('parses Bus trip correctly', (t) => {
};
const expected = {
type: 'line',
id: '',
fahrtNr: '',
id: 'bus-807',
fahrtNr: '807',
name: 'Bus 807',
public: true,
product: undefined,
@ -84,8 +84,28 @@ tap.test('parses Bus trip correctly', (t) => {
t.end();
});
tap.test('parses db trip correctly', (t) => {
const input = {
reisetag: '2025-01-17',
regulaereVerkehrstage: 'daily',
zugName: 'ag 84100',
};
const expected = {
type: 'line',
id: 'ag-84100',
name: 'ag 84100',
fahrtNr: '84100',
public: true,
product: undefined,
productName: undefined,
mode: undefined,
operator: null,
};
t.same(parse(ctx, input), expected);
t.end();
});
tap.test('parses Bus leg correctly', (t) => {
tap.test('parses db Bus leg correctly', (t) => {
const input = {
journeyId: 'foo',
verkehrsmittel: {
@ -143,7 +163,7 @@ tap.test('parses ris entry correctly', (t) => {
type: 'line',
id: 'rb-51-15538',
fahrtNr: '15538',
name: 'RB 51 (15538)',
name: 'RB 51',
public: true,
product: 'nationalExpress',
productName: 'RB',
@ -155,8 +175,94 @@ tap.test('parses ris entry correctly', (t) => {
t.end();
});
tap.test('parses dbnav trip with long name correctly', (t) => {
const input = {fahrplan: {regulaererFahrplan: 'daily'}, kurztext: 'ag', mitteltext: 'ag RE22', langtext: 'ag RE22', gleis: '13', himNotizen: [], echtzeitNotizen: [], verkehrsmittelNummer: '84100', richtung: 'Nürnberg Hbf', produktGattung: 'RB', reisetag: '2025-01-17'};
const expected = {
type: 'line',
id: 'ag-re22',
name: 'ag RE22',
fahrtNr: '84100',
public: true,
productName: 'ag',
product: 'regional',
mode: 'train',
operator: null,
};
t.same(parse(ctx, input), expected);
t.end();
});
tap.test('parses dbnav ruf correctly', (t) => {
tap.test('parses dbnav trip sbahn correctly', (t) => {
const input = {fahrplan: {regulaererFahrplan: 'Mo - Sa', tageOhneFahrt: 'not 18., 21. Apr 2025, 1., 29. May 2025, 9., 19. Jun 2025, 3. Oct 2025, 1. Nov 2025'}, kurztext: 'S', mitteltext: 'S 6', gleis: '4', attributNotizen: [], echtzeitNotizen: [], himNotizen: [], verkehrsmittelNummer: '6', richtung: 'Köln-Worringen', produktGattung: 'SBAHN', reisetag: '2025-01-10'};
const expected = {
type: 'line',
id: 's-6',
fahrtNr: '6',
name: 'S 6',
public: true,
productName: 'S',
mode: 'train',
product: 'suburban',
operator: null,
};
t.same(parse(ctx, input), expected);
t.end();
});
tap.test('parses dbnav leg with long name correctly', (t) => {
const input = {administrationId: 'S9____', risZuglaufId: 'ag_84100', risAbfahrtId: '8001679_2025-01-17T16:20:00+01:00', kurztext: 'ag', mitteltext: 'ag RE22', langtext: 'ag RE22 (63070) / ag RE22 (84100)', zuglaufId: 'foo', reservierungsMeldungen: [], nummer: 0, abschnittsDauer: 3900, typ: 'FAHRZEUG', verkehrsmittelNummer: '84100', richtung: 'Nürnberg Hbf', produktGattung: 'RB', wagenreihung: false};
const expected = {
type: 'line',
id: 'ag-84100',
fahrtNr: '84100',
name: 'ag RE22',
public: true,
productName: 'ag',
mode: 'train',
product: 'regional',
adminCode: 'S9____',
operator: null,
};
t.same(parse(ctx, input), expected);
t.end();
});
tap.test('parses dbnav leg sbahn correctly', (t) => {
const input = {
administrationId: '8003S_',
risZuglaufId: 'S_31600',
risAbfahrtId: '8003368_2025-01-10T17:21:00+01:00',
kurztext: 'S',
mitteltext: 'S 6',
langtext: 'S 6',
zuglaufId: '2|#VN#1#ST#1736364871#PI#1#ZI#212722#TA#5#DA#100125#1S#8004948#1T#1614#LS#8003373#LT#1746#PU#81#RT#1#CA#s#ZE#6#ZB#S 6#PC#4#FR#8004948#FT#1614#TO#8003373#TT#1746#',
nummer: 4,
typ: 'FAHRZEUG',
abgangsDatum: '2025-01-10T17:21:00+01:00',
ankunftsDatum: '2025-01-10T17:23:00+01:00',
verkehrsmittelNummer: '6',
richtung: 'Köln-Worringen',
produktGattung: 'SBAHN',
wagenreihung: true,
};
const expected = {
type: 'line',
id: 's-31600',
fahrtNr: '31600',
name: 'S 6',
public: true,
productName: 'S',
mode: 'train',
product: 'suburban',
adminCode: '8003S_',
operator: null,
};
t.same(parse(ctx, input), expected);
t.end();
});
tap.test('parses dbnav board ruf correctly', (t) => {
const input = {zuglaufId: 'foo', kurztext: 'RUF', mitteltext: 'RUF 9870', produktGattung: 'ANRUFPFLICHTIGEVERKEHRE'};
const expected = {
type: 'line',