From ab5ca3db8bcaa42097aec084c8401f70d1735a20 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Fri, 29 Jun 2018 14:58:43 +0200 Subject: [PATCH] rename journeyLeg() to trip() :boom:, adapt tests --- docs/changelog.md | 11 ++++++----- docs/migrating-to-3.md | 8 ++++++-- index.js | 10 +++++----- test/db.js | 6 +++--- test/insa.js | 6 +++--- test/nahsh.js | 6 +++--- test/oebb.js | 6 +++--- test/vbb.js | 6 +++--- 8 files changed, 32 insertions(+), 27 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 687c3620..9d35c17d 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -8,8 +8,8 @@ This version is not fully backwords-compatible. Check out [the migration guide]( - 0db84ce #61 parse remarks for stopovers and journey legs - ac9819b `arrivals()` method – [docs](arrivals.md) -- 21c273c `journeys()`/`journeyLeg()`: leg stopovers: parse & expose delays -- 021ae45 `journeys()`/`journeyLeg()`: leg stopovers: parse & expose platforms +- 21c273c `journeys()`/`trip()`: leg stopovers: parse & expose delays +- 021ae45 `journeys()`/`trip()`: leg stopovers: parse & expose platforms - 84bce0c `arrivals()`/`departures()`: parse & expose platforms - 85e0bdf `journeys()`: `startWithWalking` option with default `true` - f6ae29c journey legs with `type: 'walking'` now have a `distance` in meters @@ -24,12 +24,13 @@ This version is not fully backwords-compatible. Check out [the migration guide]( - a356a26 throw if 0 products enabled - c82ad23 `journeys()`: `opt.when` → `opt.departure`/`opt.arrival` - 665bed9 rename `location(id)` to `station(id)` -- 6611f26 `journeys()`/`journeyLeg()`: `leg.passed` → `leg.stopovers` -- ebe4fa6 `journeys()`/`journeyLeg()`: `opt.passedStations` → `opt.stopovers` -- 3e672ee `journeys()`/`journeyLeg()`: `stopover.station` → `stopover.stop` +- 6611f26 `journeys()`/`trip()`: `leg.passed` → `leg.stopovers` +- ebe4fa6 `journeys()`/`trip()`: `opt.passedStations` → `opt.stopovers` +- 3e672ee `journeys()`/`trip()`: `stopover.station` → `stopover.stop` - 2e6aefe journey leg, departure, movement: `journeyId` -> `tripId` - 8881d8a & b6fbaa5: change parsers signature to `parse…(profile, opt, data)` - cabe5fa: option to parse & expose `station.lines`, default off +- c8ff217 rename `journeyLeg()` to `trip()` ### bugfixes diff --git a/docs/migrating-to-3.md b/docs/migrating-to-3.md index 4bda6e90..93f54b4c 100644 --- a/docs/migrating-to-3.md +++ b/docs/migrating-to-3.md @@ -1,6 +1,10 @@ # Migrating to `hafas-client@3` -## If you use the `journeys()` or `journeyLeg()` methods… +## If you use the `journeyLeg()` method… + +…change the `journeyLeg(id, lineName)` call to `trip(id, lineName)`. c8ff217 + +## If you use the `journeys()` or `trip()` methods… - …instead of `journey.departure`, use `journey.legs[0].departure`. 005f3f8 - …instead of `journey.arrival`, use `journey.legs[last].arrival`. 005f3f8 @@ -13,7 +17,7 @@ …use `opt.departure` instead. Use `opt.arrival` to get journeys arriving before the specified date+time. This replaces the `opt.when` & `opt.whenRepresents` options from `hafas-client@2`. c82ad23 -## If you use the `journeys()` and `opt.polylines` or `journeyLeg()` and `opt.polyline`… +## If you use the `journeys()` and `opt.polylines` or `trip()` and `opt.polyline`… …`leg.polyline` will be [parsed for you now](https://github.com/public-transport/hafas-client/blob/f6c824eecb459181ea90ddf41bf1a1e8b64539ec/docs/journey-leg.md#polyline-option). diff --git a/index.js b/index.js index 6dee9941..97068587 100644 --- a/index.js +++ b/index.js @@ -315,9 +315,9 @@ const createClient = (profile, request = _request) => { }) } - const journeyLeg = (ref, lineName, opt = {}) => { - if (!isNonEmptyString(ref)) { - throw new Error('ref must be a non-empty string.') + const trip = (id, lineName, opt = {}) => { + if (!isNonEmptyString(id)) { + throw new Error('id must be a non-empty string.') } if (!isNonEmptyString(lineName)) { throw new Error('lineName must be a non-empty string.') @@ -335,7 +335,7 @@ const createClient = (profile, request = _request) => { meth: 'JourneyDetails', req: { // todo: getTrainComposition - jid: ref, + jid: id, name: lineName, date: profile.formatDate(profile, opt.when), getPolyline: !!opt.polyline @@ -413,7 +413,7 @@ const createClient = (profile, request = _request) => { } const client = {departures, arrivals, journeys, locations, station, nearby} - if (profile.journeyLeg) client.journeyLeg = journeyLeg + if (profile.journeyLeg) client.trip = trip if (profile.radar) client.radar = radar Object.defineProperty(client, 'profile', {value: profile}) return client diff --git a/test/db.js b/test/db.js index 9bcdc7a6..c47e0c71 100644 --- a/test/db.js +++ b/test/db.js @@ -189,7 +189,7 @@ test('earlier/later journeys, Jungfernheide -> München Hbf', co(function* (t) { t.end() })) -test('journey leg details', co(function* (t) { +test('trip details', co(function* (t) { const journeys = yield client.journeys(berlinHbf, münchenHbf, { results: 1, departure: when }) @@ -197,7 +197,7 @@ test('journey leg details', co(function* (t) { const p = journeys[0].legs[0] t.ok(p.id, 'precondition failed') t.ok(p.line.name, 'precondition failed') - const leg = yield client.journeyLeg(p.id, p.line.name, {when}) + const trip = yield client.trip(p.id, p.line.name, {when}) const validateJourneyLeg = createValidateJourneyLeg(cfg) const validate = createValidate(cfg, { @@ -206,7 +206,7 @@ test('journey leg details', co(function* (t) { validateJourneyLeg(validate, leg, name) } }) - validate(t, leg, 'journeyLeg', 'leg') + validate(t, trip, 'journeyLeg', 'trip') t.end() })) diff --git a/test/insa.js b/test/insa.js index 365740a1..5250f96d 100644 --- a/test/insa.js +++ b/test/insa.js @@ -152,7 +152,7 @@ test('earlier/later journeys', co(function* (t) { t.end() })) -test('journey leg details', co(function* (t) { +test('trip details', co(function* (t) { const journeys = yield client.journeys(magdeburgHbf, magdeburgBuckau, { results: 1, departure: when }) @@ -160,9 +160,9 @@ test('journey leg details', co(function* (t) { const p = journeys[0].legs[0] t.ok(p.id, 'precondition failed') t.ok(p.line.name, 'precondition failed') - const leg = yield client.journeyLeg(p.id, p.line.name, {when}) + const trip = yield client.trip(p.id, p.line.name, {when}) - validate(t, leg, 'journeyLeg', 'leg') + validate(t, trip, 'journeyLeg', 'trip') t.end() })) diff --git a/test/nahsh.js b/test/nahsh.js index a502908b..6c29000f 100644 --- a/test/nahsh.js +++ b/test/nahsh.js @@ -184,7 +184,7 @@ test('earlier/later journeys, Kiel Hbf -> Flensburg', co(function* (t) { // todo: with detour test // todo: without detour test -test('journey leg details for Flensburg to Husum', co(function* (t) { +test('trip details', co(function* (t) { const journeys = yield client.journeys(flensburg, husum, { results: 1, departure: when }) @@ -192,9 +192,9 @@ test('journey leg details for Flensburg to Husum', co(function* (t) { const p = journeys[0].legs[0] t.ok(p.id, 'precondition failed') t.ok(p.line.name, 'precondition failed') - const leg = yield client.journeyLeg(p.id, p.line.name, {when}) + const trip = yield client.trip(p.id, p.line.name, {when}) - validate(t, leg, 'journeyLeg', 'leg') + validate(t, trip, 'journeyLeg', 'trip') t.end() })) diff --git a/test/oebb.js b/test/oebb.js index d97581d3..3c2f045c 100644 --- a/test/oebb.js +++ b/test/oebb.js @@ -209,7 +209,7 @@ test('earlier/later journeys, Salzburg Hbf -> Wien Westbahnhof', co(function* (t t.end() })) -test('leg details for Wien Westbahnhof to München Hbf', co(function* (t) { +test('trip details', co(function* (t) { const journeys = yield client.journeys(wienWestbahnhof, muenchenHbf, { results: 1, departure: when }) @@ -217,9 +217,9 @@ test('leg details for Wien Westbahnhof to München Hbf', co(function* (t) { const p = journeys[0].legs[0] t.ok(p.id, 'precondition failed') t.ok(p.line.name, 'precondition failed') - const leg = yield client.journeyLeg(p.id, p.line.name, {when}) + const trip = yield client.trip(p.id, p.line.name, {when}) - validate(t, leg, 'journeyLeg', 'leg') + validate(t, trip, 'journeyLeg', 'trip') t.end() })) diff --git a/test/vbb.js b/test/vbb.js index 36601c6d..3ce8c9bb 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -187,7 +187,7 @@ test('earlier/later journeys', co(function* (t) { t.end() })) -test('journey leg details', co(function* (t) { +test('trip details', co(function* (t) { const journeys = yield client.journeys(spichernstr, amrumerStr, { results: 1, departure: when }) @@ -195,9 +195,9 @@ test('journey leg details', co(function* (t) { const p = journeys[0].legs[0] t.ok(p.id, 'precondition failed') t.ok(p.line.name, 'precondition failed') - const leg = yield client.journeyLeg(p.id, p.line.name, {when}) + const trip = yield client.trip(p.id, p.line.name, {when}) - validate(t, leg, 'journeyLeg', 'leg') + validate(t, trip, 'journeyLeg', 'trip') t.end() }))