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

45 lines
961 B
JavaScript
Raw Permalink Normal View History

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,
validate,
fromId,
toId,
when,
} = cfg;
const modelRes = await fetchJourneys(fromId, toId, {
results: 1, departure: when,
stopovers: false,
});
validate(t, modelRes, 'journeysResult', 'modelRes');
const [model] = modelRes.journeys;
// todo: move to journeys validator?
t.equal(typeof model.refreshToken, 'string');
t.ok(model.refreshToken);
const refreshedRes = await refreshJourney(model.refreshToken, {
stopovers: false,
});
validate(t, refreshedRes, 'refreshJourneyResult', 'refreshedRes');
const refreshed = refreshedRes.journey;
t.same(simplify(refreshed), simplify(model));
};
2022-05-07 16:17:37 +02:00
export {
testRefreshJourney,
};