2018-07-24 18:16:46 +02:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
const testRefreshJourney = async (cfg) => {
|
2018-07-24 18:16:46 +02:00
|
|
|
const {
|
|
|
|
test: t,
|
|
|
|
fetchJourneys,
|
|
|
|
refreshJourney,
|
|
|
|
fromId,
|
|
|
|
toId,
|
|
|
|
when,
|
|
|
|
// todo: validate
|
|
|
|
} = cfg
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
const [model] = await fetchJourneys(fromId, toId, {
|
2018-07-24 18:16:46 +02:00
|
|
|
results: 1, departure: when,
|
|
|
|
stopovers: false
|
|
|
|
})
|
|
|
|
|
|
|
|
// todo: move to journeys validator?
|
|
|
|
t.equal(typeof model.refreshToken, 'string')
|
|
|
|
t.ok(model.refreshToken)
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
const refreshed = await refreshJourney(model.refreshToken, {
|
2018-07-24 18:16:46 +02:00
|
|
|
stopovers: false
|
|
|
|
})
|
|
|
|
t.deepEqual(simplify(refreshed), simplify(model))
|
2018-11-21 19:07:37 +01:00
|
|
|
}
|
2018-07-24 18:16:46 +02:00
|
|
|
|
|
|
|
module.exports = testRefreshJourney
|