db-vendo-client/test/e2e/lib/arrivals.js

32 lines
678 B
JavaScript
Raw Normal View History

2018-11-21 19:07:37 +01:00
const testArrivals = async (cfg) => {
const {test: t, res, validate} = cfg;
const ids = cfg.ids || (cfg.id
? [cfg.id]
: []);
const {arrivals: arrs} = res;
validate(t, res, 'arrivalsResponse', 'res');
2018-06-26 18:10:41 +02:00
for (let i = 0; i < arrs.length; i++) {
let stop = arrs[i].stop;
let name = `res.arrivals[${i}].stop`;
if (stop.station) {
stop = stop.station;
name += '.station';
2018-07-11 13:25:22 +02:00
}
2018-06-26 18:10:41 +02:00
2021-08-24 00:43:20 +02:00
t.ok(
ids.includes(stop.id)
|| stop.station && ids.includes(stop.station.id),
2021-08-24 00:43:20 +02:00
name + '.id is invalid',
);
2018-06-26 18:10:41 +02:00
}
// todo: move into arrivals validator
t.same(arrs, arrs.sort((a, b) => t.when > b.when), 'res.arrivals must be sorted by .when');
};
2018-06-26 18:10:41 +02:00
2022-05-07 16:17:37 +02:00
export {
testArrivals,
};