diff --git a/test/db.js b/test/db.js index 79895f2d..e6db740a 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 journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const testDepartures = require('./lib/departures') const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o) @@ -92,7 +93,18 @@ test('journeys – Berlin Schwedter Str. to München Hbf', co(function* (t) { })) // todo: journeys, only one product -// todo: journeys, fails with no product + +test('journeys – fails with no product', (t) => { + journeysFailsWithNoProduct({ + test: t, + fetchJourneys: client.journeys, + fromId: blnSchwedterStr, + toId: münchenHbf, + when, + products + }) + t.end() +}) test('Berlin Schwedter Str. to Torfstraße 17', co(function* (t) { const torfstr = { diff --git a/test/insa.js b/test/insa.js index 59e0f331..70e68e37 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 journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const testDepartures = require('./lib/departures') const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o) @@ -54,7 +55,18 @@ test('journeys – Magdeburg Hbf to Magdeburg-Buckau', co(function* (t) { })) // todo: journeys, only one product -// todo: journeys, fails with no product + +test('journeys – fails with no product', (t) => { + journeysFailsWithNoProduct({ + test: t, + fetchJourneys: client.journeys, + fromId: magdeburgHbf, + toId: magdeburgBuckau, + when, + products + }) + t.end() +}) test('Magdeburg Hbf to 39104 Magdeburg, Sternstr. 10', co(function*(t) { const sternStr = { diff --git a/test/lib/journeys-fails-with-no-product.js b/test/lib/journeys-fails-with-no-product.js new file mode 100644 index 00000000..b4ae96f4 --- /dev/null +++ b/test/lib/journeys-fails-with-no-product.js @@ -0,0 +1,23 @@ +'use strict' + +const journeysFailsWithNoProduct = (cfg) => { + const { + test: t, + fetchJourneys, + fromId, + toId, + when, + products + } = cfg + + const productsObj = Object.create(null) + for (let p of products) productsObj[p.id] = false + + t.throws(() => { + client.journeys(fromId, toId, {when, products}) + // silence rejections, we're only interested in exceptions + .catch(() => {}) + }) +} + +module.exports = journeysFailsWithNoProduct diff --git a/test/nahsh.js b/test/nahsh.js index 3c2db30d..34f816be 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 journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const testDepartures = require('./lib/departures') const when = createWhen('Europe/Berlin', 'de-DE') @@ -87,7 +88,18 @@ test('journeys – Kiel Hbf to Flensburg', co(function* (t) { })) // todo: journeys, only one product -// todo: journeys, fails with no product + +test('journeys – fails with no product', (t) => { + journeysFailsWithNoProduct({ + test: t, + fetchJourneys: client.journeys, + fromId: kielHbf, + toId: flensburg, + when, + products + }) + t.end() +}) test('Kiel Hbf to Husum, Zingel 10', co(function* (t) { const zingel = { diff --git a/test/oebb.js b/test/oebb.js index d32efdd5..fc92c581 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 journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const testDepartures = require('./lib/departures') const when = createWhen('Europe/Vienna', 'de-AT') @@ -79,7 +80,18 @@ test.skip('journeys – Salzburg Hbf to Wien Westbahnhof', co(function* (t) { })) // todo: journeys, only one product -// todo: journeys, fails with no product + +test('journeys – fails with no product', (t) => { + journeysFailsWithNoProduct({ + test: t, + fetchJourneys: client.journeys, + fromId: salzburgHbf, + toId: wienFickeystr, + when, + products + }) + t.end() +}) test('Salzburg Hbf to 1220 Wien, Wagramer Straße 5', co(function* (t) { const wagramerStr = { diff --git a/test/vbb.js b/test/vbb.js index 7d84092f..23574746 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 journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const testDepartures = require('./lib/departures') const when = createWhen('Europe/Berlin', 'de-DE') @@ -159,26 +160,14 @@ test('journeys – only subway', co(function* (t) { })) test('journeys – fails with no product', (t) => { - // todo: make this test work - // t.plan(1) - try { - client.journeys(spichernstr, bismarckstr, { - when, - products: { - suburban: false, - subway: false, - tram: false, - bus: false, - ferry: false, - express: false, - regional: false - } - }) - // silence rejections, we're only interested in exceptions - .catch(() => {}) - } catch (err) { - t.ok(err, 'error thrown') - } + journeysFailsWithNoProduct({ + test: t, + fetchJourneys: client.journeys, + fromId: spichernstr, + toId: bismarckstr, + when, + products + }) t.end() })