diff --git a/test/db.js b/test/db.js index 21dc36e5..89cf28c1 100644 --- a/test/db.js +++ b/test/db.js @@ -15,6 +15,7 @@ const { station: createValidateStation } = require('./lib/validators') const createValidate = require('./lib/validate-fptf-with') +const testJourneysStationToStation = require('./lib/journeys-station-to-station') const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o) @@ -60,18 +61,26 @@ const client = createClient(dbProfile) const berlinHbf = '8011160' const münchenHbf = '8000261' const jungfernheide = '8011167' +const blnSchwedterStr = '732652' const atze = '991598902' const westhafen = '008089116' const wedding = '008089131' const württembergallee = '731084' const regensburgHbf = '8000309' -test('Berlin Jungfernheide to München Hbf', co(function* (t) { - const journeys = yield client.journeys(jungfernheide, münchenHbf, { - when, passedStations: true +test('journeys – Berlin Schwedter Str. to München Hbf', co(function* (t) { + const journeys = yield client.journeys(blnSchwedterStr, münchenHbf, { + results: 3, when, passedStations: true }) - validate(t, journeys, 'journeys', 'journeys') + yield testJourneysStationToStation({ + test: t, + journeys, + validate, + fromId: blnSchwedterStr, + toId: münchenHbf + }) + // todo: find a journey where there pricing info is always available for (let journey of journeys) { if (journey.price) assertValidPrice(t, journey.price) } diff --git a/test/insa.js b/test/insa.js index 33c6a439..99b48497 100644 --- a/test/insa.js +++ b/test/insa.js @@ -10,6 +10,7 @@ const createClient = require('..') const insaProfile = require('../p/insa') const products = require('../p/insa/products') const createValidate = require('./lib/validate-fptf-with') +const testJourneysStationToStation = require('./lib/journeys-station-to-station') const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o) @@ -32,20 +33,18 @@ const hasselbachplatzSternstrasse = '000006545' const stendal = '008010334' const dessau = '008010077' -test('Magdeburg Hbf to Magdeburg-Buckau', co(function*(t) { +test('journeys – Magdeburg Hbf to Magdeburg-Buckau', co(function* (t) { const journeys = yield client.journeys(magdeburgHbf, magdeburgBuckau, { - when, - passedStations: true + results: 3, when, passedStations: true }) - validate(t, journeys, 'journeys', 'journeys') - - for (let j of journeys) { - const firstLeg = j.legs[0] - const lastLeg = j.legs[j.legs.length - 1] - t.strictEqual(firstLeg.origin.id, magdeburgHbf) - t.strictEqual(lastLeg.destination.id, magdeburgBuckau) - } + yield testJourneysStationToStation({ + test: t, + journeys, + validate, + fromId: magdeburgHbf, + toId: magdeburgBuckau + }) t.end() })) diff --git a/test/lib/journeys-station-to-station.js b/test/lib/journeys-station-to-station.js new file mode 100644 index 00000000..8d44fce4 --- /dev/null +++ b/test/lib/journeys-station-to-station.js @@ -0,0 +1,20 @@ +'use strict' + +const co = require('./co') + +const testJourneysStationToStation = co(function* (cfg) { + const {test: t, journeys, validate, fromId, toId} = cfg + + validate(t, journeys, 'journeys', 'journeys') + t.strictEqual(journeys.length, 3) + for (let i = 0; i < journeys.length; i++) { + const j = journeys[i] + + const firstLeg = j.legs[0] + const lastLeg = j.legs[j.legs.length - 1] + t.strictEqual(firstLeg.origin.id, fromId) + t.strictEqual(lastLeg.destination.id, toId) + } +}) + +module.exports = testJourneysStationToStation diff --git a/test/nahsh.js b/test/nahsh.js index b0d3c7f0..6b41e9b3 100644 --- a/test/nahsh.js +++ b/test/nahsh.js @@ -14,6 +14,7 @@ const { station: createValidateStation } = require('./lib/validators') const createValidate = require('./lib/validate-fptf-with') +const testJourneysStationToStation = require('./lib/journeys-station-to-station') const when = createWhen('Europe/Berlin', 'de-DE') @@ -60,24 +61,25 @@ const luebeckHbf = '8000237' const husum = '8000181' const schleswig = '8005362' -test('Kiel Hbf to Flensburg', co(function* (t) { +test('journeys – Kiel Hbf to Flensburg', co(function* (t) { const journeys = yield client.journeys(kielHbf, flensburg, { - when, passedStations: true, results: 3 + results: 3, when, passedStations: true + }) + + yield testJourneysStationToStation({ + test: t, + journeys, + validate, + fromId: kielHbf, + toId: flensburg }) - validate(t, journeys, 'journeys', 'journeys') - t.strictEqual(journeys.length, 3) for (let i = 0; i < journeys.length; i++) { const j = journeys[i] - - const firstLeg = j.legs[0] - const lastLeg = j.legs[j.legs.length - 1] - t.strictEqual(firstLeg.origin.id, kielHbf) - t.strictEqual(lastLeg.destination.id, flensburg) - // todo: find a journey where there pricing info is always available - if (j.price) assertValidPrice(t, j.price) + if (j.price) assertValidPrice(t, j.price, `journeys[${i}].price`) } + t.end() })) diff --git a/test/oebb.js b/test/oebb.js index 2913160f..529b0a40 100644 --- a/test/oebb.js +++ b/test/oebb.js @@ -14,6 +14,7 @@ const { station: createValidateStation } = require('./lib/validators') const createValidate = require('./lib/validate-fptf-with') +const testJourneysStationToStation = require('./lib/journeys-station-to-station') const when = createWhen('Europe/Vienna', 'de-AT') @@ -45,20 +46,29 @@ const test = tapePromise(tape) const client = createClient(oebbProfile) const salzburgHbf = '8100002' -const wienWestbahnhof = '1291501' +const wienFickeystr = '911014' const wien = '1190100' +const wienWestbahnhof = '1291501' const klagenfurtHbf = '8100085' const muenchenHbf = '8000261' const wienRenngasse = '1390186' -test('Salzburg Hbf to Wien Westbahnhof', co(function* (t) { - const journeys = yield client.journeys(salzburgHbf, wienWestbahnhof, { - when, passedStations: true +test('journeys – Salzburg Hbf to Wien Westbahnhof', co(function* (t) { + const journeys = yield client.journeys(salzburgHbf, wienFickeystr, { + results: 3, when, passedStations: true }) - validate(t, journeys, 'journeys', 'journeys') - for (let journey of journeys) { - if (journey.price) assertValidPrice(t, journey.price) + yield testJourneysStationToStation({ + test: t, + journeys, + validate, + fromId: salzburgHbf, + toId: wienFickeystr + }) + + for (let i = 0; i < journeys.length; i++) { + const j = journeys[i] + if (j.price) assertValidPrice(t, j.price, `journeys[${i}].price`) } t.end() diff --git a/test/vbb.js b/test/vbb.js index ac194542..e49d5ef1 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -20,8 +20,7 @@ const { movement: _validateMovement } = require('./lib/validators') const createValidate = require('./lib/validate-fptf-with') - -const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o) +const testJourneysStationToStation = require('./lib/journeys-station-to-station') const when = createWhen('Europe/Berlin', 'de-DE') @@ -106,23 +105,20 @@ const württembergallee = '900000026153' const berlinerStr = '900000044201' const landhausstr = '900000043252' -test('journeys – station to station', co(function* (t) { - const journeys = yield client.journeys(spichernstr, amrumerStr, { +test('journeys – Spichernstr. to Bismarckstr.', co(function* (t) { + const journeys = yield client.journeys(spichernstr, bismarckstr, { results: 3, when, passedStations: true }) - validate(t, journeys, 'journeys', 'journeys') - t.strictEqual(journeys.length, 3) - for (let i = 0; i < journeys.length; i++) { - const j = journeys[i] + yield testJourneysStationToStation({ + test: t, + journeys, + validate, + fromId: spichernstr, + toId: bismarckstr + }) + // todo: find a journey where there ticket info is always available - const firstLeg = j.legs[0] - const lastLeg = j.legs[j.legs.length - 1] - t.strictEqual(firstLeg.origin.id, spichernstr) - t.strictEqual(lastLeg.destination.id, amrumerStr) - - // todo: find a journey where there ticket info is always available - } t.end() }))