diff --git a/test/db.js b/test/db.js index de2af4bf..9bcdc7a6 100644 --- a/test/db.js +++ b/test/db.js @@ -22,6 +22,7 @@ const testJourneysStationToPoi = require('./lib/journeys-station-to-poi') const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const testDepartures = require('./lib/departures') +const testArrivals = require('./lib/arrivals') const testJourneysWithDetour = require('./lib/journeys-with-detour') 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() })) +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) { const nearby = yield client.nearby({ type: 'location', diff --git a/test/insa.js b/test/insa.js index 7f622154..365740a1 100644 --- a/test/insa.js +++ b/test/insa.js @@ -16,6 +16,7 @@ const testJourneysStationToPoi = require('./lib/journeys-station-to-poi') const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const testDepartures = require('./lib/departures') +const testArrivals = require('./lib/arrivals') const testJourneysWithDetour = require('./lib/journeys-with-detour') 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() })) +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 test('locations named Magdeburg', co(function*(t) { diff --git a/test/lib/validators.js b/test/lib/validators.js index 4a7c9bbb..f879c8d5 100644 --- a/test/lib/validators.js +++ b/test/lib/validators.js @@ -226,8 +226,8 @@ const validateJourneys = (val, js, name = 'journeys') => { } } -const createValidateDeparture = (cfg) => { - const validateDeparture = (val, dep, name = 'departure') => { +const createValidateArrivalOrDeparture = (cfg) => { + const validateArrivalOrDeparture = (val, dep, name = 'arrOrDep') => { a.ok(isObj(dep), name + ' must be an object') // 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.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') => { a.ok(Array.isArray(deps), name + ' must be an array') a.ok(deps.length > 0, name + ' must not be empty') @@ -314,8 +321,10 @@ module.exports = { journeyLeg: createValidateJourneyLeg, journey: () => validateJourney, journeys: () => validateJourneys, - departure: createValidateDeparture, + arrival: createValidateArrivalOrDeparture, + departure: createValidateArrivalOrDeparture, departures: () => validateDepartures, + arrivals: () => validateArrivals, movement: () => validateMovement, movements: () => validateMovements } diff --git a/test/nahsh.js b/test/nahsh.js index a0fe19db..a502908b 100644 --- a/test/nahsh.js +++ b/test/nahsh.js @@ -20,6 +20,7 @@ const testJourneysStationToPoi = require('./lib/journeys-station-to-poi') const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const testDepartures = require('./lib/departures') +const testArrivals = require('./lib/arrivals') const when = createWhen('Europe/Berlin', 'de-DE') @@ -229,6 +230,22 @@ test('departures with station object', co(function* (t) { 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) { const kielHbfPosition = { type: 'location', diff --git a/test/oebb.js b/test/oebb.js index a55a8a47..d97581d3 100644 --- a/test/oebb.js +++ b/test/oebb.js @@ -265,6 +265,8 @@ test('departures with station object', co(function* (t) { t.end() })) +// todo: arrivals + test('nearby Salzburg Hbf', co(function* (t) { const nearby = yield client.nearby({ type: 'location', diff --git a/test/vbb.js b/test/vbb.js index f74eaf4a..36601c6d 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -26,6 +26,7 @@ const testJourneysStationToPoi = require('./lib/journeys-station-to-poi') const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const testDepartures = require('./lib/departures') +const testArrivals = require('./lib/arrivals') const testJourneysWithDetour = require('./lib/journeys-with-detour') const when = createWhen('Europe/Berlin', 'de-DE') @@ -303,6 +304,20 @@ test('departures at 7-digit station', co(function* (t) { 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) { const berlinerStr = '900000044201' const landhausstr = '900000043252'