db-vendo-client/test/e2e/lib/refresh-journey.js

41 lines
811 B
JavaScript
Raw Normal View History

'use strict'
const simplify = j => j.legs.map(l => {
return {
origin: l.origin,
destination: l.destination,
2019-08-23 19:37:23 +02:00
departure: l.plannedDeparture || l.departure,
arrival: l.plannedArrival || l.arrival,
line: l.line
}
})
2018-11-21 19:07:37 +01:00
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)
2018-11-21 19:07:37 +01:00
const refreshed = await refreshJourney(model.refreshToken, {
stopovers: false
})
t.deepEqual(simplify(refreshed), simplify(model))
2018-11-21 19:07:37 +01:00
}
module.exports = testRefreshJourney