From cb5e01ed5bd69e89500f605c41622c9cc5d395b2 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Tue, 24 Apr 2018 16:58:17 +0200 Subject: [PATCH] departures tests: use helper fn --- test/db.js | 21 +++++++++------------ test/insa.js | 27 +++++++++++---------------- test/nahsh.js | 21 ++++++++------------- test/oebb.js | 31 ++++++++++++++----------------- test/vbb.js | 22 ++++++++++------------ 5 files changed, 52 insertions(+), 70 deletions(-) diff --git a/test/db.js b/test/db.js index 5041ea99..79895f2d 100644 --- a/test/db.js +++ b/test/db.js @@ -19,6 +19,7 @@ const testJourneysStationToStation = require('./lib/journeys-station-to-station' const testJourneysStationToAddress = require('./lib/journeys-station-to-address') const testJourneysStationToPoi = require('./lib/journeys-station-to-poi') const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') +const testDepartures = require('./lib/departures') const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o) @@ -184,21 +185,17 @@ test('journey leg details', co(function* (t) { t.end() })) -test('departures at Berlin Jungfernheide', co(function* (t) { - const deps = yield client.departures(jungfernheide, { +test('departures at Berlin Schwedter Str.', co(function* (t) { + const departures = yield client.departures(blnSchwedterStr, { duration: 5, when }) - validate(t, deps, 'departures', 'departures') - for (let i = 0; i < deps.length; i++) { - const dep = deps[i] - const name = `deps[${i}]` - // todo: make this pass - // t.equal(dep.station.id, jungfernheide, name + '.station.id is invalid') - } - // todo: move into deps validator - t.deepEqual(deps, deps.sort((a, b) => t.when > b.when)) - + yield testDepartures({ + test: t, + departures, + validate, + id: blnSchwedterStr + }) t.end() })) diff --git a/test/insa.js b/test/insa.js index 0f2072c0..59e0f331 100644 --- a/test/insa.js +++ b/test/insa.js @@ -14,6 +14,7 @@ const testJourneysStationToStation = require('./lib/journeys-station-to-station' const testJourneysStationToAddress = require('./lib/journeys-station-to-address') const testJourneysStationToPoi = require('./lib/journeys-station-to-poi') const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') +const testDepartures = require('./lib/departures') const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o) @@ -32,6 +33,7 @@ const client = createClient(insaProfile) const magdeburgHbf = '8010224' const magdeburgBuckau = '8013456' +const leiterstr = '7464' const hasselbachplatzSternstrasse = '000006545' const stendal = '008010334' const dessau = '008010077' @@ -150,24 +152,17 @@ test('journey leg details', co(function* (t) { t.end() })) -test('departures at Magdeburg Hbf', co(function*(t) { - const deps = yield client.departures(magdeburgHbf, { - duration: 5, - when +test('departures at Magdeburg Leiterstr.', co(function*(t) { + const departures = yield client.departures(leiterstr, { + duration: 5, when }) - validate(t, deps, 'departures', 'departures') - for (let i = 0; i < deps.length; i++) { - const dep = deps[i] - const name = `deps[${i}]` - - // todo: fix this - // t.equal(dep.station.name, 'Magdeburg Hbf', name + '.station.name is invalid') - // t.equal(dep.station.id, magdeburgHbf, name + '.station.id is invalid') - } - // todo: move into deps validator - t.deepEqual(deps, deps.sort((a, b) => t.when > b.when)) - + yield testDepartures({ + test: t, + departures, + validate, + id: leiterstr + }) t.end() })) diff --git a/test/nahsh.js b/test/nahsh.js index 12756e03..3c2db30d 100644 --- a/test/nahsh.js +++ b/test/nahsh.js @@ -18,6 +18,7 @@ const testJourneysStationToStation = require('./lib/journeys-station-to-station' const testJourneysStationToAddress = require('./lib/journeys-station-to-address') const testJourneysStationToPoi = require('./lib/journeys-station-to-poi') const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') +const testDepartures = require('./lib/departures') const when = createWhen('Europe/Berlin', 'de-DE') @@ -176,22 +177,16 @@ test('journey leg details for Flensburg to Husum', co(function* (t) { })) test('departures at Kiel Hbf', co(function* (t) { - const deps = yield client.departures(kielHbf, { + const departures = yield client.departures(kielHbf, { duration: 30, when }) - validate(t, deps, 'departures', 'departures') - for (let i = 0; i < deps.length; i++) { - const dep = deps[i] - const name = `deps[${i}]` - - // todo: fix this - // t.equal(dep.station.name, 'Kiel Hauptbahnhof', name + '.station.name is invalid') - // t.equal(dep.station.id, kielHbf, name + '.station.id is invalid') - } - // todo: move into deps validator - t.deepEqual(deps, deps.sort((a, b) => t.when > b.when)) - + yield testDepartures({ + test: t, + departures, + validate, + id: kielHbf + }) t.end() })) diff --git a/test/oebb.js b/test/oebb.js index 9a0480f2..d32efdd5 100644 --- a/test/oebb.js +++ b/test/oebb.js @@ -18,6 +18,7 @@ const testJourneysStationToStation = require('./lib/journeys-station-to-station' const testJourneysStationToAddress = require('./lib/journeys-station-to-address') const testJourneysStationToPoi = require('./lib/journeys-station-to-poi') const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') +const testDepartures = require('./lib/departures') const when = createWhen('Europe/Vienna', 'de-AT') @@ -56,7 +57,7 @@ const klagenfurtHbf = '8100085' const muenchenHbf = '8000261' const wienRenngasse = '1390186' -test('journeys – Salzburg Hbf to Wien Westbahnhof', co(function* (t) { +test.skip('journeys – Salzburg Hbf to Wien Westbahnhof', co(function* (t) { const journeys = yield client.journeys(salzburgHbf, wienFickeystr, { results: 3, when, passedStations: true }) @@ -213,24 +214,20 @@ test('leg details for Wien Westbahnhof to München Hbf', co(function* (t) { t.end() })) -test('departures at Wien Renngasse', co(function* (t) { - const deps = yield client.departures(wienRenngasse, { - duration: 5, when +test.skip('departures at Wien Renngasse', co(function* (t) { + const wienLeibenfrostgasse = '1390469' + const departures = yield client.departures(wienLeibenfrostgasse, { + duration: 15, when }) - validate(t, deps, 'departures', 'departures') - for (let i = 0; i < deps.length; i++) { - const dep = deps[i] - const name = `deps[${i}]` - - // todo: fis this - // ÖBB HAFAS data is just too detailed :P - // t.equal(dep.station.name, 'Wien Renngasse', name + '.station.name is invalid') - // t.equal(dep.station.id, wienRenngasse, name + '.station.id is invalid') - } - // todo: move into deps validator - t.deepEqual(deps, deps.sort((a, b) => t.when > b.when)) - + // todo: fix this + // ÖBB HAFAS data is just too detailed :P + yield testDepartures({ + test: t, + departures, + validate, + id: wienLeibenfrostgasse + }) t.end() })) diff --git a/test/vbb.js b/test/vbb.js index a34c05bc..7d84092f 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -24,6 +24,7 @@ const testJourneysStationToStation = require('./lib/journeys-station-to-station' const testJourneysStationToAddress = require('./lib/journeys-station-to-address') const testJourneysStationToPoi = require('./lib/journeys-station-to-poi') const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') +const testDepartures = require('./lib/departures') const when = createWhen('Europe/Berlin', 'de-DE') @@ -273,19 +274,16 @@ test('journeys: via works – with detour', co(function* (t) { })) test('departures', co(function* (t) { - const deps = yield client.departures(spichernstr, {duration: 5, when}) - - validate(t, deps, 'departures', 'departures') - for (let i = 0; i < deps.length; i++) { - const dep = deps[i] - const name = `deps[${i}]` - - t.equal(dep.station.name, 'U Spichernstr.', name + '.station.name is invalid') - t.equal(dep.station.id, spichernstr, name + '.station.id is invalid') - } - // todo: move into deps validator - t.deepEqual(deps, deps.sort((a, b) => t.when > b.when)) + const departures = yield client.departures(spichernstr, { + duration: 5, when + }) + yield testDepartures({ + test: t, + departures, + validate, + id: spichernstr + }) t.end() }))