mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
VBB: 9<->12 digit station IDs
This commit is contained in:
parent
6d4b20ecc1
commit
541505e720
3 changed files with 27 additions and 24 deletions
|
@ -1,6 +1,7 @@
|
|||
'use strict'
|
||||
|
||||
const shorten = require('vbb-short-station-name')
|
||||
const {to12Digit, to9Digit} = require('vbb-translate-ids')
|
||||
|
||||
const _formatStation = require('../../format/station')
|
||||
const _parseLine = require('../../parse/line')
|
||||
|
@ -34,14 +35,17 @@ const parseLine = (profile, l) => {
|
|||
|
||||
const parseLocation = (profile, l) => {
|
||||
const res = _parseLocation(profile, l)
|
||||
if (res.type === 'station') {
|
||||
res.id = to12Digit(res.id)
|
||||
res.name = shorten(res.name)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
const isIBNR = /^\d{9,}$/
|
||||
const formatStation = (id) => {
|
||||
// todo: convert short to long IDs
|
||||
if (!isIBNR.test(id)) throw new Error('station ID must be an IBNR.')
|
||||
id = to9Digit(id)
|
||||
return _formatStation(id)
|
||||
}
|
||||
|
||||
|
@ -72,6 +76,7 @@ const vbbProfile = {
|
|||
parseLine,
|
||||
parseProducts: modes.parseBitmask,
|
||||
|
||||
formatStation,
|
||||
formatProducts
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,8 @@
|
|||
"pinkie-promise": "^2.0.1",
|
||||
"query-string": "^5.0.0",
|
||||
"slugg": "^1.2.0",
|
||||
"vbb-short-station-name": "^0.4.0"
|
||||
"vbb-short-station-name": "^0.4.0",
|
||||
"vbb-translate-ids": "^3.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"db-stations": "^1.25.0",
|
||||
|
|
37
test/vbb.js
37
test/vbb.js
|
@ -26,9 +26,12 @@ const findStation = (query) => stations(query, true, false)
|
|||
const test = tapePromise(tape)
|
||||
const client = createClient(vbbProfile)
|
||||
|
||||
const amrumerStr = '900000009101'
|
||||
const spichernstr = '900000042101'
|
||||
const bismarckstr = '900000024201'
|
||||
|
||||
test('journeys – station to station', async (t) => {
|
||||
// U Spichernstr. to U Amrumer Str.
|
||||
const journeys = await client.journeys('900000042101', '900000009101', {
|
||||
const journeys = await client.journeys(spichernstr, amrumerStr, {
|
||||
results: 3, when, passedStations: true
|
||||
})
|
||||
|
||||
|
@ -38,11 +41,11 @@ test('journeys – station to station', async (t) => {
|
|||
for (let journey of journeys) {
|
||||
assertValidStation(t, journey.origin)
|
||||
t.ok(journey.origin.name.indexOf('(Berlin)') === -1)
|
||||
t.strictEqual(journey.origin.id, '900000042101')
|
||||
t.strictEqual(journey.origin.id, spichernstr)
|
||||
assertValidWhen(t, journey.departure)
|
||||
|
||||
assertValidStation(t, journey.destination)
|
||||
t.strictEqual(journey.destination.id, '900000009101')
|
||||
t.strictEqual(journey.destination.id, amrumerStr)
|
||||
assertValidWhen(t, journey.arrival)
|
||||
|
||||
t.ok(Array.isArray(journey.parts))
|
||||
|
@ -53,11 +56,11 @@ test('journeys – station to station', async (t) => {
|
|||
t.ok(part.id)
|
||||
assertValidStation(t, part.origin)
|
||||
t.ok(part.origin.name.indexOf('(Berlin)') === -1)
|
||||
t.strictEqual(part.origin.id, '900000042101')
|
||||
t.strictEqual(part.origin.id, spichernstr)
|
||||
assertValidWhen(t, part.departure)
|
||||
|
||||
assertValidStation(t, part.destination)
|
||||
t.strictEqual(part.destination.id, '900000009101')
|
||||
t.strictEqual(part.destination.id, amrumerStr)
|
||||
assertValidWhen(t, part.arrival)
|
||||
|
||||
assertValidLine(t, part.line)
|
||||
|
@ -71,8 +74,7 @@ test('journeys – station to station', async (t) => {
|
|||
})
|
||||
|
||||
test('journeys – only subway', async (t) => {
|
||||
// U Spichernstr. to U Bismarckstr.
|
||||
const journeys = await client.journeys('900000042101', '900000024201', {
|
||||
const journeys = await client.journeys(spichernstr, bismarckstr, {
|
||||
results: 20, when,
|
||||
products: {
|
||||
suburban: false,
|
||||
|
@ -102,8 +104,7 @@ test('journeys – only subway', async (t) => {
|
|||
|
||||
test('journeys – fails with no product', async (t) => {
|
||||
try {
|
||||
// U Spichernstr. to U Bismarckstr.
|
||||
await client.journeys('900000042101', '900000024201', {
|
||||
await client.journeys(spichernstr, bismarckstr, {
|
||||
when,
|
||||
products: {
|
||||
suburban: false,
|
||||
|
@ -122,8 +123,7 @@ test('journeys – fails with no product', async (t) => {
|
|||
})
|
||||
|
||||
test('journey part details', async (t) => {
|
||||
// U Spichernstr. to U Amrumer Str.
|
||||
const journeys = await client.journeys('900000042101', '900000009101', {
|
||||
const journeys = await client.journeys(spichernstr, amrumerStr, {
|
||||
results: 1, when
|
||||
})
|
||||
|
||||
|
@ -149,8 +149,7 @@ test('journey part details', async (t) => {
|
|||
|
||||
|
||||
test('journeys – station to address', async (t) => {
|
||||
// U Spichernstr. to Torfstraße 17
|
||||
const journeys = await client.journeys('900000042101', {
|
||||
const journeys = await client.journeys(spichernstr, {
|
||||
type: 'address', name: 'Torfstraße 17',
|
||||
latitude: 52.5416823, longitude: 13.3491223
|
||||
}, {results: 1, when})
|
||||
|
@ -176,8 +175,7 @@ test('journeys – station to address', async (t) => {
|
|||
|
||||
|
||||
test('journeys – station to POI', async (t) => {
|
||||
// U Spichernstr. to ATZE Musiktheater
|
||||
const journeys = await client.journeys('900000042101', {
|
||||
const journeys = await client.journeys(spichernstr, {
|
||||
type: 'poi', name: 'ATZE Musiktheater', id: 9980720,
|
||||
latitude: 52.543333, longitude: 13.351686
|
||||
}, {results: 1, when})
|
||||
|
@ -202,9 +200,8 @@ test('journeys – station to POI', async (t) => {
|
|||
|
||||
|
||||
|
||||
test('departures', async (t) => {
|
||||
// U Spichernstr.
|
||||
const deps = await client.departures('900000042101', {duration: 5, when})
|
||||
test.only('departures', async (t) => {
|
||||
const deps = await client.departures(spichernstr, {duration: 5, when})
|
||||
|
||||
t.ok(Array.isArray(deps))
|
||||
t.deepEqual(deps, deps.sort((a, b) => t.when > b.when))
|
||||
|
@ -214,7 +211,7 @@ test('departures', async (t) => {
|
|||
|
||||
t.equal(dep.station.name, 'U Spichernstr.')
|
||||
assertValidStation(t, dep.station)
|
||||
t.strictEqual(dep.station.id, '900000042101')
|
||||
t.strictEqual(dep.station.id, spichernstr)
|
||||
|
||||
assertValidWhen(t, dep.when)
|
||||
t.ok(findStation(dep.direction))
|
||||
|
|
Loading…
Add table
Reference in a new issue