diff --git a/docs/radar.md b/docs/radar.md index 994cc3a3..4f8ff5d6 100644 --- a/docs/radar.md +++ b/docs/radar.md @@ -30,7 +30,10 @@ const vbbProfile = require('hafas-client/p/vbb') const client = createClient(vbbProfile, 'my-awesome-program') -await client.radar({ +const { + movements, + realtimeDataUpdatedAt, +} = await client.radar({ north: 52.52411, west: 13.41002, south: 52.51942, @@ -38,7 +41,9 @@ await client.radar({ }, {results: 5}) ``` -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. + +`movements` may look like this: ```js [ { diff --git a/index.js b/index.js index 01e16f1d..7fef52db 100644 --- a/index.js +++ b/index.js @@ -619,8 +619,14 @@ const createClient = (profile, userAgent, opt = {}) => { if (!Array.isArray(res.jnyL)) return [] const ctx = {profile, opt, common, res} - // todo [breaking]: return object with realtimeDataUpdatedAt - return res.jnyL.map(m => profile.parseMovement(ctx, m)) + const movements = res.jnyL.map(m => profile.parseMovement(ctx, m)) + + return { + movements, + realtimeDataUpdatedAt: res.planrtTS && res.planrtTS !== '0' + ? parseInt(res.planrtTS) + : null, + } } const reachableFrom = async (address, opt = {}) => { diff --git a/test/e2e/bvg.js b/test/e2e/bvg.js index ae1cb7bd..87122881 100644 --- a/test/e2e/bvg.js +++ b/test/e2e/bvg.js @@ -416,7 +416,7 @@ tap.test('stop', async (t) => { }) tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 52.52411, west: 13.41002, south: 52.51942, @@ -425,7 +425,7 @@ tap.test('radar', async (t) => { duration: 5 * 60, when }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/cfl.js b/test/e2e/cfl.js index d08d0567..105762ab 100644 --- a/test/e2e/cfl.js +++ b/test/e2e/cfl.js @@ -257,7 +257,7 @@ tap.test('stop Mersch', async (t) => { }) tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 49.9, west: 6.05, south: 49.8, @@ -266,6 +266,6 @@ tap.test('radar', async (t) => { duration: 5 * 60, when, results: 10 }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/cmta.js b/test/e2e/cmta.js index 8fe383fb..7d1b9baf 100644 --- a/test/e2e/cmta.js +++ b/test/e2e/cmta.js @@ -235,7 +235,7 @@ tap.test('station Domain', async (t) => { }) tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 30.240877, west: -97.804588, south: 30.225378, @@ -244,7 +244,7 @@ tap.test('radar', async (t) => { duration: 5 * 60, when, results: 10 }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/db-busradar-nrw.js b/test/e2e/db-busradar-nrw.js index 36ae6374..9e404ee1 100644 --- a/test/e2e/db-busradar-nrw.js +++ b/test/e2e/db-busradar-nrw.js @@ -123,7 +123,7 @@ tap.test('station Hagen-Vorhalle', async (t) => { }) tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 51.5, west: 7.2, south: 51.2, @@ -136,6 +136,6 @@ tap.test('radar', async (t) => { ...cfg, stationCoordsOptional: true, }, {}) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/db.js b/test/e2e/db.js index 41bc4981..685a119c 100644 --- a/test/e2e/db.js +++ b/test/e2e/db.js @@ -445,7 +445,7 @@ tap.test('line with additionalName', async (t) => { }) tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 52.52411, west: 13.41002, south: 52.51942, @@ -454,7 +454,7 @@ tap.test('radar', async (t) => { duration: 5 * 60, when }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/hvv.js b/test/e2e/hvv.js index 02a2fcef..ad7d4542 100644 --- a/test/e2e/hvv.js +++ b/test/e2e/hvv.js @@ -238,7 +238,7 @@ tap.skip('station Hamburg Barmbek', async (t) => { }) tap.skip('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 53.569, west: 10.022, south: 53.55, @@ -247,6 +247,6 @@ tap.skip('radar', async (t) => { duration: 5 * 60, when, results: 10 }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/insa.js b/test/e2e/insa.js index a2046320..6dfd32f6 100644 --- a/test/e2e/insa.js +++ b/test/e2e/insa.js @@ -279,7 +279,7 @@ tap.test('station Magdeburg-Buckau', async (t) => { }) tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 52.148364, west: 11.600826, south: 52.108486, @@ -292,7 +292,7 @@ tap.test('radar', async (t) => { stationCoordsOptional: true, // see #28 }) const validate = createValidate(customCfg, validators) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/invg.js b/test/e2e/invg.js index 16c63bb4..5d259ff1 100644 --- a/test/e2e/invg.js +++ b/test/e2e/invg.js @@ -279,7 +279,7 @@ tap.test('stop Ettinger Str.', async (t) => { }) tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 48.74453, west: 11.42733, south: 48.73453, @@ -288,6 +288,6 @@ tap.test('radar', async (t) => { duration: 5 * 60, when, results: 10 }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/lib/validators.js b/test/e2e/lib/validators.js index 16c82ec9..47acc9ce 100644 --- a/test/e2e/lib/validators.js +++ b/test/e2e/lib/validators.js @@ -632,6 +632,14 @@ const validateMovements = (val, ms, name = 'movements') => { } } +const validateRadarResult = (val, res, name = 'movementsResult') => { + a.ok(isObj(res), name + ' must be an object') + + val.movements(val, res.movements, name + '.movements') + + val.realtimeDataUpdatedAt(val, res.realtimeDataUpdatedAt, name + '.realtimeDataUpdatedAt') +} + module.exports = { realtimeDataUpdatedAt: createValidateRealtimeDataUpdatedAt, products: createValidateProducts, @@ -660,5 +668,6 @@ module.exports = { arrivalsResponse: createValidateArrivalsResponse, departuresResponse: createValidateDeparturesResponse, movement: createValidateMovement, - movements: () => validateMovements + movements: () => validateMovements, + radarResult: () => validateRadarResult, } diff --git a/test/e2e/mobil-nrw.js b/test/e2e/mobil-nrw.js index 087dfcc4..a96c757b 100644 --- a/test/e2e/mobil-nrw.js +++ b/test/e2e/mobil-nrw.js @@ -236,7 +236,7 @@ tap.test('station Aachen Hbf', async (t) => { }) tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 51.4358, west: 6.7625, south: 51.4214, @@ -245,7 +245,7 @@ tap.test('radar', async (t) => { duration: 5 * 60, when, results: 10, }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/mobiliteit-lu.js b/test/e2e/mobiliteit-lu.js index b0260d16..7bd3f471 100644 --- a/test/e2e/mobiliteit-lu.js +++ b/test/e2e/mobiliteit-lu.js @@ -260,7 +260,7 @@ tap.test('stop Mersch', async (t) => { }) tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 49.9, west: 6.05, south: 49.8, @@ -269,6 +269,6 @@ tap.test('radar', async (t) => { duration: 5 * 60, when, results: 10 }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/nahsh.js b/test/e2e/nahsh.js index 557ee91a..b1d37b10 100644 --- a/test/e2e/nahsh.js +++ b/test/e2e/nahsh.js @@ -330,7 +330,7 @@ tap.test('stop', async (t) => { }) tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 54.4, west: 10.0, south: 54.2, @@ -351,7 +351,7 @@ tap.test('radar', async (t) => { validateStation(validate, s, name) } }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/nvv.js b/test/e2e/nvv.js index 0432931a..f56c12e2 100644 --- a/test/e2e/nvv.js +++ b/test/e2e/nvv.js @@ -253,7 +253,7 @@ tap.test('station Auestadion', async (t) => { }) tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 51.320153, west: 9.458359, south: 51.304304, @@ -262,7 +262,7 @@ tap.test('radar', async (t) => { duration: 5 * 60, when, results: 10 }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/oebb.js b/test/e2e/oebb.js index c93cba87..4129dece 100644 --- a/test/e2e/oebb.js +++ b/test/e2e/oebb.js @@ -367,7 +367,7 @@ tap.test('stop', async (t) => { }) tap.test('radar Salzburg', async (t) => { - let vehicles = await client.radar({ + let res = await client.radar({ north: 47.827203, west: 13.001261, south: 47.773278, @@ -377,7 +377,7 @@ tap.test('radar Salzburg', async (t) => { }) // todo: find a way to always get frames from the API - vehicles = vehicles.filter(m => m.frames && m.frames.length > 0) + res.movements = res.movements.filter(m => m.frames && m.frames.length > 0) // todo: find a way to always get products from the API // todo: cfg.stationProductsOptional option @@ -396,7 +396,7 @@ tap.test('radar Salzburg', async (t) => { }, name) }, }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/pkp.js b/test/e2e/pkp.js index 739d207f..7a1f5b6b 100644 --- a/test/e2e/pkp.js +++ b/test/e2e/pkp.js @@ -131,7 +131,7 @@ tap.skip('nearby', async (t) => { }) tap.skip('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 48.74453, west: 11.42733, south: 48.73453, @@ -140,7 +140,7 @@ tap.skip('radar', async (t) => { duration: 5 * 60, when, results: 10 }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/rejseplanen.js b/test/e2e/rejseplanen.js index 17d78e14..6e5f5292 100644 --- a/test/e2e/rejseplanen.js +++ b/test/e2e/rejseplanen.js @@ -184,7 +184,7 @@ tap.test('stop Næstved', async (t) => { }) tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 55.695, west: 12.498, south: 55.639, @@ -193,6 +193,6 @@ tap.test('radar', async (t) => { duration: 5 * 60, when, results: 10, }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/rmv.js b/test/e2e/rmv.js index 41237c66..2ffa5589 100644 --- a/test/e2e/rmv.js +++ b/test/e2e/rmv.js @@ -83,7 +83,7 @@ tap.test('arrivals at Wiesbaden Hbf', async (t) => { // todo: nearby tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 53.090516, west: 8.750106, south: 53.062859, @@ -92,7 +92,7 @@ tap.test('radar', async (t) => { duration: 5 * 60, when, results: 10 }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/rsag.js b/test/e2e/rsag.js index 329331b1..6b0fba5e 100644 --- a/test/e2e/rsag.js +++ b/test/e2e/rsag.js @@ -100,7 +100,7 @@ tap.test('arrivals at Platz der Jugend', async (t) => { // todo: nearby tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 54.116968, west: 12.029738, south: 54.060517, @@ -109,7 +109,7 @@ tap.test('radar', async (t) => { duration: 5 * 60, when, results: 10 }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/saarfahrplan.js b/test/e2e/saarfahrplan.js index adbf345b..d1875b47 100644 --- a/test/e2e/saarfahrplan.js +++ b/test/e2e/saarfahrplan.js @@ -269,7 +269,7 @@ tap.test('stop', async (t) => { }) tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 49.27, west: 6.97, south: 49.22, @@ -278,6 +278,6 @@ tap.test('radar', async (t) => { duration: 5 * 60, when }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/sbahn-muenchen.js b/test/e2e/sbahn-muenchen.js index 4f1c9d8f..3b0eeabd 100644 --- a/test/e2e/sbahn-muenchen.js +++ b/test/e2e/sbahn-muenchen.js @@ -252,7 +252,7 @@ tap.test('station Karl-Theodor-Straße', async (t) => { }) tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 48.145121, west: 11.543736, south: 48.138339, @@ -261,7 +261,7 @@ tap.test('radar', async (t) => { duration: 5 * 60, when, results: 10 }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/sncb.js b/test/e2e/sncb.js index fc3be17f..96be5e70 100644 --- a/test/e2e/sncb.js +++ b/test/e2e/sncb.js @@ -88,7 +88,7 @@ tap.test('arrivals at Bruxelles Midi', async (t) => { // todo: nearby tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 51.065, west: 3.688, south: 51.04, @@ -97,7 +97,7 @@ tap.test('radar', async (t) => { duration: 5 * 60, when, results: 10 }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/vbb.js b/test/e2e/vbb.js index aba36f38..61840386 100644 --- a/test/e2e/vbb.js +++ b/test/e2e/vbb.js @@ -402,7 +402,7 @@ tap.test('stop', async (t) => { }) tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 52.52411, west: 13.41002, south: 52.51942, @@ -411,7 +411,7 @@ tap.test('radar', async (t) => { duration: 5 * 60, when }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/vbn.js b/test/e2e/vbn.js index 515d7841..6543a599 100644 --- a/test/e2e/vbn.js +++ b/test/e2e/vbn.js @@ -83,7 +83,7 @@ tap.test('arrivals at Bremen Humboldtstr.', async (t) => { // todo: nearby tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 53.090516, west: 8.750106, south: 53.062859, @@ -92,7 +92,7 @@ tap.test('radar', async (t) => { duration: 5 * 60, when, results: 10 }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/vrn.js b/test/e2e/vrn.js index b9a8a63e..05f06d56 100644 --- a/test/e2e/vrn.js +++ b/test/e2e/vrn.js @@ -217,7 +217,7 @@ tap.test('station Meckesheim', async (t) => { }) tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 49.4940, west: 8.4560, south: 49.4774, @@ -226,6 +226,6 @@ tap.test('radar', async (t) => { duration: 5 * 60, when, results: 10, }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/vsn.js b/test/e2e/vsn.js index ec528627..d34f2965 100644 --- a/test/e2e/vsn.js +++ b/test/e2e/vsn.js @@ -169,7 +169,7 @@ tap.test('stop Jugendherberge', async (t) => { }) tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 52, west: 9.8, south: 51.51, @@ -177,6 +177,6 @@ tap.test('radar', async (t) => { }, { duration: 5 * 60, when, results: 10 }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() }) diff --git a/test/e2e/zvv.js b/test/e2e/zvv.js index e1701808..68bedb5c 100644 --- a/test/e2e/zvv.js +++ b/test/e2e/zvv.js @@ -114,7 +114,7 @@ tap.test('locations named Rennweg', async (t) => { }) tap.test('radar', async (t) => { - const vehicles = await client.radar({ + const res = await client.radar({ north: 47.387, west: 8.514, south: 47.356, @@ -123,6 +123,6 @@ tap.test('radar', async (t) => { duration: 5 * 60, when, results: 10, }) - validate(t, vehicles, 'movements', 'vehicles') + validate(t, res, 'radarResult', 'res') t.end() })