From da10988b2915555d00786a54449218b977f1b59c Mon Sep 17 00:00:00 2001 From: Jannis R Date: Tue, 24 Jul 2018 18:16:46 +0200 Subject: [PATCH] add tests for refreshJourneys (c88071f) :white_check_mark: --- test/db.js | 14 ++++++++++ test/insa.js | 14 ++++++++++ test/lib/refresh-journey.js | 51 +++++++++++++++++++++++++++++++++++++ test/nahsh.js | 14 ++++++++++ test/oebb.js | 14 ++++++++++ test/vbb.js | 14 ++++++++++ test/vbn.js | 14 ++++++++++ 7 files changed, 135 insertions(+) create mode 100644 test/lib/refresh-journey.js diff --git a/test/db.js b/test/db.js index 2486a412..e4d0d013 100644 --- a/test/db.js +++ b/test/db.js @@ -20,6 +20,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 testRefreshJourney = require('./lib/refresh-journey') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const testDepartures = require('./lib/departures') const testDeparturesInDirection = require('./lib/departures-in-direction') @@ -192,6 +193,19 @@ test('earlier/later journeys, Jungfernheide -> München Hbf', co(function* (t) { t.end() })) +test('refreshJourney', co(function* (t) { + yield testRefreshJourney({ + test: t, + fetchJourneys: client.journeys, + refreshJourney: client.refreshJourney, + validate, + fromId: jungfernheide, + toId: münchenHbf, + when + }) + t.end() +})) + test('trip details', co(function* (t) { const journeys = yield client.journeys(berlinHbf, münchenHbf, { results: 1, departure: when diff --git a/test/insa.js b/test/insa.js index 90aee588..cca2762b 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 testRefreshJourney = require('./lib/refresh-journey') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const testDepartures = require('./lib/departures') const testDeparturesInDirection = require('./lib/departures-in-direction') @@ -154,6 +155,19 @@ test('earlier/later journeys', co(function* (t) { t.end() })) +test('refreshJourney', co(function* (t) { + yield testRefreshJourney({ + test: t, + fetchJourneys: client.journeys, + refreshJourney: client.refreshJourney, + validate, + fromId: magdeburgHbf, + toId: magdeburgBuckau, + when + }) + t.end() +})) + test('trip details', co(function* (t) { const journeys = yield client.journeys(magdeburgHbf, magdeburgBuckau, { results: 1, departure: when diff --git a/test/lib/refresh-journey.js b/test/lib/refresh-journey.js new file mode 100644 index 00000000..8311e689 --- /dev/null +++ b/test/lib/refresh-journey.js @@ -0,0 +1,51 @@ +'use strict' + +const co = require('./co') + +const simplify = j => j.legs.map(l => { + let departure = null + if (l.departure) { + departure = +new Date(l.departure) + if ('number' === typeof l.departureDelay) departure -= l.departureDelay * 1000 + } + let arrival = null + if (l.arrival) { + arrival = +new Date(l.arrival) + if ('number' === typeof l.arrivalDelay) arrival -= l.arrivalDelay * 1000 + } + return { + origin: l.origin, + destination: l.destination, + scheduledDeparture: departure, + scheduledArrival: arrival, + line: l.line + } +}) + +const testRefreshJourney = co(function* (cfg) { + const { + test: t, + fetchJourneys, + refreshJourney, + fromId, + toId, + when, + // todo: validate + } = cfg + + const [model] = yield fetchJourneys(fromId, toId, { + results: 1, departure: when, + stopovers: false + }) + + // todo: move to journeys validator? + t.equal(typeof model.refreshToken, 'string') + t.ok(model.refreshToken) + + const refreshed = yield refreshJourney(model.refreshToken, { + stopovers: false + }) + t.deepEqual(simplify(refreshed), simplify(model)) +}) + +module.exports = testRefreshJourney diff --git a/test/nahsh.js b/test/nahsh.js index f17c1c62..bd5bd8d4 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 testRefreshJourney = require('./lib/refresh-journey') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const testDepartures = require('./lib/departures') const testDeparturesInDirection = require('./lib/departures-in-direction') @@ -186,6 +187,19 @@ test('earlier/later journeys, Kiel Hbf -> Flensburg', co(function* (t) { t.end() })) +test('refreshJourney', co(function* (t) { + yield testRefreshJourney({ + test: t, + fetchJourneys: client.journeys, + refreshJourney: client.refreshJourney, + validate, + fromId: kielHbf, + toId: flensburg, + when + }) + t.end() +})) + // todo: with detour test // todo: without detour test diff --git a/test/oebb.js b/test/oebb.js index f383e6ba..6ee84408 100644 --- a/test/oebb.js +++ b/test/oebb.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 testRefreshJourney = require('./lib/refresh-journey') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const testJourneysWithDetour = require('./lib/journeys-with-detour') const testDeparturesInDirection = require('./lib/departures-in-direction') @@ -213,6 +214,19 @@ test('earlier/later journeys, Salzburg Hbf -> Wien Westbahnhof', co(function* (t t.end() })) +test('refreshJourney', co(function* (t) { + yield testRefreshJourney({ + test: t, + fetchJourneys: client.journeys, + refreshJourney: client.refreshJourney, + validate, + fromId: salzburgHbf, + toId: wienWestbahnhof, + when + }) + t.end() +})) + test('trip details', co(function* (t) { const journeys = yield client.journeys(wienWestbahnhof, muenchenHbf, { results: 1, departure: when diff --git a/test/vbb.js b/test/vbb.js index 9968fcd4..219ee366 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 testRefreshJourney = require('./lib/refresh-journey') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const testDepartures = require('./lib/departures') const testDeparturesInDirection = require('./lib/departures-in-direction') @@ -189,6 +190,19 @@ test('earlier/later journeys', co(function* (t) { t.end() })) +test('refreshJourney', co(function* (t) { + yield testRefreshJourney({ + test: t, + fetchJourneys: client.journeys, + refreshJourney: client.refreshJourney, + validate, + fromId: spichernstr, + toId: bismarckstr, + when + }) + t.end() +})) + test('trip details', co(function* (t) { const journeys = yield client.journeys(spichernstr, amrumerStr, { results: 1, departure: when diff --git a/test/vbn.js b/test/vbn.js index 241e442a..6b6bacea 100644 --- a/test/vbn.js +++ b/test/vbn.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 testRefreshJourney = require('./lib/refresh-journey') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const testDepartures = require('./lib/departures') const testArrivals = require('./lib/arrivals') @@ -146,6 +147,19 @@ test.skip('earlier/later journeys', co(function* (t) { t.end() })) +test.skip('refreshJourney', co(function* (t) { + yield testRefreshJourney({ + test: t, + fetchJourneys: client.journeys, + refreshJourney: client.refreshJourney, + validate, + fromId: bremenHbf, + toId: bremerhavenHbf, + when + }) + t.end() +})) + test.skip('trip details', co(function* (t) { const journeys = yield client.journeys(bremenHbf, bremerhavenHbf, { results: 1, departure: when