db-vendo-client/test/lib/departures-without-related-stations.js

40 lines
1 KiB
JavaScript
Raw Normal View History

'use strict'
2018-11-21 19:07:37 +01:00
const testDeparturesWithoutUnrelatedStations = async (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())
}
2018-11-21 19:07:37 +01:00
const depsWith = await fetchDepartures(id, {
when,
duration: cfg.duration || 20,
products: cfg.products || {}
})
t.ok(depsWith.some(isUnrelatedLine), 'precondition failed: no line at related station found')
2018-11-21 19:07:37 +01:00
const depsWithout = await 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')
2018-11-21 19:07:37 +01:00
}
module.exports = testDeparturesWithoutUnrelatedStations