From f097022b9a0a87b2ec5ec98372abc4d35e698f4b Mon Sep 17 00:00:00 2001 From: Jannis R Date: Fri, 28 Dec 2018 21:17:03 +0100 Subject: [PATCH] tests for departure.nextStopovers/arrival.previousStopovers :white_check_mark: --- test/bvg.js | 3 ++- test/cmta.js | 3 ++- test/db.js | 6 ++++-- test/insa.js | 3 ++- test/lib/validators.js | 28 ++++++++++++++++++++++++++-- test/nahsh.js | 3 ++- test/oebb.js | 3 ++- test/sbahn-muenchen.js | 6 ++++-- test/vbb.js | 6 ++++-- test/vbn.js | 6 ++++-- 10 files changed, 52 insertions(+), 15 deletions(-) diff --git a/test/bvg.js b/test/bvg.js index 35ad8a4a..9bdc17d4 100644 --- a/test/bvg.js +++ b/test/bvg.js @@ -249,7 +249,8 @@ test('journeys: via works – with detour', co(function* (t) { test('departures', co(function* (t) { const departures = yield client.departures(spichernstr, { - duration: 5, when + duration: 5, when, + stopovers: true }) yield testDepartures({ diff --git a/test/cmta.js b/test/cmta.js index 1e9a53c0..205b1988 100644 --- a/test/cmta.js +++ b/test/cmta.js @@ -178,7 +178,8 @@ test('trip details', co(function* (t) { test('departures at Broadie Oaks', co(function*(t) { const departures = yield client.departures(broadieOaks, { - duration: 10, when + duration: 10, when, + stopovers: true }) yield testDepartures({ diff --git a/test/db.js b/test/db.js index 3b8082c5..bc6de413 100644 --- a/test/db.js +++ b/test/db.js @@ -245,7 +245,8 @@ test('trip details', co(function* (t) { test('departures at Berlin Schwedter Str.', co(function* (t) { const departures = yield client.departures(blnSchwedterStr, { - duration: 5, when + duration: 5, when, + stopovers: true }) yield testDepartures({ @@ -300,7 +301,8 @@ test('departures without related stations', co(function* (t) { test('arrivals at Berlin Schwedter Str.', co(function* (t) { const arrivals = yield client.arrivals(blnSchwedterStr, { - duration: 5, when + duration: 5, when, + stopovers: true }) yield testArrivals({ diff --git a/test/insa.js b/test/insa.js index 4b43044e..da169295 100644 --- a/test/insa.js +++ b/test/insa.js @@ -171,7 +171,8 @@ test('trip details', co(function* (t) { test('departures at Magdeburg Leiterstr.', co(function*(t) { const departures = yield client.departures(leiterstr, { - duration: 5, when + duration: 5, when, + stopovers: true }) yield testDepartures({ diff --git a/test/lib/validators.js b/test/lib/validators.js index d5ba436d..4af1d0b1 100644 --- a/test/lib/validators.js +++ b/test/lib/validators.js @@ -334,8 +334,32 @@ const createValidateArrivalOrDeparture = (type, cfg) => { return validateArrivalOrDeparture } -const createValidateArrival = cfg => createValidateArrivalOrDeparture('arrival', cfg) -const createValidateDeparture = cfg => createValidateArrivalOrDeparture('departure', cfg) +const createValidateArrival = (cfg) => { + const validate = createValidateArrivalOrDeparture('arrival', cfg) + return (val, arr, name = 'arrival') => { + validate(val, arr, name) + if ('previousStopovers' in arr) { + const n = name + '.previousStopovers' + a.ok(Array.isArray(arr.previousStopovers), n + ' must be an array') + for (let i = 0; i < arr.previousStopovers.length; i++) { + val.stopover(val, arr.previousStopovers[i], n + `[${i}]`) + } + } + } +} +const createValidateDeparture = (cfg) => { + const validate = createValidateArrivalOrDeparture('departure', cfg) + return (val, dep, name = 'departure') => { + validate(val, dep, name) + if ('nextStopovers' in dep) { + const n = name + '.nextStopovers' + a.ok(Array.isArray(dep.nextStopovers), n + ' must be an array') + for (let i = 0; i < dep.nextStopovers.length; i++) { + val.stopover(val, dep.nextStopovers[i], n + `[${i}]`) + } + } + } +} const validateArrivals = (val, deps, name = 'arrivals') => { a.ok(Array.isArray(deps), name + ' must be an array') diff --git a/test/nahsh.js b/test/nahsh.js index 1a2a2d57..b32435e2 100644 --- a/test/nahsh.js +++ b/test/nahsh.js @@ -221,7 +221,8 @@ test('trip details', co(function* (t) { test('departures at Kiel Räucherei', co(function* (t) { const departures = yield client.departures(kielRaeucherei, { - duration: 30, when + duration: 30, when, + stopovers: true }) yield testDepartures({ diff --git a/test/oebb.js b/test/oebb.js index e651958e..1b248c62 100644 --- a/test/oebb.js +++ b/test/oebb.js @@ -251,7 +251,8 @@ test('departures at Wien Leibenfrostgasse', co(function* (t) { ] const deps = yield client.departures(wienLeibenfrostgasse, { - duration: 15, when + duration: 15, when, + stopovers: true }) validate(t, deps, 'departures', 'departures') diff --git a/test/sbahn-muenchen.js b/test/sbahn-muenchen.js index bcb2f989..68bfc185 100644 --- a/test/sbahn-muenchen.js +++ b/test/sbahn-muenchen.js @@ -174,7 +174,8 @@ test('trip details', co(function* (t) { test('departures at Karl-Theodor-Straße', co(function*(t) { const departures = yield client.departures(karlTheodorStr, { - duration: 10, when + duration: 10, when, + stopovers: true }) yield testDepartures({ @@ -204,7 +205,8 @@ test('departures with station object', co(function* (t) { test('arrivals at Karl-Theodor-Straße', co(function*(t) { const arrivals = yield client.arrivals(karlTheodorStr, { - duration: 10, when + duration: 10, when, + stopovers: true }) yield testArrivals({ diff --git a/test/vbb.js b/test/vbb.js index 98e50c7d..4be3e1a2 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -224,7 +224,8 @@ test('journeys: via works – with detour', co(function* (t) { test('departures', co(function* (t) { const departures = yield client.departures(spichernstr, { - duration: 5, when + duration: 5, when, + stopovers: true }) yield testDepartures({ @@ -286,7 +287,8 @@ test('departures without related stations', co(function* (t) { test('arrivals', co(function* (t) { const arrivals = yield client.arrivals(spichernstr, { - duration: 5, when + duration: 5, when, + stopovers: true }) yield testArrivals({ diff --git a/test/vbn.js b/test/vbn.js index d31c4fab..72cbc3ea 100644 --- a/test/vbn.js +++ b/test/vbn.js @@ -177,7 +177,8 @@ test.skip('trip details', co(function* (t) { test.skip('departures at Magdeburg Leiterstr.', co(function*(t) { const departures = yield client.departures(leiterstr, { - duration: 5, when + duration: 5, when, + stopovers: false }) yield testDepartures({ @@ -207,7 +208,8 @@ test.skip('departures with station object', co(function* (t) { test.skip('arrivals at Magdeburg Leiterstr.', co(function*(t) { const arrivals = yield client.arrivals(leiterstr, { - duration: 5, when + duration: 5, when, + stopovers: true }) yield testArrivals({