journeys fails with no product tests: use helper fn

This commit is contained in:
Jannis R 2018-04-25 13:07:31 +02:00
parent 2ffcf02946
commit fecd2aefc0
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
6 changed files with 84 additions and 24 deletions

View file

@ -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 = {

View file

@ -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 = {

View file

@ -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

View file

@ -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 = {

View file

@ -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 = {

View file

@ -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, {
journeysFailsWithNoProduct({
test: t,
fetchJourneys: client.journeys,
fromId: spichernstr,
toId: bismarckstr,
when,
products: {
suburban: false,
subway: false,
tram: false,
bus: false,
ferry: false,
express: false,
regional: false
}
products
})
// silence rejections, we're only interested in exceptions
.catch(() => {})
} catch (err) {
t.ok(err, 'error thrown')
}
t.end()
})