rename journeyLeg() to trip() 💥, adapt tests

This commit is contained in:
Jannis R 2018-06-29 14:58:43 +02:00 committed by Jannis Redmann
parent 86fc27e340
commit ab5ca3db8b
8 changed files with 32 additions and 27 deletions

View file

@ -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

View file

@ -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).

View file

@ -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

View file

@ -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()
}))

View file

@ -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()
}))

View file

@ -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()
}))

View file

@ -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()
}))

View file

@ -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()
}))