mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
41 lines
1 KiB
JavaScript
41 lines
1 KiB
JavaScript
'use strict'
|
|
|
|
const co = require('./co')
|
|
|
|
const testDeparturesWithoutUnrelatedStations = co(function* (cfg) {
|
|
const {
|
|
test: t,
|
|
fetchDepartures,
|
|
id,
|
|
when
|
|
// duration, products
|
|
} = cfg
|
|
|
|
const relatedLines = cfg.linesOfRelatedStations
|
|
.map(lName => lName.toLowerCase().trim())
|
|
|
|
const isUnrelatedLine = (dep) => {
|
|
if (!dep.line || !dep.line.name) return false
|
|
return relatedLines.includes(dep.line.name.toLowerCase().trim())
|
|
}
|
|
|
|
const depsWith = yield fetchDepartures(id, {
|
|
when,
|
|
duration: cfg.duration || 20,
|
|
products: cfg.products || {}
|
|
})
|
|
t.ok(depsWith.some(isUnrelatedLine), 'precondition failed: no line at related station found')
|
|
|
|
const depsWithout = yield fetchDepartures(id, {
|
|
includeRelatedStations: false,
|
|
when,
|
|
duration: cfg.duration || 20,
|
|
products: cfg.products || {}
|
|
})
|
|
|
|
const unrelatedDep = depsWithout.find(isUnrelatedLine)
|
|
if (unrelatedDep) t.fail('line at related station: ' + unrelatedDep.line.name)
|
|
else t.pass('no lines from related stations')
|
|
})
|
|
|
|
module.exports = testDeparturesWithoutUnrelatedStations
|