db-vendo-client/test/e2e/lib/refresh-journey.js
2021-05-20 16:49:21 +01:00

40 lines
806 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.same(simplify(refreshed), simplify(model))
}
module.exports = testRefreshJourney