Skip to content

Commit

Permalink
boards: correctly handle missing rt info
Browse files Browse the repository at this point in the history
  • Loading branch information
traines-source committed Dec 12, 2024
1 parent e18ac3f commit 5bb4e66
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 16 deletions.
2 changes: 1 addition & 1 deletion parse/arrival-or-departure.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const createParseArrOrDep = (prefix) => {
const res = {
tripId: d.journeyID || d.train.journeyId,
stop: profile.parseLocation(ctx, d.station),
...profile.parseWhen(ctx, null, d.timeSchedule ? d.timeSchedule : d.time, d.timePredicted ? d.timePredicted : d.time, d.canceled),
...profile.parseWhen(ctx, null, d.timeSchedule ? d.timeSchedule : d.time, d.timeType != 'SCHEDULE' ? d.timePredicted ? d.timePredicted : d.time : null, d.canceled),
...profile.parsePlatform(ctx, d.platformSchedule ? d.platformSchedule : d.platform, d.platformPredicted ? d.platformPredicted : d.platform, d.canceled),
// prognosisType: TODO
direction: d.transport?.direction?.stopPlaces?.length > 0 && profile.parseStationName(ctx, d.transport?.direction?.stopPlaces[0].name) || profile.parseStationName(ctx, d.destination?.name) || null,
Expand Down
2 changes: 1 addition & 1 deletion test/db-arrivals.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const opt = {
products: {},
};

tap.test('parses an arrival correctly (DB)', (t) => {
tap.test('parses a RIS::Boards arrival correctly', (t) => {
const ctx = {profile, opt, common: null, res};
const arrivals = res.arrivals.map(d => profile.parseArrival(ctx, d));

Expand Down
33 changes: 33 additions & 0 deletions test/db-departures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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-departures-regio-guide.json');
import {dbDepartures as expected} from './fixtures/db-departures-regio-guide.js';

const client = createClient(rawProfile, 'public-transport/hafas-client:test');
const {profile} = client;

const opt = {
direction: null,
duration: 10,
linesOfStops: true,
remarks: true,
stopovers: true,
includeRelatedStations: true,
when: '2019-08-19T20:30:00+02:00',
products: {},
};

tap.test('parses a regio-guide departure correctly', (t) => {
const ctx = {profile, opt, common: null, res};
const departures = res.items.map(d => profile.parseDeparture(ctx, d));

t.same(departures, expected);
t.end();
});
28 changes: 14 additions & 14 deletions test/fixtures/db-arrivals.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const dbArrivals = [
},
when: '2024-12-08T01:00:00+01:00',
plannedWhen: '2024-12-08T01:00:00+01:00',
delay: 0,
delay: null,
platform: '6',
plannedPlatform: '6',
direction: null,
provenance: 'Berlin Beusselstraße',
line: {
type: 'line',
id: 's-42-42323',
fahrtNr: 42323,
fahrtNr: '42323',
name: 'S 42 (42323)',
public: true,
productName: 'S',
Expand Down Expand Up @@ -51,15 +51,15 @@ const dbArrivals = [
},
when: '2024-12-08T01:00:00+01:00',
plannedWhen: '2024-12-08T01:00:00+01:00',
delay: 0,
delay: null,
platform: null,
plannedPlatform: null,
direction: null,
provenance: 'Rudow (U), Berlin',
line: {
type: 'line',
id: 'u-7-15421',
fahrtNr: 15421,
fahrtNr: '15421',
name: 'U 7 (15421)',
public: true,
productName: 'U',
Expand Down Expand Up @@ -99,15 +99,15 @@ const dbArrivals = [
},
when: '2024-12-08T01:03:00+01:00',
plannedWhen: '2024-12-08T01:03:00+01:00',
delay: 0,
delay: null,
platform: null,
plannedPlatform: null,
direction: null,
provenance: 'Goerdelersteg, Berlin',
line: {
type: 'line',
id: 'bus-m21-93424',
fahrtNr: 93424,
fahrtNr: '93424',
name: 'Bus M21 (93424)',
public: true,
productName: 'Bus',
Expand Down Expand Up @@ -147,15 +147,15 @@ const dbArrivals = [
},
when: '2024-12-08T01:05:00+01:00',
plannedWhen: '2024-12-08T01:05:00+01:00',
delay: 0,
delay: null,
platform: '5',
plannedPlatform: '5',
direction: null,
provenance: 'Berlin Beusselstraße',
line: {
type: 'line',
id: 's-41-41254',
fahrtNr: 41254,
fahrtNr: '41254',
name: 'S 41 (41254)',
public: true,
productName: 'S',
Expand Down Expand Up @@ -189,15 +189,15 @@ const dbArrivals = [
},
when: '2024-12-08T01:10:00+01:00',
plannedWhen: '2024-12-08T01:10:00+01:00',
delay: 0,
delay: null,
platform: null,
plannedPlatform: null,
direction: null,
provenance: 'Rudow (U), Berlin',
line: {
type: 'line',
id: 'u-7-15422',
fahrtNr: 15422,
fahrtNr: '15422',
name: 'U 7 (15422)',
public: true,
productName: 'U',
Expand Down Expand Up @@ -237,15 +237,15 @@ const dbArrivals = [
},
when: '2024-12-08T01:10:00+01:00',
plannedWhen: '2024-12-08T01:10:00+01:00',
delay: 0,
delay: null,
platform: '6',
plannedPlatform: '6',
direction: null,
provenance: 'Berlin Beusselstraße',
line: {
type: 'line',
id: 's-42-42325',
fahrtNr: 42325,
fahrtNr: '42325',
name: 'S 42 (42325)',
public: true,
productName: 'S',
Expand Down Expand Up @@ -279,15 +279,15 @@ const dbArrivals = [
},
when: '2024-12-08T01:10:00+01:00',
plannedWhen: '2024-12-08T01:10:00+01:00',
delay: 0,
delay: null,
platform: null,
plannedPlatform: null,
direction: null,
provenance: 'Rathaus Spandau (S+U), Berlin',
line: {
type: 'line',
id: 'u-7-15752',
fahrtNr: 15752,
fahrtNr: '15752',
name: 'U 7 (15752)',
public: true,
productName: 'U',
Expand Down
111 changes: 111 additions & 0 deletions test/fixtures/db-departures-regio-guide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
const dbDepartures = [
{
tripId: '20241212-d1494ce6-1a01-38de-bf84-c0bceb12f503',
stop: {
type: 'stop',
id: '8000365',
name: 'Dombühl',
location: null,
},
when: '2024-12-12T12:34:00+01:00',
plannedWhen: '2024-12-12T12:34:00+01:00',
delay: 0,
platform: '3',
plannedPlatform: '3',
direction: 'Nürnberg Hbf',
provenance: null,
line: {
type: 'line',
id: '88617',
fahrtNr: '88617',
name: 'RE 90',
public: true,
productName: 'RE',
mode: 'train',
product: 'regional',
operator: null,
},
remarks: [],
origin: null,
destination: {
type: 'stop',
id: '8000284',
name: 'Nürnberg Hbf',
location: null,
},
},
{
tripId: '20241212-abd01ce0-cca3-3759-aa4b-410ea4d0a720',
stop: {
type: 'stop',
id: '682943',
name: 'Bahnhof, Dombühl',
location: null,
},
when: '2024-12-12T12:50:00+01:00',
plannedWhen: '2024-12-12T12:50:00+01:00',
delay: null,
platform: null,
plannedPlatform: null,
direction: 'Gymnasium, Dinkelsbühl',
provenance: null,
line: {
type: 'line',
id: '2221',
fahrtNr: '2221',
name: 'Bus 813',
public: true,
productName: 'Bus',
mode: 'bus',
product: 'bus',
operator: null,
},
remarks: [],
origin: null,
destination: {
type: 'stop',
id: '676542',
name: 'Gymnasium, Dinkelsbühl',
location: null,
},
},
{
tripId: '20241212-ab6272a5-4bf6-32c1-9344-b47e1fc49eeb',
stop: {
type: 'stop',
id: '682943',
name: 'Bahnhof, Dombühl',
location: null,
},
when: '2024-12-12T12:50:00+01:00',
plannedWhen: '2024-12-12T12:50:00+01:00',
delay: null,
platform: null,
plannedPlatform: null,
direction: 'Bahnhof, Rothenburg ob der Tauber',
provenance: null,
line: {
type: 'line',
id: '2177',
fahrtNr: '2177',
name: 'Bus 807',
public: true,
productName: 'Bus',
mode: 'bus',
product: 'bus',
operator: null,
},
remarks: [],
origin: null,
destination: {
type: 'stop',
id: '683407',
name: 'Bahnhof, Rothenburg ob der Tauber',
location: null,
},
},
];

export {
dbDepartures,
};
1 change: 1 addition & 0 deletions test/fixtures/db-departures-regio-guide.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"isArrival":false,"evaNo":"8000365","stationName":"Dombühl","items":[{"station":{"evaNo":"8000365","name":"Dombühl","canceled":false},"train":{"journeyId":"20241212-d1494ce6-1a01-38de-bf84-c0bceb12f503","category":"RE","type":"REGIONAL_TRAIN","no":88617,"lineName":"90"},"category":"REGIONAL","time":"2024-12-12T11:34:00.000Z","timePredicted":"2024-12-12T11:34:00.000Z","diff":0,"timeType":"PREVIEW","platform":"3","platformPredicted":"3","administration":{"id":"GARE","operatorCode":"RE","operatorName":"Arverio Baden-Württemberg (RE)"},"canceled":false,"departureId":"8000365_D_1","destination":{"evaNo":"8000284","name":"Nürnberg Hbf","canceled":false}},{"station":{"evaNo":"682943","name":"Bahnhof, Dombühl","canceled":false},"train":{"journeyId":"20241212-abd01ce0-cca3-3759-aa4b-410ea4d0a720","category":"Bus","type":"BUS","no":2221,"lineName":"813"},"category":"BUS","time":"2024-12-12T11:50:00.000Z","timePredicted":"2024-12-12T11:50:00.000Z","diff":0,"timeType":"SCHEDULE","platform":"","platformPredicted":"","administration":{"id":"vgn063","operatorCode":"DPN","operatorName":"Nahreisezug"},"canceled":false,"departureId":"682943_D_1","destination":{"evaNo":"676542","name":"Gymnasium, Dinkelsbühl","canceled":false}},{"station":{"evaNo":"682943","name":"Bahnhof, Dombühl","canceled":false},"train":{"journeyId":"20241212-ab6272a5-4bf6-32c1-9344-b47e1fc49eeb","category":"Bus","type":"BUS","no":2177,"lineName":"807"},"category":"BUS","time":"2024-12-12T11:50:00.000Z","timePredicted":"2024-12-12T11:50:00.000Z","diff":0,"timeType":"SCHEDULE","platform":"","platformPredicted":"","administration":{"id":"vgn063","operatorCode":"DPN","operatorName":"Nahreisezug"},"canceled":false,"departureId":"682943_D_1","destination":{"evaNo":"683407","name":"Bahnhof, Rothenburg ob der Tauber","canceled":false}}],"availableTransports":[{"id":"REGIONAL","text":"Regional"},{"id":"BUS","text":"Bus"}],"timeStart":"2024-12-12T11:33:30.000Z","timeEnd":"2024-12-12T12:03:30.000Z"}

0 comments on commit 5bb4e66

Please sign in to comment.