2017-11-14 02:50:24 +01:00
|
|
|
|
'use strict'
|
|
|
|
|
|
|
|
|
|
const a = require('assert')
|
|
|
|
|
const isRoughlyEqual = require('is-roughly-equal')
|
|
|
|
|
const stations = require('vbb-stations-autocomplete')
|
2017-11-14 02:59:17 +01:00
|
|
|
|
const tapePromise = require('tape-promise').default
|
|
|
|
|
const tape = require('tape')
|
2017-12-11 15:20:50 +01:00
|
|
|
|
const shorten = require('vbb-short-station-name')
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
2018-01-23 01:49:41 +01:00
|
|
|
|
const co = require('./co')
|
2017-11-14 02:50:24 +01:00
|
|
|
|
const createClient = require('..')
|
|
|
|
|
const vbbProfile = require('../p/vbb')
|
|
|
|
|
const {
|
2017-12-11 15:20:50 +01:00
|
|
|
|
assertValidStation: _assertValidStation,
|
2017-11-14 02:50:24 +01:00
|
|
|
|
assertValidPoi,
|
|
|
|
|
assertValidAddress,
|
|
|
|
|
assertValidLocation,
|
2017-12-11 14:51:09 +01:00
|
|
|
|
assertValidLine: _assertValidLine,
|
2017-11-20 15:08:30 +01:00
|
|
|
|
assertValidStopover,
|
2017-12-28 22:57:22 +01:00
|
|
|
|
hour, createWhen,
|
2017-12-12 23:15:06 +01:00
|
|
|
|
assertValidWhen,
|
2017-12-11 15:41:27 +01:00
|
|
|
|
assertValidTicket
|
2017-11-14 02:50:24 +01:00
|
|
|
|
} = require('./util')
|
|
|
|
|
|
2017-12-28 22:57:22 +01:00
|
|
|
|
const when = createWhen('Europe/Berlin', 'de-DE')
|
|
|
|
|
|
2017-12-11 15:20:50 +01:00
|
|
|
|
const assertValidStation = (t, s, coordsOptional = false) => {
|
|
|
|
|
_assertValidStation(t, s, coordsOptional)
|
|
|
|
|
t.equal(s.name, shorten(s.name))
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-11 14:41:28 +01:00
|
|
|
|
const assertValidStationProducts = (t, p) => {
|
|
|
|
|
t.ok(p)
|
|
|
|
|
t.equal(typeof p.suburban, 'boolean')
|
|
|
|
|
t.equal(typeof p.subway, 'boolean')
|
|
|
|
|
t.equal(typeof p.tram, 'boolean')
|
|
|
|
|
t.equal(typeof p.bus, 'boolean')
|
|
|
|
|
t.equal(typeof p.ferry, 'boolean')
|
|
|
|
|
t.equal(typeof p.express, 'boolean')
|
|
|
|
|
t.equal(typeof p.regional, 'boolean')
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-11 14:51:09 +01:00
|
|
|
|
const assertValidLine = (t, l) => {
|
|
|
|
|
_assertValidLine(t, l)
|
|
|
|
|
if (l.symbol !== null) t.equal(typeof l.symbol, 'string')
|
|
|
|
|
if (l.nr !== null) t.equal(typeof l.nr, 'number')
|
|
|
|
|
if (l.metro !== null) t.equal(typeof l.metro, 'boolean')
|
|
|
|
|
if (l.express !== null) t.equal(typeof l.express, 'boolean')
|
|
|
|
|
if (l.night !== null) t.equal(typeof l.night, 'boolean')
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-23 00:50:21 +01:00
|
|
|
|
const findStation = (query) => stations(query, true, false)[0]
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
2017-11-14 02:59:17 +01:00
|
|
|
|
const test = tapePromise(tape)
|
2017-11-14 02:50:24 +01:00
|
|
|
|
const client = createClient(vbbProfile)
|
|
|
|
|
|
2017-11-20 01:05:48 +01:00
|
|
|
|
const amrumerStr = '900000009101'
|
|
|
|
|
const spichernstr = '900000042101'
|
|
|
|
|
const bismarckstr = '900000024201'
|
|
|
|
|
|
2018-01-23 01:49:41 +01:00
|
|
|
|
test('journeys – station to station', co(function* (t) {
|
2017-11-29 02:27:31 +01:00
|
|
|
|
const journeys = yield client.journeys(spichernstr, amrumerStr, {
|
2017-11-14 02:50:24 +01:00
|
|
|
|
results: 3, when, passedStations: true
|
|
|
|
|
})
|
2017-11-14 02:59:17 +01:00
|
|
|
|
|
|
|
|
|
t.ok(Array.isArray(journeys))
|
|
|
|
|
t.strictEqual(journeys.length, 3)
|
|
|
|
|
|
|
|
|
|
for (let journey of journeys) {
|
2018-03-02 00:35:54 +01:00
|
|
|
|
t.equal(journey.type, 'journey')
|
|
|
|
|
|
2017-11-14 02:59:17 +01:00
|
|
|
|
assertValidStation(t, journey.origin)
|
2017-12-11 14:41:28 +01:00
|
|
|
|
assertValidStationProducts(t, journey.origin.products)
|
2017-11-14 02:59:17 +01:00
|
|
|
|
t.ok(journey.origin.name.indexOf('(Berlin)') === -1)
|
2017-11-20 01:05:48 +01:00
|
|
|
|
t.strictEqual(journey.origin.id, spichernstr)
|
2017-12-28 22:57:22 +01:00
|
|
|
|
assertValidWhen(t, journey.departure, when)
|
2017-11-14 02:59:17 +01:00
|
|
|
|
|
|
|
|
|
assertValidStation(t, journey.destination)
|
2017-12-11 14:41:28 +01:00
|
|
|
|
assertValidStationProducts(t, journey.destination.products)
|
2017-11-20 01:05:48 +01:00
|
|
|
|
t.strictEqual(journey.destination.id, amrumerStr)
|
2017-12-28 22:57:22 +01:00
|
|
|
|
assertValidWhen(t, journey.arrival, when)
|
2017-11-14 02:59:17 +01:00
|
|
|
|
|
2017-12-28 17:14:53 +01:00
|
|
|
|
t.ok(Array.isArray(journey.legs))
|
|
|
|
|
t.strictEqual(journey.legs.length, 1)
|
|
|
|
|
const leg = journey.legs[0]
|
|
|
|
|
|
|
|
|
|
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)
|
2017-12-28 22:57:22 +01:00
|
|
|
|
assertValidWhen(t, leg.departure, when)
|
2017-12-28 17:14:53 +01:00
|
|
|
|
|
|
|
|
|
assertValidStation(t, leg.destination)
|
|
|
|
|
assertValidStationProducts(t, leg.destination.products)
|
|
|
|
|
t.strictEqual(leg.destination.id, amrumerStr)
|
2017-12-28 22:57:22 +01:00
|
|
|
|
assertValidWhen(t, leg.arrival, when)
|
2017-12-28 17:14:53 +01:00
|
|
|
|
|
|
|
|
|
assertValidLine(t, leg.line)
|
2018-01-23 02:26:53 +01:00
|
|
|
|
if (!findStation(leg.direction)) {
|
|
|
|
|
const err = new Error('unknown direction: ' + leg.direction)
|
|
|
|
|
err.stack = err.stack.split('\n').slice(0, 2).join('\n')
|
|
|
|
|
console.error(err)
|
|
|
|
|
}
|
2017-12-28 17:14:53 +01:00
|
|
|
|
t.ok(leg.direction.indexOf('(Berlin)') === -1)
|
|
|
|
|
|
|
|
|
|
t.ok(Array.isArray(leg.passed))
|
|
|
|
|
for (let passed of leg.passed) assertValidStopover(t, passed)
|
2017-12-11 15:41:27 +01:00
|
|
|
|
|
2017-12-11 15:49:58 +01:00
|
|
|
|
// todo: find a journey where there ticket info is always available
|
|
|
|
|
if (journey.tickets) {
|
|
|
|
|
t.ok(Array.isArray(journey.tickets))
|
|
|
|
|
for (let ticket of journey.tickets) assertValidTicket(t, ticket)
|
|
|
|
|
}
|
2017-11-14 02:59:17 +01:00
|
|
|
|
}
|
|
|
|
|
t.end()
|
2017-11-29 02:27:31 +01:00
|
|
|
|
}))
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
2018-01-23 01:49:41 +01:00
|
|
|
|
test('journeys – only subway', co(function* (t) {
|
2017-11-29 02:27:31 +01:00
|
|
|
|
const journeys = yield client.journeys(spichernstr, bismarckstr, {
|
2017-11-14 02:50:24 +01:00
|
|
|
|
results: 20, when,
|
|
|
|
|
products: {
|
|
|
|
|
suburban: false,
|
|
|
|
|
subway: true,
|
|
|
|
|
tram: false,
|
|
|
|
|
bus: false,
|
|
|
|
|
ferry: false,
|
|
|
|
|
express: false,
|
|
|
|
|
regional: false
|
|
|
|
|
}
|
|
|
|
|
})
|
2017-11-14 02:59:17 +01:00
|
|
|
|
|
|
|
|
|
t.ok(Array.isArray(journeys))
|
|
|
|
|
t.ok(journeys.length > 1)
|
|
|
|
|
|
|
|
|
|
for (let journey of journeys) {
|
2017-12-28 17:14:53 +01:00
|
|
|
|
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')
|
2017-11-14 02:50:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-14 02:59:17 +01:00
|
|
|
|
}
|
|
|
|
|
t.end()
|
2017-11-29 02:27:31 +01:00
|
|
|
|
}))
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
2018-01-23 01:49:41 +01:00
|
|
|
|
test('journeys – fails with no product', co(function* (t) {
|
2017-11-14 02:59:17 +01:00
|
|
|
|
try {
|
2018-03-02 16:34:22 +01:00
|
|
|
|
client.journeys(spichernstr, bismarckstr, {
|
2017-11-14 02:59:17 +01:00
|
|
|
|
when,
|
|
|
|
|
products: {
|
|
|
|
|
suburban: false,
|
|
|
|
|
subway: false,
|
|
|
|
|
tram: false,
|
|
|
|
|
bus: false,
|
|
|
|
|
ferry: false,
|
|
|
|
|
express: false,
|
|
|
|
|
regional: false
|
|
|
|
|
}
|
|
|
|
|
})
|
2018-03-02 16:34:22 +01:00
|
|
|
|
// silence rejections, we're only interested in exceptions
|
|
|
|
|
.catch(() => {})
|
2017-11-14 02:59:17 +01:00
|
|
|
|
} catch (err) {
|
2017-11-14 02:50:24 +01:00
|
|
|
|
t.ok(err, 'error thrown')
|
|
|
|
|
t.end()
|
2017-11-14 02:59:17 +01:00
|
|
|
|
}
|
2017-11-29 02:27:31 +01:00
|
|
|
|
}))
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
2018-03-04 19:54:21 +01:00
|
|
|
|
test('earlier/later journeys', co(function* (t) {
|
|
|
|
|
const model = yield client.journeys(spichernstr, bismarckstr, {
|
|
|
|
|
results: 3, when
|
|
|
|
|
})
|
|
|
|
|
|
2018-03-04 20:38:50 +01:00
|
|
|
|
t.equal(typeof model.earlierRef, 'string')
|
|
|
|
|
t.ok(model.earlierRef)
|
|
|
|
|
t.equal(typeof model.laterRef, 'string')
|
|
|
|
|
t.ok(model.laterRef)
|
2018-03-04 19:54:21 +01:00
|
|
|
|
|
2018-03-04 20:41:26 +01:00
|
|
|
|
// when and earlierThan/laterThan should be mutually exclusive
|
|
|
|
|
t.throws(() => {
|
|
|
|
|
client.journeys(spichernstr, bismarckstr, {
|
|
|
|
|
when, earlierThan: model.earlierRef
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
t.throws(() => {
|
|
|
|
|
client.journeys(spichernstr, bismarckstr, {
|
|
|
|
|
when, laterThan: model.laterRef
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2018-03-04 19:54:21 +01:00
|
|
|
|
let earliestDep = Infinity, latestDep = -Infinity
|
|
|
|
|
for (let j of model) {
|
|
|
|
|
const dep = +new Date(j.departure)
|
|
|
|
|
if (dep < earliestDep) earliestDep = dep
|
|
|
|
|
else if (dep > latestDep) latestDep = dep
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const earlier = yield client.journeys(spichernstr, bismarckstr, {
|
|
|
|
|
results: 3,
|
|
|
|
|
// todo: single journey ref?
|
2018-03-04 20:41:26 +01:00
|
|
|
|
earlierThan: model.earlierRef
|
2018-03-04 19:54:21 +01:00
|
|
|
|
})
|
|
|
|
|
for (let j of earlier) {
|
|
|
|
|
t.ok(new Date(j.departure) < earliestDep)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const later = yield client.journeys(spichernstr, bismarckstr, {
|
|
|
|
|
results: 3,
|
|
|
|
|
// todo: single journey ref?
|
2018-03-04 20:41:26 +01:00
|
|
|
|
laterThan: model.laterRef
|
2018-03-04 19:54:21 +01:00
|
|
|
|
})
|
|
|
|
|
for (let j of later) {
|
|
|
|
|
t.ok(new Date(j.departure) > latestDep)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t.end()
|
|
|
|
|
}))
|
|
|
|
|
|
2018-01-23 01:49:41 +01:00
|
|
|
|
test('journey leg details', co(function* (t) {
|
2017-11-29 02:27:31 +01:00
|
|
|
|
const journeys = yield client.journeys(spichernstr, amrumerStr, {
|
2017-11-14 02:59:17 +01:00
|
|
|
|
results: 1, when
|
2017-11-14 02:50:24 +01:00
|
|
|
|
})
|
|
|
|
|
|
2017-12-28 17:14:53 +01:00
|
|
|
|
const p = journeys[0].legs[0]
|
2017-11-14 02:59:17 +01:00
|
|
|
|
t.ok(p.id, 'precondition failed')
|
|
|
|
|
t.ok(p.line.name, 'precondition failed')
|
2017-12-28 17:14:53 +01:00
|
|
|
|
const leg = yield client.journeyLeg(p.id, p.line.name, {when})
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
2017-12-28 17:14:53 +01:00
|
|
|
|
t.equal(typeof leg.id, 'string')
|
|
|
|
|
t.ok(leg.id)
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
2017-12-28 17:14:53 +01:00
|
|
|
|
assertValidLine(t, leg.line)
|
2017-11-14 02:59:17 +01:00
|
|
|
|
|
2017-12-28 17:14:53 +01:00
|
|
|
|
t.equal(typeof leg.direction, 'string')
|
|
|
|
|
t.ok(leg.direction)
|
2017-11-14 02:59:17 +01:00
|
|
|
|
|
2017-12-28 17:14:53 +01:00
|
|
|
|
t.ok(Array.isArray(leg.passed))
|
|
|
|
|
for (let passed of leg.passed) assertValidStopover(t, passed)
|
2017-11-14 02:59:17 +01:00
|
|
|
|
|
|
|
|
|
t.end()
|
2017-11-29 02:27:31 +01:00
|
|
|
|
}))
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-01-23 01:49:41 +01:00
|
|
|
|
test('journeys – station to address', co(function* (t) {
|
2017-11-29 02:27:31 +01:00
|
|
|
|
const journeys = yield client.journeys(spichernstr, {
|
2018-03-05 00:22:31 +01:00
|
|
|
|
type: 'location',
|
|
|
|
|
address: 'Torfstr. 17, Berlin',
|
|
|
|
|
latitude: 52.541797, longitude: 13.350042
|
2017-11-14 02:50:24 +01:00
|
|
|
|
}, {results: 1, when})
|
|
|
|
|
|
2017-11-14 02:59:17 +01:00
|
|
|
|
t.ok(Array.isArray(journeys))
|
|
|
|
|
t.strictEqual(journeys.length, 1)
|
|
|
|
|
const journey = journeys[0]
|
2017-12-28 17:14:53 +01:00
|
|
|
|
const leg = journey.legs[journey.legs.length - 1]
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
2017-12-28 17:14:53 +01:00
|
|
|
|
assertValidStation(t, leg.origin)
|
|
|
|
|
assertValidStationProducts(t, leg.origin.products)
|
2017-12-28 22:57:22 +01:00
|
|
|
|
assertValidWhen(t, leg.departure, when)
|
2017-11-14 02:59:17 +01:00
|
|
|
|
|
2017-12-28 17:14:53 +01:00
|
|
|
|
const dest = leg.destination
|
2017-11-14 02:59:17 +01:00
|
|
|
|
assertValidAddress(t, dest)
|
2018-03-05 00:22:31 +01:00
|
|
|
|
t.strictEqual(dest.address, '13353 Berlin-Wedding, Torfstr. 17')
|
|
|
|
|
t.ok(isRoughlyEqual(.0001, dest.latitude, 52.541797))
|
|
|
|
|
t.ok(isRoughlyEqual(.0001, dest.longitude, 13.350042))
|
2017-12-28 22:57:22 +01:00
|
|
|
|
assertValidWhen(t, leg.arrival, when)
|
2017-11-14 02:59:17 +01:00
|
|
|
|
|
|
|
|
|
t.end()
|
2017-11-29 02:27:31 +01:00
|
|
|
|
}))
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-01-23 01:49:41 +01:00
|
|
|
|
test('journeys – station to POI', co(function* (t) {
|
2017-11-29 02:27:31 +01:00
|
|
|
|
const journeys = yield client.journeys(spichernstr, {
|
2018-03-05 00:22:31 +01:00
|
|
|
|
type: 'location',
|
|
|
|
|
id: '900980720',
|
|
|
|
|
name: 'Berlin, Atze Musiktheater für Kinder',
|
2017-11-14 02:50:24 +01:00
|
|
|
|
latitude: 52.543333, longitude: 13.351686
|
|
|
|
|
}, {results: 1, when})
|
|
|
|
|
|
2017-11-14 02:59:17 +01:00
|
|
|
|
t.ok(Array.isArray(journeys))
|
|
|
|
|
t.strictEqual(journeys.length, 1)
|
|
|
|
|
const journey = journeys[0]
|
2017-12-28 17:14:53 +01:00
|
|
|
|
const leg = journey.legs[journey.legs.length - 1]
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
2017-12-28 17:14:53 +01:00
|
|
|
|
assertValidStation(t, leg.origin)
|
|
|
|
|
assertValidStationProducts(t, leg.origin.products)
|
2017-12-28 22:57:22 +01:00
|
|
|
|
assertValidWhen(t, leg.departure, when)
|
2017-11-14 02:59:17 +01:00
|
|
|
|
|
2017-12-28 17:14:53 +01:00
|
|
|
|
const dest = leg.destination
|
2017-11-14 02:59:17 +01:00
|
|
|
|
assertValidPoi(t, dest)
|
2018-03-05 00:22:31 +01:00
|
|
|
|
t.strictEqual(dest.id, '900980720')
|
|
|
|
|
t.strictEqual(dest.name, 'Berlin, Atze Musiktheater für Kinder')
|
2017-12-11 19:25:29 +01:00
|
|
|
|
t.ok(isRoughlyEqual(.0001, dest.latitude, 52.543333))
|
|
|
|
|
t.ok(isRoughlyEqual(.0001, dest.longitude, 13.351686))
|
2017-12-28 22:57:22 +01:00
|
|
|
|
assertValidWhen(t, leg.arrival, when)
|
2017-11-14 02:59:17 +01:00
|
|
|
|
|
|
|
|
|
t.end()
|
2017-11-29 02:27:31 +01:00
|
|
|
|
}))
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
2018-03-16 14:30:49 +01:00
|
|
|
|
test('journeys: via works – with detour', co(function* (t) {
|
|
|
|
|
// Going from Westhafen to Wedding via Württembergalle without detour
|
2018-03-16 14:34:37 +01:00
|
|
|
|
// is currently impossible. We check if the routing engine computes a detour.
|
2018-03-06 02:47:05 +01:00
|
|
|
|
const westhafen = '900000001201'
|
|
|
|
|
const wedding = '900000009104'
|
|
|
|
|
const württembergallee = '900000026153'
|
|
|
|
|
const [journey] = yield client.journeys(westhafen, wedding, {
|
|
|
|
|
via: württembergallee,
|
|
|
|
|
results: 1,
|
2018-03-16 14:30:49 +01:00
|
|
|
|
when,
|
|
|
|
|
passedStations: true
|
2018-01-19 16:58:39 +01:00
|
|
|
|
})
|
|
|
|
|
|
2018-03-06 02:47:05 +01:00
|
|
|
|
t.ok(journey)
|
2018-01-19 16:58:39 +01:00
|
|
|
|
|
2018-03-16 14:30:49 +01:00
|
|
|
|
const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === württembergallee))
|
2018-03-16 14:38:08 +01:00
|
|
|
|
t.ok(l, 'Württembergalle is not being passed')
|
2018-03-06 02:47:05 +01:00
|
|
|
|
|
|
|
|
|
t.end()
|
|
|
|
|
}))
|
|
|
|
|
|
2018-03-16 14:30:49 +01:00
|
|
|
|
test('journeys: via works – without detour', co(function* (t) {
|
2018-03-06 02:47:05 +01:00
|
|
|
|
// When going from Ruhleben to Zoo via Kastanienallee, there is *no need*
|
2018-03-16 14:30:49 +01:00
|
|
|
|
// to change trains / no need for a "detour".
|
2018-03-06 02:47:05 +01:00
|
|
|
|
const ruhleben = '900000025202'
|
|
|
|
|
const zoo = '900000023201'
|
|
|
|
|
const kastanienallee = '900000020152'
|
|
|
|
|
const [journey] = yield client.journeys(ruhleben, zoo, {
|
|
|
|
|
via: kastanienallee,
|
|
|
|
|
results: 1,
|
|
|
|
|
when,
|
|
|
|
|
passedStations: true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.ok(journey)
|
|
|
|
|
|
2018-03-16 14:30:49 +01:00
|
|
|
|
const l = journey.legs.some(l => l.passed && l.passed.some(p => p.station.id === kastanienallee))
|
2018-03-16 14:38:08 +01:00
|
|
|
|
t.ok(l, 'Kastanienallee is not being passed')
|
2018-03-06 02:47:05 +01:00
|
|
|
|
|
|
|
|
|
t.end()
|
|
|
|
|
}))
|
|
|
|
|
|
2018-01-23 01:49:41 +01:00
|
|
|
|
test('departures', co(function* (t) {
|
2017-11-29 02:27:31 +01:00
|
|
|
|
const deps = yield client.departures(spichernstr, {duration: 5, when})
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
2017-11-14 02:59:17 +01:00
|
|
|
|
t.ok(Array.isArray(deps))
|
|
|
|
|
t.deepEqual(deps, deps.sort((a, b) => t.when > b.when))
|
|
|
|
|
for (let dep of deps) {
|
2017-12-11 15:20:50 +01:00
|
|
|
|
t.equal(typeof dep.journeyId, 'string')
|
|
|
|
|
t.ok(dep.journeyId)
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
2017-11-14 02:59:17 +01:00
|
|
|
|
t.equal(dep.station.name, 'U Spichernstr.')
|
|
|
|
|
assertValidStation(t, dep.station)
|
2017-12-11 14:41:28 +01:00
|
|
|
|
assertValidStationProducts(t, dep.station.products)
|
2017-11-20 01:05:48 +01:00
|
|
|
|
t.strictEqual(dep.station.id, spichernstr)
|
2017-11-14 02:59:17 +01:00
|
|
|
|
|
2017-12-28 22:57:22 +01:00
|
|
|
|
assertValidWhen(t, dep.when, when)
|
2018-01-23 02:26:53 +01:00
|
|
|
|
if (!findStation(dep.direction)) {
|
|
|
|
|
const err = new Error('unknown direction: ' + dep.direction)
|
|
|
|
|
err.stack = err.stack.split('\n').slice(0, 2).join('\n')
|
|
|
|
|
console.error(err)
|
|
|
|
|
}
|
2017-11-14 02:59:17 +01:00
|
|
|
|
assertValidLine(t, dep.line)
|
|
|
|
|
}
|
|
|
|
|
t.end()
|
2017-11-29 02:27:31 +01:00
|
|
|
|
}))
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
2018-01-23 01:49:41 +01:00
|
|
|
|
test('departures with station object', co(function* (t) {
|
2018-01-04 16:19:42 +01:00
|
|
|
|
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()
|
|
|
|
|
}))
|
|
|
|
|
|
2018-01-23 01:49:41 +01:00
|
|
|
|
test('departures at 7-digit station', co(function* (t) {
|
2017-11-14 02:50:24 +01:00
|
|
|
|
const eisenach = '8010097' // see derhuerst/vbb-hafas#22
|
2017-12-16 03:22:36 +01:00
|
|
|
|
yield client.departures(eisenach, {when})
|
2017-11-14 02:59:17 +01:00
|
|
|
|
t.pass('did not fail')
|
|
|
|
|
|
|
|
|
|
t.end()
|
2017-11-29 02:27:31 +01:00
|
|
|
|
}))
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-01-23 01:49:41 +01:00
|
|
|
|
test('nearby', co(function* (t) {
|
2017-11-14 02:59:17 +01:00
|
|
|
|
// Berliner Str./Bundesallee
|
2018-01-05 14:53:03 +01:00
|
|
|
|
const nearby = yield client.nearby({
|
|
|
|
|
type: 'location',
|
|
|
|
|
latitude: 52.4873452,
|
|
|
|
|
longitude: 13.3310411
|
|
|
|
|
}, {distance: 200})
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
2017-11-14 02:59:17 +01:00
|
|
|
|
t.ok(Array.isArray(nearby))
|
2017-12-11 19:53:26 +01:00
|
|
|
|
for (let n of nearby) {
|
|
|
|
|
if (n.type === 'station') assertValidStation(t, n)
|
|
|
|
|
else assertValidLocation(t, n, false)
|
|
|
|
|
}
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
2017-11-14 02:59:17 +01:00
|
|
|
|
t.equal(nearby[0].id, '900000044201')
|
|
|
|
|
t.equal(nearby[0].name, 'U Berliner Str.')
|
|
|
|
|
t.ok(nearby[0].distance > 0)
|
|
|
|
|
t.ok(nearby[0].distance < 100)
|
|
|
|
|
|
|
|
|
|
t.equal(nearby[1].id, '900000043252')
|
|
|
|
|
t.equal(nearby[1].name, 'Landhausstr.')
|
|
|
|
|
t.ok(nearby[1].distance > 100)
|
|
|
|
|
t.ok(nearby[1].distance < 200)
|
|
|
|
|
|
|
|
|
|
t.end()
|
2017-11-29 02:27:31 +01:00
|
|
|
|
}))
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-01-23 01:49:41 +01:00
|
|
|
|
test('locations', co(function* (t) {
|
2018-02-15 17:31:43 +01:00
|
|
|
|
const locations = yield client.locations('Alexanderplatz', {results: 20})
|
2017-11-14 02:59:17 +01:00
|
|
|
|
|
|
|
|
|
t.ok(Array.isArray(locations))
|
|
|
|
|
t.ok(locations.length > 0)
|
2018-02-15 17:31:43 +01:00
|
|
|
|
t.ok(locations.length <= 20)
|
2017-12-11 19:53:26 +01:00
|
|
|
|
for (let l of locations) {
|
|
|
|
|
if (l.type === 'station') assertValidStation(t, l)
|
|
|
|
|
else assertValidLocation(t, l)
|
|
|
|
|
}
|
|
|
|
|
t.ok(locations.find(s => s.type === 'station'))
|
|
|
|
|
t.ok(locations.find(s => s.id && s.name)) // POIs
|
|
|
|
|
t.ok(locations.find(s => !s.name && s.address)) // addresses
|
2017-11-14 02:59:17 +01:00
|
|
|
|
|
|
|
|
|
t.end()
|
2017-11-29 02:27:31 +01:00
|
|
|
|
}))
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
2018-01-26 17:08:07 +01:00
|
|
|
|
test('location', co(function* (t) {
|
|
|
|
|
const loc = yield client.location(spichernstr)
|
|
|
|
|
|
|
|
|
|
assertValidStation(t, loc)
|
|
|
|
|
t.equal(loc.id, spichernstr)
|
|
|
|
|
|
2018-01-26 17:40:14 +01:00
|
|
|
|
t.ok(Array.isArray(loc.lines))
|
|
|
|
|
if (Array.isArray(loc.lines)) {
|
|
|
|
|
for (let line of loc.lines) assertValidLine(t, line)
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-26 17:08:07 +01:00
|
|
|
|
t.end()
|
|
|
|
|
}))
|
|
|
|
|
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
|
|
|
|
|
2018-01-23 01:49:41 +01:00
|
|
|
|
test('radar', co(function* (t) {
|
2018-03-16 17:28:20 +01:00
|
|
|
|
const vehicles = yield client.radar({
|
|
|
|
|
north: 52.52411,
|
|
|
|
|
west: 13.41002,
|
|
|
|
|
south: 52.51942,
|
|
|
|
|
east: 13.41709
|
|
|
|
|
}, {
|
2017-11-14 02:59:17 +01:00
|
|
|
|
duration: 5 * 60, when
|
|
|
|
|
})
|
2017-11-14 02:50:24 +01:00
|
|
|
|
|
2017-11-14 02:59:17 +01:00
|
|
|
|
t.ok(Array.isArray(vehicles))
|
|
|
|
|
t.ok(vehicles.length > 0)
|
|
|
|
|
for (let v of vehicles) {
|
|
|
|
|
|
2018-01-23 02:26:53 +01:00
|
|
|
|
if (!findStation(v.direction)) {
|
|
|
|
|
const err = new Error('unknown direction: ' + v.direction)
|
|
|
|
|
err.stack = err.stack.split('\n').slice(0, 2).join('\n')
|
|
|
|
|
console.error(err)
|
|
|
|
|
}
|
2017-11-14 02:59:17 +01:00
|
|
|
|
assertValidLine(t, v.line)
|
|
|
|
|
|
2017-12-11 19:25:29 +01:00
|
|
|
|
t.equal(typeof v.location.latitude, 'number')
|
|
|
|
|
t.ok(v.location.latitude <= 55, 'vehicle is too far away')
|
|
|
|
|
t.ok(v.location.latitude >= 45, 'vehicle is too far away')
|
|
|
|
|
t.equal(typeof v.location.longitude, 'number')
|
|
|
|
|
t.ok(v.location.longitude >= 9, 'vehicle is too far away')
|
|
|
|
|
t.ok(v.location.longitude <= 15, 'vehicle is too far away')
|
2017-11-14 02:59:17 +01:00
|
|
|
|
|
|
|
|
|
t.ok(Array.isArray(v.nextStops))
|
2017-11-20 17:37:08 +01:00
|
|
|
|
for (let st of v.nextStops) {
|
|
|
|
|
assertValidStopover(t, st, true)
|
|
|
|
|
t.strictEqual(st.station.name.indexOf('(Berlin)'), -1)
|
|
|
|
|
|
|
|
|
|
if (st.arrival) {
|
|
|
|
|
t.equal(typeof st.arrival, 'string')
|
|
|
|
|
const arr = +new Date(st.arrival)
|
2017-11-14 02:59:17 +01:00
|
|
|
|
// note that this can be an ICE train
|
|
|
|
|
t.ok(isRoughlyEqual(14 * hour, +when, arr))
|
|
|
|
|
}
|
2017-11-20 17:37:08 +01:00
|
|
|
|
if (st.departure) {
|
|
|
|
|
t.equal(typeof st.departure, 'string')
|
|
|
|
|
const dep = +new Date(st.departure)
|
2017-11-14 02:59:17 +01:00
|
|
|
|
// note that this can be an ICE train
|
|
|
|
|
t.ok(isRoughlyEqual(14 * hour, +when, dep))
|
2017-11-14 02:50:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-14 02:59:17 +01:00
|
|
|
|
|
|
|
|
|
t.ok(Array.isArray(v.frames))
|
|
|
|
|
for (let f of v.frames) {
|
2017-11-20 17:37:08 +01:00
|
|
|
|
assertValidStation(t, f.origin, true)
|
2017-12-11 14:41:28 +01:00
|
|
|
|
assertValidStationProducts(t, f.origin.products)
|
2017-11-20 17:37:08 +01:00
|
|
|
|
t.strictEqual(f.origin.name.indexOf('(Berlin)'), -1)
|
|
|
|
|
assertValidStation(t, f.destination, true)
|
2017-12-11 14:41:28 +01:00
|
|
|
|
assertValidStationProducts(t, f.destination.products)
|
2017-11-20 17:37:08 +01:00
|
|
|
|
t.strictEqual(f.destination.name.indexOf('(Berlin)'), -1)
|
2017-11-14 02:59:17 +01:00
|
|
|
|
t.equal(typeof f.t, 'number')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
t.end()
|
2017-11-29 02:27:31 +01:00
|
|
|
|
}))
|