add tests for refreshJourneys (c88071f)

This commit is contained in:
Jannis R 2018-07-24 18:16:46 +02:00 committed by Jannis Redmann
parent 8a45d26fda
commit da10988b29
7 changed files with 135 additions and 0 deletions

View file

@ -20,6 +20,7 @@ const testJourneysStationToStation = require('./lib/journeys-station-to-station'
const testJourneysStationToAddress = require('./lib/journeys-station-to-address') const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
const testJourneysStationToPoi = require('./lib/journeys-station-to-poi') const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
const testRefreshJourney = require('./lib/refresh-journey')
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
const testDepartures = require('./lib/departures') const testDepartures = require('./lib/departures')
const testDeparturesInDirection = require('./lib/departures-in-direction') const testDeparturesInDirection = require('./lib/departures-in-direction')
@ -192,6 +193,19 @@ test('earlier/later journeys, Jungfernheide -> München Hbf', co(function* (t) {
t.end() 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) { test('trip details', co(function* (t) {
const journeys = yield client.journeys(berlinHbf, münchenHbf, { const journeys = yield client.journeys(berlinHbf, münchenHbf, {
results: 1, departure: when results: 1, departure: when

View file

@ -14,6 +14,7 @@ const testJourneysStationToStation = require('./lib/journeys-station-to-station'
const testJourneysStationToAddress = require('./lib/journeys-station-to-address') const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
const testJourneysStationToPoi = require('./lib/journeys-station-to-poi') const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
const testRefreshJourney = require('./lib/refresh-journey')
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
const testDepartures = require('./lib/departures') const testDepartures = require('./lib/departures')
const testDeparturesInDirection = require('./lib/departures-in-direction') const testDeparturesInDirection = require('./lib/departures-in-direction')
@ -154,6 +155,19 @@ test('earlier/later journeys', co(function* (t) {
t.end() 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) { test('trip details', co(function* (t) {
const journeys = yield client.journeys(magdeburgHbf, magdeburgBuckau, { const journeys = yield client.journeys(magdeburgHbf, magdeburgBuckau, {
results: 1, departure: when results: 1, departure: when

View file

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

View file

@ -18,6 +18,7 @@ const testJourneysStationToStation = require('./lib/journeys-station-to-station'
const testJourneysStationToAddress = require('./lib/journeys-station-to-address') const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
const testJourneysStationToPoi = require('./lib/journeys-station-to-poi') const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
const testRefreshJourney = require('./lib/refresh-journey')
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
const testDepartures = require('./lib/departures') const testDepartures = require('./lib/departures')
const testDeparturesInDirection = require('./lib/departures-in-direction') const testDeparturesInDirection = require('./lib/departures-in-direction')
@ -186,6 +187,19 @@ test('earlier/later journeys, Kiel Hbf -> Flensburg', co(function* (t) {
t.end() 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: with detour test
// todo: without detour test // todo: without detour test

View file

@ -19,6 +19,7 @@ const testJourneysStationToStation = require('./lib/journeys-station-to-station'
const testJourneysStationToAddress = require('./lib/journeys-station-to-address') const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
const testJourneysStationToPoi = require('./lib/journeys-station-to-poi') const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
const testRefreshJourney = require('./lib/refresh-journey')
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
const testJourneysWithDetour = require('./lib/journeys-with-detour') const testJourneysWithDetour = require('./lib/journeys-with-detour')
const testDeparturesInDirection = require('./lib/departures-in-direction') const testDeparturesInDirection = require('./lib/departures-in-direction')
@ -213,6 +214,19 @@ test('earlier/later journeys, Salzburg Hbf -> Wien Westbahnhof', co(function* (t
t.end() 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) { test('trip details', co(function* (t) {
const journeys = yield client.journeys(wienWestbahnhof, muenchenHbf, { const journeys = yield client.journeys(wienWestbahnhof, muenchenHbf, {
results: 1, departure: when results: 1, departure: when

View file

@ -24,6 +24,7 @@ const testJourneysStationToStation = require('./lib/journeys-station-to-station'
const testJourneysStationToAddress = require('./lib/journeys-station-to-address') const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
const testJourneysStationToPoi = require('./lib/journeys-station-to-poi') const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
const testRefreshJourney = require('./lib/refresh-journey')
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
const testDepartures = require('./lib/departures') const testDepartures = require('./lib/departures')
const testDeparturesInDirection = require('./lib/departures-in-direction') const testDeparturesInDirection = require('./lib/departures-in-direction')
@ -189,6 +190,19 @@ test('earlier/later journeys', co(function* (t) {
t.end() 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) { test('trip details', co(function* (t) {
const journeys = yield client.journeys(spichernstr, amrumerStr, { const journeys = yield client.journeys(spichernstr, amrumerStr, {
results: 1, departure: when results: 1, departure: when

View file

@ -14,6 +14,7 @@ const testJourneysStationToStation = require('./lib/journeys-station-to-station'
const testJourneysStationToAddress = require('./lib/journeys-station-to-address') const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
const testJourneysStationToPoi = require('./lib/journeys-station-to-poi') const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
const testRefreshJourney = require('./lib/refresh-journey')
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
const testDepartures = require('./lib/departures') const testDepartures = require('./lib/departures')
const testArrivals = require('./lib/arrivals') const testArrivals = require('./lib/arrivals')
@ -146,6 +147,19 @@ test.skip('earlier/later journeys', co(function* (t) {
t.end() 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) { test.skip('trip details', co(function* (t) {
const journeys = yield client.journeys(bremenHbf, bremerhavenHbf, { const journeys = yield client.journeys(bremenHbf, bremerhavenHbf, {
results: 1, departure: when results: 1, departure: when