From c02983492b72d74d061e1d29971d746c1eec3f64 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Thu, 28 Dec 2017 17:14:53 +0100 Subject: [PATCH] =?UTF-8?q?docs,=20tests:=20rename=20journey.parts=20->=20?= =?UTF-8?q?journey.legs=20=F0=9F=93=9D=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/departures.md | 2 +- docs/{journey-part.md => journey-leg.md} | 8 +-- docs/journeys.md | 2 +- readme.md | 4 +- test/db.js | 72 +++++++++---------- test/vbb.js | 92 ++++++++++++------------ 6 files changed, 90 insertions(+), 90 deletions(-) rename docs/{journey-part.md => journey-leg.md} (92%) diff --git a/docs/departures.md b/docs/departures.md index 6c37a82e..9620331d 100644 --- a/docs/departures.md +++ b/docs/departures.md @@ -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. -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: diff --git a/docs/journey-part.md b/docs/journey-leg.md similarity index 92% rename from docs/journey-part.md rename to docs/journey-leg.md index faba512e..9538199f 100644 --- a/docs/journey-part.md +++ b/docs/journey-leg.md @@ -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. @@ -13,8 +13,8 @@ const client = createClient(vbbProfile) // Hauptbahnhof to Heinrich-Heine-Str. client.journeys('900000003201', '900000100008', {results: 1}) .then(([journey]) => { - const part = journey.parts[0] - return client.journeyPart(part.id, part.line.name) + const leg = journey.legs[0] + return client.journeyLeg(leg.id, leg.line.name) }) .then(console.log) .catch(console.error) @@ -41,7 +41,7 @@ const vbbProfile = require('hafas-client/p/vbb') 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) .catch(console.error) ``` diff --git a/docs/journeys.md b/docs/journeys.md index 4617936d..98cca95e 100644 --- a/docs/journeys.md +++ b/docs/journeys.md @@ -86,7 +86,7 @@ The response may look like this: ```js [ { - parts: [ { + legs: [ { id: '1|31041|35|86|17122017', origin: { type: 'station', diff --git a/readme.md b/readme.md index 86249212..23840a56 100644 --- a/readme.md +++ b/readme.md @@ -28,7 +28,7 @@ npm install hafas-client ## API - [`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 - [`locations(query, [opt])`](docs/locations.md) – find stations, POIs and addresses - [`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 [ { - parts: [ { + legs: [ { id: '1|100067|48|81|17122017', origin: { type: 'station', diff --git a/test/db.js b/test/db.js index 35292b12..317b3c65 100644 --- a/test/db.js +++ b/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(Array.isArray(journey.parts)) - t.ok(journey.parts.length > 0, 'no parts') - const part = journey.parts[0] + t.ok(Array.isArray(journey.legs)) + t.ok(journey.legs.length > 0, 'no legs') + const leg = journey.legs[0] - assertValidStation(t, part.origin) - assertValidStationProducts(t, part.origin.products) - if (!(yield findStation(part.origin.id))) { - console.error('unknown station', part.origin.id, part.origin.name) + assertValidStation(t, leg.origin) + assertValidStationProducts(t, leg.origin.products) + if (!(yield findStation(leg.origin.id))) { + console.error('unknown station', leg.origin.id, leg.origin.name) } - t.ok(isValidWhen(part.departure)) - t.equal(typeof part.departurePlatform, 'string') + t.ok(isValidWhen(leg.departure)) + t.equal(typeof leg.departurePlatform, 'string') - assertValidStation(t, part.destination) - assertValidStationProducts(t, part.origin.products) - if (!(yield findStation(part.destination.id))) { - console.error('unknown station', part.destination.id, part.destination.name) + assertValidStation(t, leg.destination) + assertValidStationProducts(t, leg.origin.products) + if (!(yield findStation(leg.destination.id))) { + console.error('unknown station', leg.destination.id, leg.destination.name) } - t.ok(isValidWhen(part.arrival)) - t.equal(typeof part.arrivalPlatform, 'string') + t.ok(isValidWhen(leg.arrival)) + t.equal(typeof leg.arrivalPlatform, 'string') - assertValidLine(t, part.line) + assertValidLine(t, leg.line) - t.ok(Array.isArray(part.passed)) - for (let stopover of part.passed) assertValidStopover(t, stopover) + t.ok(Array.isArray(leg.passed)) + for (let stopover of leg.passed) assertValidStopover(t, stopover) 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(journeys.length >= 1, 'no journeys') const journey = journeys[0] - const part = journey.parts[journey.parts.length - 1] + const leg = journey.legs[journey.legs.length - 1] - assertValidStation(t, part.origin) - assertValidStationProducts(t, part.origin.products) - if (!(yield findStation(part.origin.id))) { - console.error('unknown station', part.origin.id, part.origin.name) + assertValidStation(t, leg.origin) + assertValidStationProducts(t, leg.origin.products) + if (!(yield findStation(leg.origin.id))) { + console.error('unknown station', leg.origin.id, leg.origin.name) } - if (part.origin.products) assertValidProducts(t, part.origin.products) - t.ok(isValidWhen(part.departure)) - t.ok(isValidWhen(part.arrival)) + if (leg.origin.products) assertValidProducts(t, leg.origin.products) + t.ok(isValidWhen(leg.departure)) + t.ok(isValidWhen(leg.arrival)) - const d = part.destination + const d = leg.destination assertValidAddress(t, d) t.equal(d.address, 'Torfstraße 17') 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(journeys.length >= 1, 'no journeys') const journey = journeys[0] - const part = journey.parts[journey.parts.length - 1] + const leg = journey.legs[journey.legs.length - 1] - assertValidStation(t, part.origin) - assertValidStationProducts(t, part.origin.products) - if (!(yield findStation(part.origin.id))) { - console.error('unknown station', part.origin.id, part.origin.name) + assertValidStation(t, leg.origin) + assertValidStationProducts(t, leg.origin.products) + if (!(yield findStation(leg.origin.id))) { + console.error('unknown station', leg.origin.id, leg.origin.name) } - if (part.origin.products) assertValidProducts(t, part.origin.products) - t.ok(isValidWhen(part.departure)) - t.ok(isValidWhen(part.arrival)) + if (leg.origin.products) assertValidProducts(t, leg.origin.products) + t.ok(isValidWhen(leg.departure)) + t.ok(isValidWhen(leg.arrival)) - const d = part.destination + const d = leg.destination assertValidPoi(t, d) t.equal(d.name, 'ATZE Musiktheater') t.ok(isRoughlyEqual(.0001, d.latitude, 52.542399)) diff --git a/test/vbb.js b/test/vbb.js index fb0676b5..cc9eec9d 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -77,29 +77,29 @@ test('journeys – station to station', co.wrap(function* (t) { t.strictEqual(journey.destination.id, amrumerStr) assertValidWhen(t, journey.arrival) - t.ok(Array.isArray(journey.parts)) - t.strictEqual(journey.parts.length, 1) - const part = journey.parts[0] + t.ok(Array.isArray(journey.legs)) + t.strictEqual(journey.legs.length, 1) + const leg = journey.legs[0] - t.equal(typeof part.id, 'string') - t.ok(part.id) - assertValidStation(t, part.origin) - assertValidStationProducts(t, part.origin.products) - t.ok(part.origin.name.indexOf('(Berlin)') === -1) - t.strictEqual(part.origin.id, spichernstr) - assertValidWhen(t, part.departure) + t.equal(typeof leg.id, 'string') + t.ok(leg.id) + assertValidStation(t, leg.origin) + assertValidStationProducts(t, leg.origin.products) + t.ok(leg.origin.name.indexOf('(Berlin)') === -1) + t.strictEqual(leg.origin.id, spichernstr) + assertValidWhen(t, leg.departure) - assertValidStation(t, part.destination) - assertValidStationProducts(t, part.destination.products) - t.strictEqual(part.destination.id, amrumerStr) - assertValidWhen(t, part.arrival) + assertValidStation(t, leg.destination) + assertValidStationProducts(t, leg.destination.products) + t.strictEqual(leg.destination.id, amrumerStr) + assertValidWhen(t, leg.arrival) - assertValidLine(t, part.line) - t.ok(findStation(part.direction)) - t.ok(part.direction.indexOf('(Berlin)') === -1) + assertValidLine(t, leg.line) + t.ok(findStation(leg.direction)) + t.ok(leg.direction.indexOf('(Berlin)') === -1) - t.ok(Array.isArray(part.passed)) - for (let passed of part.passed) assertValidStopover(t, passed) + t.ok(Array.isArray(leg.passed)) + for (let passed of leg.passed) assertValidStopover(t, passed) // todo: find a journey where there ticket info is always available if (journey.tickets) { @@ -128,11 +128,11 @@ test('journeys – only subway', co.wrap(function* (t) { t.ok(journeys.length > 1) for (let journey of journeys) { - for (let part of journey.parts) { - if (part.line) { - assertValidLine(t, part.line) - t.equal(part.line.mode, 'train') - t.equal(part.line.product, 'subway') + for (let leg of journey.legs) { + if (leg.line) { + assertValidLine(t, leg.line) + t.equal(leg.line.mode, 'train') + 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, { results: 1, when }) - const p = journeys[0].parts[0] + const p = journeys[0].legs[0] t.ok(p.id, '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.ok(part.id) + t.equal(typeof leg.id, 'string') + t.ok(leg.id) - assertValidLine(t, part.line) + assertValidLine(t, leg.line) - t.equal(typeof part.direction, 'string') - t.ok(part.direction) + t.equal(typeof leg.direction, 'string') + t.ok(leg.direction) - t.ok(Array.isArray(part.passed)) - for (let passed of part.passed) assertValidStopover(t, passed) + t.ok(Array.isArray(leg.passed)) + for (let passed of leg.passed) assertValidStopover(t, passed) t.end() })) @@ -194,18 +194,18 @@ test('journeys – station to address', co.wrap(function* (t) { t.ok(Array.isArray(journeys)) t.strictEqual(journeys.length, 1) const journey = journeys[0] - const part = journey.parts[journey.parts.length - 1] + const leg = journey.legs[journey.legs.length - 1] - assertValidStation(t, part.origin) - assertValidStationProducts(t, part.origin.products) - assertValidWhen(t, part.departure) + assertValidStation(t, leg.origin) + assertValidStationProducts(t, leg.origin.products) + assertValidWhen(t, leg.departure) - const dest = part.destination + const dest = leg.destination assertValidAddress(t, dest) t.strictEqual(dest.address, 'Torfstraße 17') t.ok(isRoughlyEqual(.0001, dest.latitude, 52.5416823)) t.ok(isRoughlyEqual(.0001, dest.longitude, 13.3491223)) - assertValidWhen(t, part.arrival) + assertValidWhen(t, leg.arrival) t.end() })) @@ -221,18 +221,18 @@ test('journeys – station to POI', co.wrap(function* (t) { t.ok(Array.isArray(journeys)) t.strictEqual(journeys.length, 1) const journey = journeys[0] - const part = journey.parts[journey.parts.length - 1] + const leg = journey.legs[journey.legs.length - 1] - assertValidStation(t, part.origin) - assertValidStationProducts(t, part.origin.products) - assertValidWhen(t, part.departure) + assertValidStation(t, leg.origin) + assertValidStationProducts(t, leg.origin.products) + assertValidWhen(t, leg.departure) - const dest = part.destination + const dest = leg.destination assertValidPoi(t, dest) t.strictEqual(dest.name, 'ATZE Musiktheater') t.ok(isRoughlyEqual(.0001, dest.latitude, 52.543333)) t.ok(isRoughlyEqual(.0001, dest.longitude, 13.351686)) - assertValidWhen(t, part.arrival) + assertValidWhen(t, leg.arrival) t.end() }))