diff --git a/test/bvg.js b/test/bvg.js index f721d3a2..a3aa3543 100644 --- a/test/bvg.js +++ b/test/bvg.js @@ -33,6 +33,7 @@ const testDeparturesInDirection = require('./lib/departures-in-direction') const testDeparturesWithoutRelatedStations = require('./lib/departures-without-related-stations') const testArrivals = require('./lib/arrivals') const testJourneysWithDetour = require('./lib/journeys-with-detour') +const testReachableFrom = require('./lib/reachable-from') const when = cfg.when @@ -367,3 +368,22 @@ test('radar', co(function* (t) { validate(t, vehicles, 'movements', 'vehicles') 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() +})) diff --git a/test/cmta.js b/test/cmta.js index a6c65e2c..a92b31fe 100644 --- a/test/cmta.js +++ b/test/cmta.js @@ -20,6 +20,7 @@ const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product const testDepartures = require('./lib/departures') const testArrivals = require('./lib/arrivals') const testJourneysWithDetour = require('./lib/journeys-with-detour') +const testReachableFrom = require('./lib/reachable-from') const when = createWhen(cmtaProfile.timezone, cmtaProfile.locale) @@ -260,3 +261,20 @@ test('radar', co(function* (t) { validate(t, vehicles, 'movements', 'vehicles') 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() +})) diff --git a/test/db.js b/test/db.js index e4d0d013..04f9b7e8 100644 --- a/test/db.js +++ b/test/db.js @@ -27,6 +27,7 @@ const testDeparturesInDirection = require('./lib/departures-in-direction') const testDeparturesWithoutRelatedStations = require('./lib/departures-without-related-stations') const testArrivals = require('./lib/arrivals') const testJourneysWithDetour = require('./lib/journeys-with-detour') +const testReachableFrom = require('./lib/reachable-from') const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o) @@ -348,3 +349,22 @@ test('station', co(function* (t) { 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() +})) diff --git a/test/lib/reachable-from.js b/test/lib/reachable-from.js new file mode 100644 index 00000000..162d8a23 --- /dev/null +++ b/test/lib/reachable-from.js @@ -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 diff --git a/test/nahsh.js b/test/nahsh.js index bd5bd8d4..8270486f 100644 --- a/test/nahsh.js +++ b/test/nahsh.js @@ -23,6 +23,7 @@ const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product const testDepartures = require('./lib/departures') const testDeparturesInDirection = require('./lib/departures-in-direction') const testArrivals = require('./lib/arrivals') +const testReachableFrom = require('./lib/reachable-from') const when = createWhen('Europe/Berlin', 'de-DE') @@ -347,3 +348,22 @@ test('radar', co(function* (t) { 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() +})) diff --git a/test/vbb.js b/test/vbb.js index bd418508..26ce99df 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -27,6 +27,7 @@ const testDeparturesInDirection = require('./lib/departures-in-direction') const testDeparturesWithoutRelatedStations = require('./lib/departures-without-related-stations') const testArrivals = require('./lib/arrivals') const testJourneysWithDetour = require('./lib/journeys-with-detour') +const testReachableFrom = require('./lib/reachable-from') const when = cfg.when @@ -357,3 +358,22 @@ test('radar', co(function* (t) { validate(t, vehicles, 'movements', 'vehicles') 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() +}))