db-vendo-client/test/lib/journeys-walking-speed.js
2020-01-05 17:50:56 +01:00

29 lines
1.2 KiB
JavaScript

'use strict'
const isRoughlyEqual = require('is-roughly-equal')
const testJourneysWalkingSpeed = async (cfg) => {
const {test: t, journeys, validate, from, to, products, minTimeDifference} = cfg
const {journeys: [journeyWithFastWalking]} = await journeys(from, to, {
results: 1, products, walkingSpeed: 'fast'
})
const legWithFastWalking = journeyWithFastWalking.legs.find(l => l.walking)
t.ok(legWithFastWalking, 'no walking leg in journey with fast walking')
const {journeys: [journeyWithSlowWalking]} = await journeys(from, to, {
results: 1, products, walkingSpeed: 'slow'
})
const legWithSlowWalking = journeyWithSlowWalking.legs.find(l => l.walking)
t.ok(legWithSlowWalking, 'no walking leg in journey with slow walking')
const fastDist = legWithFastWalking.distance
const slowDist = legWithSlowWalking.distance
t.ok(isRoughlyEqual(100, fastDist, slowDist), 'precondition failed')
const fastDur = new Date(legWithFastWalking.arrival) - new Date(legWithFastWalking.departure)
const slowDur = new Date(legWithSlowWalking.arrival) - new Date(legWithSlowWalking.departure)
t.notOk(isRoughlyEqual(minTimeDifference, fastDur, slowDur), 'walkingSpeed not applied')
t.end()
}
module.exports = testJourneysWalkingSpeed