From c0a04fc74f2c903a75c64cd58029363dd4993e4d Mon Sep 17 00:00:00 2001 From: Jannis R Date: Tue, 10 Jul 2018 22:33:52 +0200 Subject: [PATCH] tests for `includeRelatedStations` option :white_check_mark: see 1551943 --- test/db.js | 13 ++++++ .../departures-without-related-stations.js | 41 +++++++++++++++++++ test/vbb.js | 13 ++++++ 3 files changed, 67 insertions(+) create mode 100644 test/lib/departures-without-related-stations.js diff --git a/test/db.js b/test/db.js index f714b207..7b1fb76f 100644 --- a/test/db.js +++ b/test/db.js @@ -23,6 +23,7 @@ const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const testDepartures = require('./lib/departures') const testDeparturesInDirection = require('./lib/departures-in-direction') +const testDeparturesWithoutRelatedStations = require('./lib/departures-without-related-stations') const testArrivals = require('./lib/arrivals') const testJourneysWithDetour = require('./lib/journeys-with-detour') @@ -256,6 +257,18 @@ test('departures at Berlin Hbf in direction of Berlin Ostbahnhof', co(function* t.end() })) +test('departures without related stations', co(function* (t) { + yield testDeparturesWithoutRelatedStations({ + test: t, + fetchDepartures: client.departures, + id: '8089051', // Berlin Yorckstr. (S1) + when, + products: {bus: false}, + linesOfRelatedStations: ['S 2', 'S 25', 'S 26', 'U 7'] + }) + t.end() +})) + test('arrivals at Berlin Schwedter Str.', co(function* (t) { const arrivals = yield client.arrivals(blnSchwedterStr, { duration: 5, when diff --git a/test/lib/departures-without-related-stations.js b/test/lib/departures-without-related-stations.js new file mode 100644 index 00000000..02c60f57 --- /dev/null +++ b/test/lib/departures-without-related-stations.js @@ -0,0 +1,41 @@ +'use strict' + +const co = require('./co') + +const testDeparturesWithoutUnrelatedStations = co(function* (cfg) { + const { + test: t, + fetchDepartures, + id, + when + // duration, products + } = cfg + + const relatedLines = cfg.linesOfRelatedStations + .map(lName => lName.toLowerCase().trim()) + + const isUnrelatedLine = (dep) => { + if (!dep.line || !dep.line.name) return false + return relatedLines.includes(dep.line.name.toLowerCase().trim()) + } + + const depsWith = yield fetchDepartures(id, { + when, + duration: cfg.duration || 20, + products: cfg.products || {} + }) + t.ok(depsWith.some(isUnrelatedLine), 'precondition failed: no line at related station found') + + const depsWithout = yield fetchDepartures(id, { + includeRelatedStations: false, + when, + duration: cfg.duration || 20, + products: cfg.products || {} + }) + + const unrelatedDep = depsWithout.find(isUnrelatedLine) + if (unrelatedDep) t.fail('line at related station: ' + unrelatedDep.line.name) + else t.pass('no lines from related stations') +}) + +module.exports = testDeparturesWithoutUnrelatedStations diff --git a/test/vbb.js b/test/vbb.js index 6ec9817f..0a657acf 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -27,6 +27,7 @@ const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const testDepartures = require('./lib/departures') const testDeparturesInDirection = require('./lib/departures-in-direction') +const testDeparturesWithoutRelatedStations = require('./lib/departures-without-related-stations') const testArrivals = require('./lib/arrivals') const testJourneysWithDetour = require('./lib/journeys-with-detour') @@ -318,6 +319,18 @@ test('departures at 7-digit station', co(function* (t) { t.end() })) +test('departures without related stations', co(function* (t) { + yield testDeparturesWithoutRelatedStations({ + test: t, + fetchDepartures: client.departures, + id: '900000024101', // Charlottenburg + when, + products: {bus: false, suburban: false, regional: false}, + linesOfRelatedStations: ['U7'] + }) + t.end() +})) + test('arrivals', co(function* (t) { const arrivals = yield client.arrivals(spichernstr, { duration: 5, when