2018-11-21 19:07:37 +01:00
|
|
|
const testDepartures = async (cfg) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
const {test: t, res, validate} = cfg;
|
|
|
|
const ids = cfg.ids || (cfg.id
|
|
|
|
? [cfg.id]
|
|
|
|
: []);
|
|
|
|
const {departures: deps} = res;
|
2021-12-29 21:11:07 +01:00
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
validate(t, res, 'departuresResponse', 'res');
|
2018-04-26 16:17:53 +02:00
|
|
|
|
|
|
|
for (let i = 0; i < deps.length; i++) {
|
2024-02-06 22:58:49 +01:00
|
|
|
let stop = deps[i].stop;
|
|
|
|
let name = `res.departures[${i}].stop`;
|
2018-07-16 11:56:47 +02:00
|
|
|
if (stop.station) {
|
2024-02-06 22:58:49 +01:00
|
|
|
stop = stop.station;
|
|
|
|
name += '.station';
|
2018-07-11 13:25:22 +02:00
|
|
|
}
|
2018-04-26 16:17:53 +02:00
|
|
|
|
2021-08-24 00:43:20 +02:00
|
|
|
t.ok(
|
2024-02-06 22:58:49 +01:00
|
|
|
ids.includes(stop.id)
|
|
|
|
|| stop.station && ids.includes(stop.station.id),
|
2022-11-09 18:25:04 +01:00
|
|
|
`${name}.id is invalid (${stop.id}), must be one of ${ids.join('/')}`,
|
2024-02-06 22:58:49 +01:00
|
|
|
);
|
2018-04-26 16:17:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// todo: move into deps validator
|
2024-02-06 22:58:49 +01:00
|
|
|
t.same(deps, deps.sort((a, b) => t.when > b.when), 'res.departures must be sorted by .when');
|
|
|
|
};
|
2018-04-26 16:17:53 +02:00
|
|
|
|
2022-05-07 16:17:37 +02:00
|
|
|
export {
|
|
|
|
testDepartures,
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|