2018-06-26 18:10:41 +02:00
|
|
|
'use strict'
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
const testArrivals = async (cfg) => {
|
2021-08-24 00:43:20 +02:00
|
|
|
const {test: t, arrivals: arrs, validate} = cfg
|
|
|
|
const ids = cfg.ids || (cfg.id ? [cfg.id] : [])
|
2018-06-26 18:10:41 +02:00
|
|
|
|
|
|
|
validate(t, arrs, 'arrivals', 'arrivals')
|
|
|
|
t.ok(arrs.length > 0, 'must be >0 arrivals')
|
|
|
|
for (let i = 0; i < arrs.length; i++) {
|
2018-07-16 11:56:47 +02:00
|
|
|
let stop = arrs[i].stop
|
|
|
|
let name = `arrs[${i}].stop`
|
|
|
|
if (stop.station) {
|
|
|
|
stop = stop.station
|
2018-07-11 13:25:22 +02:00
|
|
|
name += '.station'
|
|
|
|
}
|
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)),
|
|
|
|
name + '.id is invalid',
|
|
|
|
)
|
2018-06-26 18:10:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// todo: move into arrivals validator
|
2021-05-20 16:42:43 +01:00
|
|
|
t.same(arrs, arrs.sort((a, b) => t.when > b.when))
|
2018-11-21 19:07:37 +01:00
|
|
|
}
|
2018-06-26 18:10:41 +02:00
|
|
|
|
|
|
|
module.exports = testArrivals
|