diff --git a/parse/arrival-or-departure.js b/parse/arrival-or-departure.js index 6893c04e..26ceaae1 100644 --- a/parse/arrival-or-departure.js +++ b/parse/arrival-or-departure.js @@ -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, diff --git a/test/db-arrivals.js b/test/db-arrivals.js index dac490f4..69d1d57e 100644 --- a/test/db-arrivals.js +++ b/test/db-arrivals.js @@ -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)); diff --git a/test/db-departures.js b/test/db-departures.js new file mode 100644 index 00000000..e2d89414 --- /dev/null +++ b/test/db-departures.js @@ -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(); +}); diff --git a/test/fixtures/db-arrivals.js b/test/fixtures/db-arrivals.js index 83011532..a8ced0af 100644 --- a/test/fixtures/db-arrivals.js +++ b/test/fixtures/db-arrivals.js @@ -9,7 +9,7 @@ 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, @@ -17,7 +17,7 @@ const dbArrivals = [ line: { type: 'line', id: 's-42-42323', - fahrtNr: 42323, + fahrtNr: '42323', name: 'S 42 (42323)', public: true, productName: 'S', @@ -51,7 +51,7 @@ 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, @@ -59,7 +59,7 @@ const dbArrivals = [ line: { type: 'line', id: 'u-7-15421', - fahrtNr: 15421, + fahrtNr: '15421', name: 'U 7 (15421)', public: true, productName: 'U', @@ -99,7 +99,7 @@ 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, @@ -107,7 +107,7 @@ const dbArrivals = [ line: { type: 'line', id: 'bus-m21-93424', - fahrtNr: 93424, + fahrtNr: '93424', name: 'Bus M21 (93424)', public: true, productName: 'Bus', @@ -147,7 +147,7 @@ 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, @@ -155,7 +155,7 @@ const dbArrivals = [ line: { type: 'line', id: 's-41-41254', - fahrtNr: 41254, + fahrtNr: '41254', name: 'S 41 (41254)', public: true, productName: 'S', @@ -189,7 +189,7 @@ 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, @@ -197,7 +197,7 @@ const dbArrivals = [ line: { type: 'line', id: 'u-7-15422', - fahrtNr: 15422, + fahrtNr: '15422', name: 'U 7 (15422)', public: true, productName: 'U', @@ -237,7 +237,7 @@ 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, @@ -245,7 +245,7 @@ const dbArrivals = [ line: { type: 'line', id: 's-42-42325', - fahrtNr: 42325, + fahrtNr: '42325', name: 'S 42 (42325)', public: true, productName: 'S', @@ -279,7 +279,7 @@ 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, @@ -287,7 +287,7 @@ const dbArrivals = [ line: { type: 'line', id: 'u-7-15752', - fahrtNr: 15752, + fahrtNr: '15752', name: 'U 7 (15752)', public: true, productName: 'U', diff --git a/test/fixtures/db-departures-regio-guide.js b/test/fixtures/db-departures-regio-guide.js new file mode 100644 index 00000000..c3b9c02c --- /dev/null +++ b/test/fixtures/db-departures-regio-guide.js @@ -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, +}; diff --git a/test/fixtures/db-departures-regio-guide.json b/test/fixtures/db-departures-regio-guide.json new file mode 100644 index 00000000..7ace276d --- /dev/null +++ b/test/fixtures/db-departures-regio-guide.json @@ -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"} \ No newline at end of file