mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
tests for reachableFrom ✅
This commit is contained in:
parent
8b572d6184
commit
e65b2d8780
6 changed files with 142 additions and 0 deletions
20
test/bvg.js
20
test/bvg.js
|
@ -33,6 +33,7 @@ const testDeparturesInDirection = require('./lib/departures-in-direction')
|
||||||
const testDeparturesWithoutRelatedStations = require('./lib/departures-without-related-stations')
|
const testDeparturesWithoutRelatedStations = require('./lib/departures-without-related-stations')
|
||||||
const testArrivals = require('./lib/arrivals')
|
const testArrivals = require('./lib/arrivals')
|
||||||
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
||||||
|
const testReachableFrom = require('./lib/reachable-from')
|
||||||
|
|
||||||
const when = cfg.when
|
const when = cfg.when
|
||||||
|
|
||||||
|
@ -367,3 +368,22 @@ test('radar', co(function* (t) {
|
||||||
validate(t, vehicles, 'movements', 'vehicles')
|
validate(t, vehicles, 'movements', 'vehicles')
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
test('reachableFrom', co(function* (t) {
|
||||||
|
const torfstr17 = {
|
||||||
|
type: 'location',
|
||||||
|
address: '13353 Berlin-Wedding, Torfstr. 17',
|
||||||
|
latitude: 52.541797,
|
||||||
|
longitude: 13.350042
|
||||||
|
}
|
||||||
|
|
||||||
|
yield testReachableFrom({
|
||||||
|
test: t,
|
||||||
|
reachableFrom: client.reachableFrom,
|
||||||
|
loc: torfstr17,
|
||||||
|
when,
|
||||||
|
maxDuration: 15,
|
||||||
|
validate
|
||||||
|
})
|
||||||
|
t.end()
|
||||||
|
}))
|
||||||
|
|
18
test/cmta.js
18
test/cmta.js
|
@ -20,6 +20,7 @@ const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product
|
||||||
const testDepartures = require('./lib/departures')
|
const testDepartures = require('./lib/departures')
|
||||||
const testArrivals = require('./lib/arrivals')
|
const testArrivals = require('./lib/arrivals')
|
||||||
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
||||||
|
const testReachableFrom = require('./lib/reachable-from')
|
||||||
|
|
||||||
const when = createWhen(cmtaProfile.timezone, cmtaProfile.locale)
|
const when = createWhen(cmtaProfile.timezone, cmtaProfile.locale)
|
||||||
|
|
||||||
|
@ -260,3 +261,20 @@ test('radar', co(function* (t) {
|
||||||
validate(t, vehicles, 'movements', 'vehicles')
|
validate(t, vehicles, 'movements', 'vehicles')
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
test('reachableFrom', co(function* (t) {
|
||||||
|
yield testReachableFrom({
|
||||||
|
test: t,
|
||||||
|
reachableFrom: client.reachableFrom,
|
||||||
|
loc: {
|
||||||
|
type: 'location',
|
||||||
|
address: '604 W 9TH ST, Austin, TX 78701',
|
||||||
|
latitude: 30.272910,
|
||||||
|
longitude: -97.747883
|
||||||
|
},
|
||||||
|
when,
|
||||||
|
maxDuration: 15,
|
||||||
|
validate
|
||||||
|
})
|
||||||
|
t.end()
|
||||||
|
}))
|
||||||
|
|
20
test/db.js
20
test/db.js
|
@ -27,6 +27,7 @@ const testDeparturesInDirection = require('./lib/departures-in-direction')
|
||||||
const testDeparturesWithoutRelatedStations = require('./lib/departures-without-related-stations')
|
const testDeparturesWithoutRelatedStations = require('./lib/departures-without-related-stations')
|
||||||
const testArrivals = require('./lib/arrivals')
|
const testArrivals = require('./lib/arrivals')
|
||||||
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
||||||
|
const testReachableFrom = require('./lib/reachable-from')
|
||||||
|
|
||||||
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
|
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
|
||||||
|
|
||||||
|
@ -348,3 +349,22 @@ test('station', co(function* (t) {
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
test('reachableFrom', co(function* (t) {
|
||||||
|
const torfstr17 = {
|
||||||
|
type: 'location',
|
||||||
|
address: 'Torfstraße 17',
|
||||||
|
latitude: 52.5416823,
|
||||||
|
longitude: 13.3491223
|
||||||
|
}
|
||||||
|
|
||||||
|
yield testReachableFrom({
|
||||||
|
test: t,
|
||||||
|
reachableFrom: client.reachableFrom,
|
||||||
|
loc: torfstr17,
|
||||||
|
when,
|
||||||
|
maxDuration: 15,
|
||||||
|
validate
|
||||||
|
})
|
||||||
|
t.end()
|
||||||
|
}))
|
||||||
|
|
44
test/lib/reachable-from.js
Normal file
44
test/lib/reachable-from.js
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const isPlainObject = require('lodash/isPlainObject')
|
||||||
|
|
||||||
|
const co = require('./co')
|
||||||
|
|
||||||
|
const testReachableFrom = co(function* (cfg) {
|
||||||
|
const {
|
||||||
|
test: t,
|
||||||
|
reachableFrom,
|
||||||
|
loc,
|
||||||
|
when,
|
||||||
|
maxDuration,
|
||||||
|
validate
|
||||||
|
} = cfg
|
||||||
|
|
||||||
|
const results = yield reachableFrom(loc, {
|
||||||
|
when, maxDuration
|
||||||
|
})
|
||||||
|
|
||||||
|
t.ok(Array.isArray(results), 'results must an array')
|
||||||
|
t.ok(results.length > 0, 'results must have >0 items')
|
||||||
|
|
||||||
|
for (let i = 0; i < results.length; i++) {
|
||||||
|
const res = results[i]
|
||||||
|
const name = `results[${i}]`
|
||||||
|
|
||||||
|
t.ok(isPlainObject(res), name + ' must be an object')
|
||||||
|
t.equal(typeof res.duration, 'number', name + '.duration must be a number')
|
||||||
|
t.ok(res.duration > 0, name + '.duration must be >0')
|
||||||
|
|
||||||
|
t.ok(Array.isArray(res.stations), name + '.stations must be an array')
|
||||||
|
t.ok(res.stations.length > 0, name + '.stations must have >0 items')
|
||||||
|
|
||||||
|
for (let j = 0; j < res.stations.length; j++) {
|
||||||
|
validate(t, res.stations[j], ['stop', 'station'], `${name}.stations[${j}]`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const sorted = results.sort((a, b) => a.duration - b.duration)
|
||||||
|
t.deepEqual(results, sorted, 'results must be sorted by res.duration')
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = testReachableFrom
|
|
@ -23,6 +23,7 @@ const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product
|
||||||
const testDepartures = require('./lib/departures')
|
const testDepartures = require('./lib/departures')
|
||||||
const testDeparturesInDirection = require('./lib/departures-in-direction')
|
const testDeparturesInDirection = require('./lib/departures-in-direction')
|
||||||
const testArrivals = require('./lib/arrivals')
|
const testArrivals = require('./lib/arrivals')
|
||||||
|
const testReachableFrom = require('./lib/reachable-from')
|
||||||
|
|
||||||
const when = createWhen('Europe/Berlin', 'de-DE')
|
const when = createWhen('Europe/Berlin', 'de-DE')
|
||||||
|
|
||||||
|
@ -347,3 +348,22 @@ test('radar', co(function* (t) {
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
test('reachableFrom', co(function* (t) {
|
||||||
|
const berlinerStr = {
|
||||||
|
type: 'location',
|
||||||
|
address: 'Husum, Berliner Straße 80',
|
||||||
|
latitude: 54.488995,
|
||||||
|
longitude: 9.056263
|
||||||
|
}
|
||||||
|
|
||||||
|
yield testReachableFrom({
|
||||||
|
test: t,
|
||||||
|
reachableFrom: client.reachableFrom,
|
||||||
|
loc: berlinerStr,
|
||||||
|
when,
|
||||||
|
maxDuration: 60,
|
||||||
|
validate
|
||||||
|
})
|
||||||
|
t.end()
|
||||||
|
}))
|
||||||
|
|
20
test/vbb.js
20
test/vbb.js
|
@ -27,6 +27,7 @@ const testDeparturesInDirection = require('./lib/departures-in-direction')
|
||||||
const testDeparturesWithoutRelatedStations = require('./lib/departures-without-related-stations')
|
const testDeparturesWithoutRelatedStations = require('./lib/departures-without-related-stations')
|
||||||
const testArrivals = require('./lib/arrivals')
|
const testArrivals = require('./lib/arrivals')
|
||||||
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
||||||
|
const testReachableFrom = require('./lib/reachable-from')
|
||||||
|
|
||||||
const when = cfg.when
|
const when = cfg.when
|
||||||
|
|
||||||
|
@ -357,3 +358,22 @@ test('radar', co(function* (t) {
|
||||||
validate(t, vehicles, 'movements', 'vehicles')
|
validate(t, vehicles, 'movements', 'vehicles')
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
test('reachableFrom', co(function* (t) {
|
||||||
|
const torfstr17 = {
|
||||||
|
type: 'location',
|
||||||
|
address: '13353 Berlin-Wedding, Torfstr. 17',
|
||||||
|
latitude: 52.541797,
|
||||||
|
longitude: 13.350042
|
||||||
|
}
|
||||||
|
|
||||||
|
yield testReachableFrom({
|
||||||
|
test: t,
|
||||||
|
reachableFrom: client.reachableFrom,
|
||||||
|
loc: torfstr17,
|
||||||
|
when,
|
||||||
|
maxDuration: 15,
|
||||||
|
validate
|
||||||
|
})
|
||||||
|
t.end()
|
||||||
|
}))
|
||||||
|
|
Loading…
Add table
Reference in a new issue