diff --git a/test/e2e/invg.js b/test/e2e/invg.js index 08b09ab3e..34368f201 100644 --- a/test/e2e/invg.js +++ b/test/e2e/invg.js @@ -18,6 +18,7 @@ const testJourneysStationToPoi = require('./lib/journeys-station-to-poi') const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') const testRefreshJourney = require('./lib/refresh-journey') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') +const testDepartures = require('./lib/departures') const testArrivals = require('./lib/arrivals') const T_MOCK = 1641897000 * 1000 // 2022-01-11T11:30:00+01 @@ -184,16 +185,12 @@ tap.test('departures at Ingolstadt Hbf', async (t) => { duration: 10, when }) - validate(t, deps, 'departures', 'departures') - t.ok(deps.length > 0, 'must be >0 departures') - // todo: move into deps validator - t.same(deps, deps.sort((a, b) => t.when > b.when)) - - for (let i = 0; i < deps.length; i++) { - const dep = deps[i] - t.ok(ids.includes(dep.stop.id), `deps[${i}].stop.id ("${dep.stop.id}") is invalid`) - } - + await testDepartures({ + test: t, + departures: deps, + validate, + ids, + }) t.end() }) @@ -224,16 +221,12 @@ tap.test('arrivals at Ingolstadt Hbf', async (t) => { duration: 10, when }) - validate(t, arrs, 'arrivals', 'arrivals') - t.ok(arrs.length > 0, 'must be >0 arrivals') - // todo: move into arrs validator - t.same(arrs, arrs.sort((a, b) => t.when > b.when)) - - for (let i = 0; i < arrs.length; i++) { - const arr = arrs[i] - t.ok(ids.includes(arr.stop.id), `arrs[${i}].stop.id ("${arr.stop.id}") is invalid`) - } - + await testArrivals({ + test: t, + arrivals: arrs, + validate, + ids, + }) t.end() }) diff --git a/test/e2e/lib/arrivals.js b/test/e2e/lib/arrivals.js index d4f4c07d4..a77936b03 100644 --- a/test/e2e/lib/arrivals.js +++ b/test/e2e/lib/arrivals.js @@ -22,7 +22,7 @@ const testArrivals = async (cfg) => { } // todo: move into arrivals validator - t.same(arrs, arrs.sort((a, b) => t.when > b.when)) + t.same(arrs, arrs.sort((a, b) => t.when > b.when), 'arrivals must be sorted by .when') } module.exports = testArrivals diff --git a/test/e2e/lib/departures.js b/test/e2e/lib/departures.js index df66463d4..2b084d398 100644 --- a/test/e2e/lib/departures.js +++ b/test/e2e/lib/departures.js @@ -22,7 +22,7 @@ const testDepartures = async (cfg) => { } // todo: move into deps validator - t.same(deps, deps.sort((a, b) => t.when > b.when)) + t.same(deps, deps.sort((a, b) => t.when > b.when), 'departures must be sorted by .when') } module.exports = testDepartures diff --git a/test/e2e/lib/validators.js b/test/e2e/lib/validators.js index 3c6155c49..163b0f4b8 100644 --- a/test/e2e/lib/validators.js +++ b/test/e2e/lib/validators.js @@ -491,19 +491,21 @@ const createValidateDeparture = (cfg) => { } } -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 _createValidateStationBoardResults = (cfg, validatorsKey) => { + const validateStationBoardResults = (val, arrsOrDeps, name) => { + a.ok(Array.isArray(arrsOrDeps), name + ' must be an array') + a.ok(arrsOrDeps.length > 0, name + ' must not be empty') + for (let i = 0; i < arrsOrDeps.length; i++) { + val[validatorsKey](val, arrsOrDeps[i], name + `[${i}]`) + } } + return validateStationBoardResults } -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') - for (let i = 0; i < deps.length; i++) { - val.departure(val, deps[i], name + `[${i}]`) - } +const createValidateArrivals = (cfg) => { + return _createValidateStationBoardResults(cfg, 'arrival') +} +const createValidateDepartures = (cfg) => { + return _createValidateStationBoardResults(cfg, 'departure') } const createValidateMovement = (cfg) => { @@ -582,8 +584,8 @@ module.exports = { trip: () => validateTrip, arrival: createValidateArrival, departure: createValidateDeparture, - departures: () => validateDepartures, - arrivals: () => validateArrivals, + arrivals: createValidateArrivals, + departures: createValidateDepartures, movement: createValidateMovement, movements: () => validateMovements } diff --git a/test/e2e/oebb.js b/test/e2e/oebb.js index 46c2d950a..d71c90a0c 100644 --- a/test/e2e/oebb.js +++ b/test/e2e/oebb.js @@ -20,6 +20,7 @@ const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') const testRefreshJourney = require('./lib/refresh-journey') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const testJourneysWithDetour = require('./lib/journeys-with-detour') +const testDepartures = require('./lib/departures') const testDeparturesInDirection = require('./lib/departures-in-direction') const T_MOCK = 1641897000 * 1000 // 2022-01-11T11:30:00+01 @@ -254,16 +255,12 @@ tap.test('departures at Wien Leibenfrostgasse', async (t) => { duration: 15, when, }) - validate(t, deps, 'departures', 'departures') - t.ok(deps.length > 0, 'must be >0 departures') - // todo: move into deps validator - t.same(deps, deps.sort((a, b) => t.when > b.when)) - - for (let i = 0; i < deps.length; i++) { - const dep = deps[i] - t.ok(ids.includes(dep.stop.id), `deps[${i}].stop.id ("${dep.stop.id}") is invalid`) - } - + await testDepartures({ + test: t, + departures: deps, + validate, + ids, + }) t.end() }) diff --git a/test/e2e/rmv.js b/test/e2e/rmv.js index 09ef0e8c1..c91191fbb 100644 --- a/test/e2e/rmv.js +++ b/test/e2e/rmv.js @@ -8,7 +8,6 @@ const rmvProfile = require('../../p/rmv') const products = require('../../p/rmv/products') const createValidate = require('./lib/validate-fptf-with') const testJourneysStationToStation = require('./lib/journeys-station-to-station') -const testRefreshJourney = require('./lib/refresh-journey') const testArrivals = require('./lib/arrivals') const testReachableFrom = require('./lib/reachable-from') @@ -71,9 +70,12 @@ tap.test('arrivals at Wiesbaden Hbf', async (t) => { duration: 10, when }) - validate(t, arrivals, 'arrivals', 'arrivals') - t.ok(arrivals.length > 0, 'must be >0 arrivals') - t.same(arrivals, arrivals.sort((a, b) => t.when > b.when)) + await testArrivals({ + test: t, + arrivals, + validate, + id: wiesbadenHbf, + }) t.end() }) diff --git a/test/e2e/rsag.js b/test/e2e/rsag.js index 8897d8476..82aa670dc 100644 --- a/test/e2e/rsag.js +++ b/test/e2e/rsag.js @@ -85,9 +85,15 @@ tap.test('arrivals at Platz der Jugend', async (t) => { duration: 30, when }) - validate(t, arrivals, 'arrivals', 'arrivals') - t.ok(arrivals.length > 0, 'must be >0 arrivals') - t.same(arrivals, arrivals.sort((a, b) => t.when > b.when)) + await testArrivals({ + test: t, + arrivals, + validate, + ids: [ + sternwarte, + '708539', // Rostock Sternwarte + ], + }) t.end() }) diff --git a/test/e2e/saarfahrplan.js b/test/e2e/saarfahrplan.js index f36283a63..4ad280796 100644 --- a/test/e2e/saarfahrplan.js +++ b/test/e2e/saarfahrplan.js @@ -16,7 +16,6 @@ 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 testRefreshJourney = require('./lib/refresh-journey') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const testJourneysWithDetour = require('./lib/journeys-with-detour') const testDepartures = require('./lib/departures') @@ -177,21 +176,12 @@ tap.test('departures', async (t) => { duration: 5, when }) - validate(t, departures, 'departures', 'departures') - t.ok(departures.length > 0, 'must be >0 departures') - for (let i = 0; i < departures.length; i++) { - let stop = departures[i].stop - let name = `departures[${i}].stop` - if (stop.station) { - stop = stop.station - name += '.station' - } - - t.equal(stop.id, saarbrueckenUhlandstr, name + '.id is invalid') - } - - // todo: move into deps validator - t.same(departures, departures.sort((a, b) => t.when > b.when)) + await testDepartures({ + test: t, + departures, + validate, + id: saarbrueckenUhlandstr, + }) t.end() }) diff --git a/test/e2e/sncb.js b/test/e2e/sncb.js index b9080d52a..ed2d5da2c 100644 --- a/test/e2e/sncb.js +++ b/test/e2e/sncb.js @@ -8,7 +8,6 @@ const sncbProfile = require('../../p/sncb') const products = require('../../p/sncb/products') const createValidate = require('./lib/validate-fptf-with') const testJourneysStationToStation = require('./lib/journeys-station-to-station') -const testRefreshJourney = require('./lib/refresh-journey') const testArrivals = require('./lib/arrivals') const testReachableFrom = require('./lib/reachable-from') @@ -76,9 +75,12 @@ tap.test('arrivals at Bruxelles Midi', async (t) => { duration: 10, when }) - validate(t, arrivals, 'arrivals', 'arrivals') - t.ok(arrivals.length > 0, 'must be >0 arrivals') - t.same(arrivals, arrivals.sort((a, b) => t.when > b.when)) + await testArrivals({ + test: t, + arrivals, + validate, + id: bruxellesMidi, + }) t.end() }) diff --git a/test/e2e/svv.js b/test/e2e/svv.js index 7d58d60f8..27bd84d62 100644 --- a/test/e2e/svv.js +++ b/test/e2e/svv.js @@ -8,7 +8,6 @@ const svvProfile = require('../../p/svv') const products = require('../../p/svv/products') const createValidate = require('./lib/validate-fptf-with') const testJourneysStationToStation = require('./lib/journeys-station-to-station') -const testRefreshJourney = require('./lib/refresh-journey') const testArrivals = require('./lib/arrivals') const testReachableFrom = require('./lib/reachable-from') const testServerInfo = require('./lib/server-info') @@ -78,9 +77,12 @@ tap.test('arrivals at Volksgarten', async (t) => { duration: 10, when }) - validate(t, arrivals, 'arrivals', 'arrivals') - t.ok(arrivals.length > 0, 'must be >0 arrivals') - t.same(arrivals, arrivals.sort((a, b) => t.when > b.when)) + await testArrivals({ + test: t, + arrivals, + validate, + id: volksgarten, + }) t.end() }) diff --git a/test/e2e/vbn.js b/test/e2e/vbn.js index e47441e93..eaf9160c1 100644 --- a/test/e2e/vbn.js +++ b/test/e2e/vbn.js @@ -70,9 +70,12 @@ tap.test('arrivals at Bremen Humboldtstr.', async (t) => { duration: 10, when }) - validate(t, arrivals, 'arrivals', 'arrivals') - t.ok(arrivals.length > 0, 'must be >0 arrivals') - t.same(arrivals, arrivals.sort((a, b) => t.when > b.when)) + await testArrivals({ + test: t, + arrivals, + validate, + id: bremenHumboldtstr, + }) t.end() }) diff --git a/test/e2e/zvv.js b/test/e2e/zvv.js index 5c55ba2b6..909c5aff7 100644 --- a/test/e2e/zvv.js +++ b/test/e2e/zvv.js @@ -9,7 +9,6 @@ const zvvProfile = require('../../p/zvv') const products = require('../../p/zvv/products') const createValidate = require('./lib/validate-fptf-with') const testJourneysStationToStation = require('./lib/journeys-station-to-station') -const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const testJourneysStationToAddress = require('./lib/journeys-station-to-address') const testJourneysStationToPoi = require('./lib/journeys-station-to-poi') const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')