2018-07-24 18:16:46 +02:00
|
|
|
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,
|
2024-02-06 22:58:49 +01:00
|
|
|
line: l.line,
|
|
|
|
};
|
|
|
|
});
|
2018-07-24 18:16:46 +02:00
|
|
|
|
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,
|
2021-12-29 21:14:50 +01:00
|
|
|
validate,
|
2018-07-24 18:16:46 +02:00
|
|
|
fromId,
|
|
|
|
toId,
|
|
|
|
when,
|
2024-02-06 22:58:49 +01:00
|
|
|
} = cfg;
|
2018-07-24 18:16:46 +02:00
|
|
|
|
2019-01-16 21:41:17 +08:00
|
|
|
const modelRes = await fetchJourneys(fromId, toId, {
|
2018-07-24 18:16:46 +02:00
|
|
|
results: 1, departure: when,
|
2024-02-06 22:58:49 +01:00
|
|
|
stopovers: false,
|
|
|
|
});
|
|
|
|
validate(t, modelRes, 'journeysResult', 'modelRes');
|
|
|
|
const [model] = modelRes.journeys;
|
2018-07-24 18:16:46 +02:00
|
|
|
|
|
|
|
// todo: move to journeys validator?
|
2024-02-06 22:58:49 +01:00
|
|
|
t.equal(typeof model.refreshToken, 'string');
|
|
|
|
t.ok(model.refreshToken);
|
2018-07-24 18:16:46 +02:00
|
|
|
|
2022-04-28 22:59:19 +02:00
|
|
|
const refreshedRes = await refreshJourney(model.refreshToken, {
|
2024-02-06 22:58:49 +01:00
|
|
|
stopovers: false,
|
|
|
|
});
|
|
|
|
validate(t, refreshedRes, 'refreshJourneyResult', 'refreshedRes');
|
|
|
|
const refreshed = refreshedRes.journey;
|
2021-12-29 21:14:50 +01:00
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
t.same(simplify(refreshed), simplify(model));
|
|
|
|
};
|
2018-07-24 18:16:46 +02:00
|
|
|
|
2022-05-07 16:17:37 +02:00
|
|
|
export {
|
|
|
|
testRefreshJourney,
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|