mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
basic tests for arrivals ✅
This commit is contained in:
parent
ac9819b1dd
commit
3ade1af7a2
6 changed files with 77 additions and 4 deletions
15
test/db.js
15
test/db.js
|
@ -22,6 +22,7 @@ const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
|
||||||
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||||
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
||||||
const testDepartures = require('./lib/departures')
|
const testDepartures = require('./lib/departures')
|
||||||
|
const testArrivals = require('./lib/arrivals')
|
||||||
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
||||||
|
|
||||||
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
|
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
|
||||||
|
@ -240,6 +241,20 @@ test('departures with station object', co(function* (t) {
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
test('arrivals at Berlin Schwedter Str.', co(function* (t) {
|
||||||
|
const arrivals = yield client.arrivals(blnSchwedterStr, {
|
||||||
|
duration: 5, when
|
||||||
|
})
|
||||||
|
|
||||||
|
yield testArrivals({
|
||||||
|
test: t,
|
||||||
|
arrivals,
|
||||||
|
validate,
|
||||||
|
id: blnSchwedterStr
|
||||||
|
})
|
||||||
|
t.end()
|
||||||
|
}))
|
||||||
|
|
||||||
test('nearby Berlin Jungfernheide', co(function* (t) {
|
test('nearby Berlin Jungfernheide', co(function* (t) {
|
||||||
const nearby = yield client.nearby({
|
const nearby = yield client.nearby({
|
||||||
type: 'location',
|
type: 'location',
|
||||||
|
|
15
test/insa.js
15
test/insa.js
|
@ -16,6 +16,7 @@ const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
|
||||||
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||||
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
||||||
const testDepartures = require('./lib/departures')
|
const testDepartures = require('./lib/departures')
|
||||||
|
const testArrivals = require('./lib/arrivals')
|
||||||
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
||||||
|
|
||||||
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
|
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
|
||||||
|
@ -195,6 +196,20 @@ test('departures with station object', co(function* (t) {
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
test('arrivals at Magdeburg Leiterstr.', co(function*(t) {
|
||||||
|
const arrivals = yield client.arrivals(leiterstr, {
|
||||||
|
duration: 5, when
|
||||||
|
})
|
||||||
|
|
||||||
|
yield testArrivals({
|
||||||
|
test: t,
|
||||||
|
arrivals,
|
||||||
|
validate,
|
||||||
|
id: leiterstr
|
||||||
|
})
|
||||||
|
t.end()
|
||||||
|
}))
|
||||||
|
|
||||||
// todo: nearby
|
// todo: nearby
|
||||||
|
|
||||||
test('locations named Magdeburg', co(function*(t) {
|
test('locations named Magdeburg', co(function*(t) {
|
||||||
|
|
|
@ -226,8 +226,8 @@ const validateJourneys = (val, js, name = 'journeys') => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const createValidateDeparture = (cfg) => {
|
const createValidateArrivalOrDeparture = (cfg) => {
|
||||||
const validateDeparture = (val, dep, name = 'departure') => {
|
const validateArrivalOrDeparture = (val, dep, name = 'arrOrDep') => {
|
||||||
a.ok(isObj(dep), name + ' must be an object')
|
a.ok(isObj(dep), name + ' must be an object')
|
||||||
// todo: let hafas-client add a .type field
|
// todo: let hafas-client add a .type field
|
||||||
|
|
||||||
|
@ -247,9 +247,16 @@ const createValidateDeparture = (cfg) => {
|
||||||
a.strictEqual(typeof dep.direction, 'string', name + '.direction must be a string')
|
a.strictEqual(typeof dep.direction, 'string', name + '.direction must be a string')
|
||||||
a.ok(dep.direction, name + '.direction must not be empty')
|
a.ok(dep.direction, name + '.direction must not be empty')
|
||||||
}
|
}
|
||||||
return validateDeparture
|
return validateArrivalOrDeparture
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const validateArrivals = (val, deps, name = 'arrivals') => {
|
||||||
|
a.ok(Array.isArray(deps), name + ' must be an array')
|
||||||
|
a.ok(deps.length > 0, name + ' must not be empty')
|
||||||
|
for (let i = 0; i < deps.length; i++) {
|
||||||
|
val.arrival(val, deps[i], name + `[${i}]`)
|
||||||
|
}
|
||||||
|
}
|
||||||
const validateDepartures = (val, deps, name = 'departures') => {
|
const validateDepartures = (val, deps, name = 'departures') => {
|
||||||
a.ok(Array.isArray(deps), name + ' must be an array')
|
a.ok(Array.isArray(deps), name + ' must be an array')
|
||||||
a.ok(deps.length > 0, name + ' must not be empty')
|
a.ok(deps.length > 0, name + ' must not be empty')
|
||||||
|
@ -314,8 +321,10 @@ module.exports = {
|
||||||
journeyLeg: createValidateJourneyLeg,
|
journeyLeg: createValidateJourneyLeg,
|
||||||
journey: () => validateJourney,
|
journey: () => validateJourney,
|
||||||
journeys: () => validateJourneys,
|
journeys: () => validateJourneys,
|
||||||
departure: createValidateDeparture,
|
arrival: createValidateArrivalOrDeparture,
|
||||||
|
departure: createValidateArrivalOrDeparture,
|
||||||
departures: () => validateDepartures,
|
departures: () => validateDepartures,
|
||||||
|
arrivals: () => validateArrivals,
|
||||||
movement: () => validateMovement,
|
movement: () => validateMovement,
|
||||||
movements: () => validateMovements
|
movements: () => validateMovements
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
|
||||||
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||||
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
||||||
const testDepartures = require('./lib/departures')
|
const testDepartures = require('./lib/departures')
|
||||||
|
const testArrivals = require('./lib/arrivals')
|
||||||
|
|
||||||
const when = createWhen('Europe/Berlin', 'de-DE')
|
const when = createWhen('Europe/Berlin', 'de-DE')
|
||||||
|
|
||||||
|
@ -229,6 +230,22 @@ test('departures with station object', co(function* (t) {
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
test('arrivals at Kiel Räucherei', co(function* (t) {
|
||||||
|
const kielRaeucherei = '3440091'
|
||||||
|
|
||||||
|
const arrivals = yield client.arrivals(kielRaeucherei, {
|
||||||
|
duration: 30, when
|
||||||
|
})
|
||||||
|
|
||||||
|
yield testArrivals({
|
||||||
|
test: t,
|
||||||
|
arrivals,
|
||||||
|
validate,
|
||||||
|
id: kielRaeucherei
|
||||||
|
})
|
||||||
|
t.end()
|
||||||
|
}))
|
||||||
|
|
||||||
test('nearby Kiel Hbf', co(function* (t) {
|
test('nearby Kiel Hbf', co(function* (t) {
|
||||||
const kielHbfPosition = {
|
const kielHbfPosition = {
|
||||||
type: 'location',
|
type: 'location',
|
||||||
|
|
|
@ -265,6 +265,8 @@ test('departures with station object', co(function* (t) {
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// todo: arrivals
|
||||||
|
|
||||||
test('nearby Salzburg Hbf', co(function* (t) {
|
test('nearby Salzburg Hbf', co(function* (t) {
|
||||||
const nearby = yield client.nearby({
|
const nearby = yield client.nearby({
|
||||||
type: 'location',
|
type: 'location',
|
||||||
|
|
15
test/vbb.js
15
test/vbb.js
|
@ -26,6 +26,7 @@ const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
|
||||||
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||||
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
||||||
const testDepartures = require('./lib/departures')
|
const testDepartures = require('./lib/departures')
|
||||||
|
const testArrivals = require('./lib/arrivals')
|
||||||
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
||||||
|
|
||||||
const when = createWhen('Europe/Berlin', 'de-DE')
|
const when = createWhen('Europe/Berlin', 'de-DE')
|
||||||
|
@ -303,6 +304,20 @@ test('departures at 7-digit station', co(function* (t) {
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
test('arrivals', co(function* (t) {
|
||||||
|
const arrivals = yield client.arrivals(spichernstr, {
|
||||||
|
duration: 5, when
|
||||||
|
})
|
||||||
|
|
||||||
|
yield testArrivals({
|
||||||
|
test: t,
|
||||||
|
arrivals,
|
||||||
|
validate,
|
||||||
|
id: spichernstr
|
||||||
|
})
|
||||||
|
t.end()
|
||||||
|
}))
|
||||||
|
|
||||||
test('nearby', co(function* (t) {
|
test('nearby', co(function* (t) {
|
||||||
const berlinerStr = '900000044201'
|
const berlinerStr = '900000044201'
|
||||||
const landhausstr = '900000043252'
|
const landhausstr = '900000043252'
|
||||||
|
|
Loading…
Add table
Reference in a new issue