mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
departures: accept station objects 🐛
As mentioned in the docs.
This commit is contained in:
parent
c02983492b
commit
75513aa0f7
3 changed files with 36 additions and 2 deletions
6
index.js
6
index.js
|
@ -12,7 +12,9 @@ const createClient = (profile) => {
|
|||
validateProfile(profile)
|
||||
|
||||
const departures = (station, opt = {}) => {
|
||||
if ('string' !== typeof station) throw new Error('station must be a string.')
|
||||
if ('object' === typeof station) station = profile.formatStation(station.id)
|
||||
else if ('string' === typeof station) station = profile.formatStation(station)
|
||||
else throw new Error('station must be an object or a string.')
|
||||
|
||||
opt = Object.assign({
|
||||
direction: null, // only show departures heading to this station
|
||||
|
@ -28,7 +30,7 @@ const createClient = (profile) => {
|
|||
type: 'DEP',
|
||||
date: profile.formatDate(profile, opt.when),
|
||||
time: profile.formatTime(profile, opt.when),
|
||||
stbLoc: profile.formatStation(station),
|
||||
stbLoc: station,
|
||||
dirLoc: dir,
|
||||
jnyFltrL: [products],
|
||||
dur: opt.duration,
|
||||
|
|
16
test/db.js
16
test/db.js
|
@ -226,6 +226,22 @@ test('departures at Berlin Jungfernheide', co.wrap(function* (t) {
|
|||
t.end()
|
||||
}))
|
||||
|
||||
test('departures with station object', co.wrap(function* (t) {
|
||||
yield client.departures({
|
||||
type: 'station',
|
||||
id: '8011167',
|
||||
name: 'Berlin Jungfernheide',
|
||||
location: {
|
||||
type: 'location',
|
||||
latitude: 1.23,
|
||||
longitude: 2.34
|
||||
}
|
||||
}, {when})
|
||||
|
||||
t.ok('did not fail')
|
||||
t.end()
|
||||
}))
|
||||
|
||||
test('nearby Berlin Jungfernheide', co.wrap(function* (t) {
|
||||
const nearby = yield client.nearby(52.530273, 13.299433, {
|
||||
results: 2, distance: 400
|
||||
|
|
16
test/vbb.js
16
test/vbb.js
|
@ -260,6 +260,22 @@ test('departures', co.wrap(function* (t) {
|
|||
t.end()
|
||||
}))
|
||||
|
||||
test('departures with station object', co.wrap(function* (t) {
|
||||
yield client.departures({
|
||||
type: 'station',
|
||||
id: spichernstr,
|
||||
name: 'U Spichernstr',
|
||||
location: {
|
||||
type: 'location',
|
||||
latitude: 1.23,
|
||||
longitude: 2.34
|
||||
}
|
||||
}, {when})
|
||||
|
||||
t.ok('did not fail')
|
||||
t.end()
|
||||
}))
|
||||
|
||||
test('departures at 7-digit station', co.wrap(function* (t) {
|
||||
const eisenach = '8010097' // see derhuerst/vbb-hafas#22
|
||||
yield client.departures(eisenach, {when})
|
||||
|
|
Loading…
Add table
Reference in a new issue