2018-04-23 13:56:00 +02:00
|
|
|
'use strict'
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
const testJourneysStationToStation = async (cfg) => {
|
2020-05-22 01:36:04 +02:00
|
|
|
const {test: t, res, validate} = cfg
|
|
|
|
const fromIds = cfg.fromIds || (cfg.fromId ? [cfg.fromId] : [])
|
|
|
|
const toIds = cfg.toIds || (cfg.toId ? [cfg.toId] : [])
|
2019-01-16 21:41:17 +08:00
|
|
|
|
|
|
|
validate(t, res, 'journeysResult', 'res')
|
|
|
|
const {journeys} = res
|
2018-04-23 13:56:00 +02:00
|
|
|
|
2019-02-01 15:35:18 +01:00
|
|
|
t.strictEqual(journeys.length, 4)
|
2018-04-23 13:56:00 +02:00
|
|
|
for (let i = 0; i < journeys.length; i++) {
|
|
|
|
const j = journeys[i]
|
2020-05-22 01:36:04 +02:00
|
|
|
const n = `res.journeys[${i}]`
|
2018-04-23 13:56:00 +02:00
|
|
|
|
2020-05-22 01:36:04 +02:00
|
|
|
const o = j.legs[0].origin
|
|
|
|
const d = j.legs[j.legs.length - 1].destination
|
|
|
|
t.ok(
|
|
|
|
fromIds.includes(o.id) ||
|
|
|
|
(o.station && fromIds.includes(o.station.id)),
|
|
|
|
`invalid ${n}.legs[0].origin`
|
|
|
|
)
|
|
|
|
t.ok(
|
|
|
|
toIds.includes(d.id) ||
|
|
|
|
(d.station && toIds.includes(d.station.id)),
|
|
|
|
`invalid ${n}.legs[${j.legs.length - 1}].destination`
|
|
|
|
)
|
2018-04-23 13:56:00 +02:00
|
|
|
}
|
2018-11-21 19:07:37 +01:00
|
|
|
}
|
2018-04-23 13:56:00 +02:00
|
|
|
|
|
|
|
module.exports = testJourneysStationToStation
|