mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
add tests for refreshJourneys (c88071f) ✅
This commit is contained in:
parent
8a45d26fda
commit
da10988b29
7 changed files with 135 additions and 0 deletions
14
test/db.js
14
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
|
||||
|
|
14
test/insa.js
14
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
|
||||
|
|
51
test/lib/refresh-journey.js
Normal file
51
test/lib/refresh-journey.js
Normal 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
|
|
@ -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
|
||||
|
||||
|
|
14
test/oebb.js
14
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
|
||||
|
|
14
test/vbb.js
14
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
|
||||
|
|
14
test/vbn.js
14
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
|
||||
|
|
Loading…
Add table
Reference in a new issue