From c4470ca9621075419506e8b083df86c4b0ee6705 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Wed, 29 Dec 2021 21:11:07 +0100 Subject: [PATCH] =?UTF-8?q?arrivals/departures:=20return=20obj=20with=20re?= =?UTF-8?q?altimeDataUpdatedAt=20&=20results=20=F0=9F=92=A5=E2=9C=85?= =?UTF-8?q?=F0=9F=93=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/departures.md | 11 ++++++--- index.js | 18 ++++++++++----- test/e2e/bvg.js | 12 +++++----- test/e2e/cfl.js | 12 +++++----- test/e2e/cmta.js | 12 +++++----- test/e2e/db-busradar-nrw.js | 16 ++++++------- test/e2e/db.js | 14 ++++++------ test/e2e/hvv.js | 12 +++++----- test/e2e/insa.js | 12 +++++----- test/e2e/invg.js | 12 +++++----- test/e2e/lib/arrivals.js | 11 ++++----- test/e2e/lib/departures-in-direction.js | 7 +++--- test/e2e/lib/departures.js | 11 ++++----- test/e2e/lib/util.js | 3 +-- test/e2e/lib/validators.js | 30 +++++++++++++++++++++++++ test/e2e/mobil-nrw.js | 12 +++++----- test/e2e/mobiliteit-lu.js | 12 +++++----- test/e2e/nahsh.js | 12 +++++----- test/e2e/nvv.js | 12 +++++----- test/e2e/oebb.js | 8 +++---- test/e2e/rejseplanen.js | 8 +++---- test/e2e/rmv.js | 4 ++-- test/e2e/rsag.js | 4 ++-- test/e2e/saarfahrplan.js | 10 ++++----- test/e2e/sbahn-muenchen.js | 12 +++++----- test/e2e/sncb.js | 4 ++-- test/e2e/svv.js | 4 ++-- test/e2e/vbb.js | 12 +++++----- test/e2e/vbn.js | 4 ++-- test/e2e/vrn.js | 8 +++---- test/e2e/vsn.js | 12 +++++----- test/e2e/zvv.js | 4 ++-- test/retry.js | 11 +++++++-- 33 files changed, 198 insertions(+), 148 deletions(-) diff --git a/docs/departures.md b/docs/departures.md index 5c5dcac3..180ddf84 100644 --- a/docs/departures.md +++ b/docs/departures.md @@ -55,7 +55,7 @@ await client.departures('900000024101', {products: {tram: false, ferry: false}}) *Note:* As stated in the [*Friendly Public Transport Format* v2 draft spec](https://github.com/public-transport/friendly-public-transport-format/blob/3bd36faa721e85d9f5ca58fb0f38cdbedb87bbca/spec/readme.md), the `when` field includes the current delay. The `delay` field, if present, expresses how much the former differs from the schedule. -You may pass the `tripId` field into [`trip(id, lineName, [opt])`](trip.md) to get details on the vehicle's trip. +You may pass a departure's `tripId` into [`trip(id, lineName, [opt])`](trip.md) to get details on the whole trip. As an example, we're going to use the [VBB profile](../p/vbb): @@ -66,10 +66,15 @@ const vbbProfile = require('hafas-client/p/vbb') const client = createClient(vbbProfile, 'my-awesome-program') // S Charlottenburg -await client.departures('900000024101', {duration: 3}) +const { + departures, + realtimeDataUpdatedAt, +} = await client.departures('900000024101', {duration: 3}) ``` -The result may look like this: +`realtimeDataUpdatedAt` is a UNIX timestamp reflecting the latest moment when (at least some) of the response's realtime data have been updated. + +`departures` may look like this: ```js [ { diff --git a/index.js b/index.js index c664c8a8..06ba8f94 100644 --- a/index.js +++ b/index.js @@ -38,7 +38,7 @@ const createClient = (profile, userAgent, opt = {}) => { throw new TypeError('userAgent must be a string'); } - const _stationBoard = async (station, type, parse, opt = {}) => { + const _stationBoard = async (station, type, resultsField, parse, opt = {}) => { if (isObj(station)) station = profile.formatStation(station.id) else if ('string' === typeof station) station = profile.formatStation(station) else throw new TypeError('station must be an object or a string.') @@ -75,19 +75,25 @@ const createClient = (profile, userAgent, opt = {}) => { const req = profile.formatStationBoardReq({profile, opt}, station, type) const {res, common} = await profile.request({profile, opt}, userAgent, req) - if (!Array.isArray(res.jnyL)) return [] const ctx = {profile, opt, common, res} - // todo [breaking]: return object with realtimeDataUpdatedAt - return res.jnyL.map(res => parse(ctx, res)) + const jnyL = Array.isArray(res.jnyL) ? res.jnyL : [] + const results = jnyL.map(res => parse(ctx, res)) .sort((a, b) => new Date(a.when) - new Date(b.when)) // todo + + return { + [resultsField]: results, + realtimeDataUpdatedAt: res.planrtTS && res.planrtTS !== '0' + ? parseInt(res.planrtTS) + : null, + } } const departures = async (station, opt = {}) => { - return await _stationBoard(station, 'DEP', profile.parseDeparture, opt) + return await _stationBoard(station, 'DEP', 'departures', profile.parseDeparture, opt) } const arrivals = async (station, opt = {}) => { - return await _stationBoard(station, 'ARR', profile.parseArrival, opt) + return await _stationBoard(station, 'ARR', 'arrivals', profile.parseArrival, opt) } const journeys = async (from, to, opt = {}) => { diff --git a/test/e2e/bvg.js b/test/e2e/bvg.js index 8b221159..7a9dbc0c 100644 --- a/test/e2e/bvg.js +++ b/test/e2e/bvg.js @@ -299,13 +299,13 @@ tap.test('journeys: via works – with detour', async (t) => { // todo: without detour test tap.test('departures', async (t) => { - const departures = await client.departures(spichernstr, { + const res = await client.departures(spichernstr, { duration: 5, when }) await testDepartures({ test: t, - departures, + res, validate, id: spichernstr }) @@ -313,7 +313,7 @@ tap.test('departures', async (t) => { }) tap.test('departures with station object', async (t) => { - const deps = await client.departures({ + const res = await client.departures({ type: 'station', id: spichernstr, name: 'U Spichernstr', @@ -324,7 +324,7 @@ tap.test('departures with station object', async (t) => { } }, {when}) - validate(t, deps, 'departures', 'departures') + validate(t, res, 'departuresResponse', 'res') t.end() }) @@ -349,13 +349,13 @@ tap.test('departures at 7-digit station', async (t) => { }) tap.test('arrivals', async (t) => { - const arrivals = await client.arrivals(spichernstr, { + const res = await client.arrivals(spichernstr, { duration: 5, when }) await testArrivals({ test: t, - arrivals, + res, validate, id: spichernstr }) diff --git a/test/e2e/cfl.js b/test/e2e/cfl.js index c65d48f0..6f39194a 100644 --- a/test/e2e/cfl.js +++ b/test/e2e/cfl.js @@ -183,13 +183,13 @@ tap.test('trip', async (t) => { }) tap.test('departures at Ettelbruck.', async (t) => { - const departures = await client.departures(ettelbruck, { + const res = await client.departures(ettelbruck, { duration: 20, when }) await testDepartures({ test: t, - departures, + res, validate, id: ettelbruck }) @@ -197,13 +197,13 @@ tap.test('departures at Ettelbruck.', async (t) => { }) tap.test('arrivals at Ettelbruck.', async (t) => { - const arrivals = await client.arrivals(ettelbruck, { + const res = await client.arrivals(ettelbruck, { duration: 20, when }) await testArrivals({ test: t, - arrivals, + res, validate, id: ettelbruck }) @@ -211,7 +211,7 @@ tap.test('arrivals at Ettelbruck.', async (t) => { }) tap.test('departures with station object', async (t) => { - const deps = await client.departures({ + const res = await client.departures({ type: 'station', id: ettelbruck, name: 'Ettelbruck', @@ -222,7 +222,7 @@ tap.test('departures with station object', async (t) => { } }, {when}) - validate(t, deps, 'departures', 'departures') + validate(t, res, 'departuresResponse', 'res') t.end() }) diff --git a/test/e2e/cmta.js b/test/e2e/cmta.js index e0df75f7..d1c765c1 100644 --- a/test/e2e/cmta.js +++ b/test/e2e/cmta.js @@ -162,13 +162,13 @@ tap.test('trip details', async (t) => { }) tap.test('departures at Broadie Oaks', async (t) => { - const departures = await client.departures(broadieOaks, { + const res = await client.departures(broadieOaks, { duration: 10, when, }) await testDepartures({ test: t, - departures, + res, validate, id: broadieOaks }) @@ -176,7 +176,7 @@ tap.test('departures at Broadie Oaks', async (t) => { }) tap.test('departures with station object', async (t) => { - const deps = await client.departures({ + const res = await client.departures({ type: 'station', id: broadieOaks, name: 'Magdeburg Hbf', @@ -187,18 +187,18 @@ tap.test('departures with station object', async (t) => { } }, {when}) - validate(t, deps, 'departures', 'departures') + validate(t, res, 'departuresResponse', 'res') t.end() }) tap.test('arrivals at Broadie Oaks', async (t) => { - const arrivals = await client.arrivals(broadieOaks, { + const res = await client.arrivals(broadieOaks, { duration: 10, when }) await testArrivals({ test: t, - arrivals, + res, validate, id: broadieOaks }) diff --git a/test/e2e/db-busradar-nrw.js b/test/e2e/db-busradar-nrw.js index 786f9994..96f99e2e 100644 --- a/test/e2e/db-busradar-nrw.js +++ b/test/e2e/db-busradar-nrw.js @@ -34,13 +34,13 @@ const bielefeldHbf = '8000036' const hagenVorhalle = '8000977' tap.test('departures at Hagen Bauhaus', async (t) => { - const departures = await client.departures(hagenBauhaus, { + const res = await client.departures(hagenBauhaus, { duration: 120, when, }) await testDepartures({ test: t, - departures, + res, validate, id: hagenBauhaus }) @@ -48,11 +48,11 @@ tap.test('departures at Hagen Bauhaus', async (t) => { }) tap.test('trip details', async (t) => { - const deps = await client.departures(hagenBauhaus, { + const res = await client.departures(hagenBauhaus, { results: 1, duration: 120, when }) - const p = deps[0] || {} + const p = res.departures[0] || {} t.ok(p.tripId, 'precondition failed') t.ok(p.line.name, 'precondition failed') const trip = await client.trip(p.tripId, p.line.name, {when}) @@ -62,7 +62,7 @@ tap.test('trip details', async (t) => { }) tap.test('departures with station object', async (t) => { - const deps = await client.departures({ + const res = await client.departures({ type: 'station', id: hagenBauhaus, name: 'Hagen(Westf) Bauhaus', @@ -73,20 +73,20 @@ tap.test('departures with station object', async (t) => { } }, {when, duration: 120}) - validate(t, deps, 'departures', 'departures') + validate(t, res, 'departuresResponse', 'res') t.end() }) // todo: departures at hagenBauhaus in direction of … tap.test('arrivals at Hagen Bauhaus', async (t) => { - const arrivals = await client.arrivals(hagenBauhaus, { + const res = await client.arrivals(hagenBauhaus, { duration: 120, when }) await testArrivals({ test: t, - arrivals, + res, validate, id: hagenBauhaus }) diff --git a/test/e2e/db.js b/test/e2e/db.js index f46809f3..b189f192 100644 --- a/test/e2e/db.js +++ b/test/e2e/db.js @@ -330,13 +330,13 @@ tap.test('trip details', async (t) => { }) tap.test('departures at Berlin Schwedter Str.', async (t) => { - const departures = await client.departures(blnSchwedterStr, { + const res = await client.departures(blnSchwedterStr, { duration: 5, when, }) await testDepartures({ test: t, - departures, + res, validate, id: blnSchwedterStr }) @@ -344,7 +344,7 @@ tap.test('departures at Berlin Schwedter Str.', async (t) => { }) tap.test('departures with station object', async (t) => { - const deps = await client.departures({ + const res = await client.departures({ type: 'station', id: jungfernheide, name: 'Berlin Jungfernheide', @@ -355,7 +355,7 @@ tap.test('departures with station object', async (t) => { } }, {when}) - validate(t, deps, 'departures', 'departures') + validate(t, res, 'departuresResponse', 'res') t.end() }) @@ -373,13 +373,13 @@ tap.test('departures at Berlin Hbf in direction of Berlin Ostbahnhof', async (t) }) tap.test('arrivals at Berlin Schwedter Str.', async (t) => { - const arrivals = await client.arrivals(blnSchwedterStr, { + const res = await client.arrivals(blnSchwedterStr, { duration: 5, when, }) await testArrivals({ test: t, - arrivals, + res, validate, id: blnSchwedterStr }) @@ -434,7 +434,7 @@ tap.test('stop', async (t) => { }) tap.test('line with additionalName', async (t) => { - const departures = await client.departures(potsdamHbf, { + const {departures} = await client.departures(potsdamHbf, { when, duration: 12 * 60, // 12 minutes products: {bus: false, suburban: false, tram: false} diff --git a/test/e2e/hvv.js b/test/e2e/hvv.js index 6428846d..f82565d2 100644 --- a/test/e2e/hvv.js +++ b/test/e2e/hvv.js @@ -151,13 +151,13 @@ tap.skip('trip details', async (t) => { }) tap.skip('departures at Hamburg Barmbek', async (t) => { - const departures = await client.departures(barmbek, { + const res = await client.departures(barmbek, { duration: 5, when, }) await testDepartures({ test: t, - departures, + res, validate, id: barmbek }) @@ -165,7 +165,7 @@ tap.skip('departures at Hamburg Barmbek', async (t) => { }) tap.skip('departures with station object', async (t) => { - const deps = await client.departures({ + const res = await client.departures({ type: 'station', id: tiefstack, name: 'Hamburg Tiefstack', @@ -176,7 +176,7 @@ tap.skip('departures with station object', async (t) => { } }, {when}) - validate(t, deps, 'departures', 'departures') + validate(t, res, 'departuresResponse', 'res') t.end() }) @@ -194,13 +194,13 @@ tap.skip('departures at Barmbek in direction of Altona', async (t) => { }) tap.skip('arrivals at Hamburg Barmbek', async (t) => { - const arrivals = await client.arrivals(barmbek, { + const res = await client.arrivals(barmbek, { duration: 5, when }) await testArrivals({ test: t, - arrivals, + res, validate, id: barmbek }) diff --git a/test/e2e/insa.js b/test/e2e/insa.js index cabbf2c7..0a423bcf 100644 --- a/test/e2e/insa.js +++ b/test/e2e/insa.js @@ -189,13 +189,13 @@ tap.test('trip details', async (t) => { }) tap.test('departures at Magdeburg Universität', async (t) => { - const departures = await client.departures(universitaet, { + const res = await client.departures(universitaet, { duration: 30, when, }) await testDepartures({ test: t, - departures, + res, validate, id: universitaet }) @@ -203,7 +203,7 @@ tap.test('departures at Magdeburg Universität', async (t) => { }) tap.test('departures with station object', async (t) => { - const deps = await client.departures({ + const res = await client.departures({ type: 'stop', id: universitaet, name: 'Universität', @@ -216,7 +216,7 @@ tap.test('departures with station object', async (t) => { duration: 30, when, }) - validate(t, deps, 'departures', 'deps') + validate(t, res, 'departuresResponse', 'res') t.end() }) @@ -235,13 +235,13 @@ tap.test('departures at Universität in direction of Spielhagenstr.', async (t) }) tap.test('arrivals at Magdeburg Universität', async (t) => { - const arrivals = await client.arrivals(universitaet, { + const res = await client.arrivals(universitaet, { duration: 30, when }) await testArrivals({ test: t, - arrivals, + res, validate, id: universitaet }) diff --git a/test/e2e/invg.js b/test/e2e/invg.js index 643f5d84..aa03bf1f 100644 --- a/test/e2e/invg.js +++ b/test/e2e/invg.js @@ -181,13 +181,13 @@ tap.test('departures at Ingolstadt Hbf', async (t) => { '80303', // stop "Ingolstadt, Hauptbahnhof Stadtauswärts" ] - const deps = await client.departures(ingolstadtHbf, { + const res = await client.departures(ingolstadtHbf, { duration: 10, when }) await testDepartures({ test: t, - departures: deps, + res, validate, ids, }) @@ -195,7 +195,7 @@ tap.test('departures at Ingolstadt Hbf', async (t) => { }) tap.test('departures with station object', async (t) => { - const deps = await client.departures({ + const res = await client.departures({ type: 'station', id: ingolstadtHbf, name: 'Ingolstadt Hbf', @@ -206,7 +206,7 @@ tap.test('departures with station object', async (t) => { } }, {when}) - validate(t, deps, 'departures', 'departures') + validate(t, res, 'departuresResponse', 'res') t.end() }) @@ -217,13 +217,13 @@ tap.test('arrivals at Ingolstadt Hbf', async (t) => { '80302' // stop "Ingolstadt, Hauptbahnhof Stadteinwärts" ] - const arrs = await client.arrivals(ingolstadtHbf, { + const res = await client.arrivals(ingolstadtHbf, { duration: 10, when }) await testArrivals({ test: t, - arrivals: arrs, + res, validate, ids, }) diff --git a/test/e2e/lib/arrivals.js b/test/e2e/lib/arrivals.js index a77936b0..e8648714 100644 --- a/test/e2e/lib/arrivals.js +++ b/test/e2e/lib/arrivals.js @@ -1,14 +1,15 @@ 'use strict' const testArrivals = async (cfg) => { - const {test: t, arrivals: arrs, validate} = cfg + const {test: t, res, validate} = cfg const ids = cfg.ids || (cfg.id ? [cfg.id] : []) + const {arrivals: arrs} = res + + validate(t, res, 'arrivalsResponse', 'res') - validate(t, arrs, 'arrivals', 'arrivals') - t.ok(arrs.length > 0, 'must be >0 arrivals') for (let i = 0; i < arrs.length; i++) { let stop = arrs[i].stop - let name = `arrs[${i}].stop` + let name = `res.arrivals[${i}].stop` if (stop.station) { stop = stop.station name += '.station' @@ -22,7 +23,7 @@ const testArrivals = async (cfg) => { } // todo: move into arrivals validator - t.same(arrs, arrs.sort((a, b) => t.when > b.when), 'arrivals must be sorted by .when') + t.same(arrs, arrs.sort((a, b) => t.when > b.when), 'res.arrivals must be sorted by .when') } module.exports = testArrivals diff --git a/test/e2e/lib/departures-in-direction.js b/test/e2e/lib/departures-in-direction.js index 4061a086..e925c53e 100644 --- a/test/e2e/lib/departures-in-direction.js +++ b/test/e2e/lib/departures-in-direction.js @@ -11,12 +11,13 @@ const testDeparturesInDirection = async (cfg) => { validate } = cfg - const deps = await fetchDepartures(id, { + const res = await fetchDepartures(id, { direction: directionIds[0], when }) - validate(t, deps, 'departures', 'departures') - t.ok(deps.length > 0, 'must be >0 departures') + const {departures: deps} = res + + validate(t, res, 'departuresResponse', 'res') for (let i = 0; i < deps.length; i++) { const dep = deps[i] diff --git a/test/e2e/lib/departures.js b/test/e2e/lib/departures.js index 958f3036..829741b1 100644 --- a/test/e2e/lib/departures.js +++ b/test/e2e/lib/departures.js @@ -1,14 +1,15 @@ 'use strict' const testDepartures = async (cfg) => { - const {test: t, departures: deps, validate} = cfg + const {test: t, res, validate} = cfg const ids = cfg.ids || (cfg.id ? [cfg.id] : []) + const {departures: deps} = res + + validate(t, res, 'departuresResponse', 'res') - validate(t, deps, 'departures', 'departures') - t.ok(deps.length > 0, 'must be >0 departures') for (let i = 0; i < deps.length; i++) { let stop = deps[i].stop - let name = `deps[${i}].stop` + let name = `res.departures[${i}].stop` if (stop.station) { stop = stop.station name += '.station' @@ -22,7 +23,7 @@ const testDepartures = async (cfg) => { } // todo: move into deps validator - t.same(deps, deps.sort((a, b) => t.when > b.when), 'departures must be sorted by .when') + t.same(deps, deps.sort((a, b) => t.when > b.when), 'res.departures must be sorted by .when') } module.exports = testDepartures diff --git a/test/e2e/lib/util.js b/test/e2e/lib/util.js index fd01932d..728f6524 100644 --- a/test/e2e/lib/util.js +++ b/test/e2e/lib/util.js @@ -23,11 +23,10 @@ const createWhen = (timezone, locale, tMock) => { }).startOf('week').plus({weeks: 1, hours: 10}).toJSDate() } -const assertValidWhen = (actual, expected, name) => { +const assertValidWhen = (actual, expected, name, delta = day + 6 * hour) => { const ts = +new Date(actual) a.ok(!Number.isNaN(ts), name + ' is not parsable by Date') // the timestamps might be from long-distance trains - const delta = day + 6 * hour if (!isRoughlyEqual(delta, +expected, ts)) { throw new AssertionError({ message: name + ' is out of range', diff --git a/test/e2e/lib/validators.js b/test/e2e/lib/validators.js index 95d44970..ca410cfe 100644 --- a/test/e2e/lib/validators.js +++ b/test/e2e/lib/validators.js @@ -6,9 +6,18 @@ const anyOf = require('validate-fptf/lib/any-of') const {assertValidWhen} = require('./util') +const DAY = 24 * 60 * 60 * 1000 + const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o) const is = val => val !== null && val !== undefined +const createValidateRealtimeDataUpdatedAt = (cfg) => { + const validateRealtimeDataUpdatedAt = (val, rtDataUpdatedAt, name = 'realtimeDataUpdatedAt') => { + assertValidWhen(rtDataUpdatedAt * 1000, cfg.when, name, 100 * DAY) + } + return validateRealtimeDataUpdatedAt +} + const createValidateProducts = (cfg) => { const validateProducts = (val, p, name = 'products') => { a.ok(isObj(p), name + ' must be an object') @@ -518,6 +527,24 @@ const createValidateDepartures = (cfg) => { return _createValidateStationBoardResults(cfg, 'departure') } +const _createValidateStationBoardResponse = (cfg, validatorsKey, arrsOrDepsKey) => { + const _validateStationBoardResponse = (val, res, name) => { + a.ok(isObj(res), name + ' must be an object') + + val.realtimeDataUpdatedAt(val, res.realtimeDataUpdatedAt, name + '.realtimeDataUpdatedAt') + + const arrsOrDeps = res[arrsOrDepsKey] + val[validatorsKey](val, arrsOrDeps, `${name}.${arrsOrDepsKey}`) + } + return _validateStationBoardResponse +} +const createValidateArrivalsResponse = (cfg) => { + return _createValidateStationBoardResponse(cfg, 'arrivals', 'arrivals') +} +const createValidateDeparturesResponse = (cfg) => { + return _createValidateStationBoardResponse(cfg, 'departures', 'departures') +} + const createValidateMovement = (cfg) => { const { maxLatitude, minLatitude, maxLongitude, minLongitude } = cfg const validateMovement = (val, m, name = 'movement') => { @@ -576,6 +603,7 @@ const validateMovements = (val, ms, name = 'movements') => { } module.exports = { + realtimeDataUpdatedAt: createValidateRealtimeDataUpdatedAt, products: createValidateProducts, station: createValidateStation, stop: () => validateStop, @@ -596,6 +624,8 @@ module.exports = { departure: createValidateDeparture, arrivals: createValidateArrivals, departures: createValidateDepartures, + arrivalsResponse: createValidateArrivalsResponse, + departuresResponse: createValidateDeparturesResponse, movement: createValidateMovement, movements: () => validateMovements } diff --git a/test/e2e/mobil-nrw.js b/test/e2e/mobil-nrw.js index b3b5e41c..b9526f81 100644 --- a/test/e2e/mobil-nrw.js +++ b/test/e2e/mobil-nrw.js @@ -156,13 +156,13 @@ tap.test('departures at Soest', async (t) => { '902737', // Bahnhof E, Soest ] - const departures = await client.departures(soest, { + const res = await client.departures(soest, { duration: 10, when, }) await testDepartures({ test: t, - departures, + res, validate, ids, }) @@ -170,7 +170,7 @@ tap.test('departures at Soest', async (t) => { }) tap.test('departures with station object', async (t) => { - const deps = await client.departures({ + const res = await client.departures({ type: 'station', id: soest, name: 'Magdeburg Hbf', @@ -181,7 +181,7 @@ tap.test('departures with station object', async (t) => { } }, {when}) - validate(t, deps, 'departures', 'departures') + validate(t, res, 'departuresResponse', 'res') t.end() }) @@ -193,13 +193,13 @@ tap.test('arrivals at Soest', async (t) => { '902737', // Bahnhof E, Soest ] - const arrivals = await client.arrivals(soest, { + const res = await client.arrivals(soest, { duration: 10, when, }) await testArrivals({ test: t, - arrivals, + res, validate, ids, }) diff --git a/test/e2e/mobiliteit-lu.js b/test/e2e/mobiliteit-lu.js index 14ada800..e118acf4 100644 --- a/test/e2e/mobiliteit-lu.js +++ b/test/e2e/mobiliteit-lu.js @@ -187,13 +187,13 @@ tap.test('trip', async (t) => { }) tap.test('departures at Ettelbruck.', async (t) => { - const departures = await client.departures(ettelbruck, { + const res = await client.departures(ettelbruck, { duration: 20, when }) await testDepartures({ test: t, - departures, + res, validate, id: ettelbruck }) @@ -201,13 +201,13 @@ tap.test('departures at Ettelbruck.', async (t) => { }) tap.test('arrivals at Ettelbruck.', async (t) => { - const arrivals = await client.arrivals(ettelbruck, { + const res = await client.arrivals(ettelbruck, { duration: 20, when }) await testArrivals({ test: t, - arrivals, + res, validate, id: ettelbruck }) @@ -215,7 +215,7 @@ tap.test('arrivals at Ettelbruck.', async (t) => { }) tap.test('departures with station object', async (t) => { - const deps = await client.departures({ + const res = await client.departures({ type: 'station', id: ettelbruck, name: 'Ettelbruck', @@ -226,7 +226,7 @@ tap.test('departures with station object', async (t) => { } }, {when}) - validate(t, deps, 'departures', 'departures') + validate(t, res, 'departuresResponse', 'res') t.end() }) diff --git a/test/e2e/nahsh.js b/test/e2e/nahsh.js index 25745346..49aa3505 100644 --- a/test/e2e/nahsh.js +++ b/test/e2e/nahsh.js @@ -224,13 +224,13 @@ tap.test('trip details', async (t) => { }) tap.test('departures at Kiel Räucherei', async (t) => { - const departures = await client.departures(kielRaeucherei, { + const res = await client.departures(kielRaeucherei, { duration: 30, when, }) await testDepartures({ test: t, - departures, + res, validate, id: kielRaeucherei }) @@ -238,7 +238,7 @@ tap.test('departures at Kiel Räucherei', async (t) => { }) tap.test('departures with station object', async (t) => { - const deps = await client.departures({ + const res = await client.departures({ type: 'station', id: kielHbf, name: 'Kiel Hbf', @@ -249,7 +249,7 @@ tap.test('departures with station object', async (t) => { } }, {when}) - validate(t, deps, 'departures', 'departures') + validate(t, res, 'departuresResponse', 'res') t.end() }) @@ -267,13 +267,13 @@ tap.test('departures at Berlin Hbf in direction of Berlin Ostbahnhof', async (t) }) tap.test('arrivals at Kiel Räucherei', async (t) => { - const arrivals = await client.arrivals(kielRaeucherei, { + const res = await client.arrivals(kielRaeucherei, { duration: 30, when }) await testArrivals({ test: t, - arrivals, + res, validate, id: kielRaeucherei }) diff --git a/test/e2e/nvv.js b/test/e2e/nvv.js index 482adfae..b5107009 100644 --- a/test/e2e/nvv.js +++ b/test/e2e/nvv.js @@ -171,13 +171,13 @@ tap.test('trip details', async (t) => { }) tap.test('departures at Kassel Auestadion.', async (t) => { - const departures = await client.departures(auestadion, { + const res = await client.departures(auestadion, { duration: 11, when, }) await testDepartures({ test: t, - departures, + res, validate, id: auestadion }) @@ -185,7 +185,7 @@ tap.test('departures at Kassel Auestadion.', async (t) => { }) tap.test('departures with station object', async (t) => { - const deps = await client.departures({ + const res = await client.departures({ type: 'station', id: auestadion, name: 'Kassel Auestadion', @@ -196,7 +196,7 @@ tap.test('departures with station object', async (t) => { } }, {when}) - validate(t, deps, 'departures', 'departures') + validate(t, res, 'departuresResponse', 'res') t.end() }) @@ -214,13 +214,13 @@ tap.test('departures at Auestadion in direction of Friedrichsplatz', async (t) = }) tap.test('arrivals at Kassel Weigelstr.', async (t) => { - const arrivals = await client.arrivals(weigelstr, { + const res = await client.arrivals(weigelstr, { duration: 5, when }) await testArrivals({ test: t, - arrivals, + res, validate, id: weigelstr, }) diff --git a/test/e2e/oebb.js b/test/e2e/oebb.js index 283b80fc..27e9ce4c 100644 --- a/test/e2e/oebb.js +++ b/test/e2e/oebb.js @@ -251,13 +251,13 @@ tap.test('departures at Wien Leibenfrostgasse', async (t) => { '904030' // stop "Wien Leibenfrostgasse (Ziegelofengasse)" ] - const deps = await client.departures(wienLeibenfrostgasse, { + const res = await client.departures(wienLeibenfrostgasse, { duration: 15, when, }) await testDepartures({ test: t, - departures: deps, + res, validate, ids, }) @@ -265,7 +265,7 @@ tap.test('departures at Wien Leibenfrostgasse', async (t) => { }) tap.test('departures with station object', async (t) => { - const deps = await client.departures({ + const res = await client.departures({ type: 'station', id: salzburgHbf, name: 'Salzburg Hbf', @@ -276,7 +276,7 @@ tap.test('departures with station object', async (t) => { } }, {when}) - validate(t, deps, 'departures', 'departures') + validate(t, res, 'departuresResponse', 'res') t.end() }) diff --git a/test/e2e/rejseplanen.js b/test/e2e/rejseplanen.js index a253ea2d..8de32ea4 100644 --- a/test/e2e/rejseplanen.js +++ b/test/e2e/rejseplanen.js @@ -118,13 +118,13 @@ tap.test('trip', async (t) => { }) tap.test('departures at Næstved.', async (t) => { - const departures = await client.departures(næstved, { + const res = await client.departures(næstved, { duration: 20, when, }) await testDepartures({ test: t, - departures, + res, validate, ids: [ næstved, @@ -136,13 +136,13 @@ tap.test('departures at Næstved.', async (t) => { }) tap.test('arrivals at Næstved.', async (t) => { - const arrivals = await client.arrivals(næstved, { + const res = await client.arrivals(næstved, { duration: 20, when }) await testArrivals({ test: t, - arrivals, + res, validate, ids: [ næstved, diff --git a/test/e2e/rmv.js b/test/e2e/rmv.js index c91191fb..214f97d9 100644 --- a/test/e2e/rmv.js +++ b/test/e2e/rmv.js @@ -66,13 +66,13 @@ tap.test('trip details', async (t) => { }) tap.test('arrivals at Wiesbaden Hbf', async (t) => { - const arrivals = await client.arrivals(wiesbadenHbf, { + const res = await client.arrivals(wiesbadenHbf, { duration: 10, when }) await testArrivals({ test: t, - arrivals, + res, validate, id: wiesbadenHbf, }) diff --git a/test/e2e/rsag.js b/test/e2e/rsag.js index 82aa670d..329331b1 100644 --- a/test/e2e/rsag.js +++ b/test/e2e/rsag.js @@ -81,13 +81,13 @@ tap.test('refreshJourney', async (t) => { }) tap.test('arrivals at Platz der Jugend', async (t) => { - const arrivals = await client.arrivals(sternwarte, { + const res = await client.arrivals(sternwarte, { duration: 30, when }) await testArrivals({ test: t, - arrivals, + res, validate, ids: [ sternwarte, diff --git a/test/e2e/saarfahrplan.js b/test/e2e/saarfahrplan.js index 8f8842ec..3dfe8428 100644 --- a/test/e2e/saarfahrplan.js +++ b/test/e2e/saarfahrplan.js @@ -172,13 +172,13 @@ tap.test('trip details', async (t) => { }) tap.test('departures', async (t) => { - const departures = await client.departures(saarbrueckenUhlandstr, { + const res = await client.departures(saarbrueckenUhlandstr, { duration: 5, when }) await testDepartures({ test: t, - departures, + res, validate, id: saarbrueckenUhlandstr, }) @@ -186,9 +186,9 @@ tap.test('departures', async (t) => { }) tap.test('departures with stop object', async (t) => { - const deps = await client.departures({ + const res = await client.departures({ type: 'stop', - id: '8000323', + id: saarbrueckenHbf, name: 'Saarbrücken Hbf', location: { type: 'location', @@ -197,7 +197,7 @@ tap.test('departures with stop object', async (t) => { } }, {when}) - validate(t, deps, 'departures', 'departures') + validate(t, res, 'departuresResponse', 'res') t.end() }) diff --git a/test/e2e/sbahn-muenchen.js b/test/e2e/sbahn-muenchen.js index 64939adc..ee152b0e 100644 --- a/test/e2e/sbahn-muenchen.js +++ b/test/e2e/sbahn-muenchen.js @@ -178,13 +178,13 @@ tap.test('trip details', async (t) => { tap.test('departures at Dietlindenstraße', async (t) => { const dietlindenstr = '624391' - const departures = await client.departures(dietlindenstr, { + const res = await client.departures(dietlindenstr, { duration: 10, when, }) await testDepartures({ test: t, - departures, + res, validate, id: dietlindenstr }) @@ -192,7 +192,7 @@ tap.test('departures at Dietlindenstraße', async (t) => { }) tap.test('departures with station object', async (t) => { - const deps = await client.departures({ + const res = await client.departures({ type: 'station', id: mittersendling, name: 'Mittersendling', @@ -203,18 +203,18 @@ tap.test('departures with station object', async (t) => { } }, {when}) - validate(t, deps, 'departures', 'departures') + validate(t, res, 'departuresResponse', 'res') t.end() }) tap.test('arrivals at Karl-Theodor-Straße', async (t) => { - const arrivals = await client.arrivals(karlTheodorStr, { + const res = await client.arrivals(karlTheodorStr, { duration: 10, when, }) await testArrivals({ test: t, - arrivals, + res, validate, id: karlTheodorStr }) diff --git a/test/e2e/sncb.js b/test/e2e/sncb.js index ed2d5da2..bdde56ee 100644 --- a/test/e2e/sncb.js +++ b/test/e2e/sncb.js @@ -71,13 +71,13 @@ tap.test('trip details', async (t) => { }) tap.test('arrivals at Bruxelles Midi', async (t) => { - const arrivals = await client.arrivals(bruxellesMidi, { + const res = await client.arrivals(bruxellesMidi, { duration: 10, when }) await testArrivals({ test: t, - arrivals, + res, validate, id: bruxellesMidi, }) diff --git a/test/e2e/svv.js b/test/e2e/svv.js index 27bd84d6..f0b6a567 100644 --- a/test/e2e/svv.js +++ b/test/e2e/svv.js @@ -73,13 +73,13 @@ tap.test('trip details', async (t) => { }) tap.test('arrivals at Volksgarten', async (t) => { - const arrivals = await client.arrivals(volksgarten, { + const res = await client.arrivals(volksgarten, { duration: 10, when }) await testArrivals({ test: t, - arrivals, + res, validate, id: volksgarten, }) diff --git a/test/e2e/vbb.js b/test/e2e/vbb.js index 4e1d18b7..1d2889bf 100644 --- a/test/e2e/vbb.js +++ b/test/e2e/vbb.js @@ -285,13 +285,13 @@ tap.test('journeys: via works – with detour', async (t) => { // todo: without detour test tap.test('departures', async (t) => { - const departures = await client.departures(spichernstr, { + const res = await client.departures(spichernstr, { duration: 5, when, }) await testDepartures({ test: t, - departures, + res, validate, id: spichernstr }) @@ -299,7 +299,7 @@ tap.test('departures', async (t) => { }) tap.test('departures with station object', async (t) => { - const deps = await client.departures({ + const res = await client.departures({ type: 'station', id: spichernstr, name: 'U Spichernstr', @@ -310,7 +310,7 @@ tap.test('departures with station object', async (t) => { } }, {when}) - validate(t, deps, 'departures', 'departures') + validate(t, res, 'departuresResponse', 'res') t.end() }) @@ -335,13 +335,13 @@ tap.test('departures at 7-digit station', async (t) => { }) tap.test('arrivals', async (t) => { - const arrivals = await client.arrivals(spichernstr, { + const res = await client.arrivals(spichernstr, { duration: 5, when, }) await testArrivals({ test: t, - arrivals, + res, validate, id: spichernstr }) diff --git a/test/e2e/vbn.js b/test/e2e/vbn.js index eaf9160c..43589871 100644 --- a/test/e2e/vbn.js +++ b/test/e2e/vbn.js @@ -66,13 +66,13 @@ tap.test('trip details', async (t) => { }) tap.test('arrivals at Bremen Humboldtstr.', async (t) => { - const arrivals = await client.arrivals(bremenHumboldtstr, { + const res = await client.arrivals(bremenHumboldtstr, { duration: 10, when }) await testArrivals({ test: t, - arrivals, + res, validate, id: bremenHumboldtstr, }) diff --git a/test/e2e/vrn.js b/test/e2e/vrn.js index 24cfea26..6908fcf3 100644 --- a/test/e2e/vrn.js +++ b/test/e2e/vrn.js @@ -145,13 +145,13 @@ tap.test('trip details', async (t) => { }) tap.test('departures at Meckesheim', async (t) => { - const departures = await client.departures(meckesheim, { + const res = await client.departures(meckesheim, { duration: 3 * 60, when, }) await testDepartures({ test: t, - departures, + res, validate, id: meckesheim }) @@ -173,13 +173,13 @@ tap.test('departures at Meckesheim in direction of Reilsheim', async (t) => { }) tap.test('arrivals at Meckesheim', async (t) => { - const arrivals = await client.arrivals(meckesheim, { + const res = await client.arrivals(meckesheim, { duration: 3 * 60, when }) await testArrivals({ test: t, - arrivals, + res, validate, id: meckesheim }) diff --git a/test/e2e/vsn.js b/test/e2e/vsn.js index ad23a4bf..91285afe 100644 --- a/test/e2e/vsn.js +++ b/test/e2e/vsn.js @@ -101,13 +101,13 @@ tap.test('trip', async (t) => { }) tap.test('departures at Kornmarkt.', async (t) => { - const departures = await client.departures(kornmarkt, { + const res = await client.departures(kornmarkt, { duration: 20, when }) await testDepartures({ test: t, - departures, + res, validate, id: kornmarkt }) @@ -115,13 +115,13 @@ tap.test('departures at Kornmarkt.', async (t) => { }) tap.test('arrivals at Kornmarkt.', async (t) => { - const arrivals = await client.arrivals(kornmarkt, { + const res = await client.arrivals(kornmarkt, { duration: 20, when }) await testArrivals({ test: t, - arrivals, + res, validate, id: kornmarkt }) @@ -129,7 +129,7 @@ tap.test('arrivals at Kornmarkt.', async (t) => { }) tap.test('departures with station object', async (t) => { - const deps = await client.departures({ + const res = await client.departures({ type: 'station', id: kornmarkt, name: 'Kornmarkt', @@ -140,7 +140,7 @@ tap.test('departures with station object', async (t) => { } }, {when}) - validate(t, deps, 'departures', 'departures') + validate(t, res, 'departuresResponse', 'res') t.end() }) diff --git a/test/e2e/zvv.js b/test/e2e/zvv.js index 909c5aff..96336594 100644 --- a/test/e2e/zvv.js +++ b/test/e2e/zvv.js @@ -79,13 +79,13 @@ tap.test('trip details', async (t) => { tap.test('departures at ETH/Universitätsspital', async (t) => { // todo const polyterrasseETH = '8503500' - const departures = await client.departures(ethUniversitätsspital, { + const res = await client.departures(ethUniversitätsspital, { duration: 5, when, }) await testDepartures({ test: t, - departures, + res, validate, ids: [ethUniversitätsspital, polyterrasseETH], }) diff --git a/test/retry.js b/test/retry.js index 659c7518..0697b80d 100644 --- a/test/retry.js +++ b/test/retry.js @@ -42,9 +42,16 @@ tap.test('withRetrying works', (t) => { }) const client = createClient(profile, userAgent) - t.plan(1 + 4) + t.plan(2 + 4) client.departures(spichernstr, {duration: 1}) - .then(deps => t.same(deps, [], 'resolved with invalid value')) + .then((res) => { + const { + departures: deps, + realtimeDataUpdatedAt, + } = res + t.same(deps, [], 'resolved with invalid value') + t.equal(realtimeDataUpdatedAt, null, 'resolved with invalid value') + }) .catch(t.ifError) setTimeout(() => t.equal(calls, 1), 50) // buffer