mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 23:29:35 +02:00
40 lines
811 B
JavaScript
40 lines
811 B
JavaScript
'use strict'
|
|
|
|
const simplify = j => j.legs.map(l => {
|
|
return {
|
|
origin: l.origin,
|
|
destination: l.destination,
|
|
departure: l.plannedDeparture || l.departure,
|
|
arrival: l.plannedArrival || l.arrival,
|
|
line: l.line
|
|
}
|
|
})
|
|
|
|
const testRefreshJourney = async (cfg) => {
|
|
const {
|
|
test: t,
|
|
fetchJourneys,
|
|
refreshJourney,
|
|
fromId,
|
|
toId,
|
|
when,
|
|
// todo: validate
|
|
} = cfg
|
|
|
|
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')
|
|
t.ok(model.refreshToken)
|
|
|
|
const refreshed = await refreshJourney(model.refreshToken, {
|
|
stopovers: false
|
|
})
|
|
t.deepEqual(simplify(refreshed), simplify(model))
|
|
}
|
|
|
|
module.exports = testRefreshJourney
|