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