diff --git a/test/bvg.js b/test/bvg.js index 421e734d..75598244 100644 --- a/test/bvg.js +++ b/test/bvg.js @@ -66,7 +66,7 @@ const jannowitzbrücke = '900000100004' const hour = 60 * 60 * 1000 test('journeys – Spichernstr. to Bismarckstr.', async (t) => { - const journeys = await client.journeys(spichernstr, bismarckstr, { + const res = await client.journeys(spichernstr, bismarckstr, { results: 3, departure: when, stopovers: true @@ -74,7 +74,7 @@ test('journeys – Spichernstr. to Bismarckstr.', async (t) => { await testJourneysStationToStation({ test: t, - journeys, + res, validate, fromId: spichernstr, toId: bismarckstr @@ -85,7 +85,7 @@ test('journeys – Spichernstr. to Bismarckstr.', async (t) => { }) test('journeys – only subway', async (t) => { - const journeys = await client.journeys(spichernstr, bismarckstr, { + const res = await client.journeys(spichernstr, bismarckstr, { results: 20, departure: when, products: { @@ -99,14 +99,15 @@ test('journeys – only subway', async (t) => { } }) - validate(t, journeys, 'journeys', 'journeys') - t.ok(journeys.length > 1) - for (let i = 0; i < journeys.length; i++) { - const journey = journeys[i] + validate(t, res, 'journeysResult', 'res') + + t.ok(res.journeys.length > 1) + for (let i = 0; i < res.journeys.length; i++) { + const journey = res.journeys[i] for (let j = 0; j < journey.legs.length; j++) { const leg = journey.legs[j] - const name = `journeys[${i}].legs[${j}].line` + const name = `res.journeys[${i}].legs[${j}].line` if (leg.line) { t.equal(leg.line.mode, 'train', name + '.mode is invalid') t.equal(leg.line.product, 'subway', name + '.product is invalid') @@ -166,11 +167,11 @@ test('refreshJourney', async (t) => { }) test('trip details', async (t) => { - const journeys = await client.journeys(spichernstr, amrumerStr, { + const res = await client.journeys(spichernstr, amrumerStr, { results: 1, departure: when }) - const p = journeys[0].legs[0] + const p = res.journeys[0].legs[0] t.ok(p.tripId, 'precondition failed') t.ok(p.line.name, 'precondition failed') const trip = await client.trip(p.tripId, p.line.name, {when}) @@ -186,14 +187,14 @@ test('journeys – station to address', async (t) => { latitude: 52.541797, longitude: 13.350042 } - const journeys = await client.journeys(spichernstr, torfstr, { + const res = await client.journeys(spichernstr, torfstr, { results: 3, departure: when }) await testJourneysStationToAddress({ test: t, - journeys, + res, validate, fromId: spichernstr, to: torfstr @@ -209,14 +210,14 @@ test('journeys – station to POI', async (t) => { latitude: 52.543333, longitude: 13.351686 } - const journeys = await client.journeys(spichernstr, atze, { + const res = await client.journeys(spichernstr, atze, { results: 3, departure: when }) await testJourneysStationToPoi({ test: t, - journeys, + res, validate, fromId: spichernstr, to: atze @@ -227,7 +228,7 @@ test('journeys – station to POI', async (t) => { test('journeys: via works – with detour', async (t) => { // Going from Westhafen to Wedding via Württembergalle without detour // is currently impossible. We check if the routing engine computes a detour. - const journeys = await client.journeys(westhafen, wedding, { + const res = await client.journeys(westhafen, wedding, { via: württembergallee, results: 1, departure: when, @@ -236,7 +237,7 @@ test('journeys: via works – with detour', async (t) => { await testJourneysWithDetour({ test: t, - journeys, + res, validate, detourIds: [württembergallee] }) diff --git a/test/cmta.js b/test/cmta.js index d682482e..f0081f68 100644 --- a/test/cmta.js +++ b/test/cmta.js @@ -42,7 +42,7 @@ const domain = '5919' const capitol591 = '591' test('journeys – Broadie Oaks to Domain', async (t) => { - const journeys = await client.journeys(broadieOaks, domain, { + const res = await client.journeys(broadieOaks, domain, { results: 3, departure: when, stopovers: true @@ -50,7 +50,7 @@ test('journeys – Broadie Oaks to Domain', async (t) => { await testJourneysStationToStation({ test: t, - journeys, + res, validate, fromId: broadieOaks, toId: domain @@ -80,14 +80,14 @@ test('Domain to 1104 Elm Street, Austin, TX 78703', async (t) => { longitude: -97.758292 } - const journeys = await client.journeys(domain, someAddress, { + const res = await client.journeys(domain, someAddress, { results: 3, departure: when }) await testJourneysStationToAddress({ test: t, - journeys, + res, validate, fromId: domain, to: someAddress @@ -103,14 +103,14 @@ test('Domain to Whole Foods Market - North Lamar Blvd', async (t) => { latitude: 30.270653, longitude: -97.753564 } - const journeys = await client.journeys(domain, wholeFoodsMarket, { + const res = await client.journeys(domain, wholeFoodsMarket, { results: 3, departure: when }) await testJourneysStationToPoi({ test: t, - journeys, + res, validate, fromId: domain, to: wholeFoodsMarket @@ -148,11 +148,11 @@ test('refreshJourney', async (t) => { }) test('trip details', async (t) => { - const journeys = await client.journeys(broadieOaks, domain, { + const res = await client.journeys(broadieOaks, domain, { results: 1, departure: when }) - const p = journeys[0].legs[0] + const p = res.journeys[0].legs[0] t.ok(p.tripId, 'precondition failed') t.ok(p.line.name, 'precondition failed') const trip = await client.trip(p.tripId, p.line.name, {when}) diff --git a/test/db.js b/test/db.js index 413eb470..21d8d532 100644 --- a/test/db.js +++ b/test/db.js @@ -88,7 +88,7 @@ const blnJannowitzbrücke = '8089019' const potsdamHbf = '8012666' test('journeys – Berlin Schwedter Str. to München Hbf', async (t) => { - const journeys = await client.journeys(blnSchwedterStr, münchenHbf, { + const res = await client.journeys(blnSchwedterStr, münchenHbf, { results: 3, departure: when, stopovers: true @@ -96,13 +96,13 @@ test('journeys – Berlin Schwedter Str. to München Hbf', async (t) => { await testJourneysStationToStation({ test: t, - journeys, + res, validate, fromId: blnSchwedterStr, toId: münchenHbf }) // todo: find a journey where there pricing info is always available - for (let journey of journeys) { + for (let journey of res.journeys) { if (journey.price) assertValidPrice(t, journey.price) } @@ -130,14 +130,14 @@ test('Berlin Schwedter Str. to Torfstraße 17', async (t) => { latitude: 52.5416823, longitude: 13.3491223 } - const journeys = await client.journeys(blnSchwedterStr, torfstr, { + const res = await client.journeys(blnSchwedterStr, torfstr, { results: 3, departure: when }) await testJourneysStationToAddress({ test: t, - journeys, + res, validate, fromId: blnSchwedterStr, to: torfstr @@ -153,14 +153,14 @@ test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => { latitude: 52.542417, longitude: 13.350437 } - const journeys = await client.journeys(blnSchwedterStr, atze, { + const res = await client.journeys(blnSchwedterStr, atze, { results: 3, departure: when }) await testJourneysStationToPoi({ test: t, - journeys, + res, validate, fromId: blnSchwedterStr, to: atze @@ -171,7 +171,7 @@ test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => { test('journeys: via works – with detour', async (t) => { // Going from Westhafen to Wedding via Württembergalle without detour // is currently impossible. We check if the routing engine computes a detour. - const journeys = await client.journeys(westhafen, wedding, { + const res = await client.journeys(westhafen, wedding, { via: württembergallee, results: 1, departure: when, @@ -180,7 +180,7 @@ test('journeys: via works – with detour', async (t) => { await testJourneysWithDetour({ test: t, - journeys, + res, validate, detourIds: [württembergallee] }) @@ -226,11 +226,11 @@ test('refreshJourney', async (t) => { }) test('trip details', async (t) => { - const journeys = await client.journeys(berlinHbf, münchenHbf, { + const res = await client.journeys(berlinHbf, münchenHbf, { results: 1, departure: when }) - const p = journeys[0].legs[0] + const p = res.journeys[0].legs[0] t.ok(p.tripId, 'precondition failed') t.ok(p.line.name, 'precondition failed') const trip = await client.trip(p.tripId, p.line.name, {when}) diff --git a/test/insa.js b/test/insa.js index adcb9eb3..ed3a0106 100644 --- a/test/insa.js +++ b/test/insa.js @@ -47,7 +47,7 @@ const dessau = '8010077' const universitaet = '19686' test('journeys – Magdeburg Hbf to Magdeburg-Buckau', async (t) => { - const journeys = await client.journeys(magdeburgHbf, magdeburgBuckau, { + const res = await client.journeys(magdeburgHbf, magdeburgBuckau, { results: 3, departure: when, stopovers: true @@ -55,7 +55,7 @@ test('journeys – Magdeburg Hbf to Magdeburg-Buckau', async (t) => { await testJourneysStationToStation({ test: t, - journeys, + res, validate, fromId: magdeburgHbf, toId: magdeburgBuckau @@ -85,14 +85,14 @@ test('Magdeburg Hbf to 39104 Magdeburg, Sternstr. 10', async (t) => { longitude: 11.422332 } - const journeys = await client.journeys(magdeburgHbf, sternStr, { + const res = await client.journeys(magdeburgHbf, sternStr, { results: 3, departure: when }) await testJourneysStationToAddress({ test: t, - journeys, + res, validate, fromId: magdeburgHbf, to: sternStr @@ -108,14 +108,14 @@ test('Magdeburg Hbf to Kloster Unser Lieben Frauen', async (t) => { latitude: 52.127601, longitude: 11.636437 } - const journeys = await client.journeys(magdeburgHbf, kloster, { + const res = await client.journeys(magdeburgHbf, kloster, { results: 3, departure: when }) await testJourneysStationToPoi({ test: t, - journeys, + res, validate, fromId: magdeburgHbf, to: kloster @@ -127,7 +127,7 @@ test('journeys: via works – with detour', async (t) => { // Going from Magdeburg, Hasselbachplatz (Sternstr.) (Tram/Bus) to Stendal // via Dessau without detour is currently impossible. We check if the routing // engine computes a detour. - const journeys = await client.journeys(hasselbachplatzSternstrasse, stendal, { + const res = await client.journeys(hasselbachplatzSternstrasse, stendal, { via: dessau, results: 1, departure: when, @@ -136,7 +136,7 @@ test('journeys: via works – with detour', async (t) => { await testJourneysWithDetour({ test: t, - journeys, + res, validate, detourIds: [dessau] }) @@ -159,11 +159,11 @@ test('earlier/later journeys', async (t) => { }) test('trip details', async (t) => { - const journeys = await client.journeys(magdeburgHbf, magdeburgBuckau, { + const res = await client.journeys(magdeburgHbf, magdeburgBuckau, { results: 1, departure: when }) - const p = journeys[0].legs[0] + const p = res.journeys[0].legs[0] t.ok(p.tripId, 'precondition failed') t.ok(p.line.name, 'precondition failed') const trip = await client.trip(p.tripId, p.line.name, {when}) diff --git a/test/lib/earlier-later-journeys.js b/test/lib/earlier-later-journeys.js index 8eff697f..76c11a77 100644 --- a/test/lib/earlier-later-journeys.js +++ b/test/lib/earlier-later-journeys.js @@ -51,7 +51,7 @@ const testEarlierLaterJourneys = async (cfg) => { }) let earliestDep = Infinity, latestDep = -Infinity - for (let j of model) { + for (let j of model.journeys) { if (j.legs[0].departure === null) continue const dep = +new Date(j.legs[0].departure) if (dep < earliestDep) earliestDep = dep @@ -63,7 +63,7 @@ const testEarlierLaterJourneys = async (cfg) => { // todo: single journey ref? earlierThan: model.earlierRef }) - for (let j of earlier) { + for (let j of earlier.journeys) { const firstLeg = j.legs[0] const dep = new Date(firstLeg.departure || firstLeg.formerScheduledDeparture) t.ok(dep < earliestDep) @@ -74,7 +74,7 @@ const testEarlierLaterJourneys = async (cfg) => { // todo: single journey ref? laterThan: model.laterRef }) - for (let j of later) { + for (let j of later.journeys) { const firstLeg = j.legs[0] const dep = new Date(firstLeg.departure || firstLeg.formerScheduledDeparture) t.ok(dep > latestDep) diff --git a/test/lib/journeys-station-to-address.js b/test/lib/journeys-station-to-address.js index 5c67d0b8..cce06045 100644 --- a/test/lib/journeys-station-to-address.js +++ b/test/lib/journeys-station-to-address.js @@ -3,10 +3,12 @@ const isRoughlyEqual = require('is-roughly-equal') const testJourneysStationToAddress = async (cfg) => { - const {test: t, journeys, validate, fromId} = cfg + const {test: t, res, validate, fromId} = cfg const {address, latitude, longitude} = cfg.to - validate(t, journeys, 'journeys', 'journeys') + validate(t, res, 'journeysResult', 'res') + const {journeys} = res + t.strictEqual(journeys.length, 3) for (let i = 0; i < journeys.length; i++) { const j = journeys[i] @@ -16,7 +18,7 @@ const testJourneysStationToAddress = async (cfg) => { t.ok(orig.id, fromId) const d = j.legs[j.legs.length - 1].destination - const n = `journeys[0].legs[${i}].destination` + const n = `res.journeys[0].legs[${i}].destination` t.strictEqual(d.type, 'location', n + '.type is invalid') t.strictEqual(d.address, address, n + '.address is invalid') diff --git a/test/lib/journeys-station-to-poi.js b/test/lib/journeys-station-to-poi.js index a5fe94b6..474152de 100644 --- a/test/lib/journeys-station-to-poi.js +++ b/test/lib/journeys-station-to-poi.js @@ -3,16 +3,18 @@ const isRoughlyEqual = require('is-roughly-equal') const testJourneysStationToPoi = async (cfg) => { - const {test: t, journeys, validate, fromId} = cfg + const {test: t, res, validate, fromId} = cfg const {id, name, latitude, longitude} = cfg.to - validate(t, journeys, 'journeys', 'journeys') + validate(t, res, 'journeysResult', 'res') + const {journeys} = res + t.strictEqual(journeys.length, 3) for (let i = 0; i < journeys.length; i++) { const j = journeys[i] let o = j.legs[0].origin - let oN = `journeys[0].legs[0].destination` + let oN = `res.journeys[0].legs[0].destination` if (o.station) { o = o.station oN += '.station' @@ -20,7 +22,7 @@ const testJourneysStationToPoi = async (cfg) => { t.strictEqual(o.id, fromId) let d = j.legs[j.legs.length - 1].destination - let dN = `journeys[${i}].legs[${j.legs.length - 1}].destination` + let dN = `res.journeys[${i}].legs[${j.legs.length - 1}].destination` if (d.station) { d = d.station dN += '.station' diff --git a/test/lib/journeys-station-to-station.js b/test/lib/journeys-station-to-station.js index fb0a8de8..4c5402fa 100644 --- a/test/lib/journeys-station-to-station.js +++ b/test/lib/journeys-station-to-station.js @@ -1,9 +1,11 @@ 'use strict' const testJourneysStationToStation = async (cfg) => { - const {test: t, journeys, validate, fromId, toId} = cfg + const {test: t, res, validate, fromId, toId} = cfg + + validate(t, res, 'journeysResult', 'res') + const {journeys} = res - validate(t, journeys, 'journeys', 'journeys') t.strictEqual(journeys.length, 3) for (let i = 0; i < journeys.length; i++) { const j = journeys[i] diff --git a/test/lib/journeys-with-detour.js b/test/lib/journeys-with-detour.js index 45980127..7263d910 100644 --- a/test/lib/journeys-with-detour.js +++ b/test/lib/journeys-with-detour.js @@ -1,12 +1,13 @@ 'use strict' const testJourneysWithDetour = async (cfg) => { - const {test: t, journeys, validate, detourIds} = cfg + const {test: t, res, validate, detourIds} = cfg // We assume that going from A to B via C *without* detour is currently // impossible. We check if the routing engine computes a detour. - validate(t, journeys, 'journeys', 'journeys') + validate(t, res, 'journeysResult', 'res') + const {journeys} = res const leg = journeys[0].legs.some((leg) => { return leg.stopovers && leg.stopovers.some((st) => ( diff --git a/test/lib/refresh-journey.js b/test/lib/refresh-journey.js index 774aff16..ea60306a 100644 --- a/test/lib/refresh-journey.js +++ b/test/lib/refresh-journey.js @@ -31,10 +31,11 @@ const testRefreshJourney = async (cfg) => { // todo: validate } = cfg - const [model] = await fetchJourneys(fromId, toId, { + const modelRes = await fetchJourneys(fromId, toId, { results: 1, departure: when, stopovers: false }) + const [model] = modelRes.journeys // todo: move to journeys validator? t.equal(typeof model.refreshToken, 'string') diff --git a/test/lib/validators.js b/test/lib/validators.js index eedfbe68..9f0510a1 100644 --- a/test/lib/validators.js +++ b/test/lib/validators.js @@ -304,6 +304,12 @@ const validateJourneys = (val, js, name = 'journeys') => { } } +const validateJourneysResult = (val, res, name = 'journeysResult') => { + a.ok(isObj(res), name + ' must be an object') + // todo: `earlierRef`, `laterRef` + val.journeys(val, res.journeys, name + '.journeys') +} + const validateTrip = (val, trip, name = 'trip') => { const withFakeTripId = Object.assign({ tripId: trip.id @@ -458,6 +464,7 @@ module.exports = { journeyLeg: createValidateJourneyLeg, journey: () => validateJourney, journeys: () => validateJourneys, + journeysResult: () => validateJourneysResult, trip: () => validateTrip, arrival: createValidateArrival, departure: createValidateDeparture, diff --git a/test/nahsh.js b/test/nahsh.js index baae8836..7b5b2e70 100644 --- a/test/nahsh.js +++ b/test/nahsh.js @@ -76,7 +76,7 @@ const seefischmarkt = '9049245' const kielRaeucherei = '9049217' test('journeys – Kiel Hbf to Flensburg', async (t) => { - const journeys = await client.journeys(kielHbf, flensburg, { + const res = await client.journeys(kielHbf, flensburg, { results: 3, departure: when, stopovers: true @@ -84,16 +84,16 @@ test('journeys – Kiel Hbf to Flensburg', async (t) => { await testJourneysStationToStation({ test: t, - journeys, + res, validate, fromId: kielHbf, toId: flensburg }) - for (let i = 0; i < journeys.length; i++) { - const j = journeys[i] + for (let i = 0; i < res.journeys.length; i++) { + const j = res.journeys[i] // todo: find a journey where there pricing info is always available - if (j.price) assertValidPrice(t, j.price, `journeys[${i}].price`) + if (j.price) assertValidPrice(t, j.price, `res.journeys[${i}].price`) } t.end() @@ -120,14 +120,14 @@ test('Kiel Hbf to Berliner Str. 80, Husum', async (t) => { latitude: 54.488995, longitude: 9.056263 } - const journeys = await client.journeys(kielHbf, berlinerStr, { + const res = await client.journeys(kielHbf, berlinerStr, { results: 3, departure: when }) await testJourneysStationToAddress({ test: t, - journeys, + res, validate, fromId: kielHbf, to: berlinerStr @@ -143,14 +143,14 @@ test('Kiel Hbf to Holstentor', async (t) => { latitude: 53.866321, longitude: 10.679976 } - const journeys = await client.journeys(kielHbf, holstentor, { + const res = await client.journeys(kielHbf, holstentor, { results: 3, departure: when }) await testJourneysStationToPoi({ test: t, - journeys, + res, validate, fromId: kielHbf, to: holstentor @@ -159,16 +159,16 @@ test('Kiel Hbf to Holstentor', async (t) => { }) test('Husum to Lübeck Hbf with stopover at Kiel Hbf', async (t) => { - const journeys = await client.journeys(husum, luebeckHbf, { + const res = await client.journeys(husum, luebeckHbf, { via: kielHbf, results: 1, departure: when, stopovers: true }) - validate(t, journeys, 'journeys', 'journeys') + validate(t, res, 'journeysResult', 'res') - const leg = journeys[0].legs.some((leg) => { + const leg = res.journeys[0].legs.some((leg) => { return leg.stopovers && leg.stopovers.some((stopover) => { const s = stopover.stop return s.station && s.station.id === kielHbf || s.id === kielHbf @@ -209,11 +209,11 @@ test('refreshJourney', async (t) => { // todo: without detour test test('trip details', async (t) => { - const journeys = await client.journeys(flensburg, husum, { + const res = await client.journeys(flensburg, husum, { results: 1, departure: when }) - const p = journeys[0].legs[0] + const p = res.journeys[0].legs[0] t.ok(p.tripId, 'precondition failed') t.ok(p.line.name, 'precondition failed') const trip = await client.trip(p.tripId, p.line.name, {when}) diff --git a/test/oebb.js b/test/oebb.js index 4fd5d142..2d98b75e 100644 --- a/test/oebb.js +++ b/test/oebb.js @@ -67,7 +67,7 @@ const wienKarlsplatz = '1390461' const wienPilgramgasse = '1390562' test.skip('journeys – Salzburg Hbf to Wien Westbahnhof', async (t) => { - const journeys = await client.journeys(salzburgHbf, wienFickeystr, { + const res = await client.journeys(salzburgHbf, wienFickeystr, { results: 3, departure: when, stopovers: true @@ -75,15 +75,15 @@ test.skip('journeys – Salzburg Hbf to Wien Westbahnhof', async (t) => { await testJourneysStationToStation({ test: t, - journeys, + res, 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`) + for (let i = 0; i < res.journeys.length; i++) { + const j = res.journeys[i] + if (j.price) assertValidPrice(t, j.price, `res.journeys[${i}].price`) } t.end() @@ -110,14 +110,14 @@ test('Salzburg Hbf to 1220 Wien, Wagramer Straße 5', async (t) => { latitude: 48.236216, longitude: 16.425863 } - const journeys = await client.journeys(salzburgHbf, wagramerStr, { + const res = await client.journeys(salzburgHbf, wagramerStr, { results: 3, departure: when }) await testJourneysStationToAddress({ test: t, - journeys, + res, validate, fromId: salzburgHbf, to: wagramerStr @@ -133,13 +133,13 @@ test('Salzburg Hbf to Albertina', async (t) => { latitude: 48.204699, longitude: 16.368404 } - const journeys = await client.journeys(salzburgHbf, albertina, { + const res = await client.journeys(salzburgHbf, albertina, { results: 3, departure: when }) await testJourneysStationToPoi({ test: t, - journeys, + res, validate, fromId: salzburgHbf, to: albertina @@ -154,7 +154,7 @@ test('journeys: via works – with detour', async (t) => { const schottenring = '1390163' const donauinsel = '1392277' const donauinselPassed = '922001' - const journeys = await client.journeys(stephansplatz, schottenring, { + const res = await client.journeys(stephansplatz, schottenring, { via: donauinsel, results: 1, departure: when, @@ -163,7 +163,7 @@ test('journeys: via works – with detour', async (t) => { await testJourneysWithDetour({ test: t, - journeys, + res, validate, detourIds: [donauinsel, donauinselPassed] }) @@ -178,16 +178,16 @@ test('journeys: via works – without detour', async (t) => { const museumsquartier = '1390171' const museumsquartierPassed = '901014' - const journeys = await client.journeys(karlsplatz, praterstern, { + const res = await client.journeys(karlsplatz, praterstern, { via: museumsquartier, results: 1, departure: when, stopovers: true }) - validate(t, journeys, 'journeys', 'journeys') + validate(t, res, 'journeysResult', 'res') - const l1 = journeys[0].legs.some((leg) => { + const l1 = res.journeys[0].legs.some((leg) => { return ( leg.destination.id === museumsquartier || leg.destination.id === museumsquartierPassed @@ -195,7 +195,7 @@ test('journeys: via works – without detour', async (t) => { }) t.notOk(l1, 'transfer at Museumsquartier') - const l2 = journeys[0].legs.some((leg) => { + const l2 = res.journeys[0].legs.some((leg) => { return leg.stopovers && leg.stopovers.some((stopover) => { return stopover.stop.id === museumsquartierPassed }) @@ -232,11 +232,11 @@ test('refreshJourney', async (t) => { }) test('trip details', async (t) => { - const journeys = await client.journeys(wienWestbahnhof, muenchenHbf, { + const res = await client.journeys(wienWestbahnhof, muenchenHbf, { results: 1, departure: when }) - const p = journeys[0].legs[0] + const p = res.journeys[0].legs[0] t.ok(p.tripId, 'precondition failed') t.ok(p.line.name, 'precondition failed') const trip = await client.trip(p.tripId, p.line.name, {when}) diff --git a/test/saarfahrplan.js b/test/saarfahrplan.js index e5f63357..aeca72e4 100644 --- a/test/saarfahrplan.js +++ b/test/saarfahrplan.js @@ -84,14 +84,14 @@ test('journeys – fails with no product', (t) => { }) test('Saarbrücken Hbf to Neunkirchen, Thomas-Mann-Straße 1', async (t) => { - const journeys = await client.journeys(saarbrueckenHbf, thomasMannStr, { + const res = await client.journeys(saarbrueckenHbf, thomasMannStr, { results: 3, departure: when }) await testJourneysStationToAddress({ test: t, - journeys, + res, validate, fromId: saarbrueckenHbf, to: thomasMannStr @@ -107,13 +107,13 @@ test('Saarbrücken Hbf to Schlossberghöhlen', async (t) => { name: 'Homburg, Schlossberghöhlen', id: '9000185' } - const journeys = await client.journeys(saarbrueckenHbf, schlossberghoehlen, { + const res = await client.journeys(saarbrueckenHbf, schlossberghoehlen, { results: 3, departure: when }) await testJourneysStationToPoi({ test: t, - journeys, + res, validate, fromId: saarbrueckenHbf, to: schlossberghoehlen @@ -128,7 +128,7 @@ test.skip('journeys: via works – with detour', async (t) => { const schottenring = '1390163' const donauinsel = '1392277' const donauinselPassed = '922001' - const journeys = await client.journeys(stephansplatz, schottenring, { + const res = await client.journeys(stephansplatz, schottenring, { via: donauinsel, results: 1, departure: when, @@ -137,7 +137,7 @@ test.skip('journeys: via works – with detour', async (t) => { await testJourneysWithDetour({ test: t, - journeys, + res, validate, detourIds: [donauinsel, donauinselPassed] }) @@ -152,16 +152,16 @@ test.skip('journeys: via works – without detour', async (t) => { const museumsquartier = '1390171' const museumsquartierPassed = '901014' - const journeys = await client.journeys(karlsplatz, praterstern, { + const res = await client.journeys(karlsplatz, praterstern, { via: museumsquartier, results: 1, departure: when, stopovers: true }) - validate(t, journeys, 'journeys', 'journeys') + validate(t, res, 'journeysResult', 'res') - const l1 = journeys[0].legs.some((leg) => { + const l1 = res.journeys[0].legs.some((leg) => { return ( leg.destination.id === museumsquartier || leg.destination.id === museumsquartierPassed @@ -169,7 +169,7 @@ test.skip('journeys: via works – without detour', async (t) => { }) t.notOk(l1, 'transfer at Museumsquartier') - const l2 = journeys[0].legs.some((leg) => { + const l2 = res.journeys[0].legs.some((leg) => { return leg.stopovers && leg.stopovers.some((stopover) => { return stopover.stop.id === museumsquartierPassed }) @@ -193,11 +193,11 @@ test('earlier/later journeys, Saarbrücken Hbf -> Saarlouis Hbf', async (t) => { }) test('trip details', async (t) => { - const journeys = await client.journeys(saarlouisHbf, metzVille, { + const res = await client.journeys(saarlouisHbf, metzVille, { results: 1, departure: when }) - const p = journeys[0].legs[0] + const p = res.journeys[0].legs[0] t.ok(p.tripId, 'precondition failed') t.ok(p.line.name, 'precondition failed') const trip = await client.trip(p.tripId, p.line.name, { when }) diff --git a/test/sbahn-muenchen.js b/test/sbahn-muenchen.js index dc09ba8b..8a581429 100644 --- a/test/sbahn-muenchen.js +++ b/test/sbahn-muenchen.js @@ -63,7 +63,7 @@ const poetschnerstr = { } test('journeys – Mittersendling to Karl-Theodor-Straße', async (t) => { - const journeys = await client.journeys(mittersendling, karlTheodorStr, { + const res = await client.journeys(mittersendling, karlTheodorStr, { results: 3, departure: when, stopovers: true @@ -71,7 +71,7 @@ test('journeys – Mittersendling to Karl-Theodor-Straße', async (t) => { await testJourneysStationToStation({ test: t, - journeys, + res, validate, fromId: mittersendling, toId: karlTheodorStr @@ -94,14 +94,14 @@ test('journeys – fails with no product', (t) => { }) test('Karl-Theodor-Straße to Pötschnerstraße 3, Neuhausen', async (t) => { - const journeys = await client.journeys(karlTheodorStr, poetschnerstr, { + const res = await client.journeys(karlTheodorStr, poetschnerstr, { results: 3, departure: when }) await testJourneysStationToAddress({ test: t, - journeys, + res, validate, fromId: karlTheodorStr, to: poetschnerstr @@ -117,14 +117,14 @@ test('Karl-Theodor-Straße to Hofbräuhaus', async (t) => { latitude: 48.137739, longitude: 11.579823 } - const journeys = await client.journeys(karlTheodorStr, hofbraeuhaus, { + const res = await client.journeys(karlTheodorStr, hofbraeuhaus, { results: 3, departure: when }) await testJourneysStationToPoi({ test: t, - journeys, + res, validate, fromId: karlTheodorStr, to: hofbraeuhaus @@ -162,11 +162,11 @@ test('refreshJourney', async (t) => { }) test('trip details', async (t) => { - const journeys = await client.journeys(mittersendling, karlTheodorStr, { + const res = await client.journeys(mittersendling, karlTheodorStr, { results: 1, departure: when }) - const p = journeys[0].legs.find(leg => leg.line) + const p = res.journeys[0].legs.find(leg => leg.line) t.ok(p.tripId, 'precondition failed') t.ok(p.line.name, 'precondition failed') const trip = await client.trip(p.tripId, p.line.name, {when}) diff --git a/test/vbb.js b/test/vbb.js index 27e9c48f..81d669db 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -49,7 +49,7 @@ const wedding = '900000009104' const württembergallee = '900000026153' test('journeys – Spichernstr. to Bismarckstr.', async (t) => { - const journeys = await client.journeys({ + const res = await client.journeys({ type: 'stop', id: spichernstr, name: 'U Spichernstr.' @@ -61,7 +61,7 @@ test('journeys – Spichernstr. to Bismarckstr.', async (t) => { await testJourneysStationToStation({ test: t, - journeys, + res, validate, fromId: spichernstr, toId: bismarckstr @@ -72,7 +72,7 @@ test('journeys – Spichernstr. to Bismarckstr.', async (t) => { }) test('journeys – only subway', async (t) => { - const journeys = await client.journeys(spichernstr, bismarckstr, { + const res = await client.journeys(spichernstr, bismarckstr, { results: 20, departure: when, products: { @@ -86,14 +86,15 @@ test('journeys – only subway', async (t) => { } }) - validate(t, journeys, 'journeys', 'journeys') - t.ok(journeys.length > 1) - for (let i = 0; i < journeys.length; i++) { - const journey = journeys[i] + validate(t, res, 'journeysResult', 'res') + + t.ok(res.journeys.length > 1) + for (let i = 0; i < res.journeys.length; i++) { + const journey = res.journeys[i] for (let j = 0; j < journey.legs.length; j++) { const leg = journey.legs[j] - const name = `journeys[${i}].legs[${i}].line` + const name = `res.journeys[${i}].legs[${i}].line` if (leg.line) { t.equal(leg.line.mode, 'train', name + '.mode is invalid') t.equal(leg.line.product, 'subway', name + '.product is invalid') @@ -146,11 +147,11 @@ test('refreshJourney', async (t) => { }) test('trip details', async (t) => { - const journeys = await client.journeys(spichernstr, amrumerStr, { + const res = await client.journeys(spichernstr, amrumerStr, { results: 1, departure: when }) - const p = journeys[0].legs[0] + const p = res.journeys[0].legs[0] t.ok(p.tripId, 'precondition failed') t.ok(p.line.name, 'precondition failed') const trip = await client.trip(p.tripId, p.line.name, {when}) @@ -166,14 +167,14 @@ test('journeys – station to address', async (t) => { latitude: 52.541797, longitude: 13.350042 } - const journeys = await client.journeys(spichernstr, torfstr, { + const res = await client.journeys(spichernstr, torfstr, { results: 3, departure: when }) await testJourneysStationToAddress({ test: t, - journeys, + res, validate, fromId: spichernstr, to: torfstr @@ -189,14 +190,14 @@ test('journeys – station to POI', async (t) => { latitude: 52.543333, longitude: 13.351686 } - const journeys = await client.journeys(spichernstr, atze, { + const res = await client.journeys(spichernstr, atze, { results: 3, departure: when }) await testJourneysStationToPoi({ test: t, - journeys, + res, validate, fromId: spichernstr, to: atze @@ -207,7 +208,7 @@ test('journeys – station to POI', async (t) => { test('journeys: via works – with detour', async (t) => { // Going from Westhafen to Wedding via Württembergalle without detour // is currently impossible. We check if the routing engine computes a detour. - const journeys = await client.journeys(westhafen, wedding, { + const res = await client.journeys(westhafen, wedding, { via: württembergallee, results: 1, departure: when, @@ -216,7 +217,7 @@ test('journeys: via works – with detour', async (t) => { await testJourneysWithDetour({ test: t, - journeys, + res, validate, detourIds: [württembergallee] }) diff --git a/test/vbn.js b/test/vbn.js index 7dfa01c9..440ec64a 100644 --- a/test/vbn.js +++ b/test/vbn.js @@ -40,7 +40,7 @@ const bremenHbf = '8000050' const bremerhavenHbf = '8000051' test.only('journeys – Bremen Hbf to Bremerhaven Hbf', async (t) => { - const journeys = await client.journeys(bremenHbf, bremerhavenHbf, { + const res = await client.journeys(bremenHbf, bremerhavenHbf, { results: 3, departure: when, stopovers: true @@ -48,7 +48,7 @@ test.only('journeys – Bremen Hbf to Bremerhaven Hbf', async (t) => { await testJourneysStationToStation({ test: t, - journeys, + res, validate, fromId: bremenHbf, toId: bremerhavenHbf @@ -78,14 +78,14 @@ test.skip('Magdeburg Hbf to 39104 Magdeburg, Sternstr. 10', async (t) => { longitude: 11.422332 } - const journeys = await client.journeys(bremenHbf, sternStr, { + const res = await client.journeys(bremenHbf, sternStr, { results: 3, departure: when }) await testJourneysStationToAddress({ test: t, - journeys, + res, validate, fromId: bremenHbf, to: sternStr @@ -101,14 +101,14 @@ test.skip('Magdeburg Hbf to Kloster Unser Lieben Frauen', async (t) => { latitude: 52.127601, longitude: 11.636437 } - const journeys = await client.journeys(bremenHbf, kloster, { + const res = await client.journeys(bremenHbf, kloster, { results: 3, departure: when }) await testJourneysStationToPoi({ test: t, - journeys, + res, validate, fromId: bremenHbf, to: kloster @@ -120,7 +120,7 @@ test.skip('journeys: via works – with detour', async (t) => { // Going from Magdeburg, Hasselbachplatz (Sternstr.) (Tram/Bus) to Stendal // via Dessau without detour is currently impossible. We check if the routing // engine computes a detour. - const journeys = await client.journeys(hasselbachplatzSternstrasse, stendal, { + const res = await client.journeys(hasselbachplatzSternstrasse, stendal, { via: dessau, results: 1, departure: when, @@ -129,7 +129,7 @@ test.skip('journeys: via works – with detour', async (t) => { await testJourneysWithDetour({ test: t, - journeys, + res, validate, detourIds: [dessau] }) @@ -165,11 +165,11 @@ test.skip('refreshJourney', async (t) => { }) test.skip('trip details', async (t) => { - const journeys = await client.journeys(bremenHbf, bremerhavenHbf, { + const res = await client.journeys(bremenHbf, bremerhavenHbf, { results: 1, departure: when }) - const p = journeys[0].legs[0] + const p = res.journeys[0].legs[0] t.ok(p.tripId, 'precondition failed') t.ok(p.line.name, 'precondition failed') const trip = await client.trip(p.tripId, p.line.name, {when})