departures: accept station objects 🐛

As mentioned in the docs.
This commit is contained in:
Jannis R 2018-01-04 16:19:42 +01:00
parent c02983492b
commit 75513aa0f7
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
3 changed files with 36 additions and 2 deletions

View file

@ -12,7 +12,9 @@ const createClient = (profile) => {
validateProfile(profile) validateProfile(profile)
const departures = (station, opt = {}) => { 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({ opt = Object.assign({
direction: null, // only show departures heading to this station direction: null, // only show departures heading to this station
@ -28,7 +30,7 @@ const createClient = (profile) => {
type: 'DEP', type: 'DEP',
date: profile.formatDate(profile, opt.when), date: profile.formatDate(profile, opt.when),
time: profile.formatTime(profile, opt.when), time: profile.formatTime(profile, opt.when),
stbLoc: profile.formatStation(station), stbLoc: station,
dirLoc: dir, dirLoc: dir,
jnyFltrL: [products], jnyFltrL: [products],
dur: opt.duration, dur: opt.duration,

View file

@ -226,6 +226,22 @@ test('departures at Berlin Jungfernheide', co.wrap(function* (t) {
t.end() 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) { test('nearby Berlin Jungfernheide', co.wrap(function* (t) {
const nearby = yield client.nearby(52.530273, 13.299433, { const nearby = yield client.nearby(52.530273, 13.299433, {
results: 2, distance: 400 results: 2, distance: 400

View file

@ -260,6 +260,22 @@ test('departures', co.wrap(function* (t) {
t.end() 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) { test('departures at 7-digit station', co.wrap(function* (t) {
const eisenach = '8010097' // see derhuerst/vbb-hafas#22 const eisenach = '8010097' // see derhuerst/vbb-hafas#22
yield client.departures(eisenach, {when}) yield client.departures(eisenach, {when})