mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
docs, tests: rename journey.parts -> journey.legs 📝✅
This commit is contained in:
parent
8985f8ccd2
commit
c02983492b
6 changed files with 90 additions and 90 deletions
|
@ -33,7 +33,7 @@ With `opt`, you can override the default options, which look like this:
|
||||||
|
|
||||||
*Note:* As stated in the [*Friendly Public Transport Format* `1.0.1`](https://github.com/public-transport/friendly-public-transport-format/tree/1.0.1), the `when` include the current delay. The `delay` field, if present, expresses how much the former differs from the schedule.
|
*Note:* As stated in the [*Friendly Public Transport Format* `1.0.1`](https://github.com/public-transport/friendly-public-transport-format/tree/1.0.1), the `when` include the current delay. The `delay` field, if present, expresses how much the former differs from the schedule.
|
||||||
|
|
||||||
You may pass the `journeyId` field into [`journeyPart(ref, lineName, [opt])`](journey-part.md) to get details on the vehicle's journey.
|
You may pass the `journeyId` field into [`journeyLeg(ref, lineName, [opt])`](journey-leg.md) to get details on the vehicle's journey.
|
||||||
|
|
||||||
As an example, we're going to use the VBB profile:
|
As an example, we're going to use the VBB profile:
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# `journeyPart(ref, lineName, [opt])`
|
# `journeyLeg(ref, lineName, [opt])`
|
||||||
|
|
||||||
This method can be used to refetch information about a leg of a journey. Note that it is not supported by every profile/endpoint.
|
This method can be used to refetch information about a leg of a journey. Note that it is not supported by every profile/endpoint.
|
||||||
|
|
||||||
|
@ -13,8 +13,8 @@ const client = createClient(vbbProfile)
|
||||||
// Hauptbahnhof to Heinrich-Heine-Str.
|
// Hauptbahnhof to Heinrich-Heine-Str.
|
||||||
client.journeys('900000003201', '900000100008', {results: 1})
|
client.journeys('900000003201', '900000100008', {results: 1})
|
||||||
.then(([journey]) => {
|
.then(([journey]) => {
|
||||||
const part = journey.parts[0]
|
const leg = journey.legs[0]
|
||||||
return client.journeyPart(part.id, part.line.name)
|
return client.journeyLeg(leg.id, leg.line.name)
|
||||||
})
|
})
|
||||||
.then(console.log)
|
.then(console.log)
|
||||||
.catch(console.error)
|
.catch(console.error)
|
||||||
|
@ -41,7 +41,7 @@ const vbbProfile = require('hafas-client/p/vbb')
|
||||||
|
|
||||||
const client = createClient(vbbProfile)
|
const client = createClient(vbbProfile)
|
||||||
|
|
||||||
client.journeyPart('1|31431|28|86|17122017', 'S9', {when: 1513534689273})
|
client.journeyLeg('1|31431|28|86|17122017', 'S9', {when: 1513534689273})
|
||||||
.then(console.log)
|
.then(console.log)
|
||||||
.catch(console.error)
|
.catch(console.error)
|
||||||
```
|
```
|
|
@ -86,7 +86,7 @@ The response may look like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
[ {
|
[ {
|
||||||
parts: [ {
|
legs: [ {
|
||||||
id: '1|31041|35|86|17122017',
|
id: '1|31041|35|86|17122017',
|
||||||
origin: {
|
origin: {
|
||||||
type: 'station',
|
type: 'station',
|
||||||
|
|
|
@ -28,7 +28,7 @@ npm install hafas-client
|
||||||
## API
|
## API
|
||||||
|
|
||||||
- [`journeys(from, to, [opt])`](docs/journeys.md) – get journeys between locations
|
- [`journeys(from, to, [opt])`](docs/journeys.md) – get journeys between locations
|
||||||
- [`journeyPart(ref, name, [opt])`](docs/journey-part.md) – get details for a part of a journey
|
- [`journeyLeg(ref, name, [opt])`](docs/journey-leg.md) – get details for a leg of a journey
|
||||||
- [`departures(station, [opt])`](docs/departures.md) – query the next departures at a station
|
- [`departures(station, [opt])`](docs/departures.md) – query the next departures at a station
|
||||||
- [`locations(query, [opt])`](docs/locations.md) – find stations, POIs and addresses
|
- [`locations(query, [opt])`](docs/locations.md) – find stations, POIs and addresses
|
||||||
- [`nearby(latitude, longitude, [opt])`](docs/nearby.md) – show stations & POIs around
|
- [`nearby(latitude, longitude, [opt])`](docs/nearby.md) – show stations & POIs around
|
||||||
|
@ -54,7 +54,7 @@ The returned [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript
|
||||||
|
|
||||||
```js
|
```js
|
||||||
[ {
|
[ {
|
||||||
parts: [ {
|
legs: [ {
|
||||||
id: '1|100067|48|81|17122017',
|
id: '1|100067|48|81|17122017',
|
||||||
origin: {
|
origin: {
|
||||||
type: 'station',
|
type: 'station',
|
||||||
|
|
72
test/db.js
72
test/db.js
|
@ -118,30 +118,30 @@ test('Berlin Jungfernheide to München Hbf', co.wrap(function* (t) {
|
||||||
}
|
}
|
||||||
t.ok(isValidWhen(journey.arrival))
|
t.ok(isValidWhen(journey.arrival))
|
||||||
|
|
||||||
t.ok(Array.isArray(journey.parts))
|
t.ok(Array.isArray(journey.legs))
|
||||||
t.ok(journey.parts.length > 0, 'no parts')
|
t.ok(journey.legs.length > 0, 'no legs')
|
||||||
const part = journey.parts[0]
|
const leg = journey.legs[0]
|
||||||
|
|
||||||
assertValidStation(t, part.origin)
|
assertValidStation(t, leg.origin)
|
||||||
assertValidStationProducts(t, part.origin.products)
|
assertValidStationProducts(t, leg.origin.products)
|
||||||
if (!(yield findStation(part.origin.id))) {
|
if (!(yield findStation(leg.origin.id))) {
|
||||||
console.error('unknown station', part.origin.id, part.origin.name)
|
console.error('unknown station', leg.origin.id, leg.origin.name)
|
||||||
}
|
}
|
||||||
t.ok(isValidWhen(part.departure))
|
t.ok(isValidWhen(leg.departure))
|
||||||
t.equal(typeof part.departurePlatform, 'string')
|
t.equal(typeof leg.departurePlatform, 'string')
|
||||||
|
|
||||||
assertValidStation(t, part.destination)
|
assertValidStation(t, leg.destination)
|
||||||
assertValidStationProducts(t, part.origin.products)
|
assertValidStationProducts(t, leg.origin.products)
|
||||||
if (!(yield findStation(part.destination.id))) {
|
if (!(yield findStation(leg.destination.id))) {
|
||||||
console.error('unknown station', part.destination.id, part.destination.name)
|
console.error('unknown station', leg.destination.id, leg.destination.name)
|
||||||
}
|
}
|
||||||
t.ok(isValidWhen(part.arrival))
|
t.ok(isValidWhen(leg.arrival))
|
||||||
t.equal(typeof part.arrivalPlatform, 'string')
|
t.equal(typeof leg.arrivalPlatform, 'string')
|
||||||
|
|
||||||
assertValidLine(t, part.line)
|
assertValidLine(t, leg.line)
|
||||||
|
|
||||||
t.ok(Array.isArray(part.passed))
|
t.ok(Array.isArray(leg.passed))
|
||||||
for (let stopover of part.passed) assertValidStopover(t, stopover)
|
for (let stopover of leg.passed) assertValidStopover(t, stopover)
|
||||||
|
|
||||||
if (journey.price) assertValidPrice(t, journey.price)
|
if (journey.price) assertValidPrice(t, journey.price)
|
||||||
}
|
}
|
||||||
|
@ -158,18 +158,18 @@ test('Berlin Jungfernheide to Torfstraße 17', co.wrap(function* (t) {
|
||||||
t.ok(Array.isArray(journeys))
|
t.ok(Array.isArray(journeys))
|
||||||
t.ok(journeys.length >= 1, 'no journeys')
|
t.ok(journeys.length >= 1, 'no journeys')
|
||||||
const journey = journeys[0]
|
const journey = journeys[0]
|
||||||
const part = journey.parts[journey.parts.length - 1]
|
const leg = journey.legs[journey.legs.length - 1]
|
||||||
|
|
||||||
assertValidStation(t, part.origin)
|
assertValidStation(t, leg.origin)
|
||||||
assertValidStationProducts(t, part.origin.products)
|
assertValidStationProducts(t, leg.origin.products)
|
||||||
if (!(yield findStation(part.origin.id))) {
|
if (!(yield findStation(leg.origin.id))) {
|
||||||
console.error('unknown station', part.origin.id, part.origin.name)
|
console.error('unknown station', leg.origin.id, leg.origin.name)
|
||||||
}
|
}
|
||||||
if (part.origin.products) assertValidProducts(t, part.origin.products)
|
if (leg.origin.products) assertValidProducts(t, leg.origin.products)
|
||||||
t.ok(isValidWhen(part.departure))
|
t.ok(isValidWhen(leg.departure))
|
||||||
t.ok(isValidWhen(part.arrival))
|
t.ok(isValidWhen(leg.arrival))
|
||||||
|
|
||||||
const d = part.destination
|
const d = leg.destination
|
||||||
assertValidAddress(t, d)
|
assertValidAddress(t, d)
|
||||||
t.equal(d.address, 'Torfstraße 17')
|
t.equal(d.address, 'Torfstraße 17')
|
||||||
t.ok(isRoughlyEqual(.0001, d.latitude, 52.5416823))
|
t.ok(isRoughlyEqual(.0001, d.latitude, 52.5416823))
|
||||||
|
@ -187,18 +187,18 @@ test('Berlin Jungfernheide to ATZE Musiktheater', co.wrap(function* (t) {
|
||||||
t.ok(Array.isArray(journeys))
|
t.ok(Array.isArray(journeys))
|
||||||
t.ok(journeys.length >= 1, 'no journeys')
|
t.ok(journeys.length >= 1, 'no journeys')
|
||||||
const journey = journeys[0]
|
const journey = journeys[0]
|
||||||
const part = journey.parts[journey.parts.length - 1]
|
const leg = journey.legs[journey.legs.length - 1]
|
||||||
|
|
||||||
assertValidStation(t, part.origin)
|
assertValidStation(t, leg.origin)
|
||||||
assertValidStationProducts(t, part.origin.products)
|
assertValidStationProducts(t, leg.origin.products)
|
||||||
if (!(yield findStation(part.origin.id))) {
|
if (!(yield findStation(leg.origin.id))) {
|
||||||
console.error('unknown station', part.origin.id, part.origin.name)
|
console.error('unknown station', leg.origin.id, leg.origin.name)
|
||||||
}
|
}
|
||||||
if (part.origin.products) assertValidProducts(t, part.origin.products)
|
if (leg.origin.products) assertValidProducts(t, leg.origin.products)
|
||||||
t.ok(isValidWhen(part.departure))
|
t.ok(isValidWhen(leg.departure))
|
||||||
t.ok(isValidWhen(part.arrival))
|
t.ok(isValidWhen(leg.arrival))
|
||||||
|
|
||||||
const d = part.destination
|
const d = leg.destination
|
||||||
assertValidPoi(t, d)
|
assertValidPoi(t, d)
|
||||||
t.equal(d.name, 'ATZE Musiktheater')
|
t.equal(d.name, 'ATZE Musiktheater')
|
||||||
t.ok(isRoughlyEqual(.0001, d.latitude, 52.542399))
|
t.ok(isRoughlyEqual(.0001, d.latitude, 52.542399))
|
||||||
|
|
92
test/vbb.js
92
test/vbb.js
|
@ -77,29 +77,29 @@ test('journeys – station to station', co.wrap(function* (t) {
|
||||||
t.strictEqual(journey.destination.id, amrumerStr)
|
t.strictEqual(journey.destination.id, amrumerStr)
|
||||||
assertValidWhen(t, journey.arrival)
|
assertValidWhen(t, journey.arrival)
|
||||||
|
|
||||||
t.ok(Array.isArray(journey.parts))
|
t.ok(Array.isArray(journey.legs))
|
||||||
t.strictEqual(journey.parts.length, 1)
|
t.strictEqual(journey.legs.length, 1)
|
||||||
const part = journey.parts[0]
|
const leg = journey.legs[0]
|
||||||
|
|
||||||
t.equal(typeof part.id, 'string')
|
t.equal(typeof leg.id, 'string')
|
||||||
t.ok(part.id)
|
t.ok(leg.id)
|
||||||
assertValidStation(t, part.origin)
|
assertValidStation(t, leg.origin)
|
||||||
assertValidStationProducts(t, part.origin.products)
|
assertValidStationProducts(t, leg.origin.products)
|
||||||
t.ok(part.origin.name.indexOf('(Berlin)') === -1)
|
t.ok(leg.origin.name.indexOf('(Berlin)') === -1)
|
||||||
t.strictEqual(part.origin.id, spichernstr)
|
t.strictEqual(leg.origin.id, spichernstr)
|
||||||
assertValidWhen(t, part.departure)
|
assertValidWhen(t, leg.departure)
|
||||||
|
|
||||||
assertValidStation(t, part.destination)
|
assertValidStation(t, leg.destination)
|
||||||
assertValidStationProducts(t, part.destination.products)
|
assertValidStationProducts(t, leg.destination.products)
|
||||||
t.strictEqual(part.destination.id, amrumerStr)
|
t.strictEqual(leg.destination.id, amrumerStr)
|
||||||
assertValidWhen(t, part.arrival)
|
assertValidWhen(t, leg.arrival)
|
||||||
|
|
||||||
assertValidLine(t, part.line)
|
assertValidLine(t, leg.line)
|
||||||
t.ok(findStation(part.direction))
|
t.ok(findStation(leg.direction))
|
||||||
t.ok(part.direction.indexOf('(Berlin)') === -1)
|
t.ok(leg.direction.indexOf('(Berlin)') === -1)
|
||||||
|
|
||||||
t.ok(Array.isArray(part.passed))
|
t.ok(Array.isArray(leg.passed))
|
||||||
for (let passed of part.passed) assertValidStopover(t, passed)
|
for (let passed of leg.passed) assertValidStopover(t, passed)
|
||||||
|
|
||||||
// todo: find a journey where there ticket info is always available
|
// todo: find a journey where there ticket info is always available
|
||||||
if (journey.tickets) {
|
if (journey.tickets) {
|
||||||
|
@ -128,11 +128,11 @@ test('journeys – only subway', co.wrap(function* (t) {
|
||||||
t.ok(journeys.length > 1)
|
t.ok(journeys.length > 1)
|
||||||
|
|
||||||
for (let journey of journeys) {
|
for (let journey of journeys) {
|
||||||
for (let part of journey.parts) {
|
for (let leg of journey.legs) {
|
||||||
if (part.line) {
|
if (leg.line) {
|
||||||
assertValidLine(t, part.line)
|
assertValidLine(t, leg.line)
|
||||||
t.equal(part.line.mode, 'train')
|
t.equal(leg.line.mode, 'train')
|
||||||
t.equal(part.line.product, 'subway')
|
t.equal(leg.line.product, 'subway')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,26 +159,26 @@ test('journeys – fails with no product', co.wrap(function* (t) {
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|
||||||
test('journey part details', co.wrap(function* (t) {
|
test('journey leg details', co.wrap(function* (t) {
|
||||||
const journeys = yield client.journeys(spichernstr, amrumerStr, {
|
const journeys = yield client.journeys(spichernstr, amrumerStr, {
|
||||||
results: 1, when
|
results: 1, when
|
||||||
})
|
})
|
||||||
|
|
||||||
const p = journeys[0].parts[0]
|
const p = journeys[0].legs[0]
|
||||||
t.ok(p.id, 'precondition failed')
|
t.ok(p.id, 'precondition failed')
|
||||||
t.ok(p.line.name, 'precondition failed')
|
t.ok(p.line.name, 'precondition failed')
|
||||||
const part = yield client.journeyPart(p.id, p.line.name, {when})
|
const leg = yield client.journeyLeg(p.id, p.line.name, {when})
|
||||||
|
|
||||||
t.equal(typeof part.id, 'string')
|
t.equal(typeof leg.id, 'string')
|
||||||
t.ok(part.id)
|
t.ok(leg.id)
|
||||||
|
|
||||||
assertValidLine(t, part.line)
|
assertValidLine(t, leg.line)
|
||||||
|
|
||||||
t.equal(typeof part.direction, 'string')
|
t.equal(typeof leg.direction, 'string')
|
||||||
t.ok(part.direction)
|
t.ok(leg.direction)
|
||||||
|
|
||||||
t.ok(Array.isArray(part.passed))
|
t.ok(Array.isArray(leg.passed))
|
||||||
for (let passed of part.passed) assertValidStopover(t, passed)
|
for (let passed of leg.passed) assertValidStopover(t, passed)
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
@ -194,18 +194,18 @@ test('journeys – station to address', co.wrap(function* (t) {
|
||||||
t.ok(Array.isArray(journeys))
|
t.ok(Array.isArray(journeys))
|
||||||
t.strictEqual(journeys.length, 1)
|
t.strictEqual(journeys.length, 1)
|
||||||
const journey = journeys[0]
|
const journey = journeys[0]
|
||||||
const part = journey.parts[journey.parts.length - 1]
|
const leg = journey.legs[journey.legs.length - 1]
|
||||||
|
|
||||||
assertValidStation(t, part.origin)
|
assertValidStation(t, leg.origin)
|
||||||
assertValidStationProducts(t, part.origin.products)
|
assertValidStationProducts(t, leg.origin.products)
|
||||||
assertValidWhen(t, part.departure)
|
assertValidWhen(t, leg.departure)
|
||||||
|
|
||||||
const dest = part.destination
|
const dest = leg.destination
|
||||||
assertValidAddress(t, dest)
|
assertValidAddress(t, dest)
|
||||||
t.strictEqual(dest.address, 'Torfstraße 17')
|
t.strictEqual(dest.address, 'Torfstraße 17')
|
||||||
t.ok(isRoughlyEqual(.0001, dest.latitude, 52.5416823))
|
t.ok(isRoughlyEqual(.0001, dest.latitude, 52.5416823))
|
||||||
t.ok(isRoughlyEqual(.0001, dest.longitude, 13.3491223))
|
t.ok(isRoughlyEqual(.0001, dest.longitude, 13.3491223))
|
||||||
assertValidWhen(t, part.arrival)
|
assertValidWhen(t, leg.arrival)
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
@ -221,18 +221,18 @@ test('journeys – station to POI', co.wrap(function* (t) {
|
||||||
t.ok(Array.isArray(journeys))
|
t.ok(Array.isArray(journeys))
|
||||||
t.strictEqual(journeys.length, 1)
|
t.strictEqual(journeys.length, 1)
|
||||||
const journey = journeys[0]
|
const journey = journeys[0]
|
||||||
const part = journey.parts[journey.parts.length - 1]
|
const leg = journey.legs[journey.legs.length - 1]
|
||||||
|
|
||||||
assertValidStation(t, part.origin)
|
assertValidStation(t, leg.origin)
|
||||||
assertValidStationProducts(t, part.origin.products)
|
assertValidStationProducts(t, leg.origin.products)
|
||||||
assertValidWhen(t, part.departure)
|
assertValidWhen(t, leg.departure)
|
||||||
|
|
||||||
const dest = part.destination
|
const dest = leg.destination
|
||||||
assertValidPoi(t, dest)
|
assertValidPoi(t, dest)
|
||||||
t.strictEqual(dest.name, 'ATZE Musiktheater')
|
t.strictEqual(dest.name, 'ATZE Musiktheater')
|
||||||
t.ok(isRoughlyEqual(.0001, dest.latitude, 52.543333))
|
t.ok(isRoughlyEqual(.0001, dest.latitude, 52.543333))
|
||||||
t.ok(isRoughlyEqual(.0001, dest.longitude, 13.351686))
|
t.ok(isRoughlyEqual(.0001, dest.longitude, 13.351686))
|
||||||
assertValidWhen(t, part.arrival)
|
assertValidWhen(t, leg.arrival)
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
Loading…
Add table
Reference in a new issue