2018-03-14 14:54:08 +01:00
|
|
|
|
'use strict'
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
const tap = require('tap')
|
2018-03-14 14:54:08 +01:00
|
|
|
|
const isRoughlyEqual = require('is-roughly-equal')
|
|
|
|
|
|
2018-04-19 18:14:10 +02:00
|
|
|
|
const {createWhen} = require('./lib/util')
|
2019-08-30 18:31:39 +02:00
|
|
|
|
const createClient = require('../..')
|
|
|
|
|
const nahshProfile = require('../../p/nahsh')
|
|
|
|
|
const products = require('../../p/nahsh/products')
|
2018-03-14 14:54:08 +01:00
|
|
|
|
const {
|
2018-04-19 18:14:10 +02:00
|
|
|
|
line: createValidateLine,
|
|
|
|
|
station: createValidateStation
|
|
|
|
|
} = require('./lib/validators')
|
|
|
|
|
const createValidate = require('./lib/validate-fptf-with')
|
2018-04-23 13:56:00 +02:00
|
|
|
|
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
2018-04-24 15:42:53 +02:00
|
|
|
|
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
|
2018-04-24 16:10:56 +02:00
|
|
|
|
const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
|
2018-04-24 15:24:59 +02:00
|
|
|
|
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
2018-07-24 18:16:46 +02:00
|
|
|
|
const testRefreshJourney = require('./lib/refresh-journey')
|
2018-04-25 13:07:31 +02:00
|
|
|
|
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
2018-04-24 16:58:17 +02:00
|
|
|
|
const testDepartures = require('./lib/departures')
|
2018-07-07 21:26:40 +02:00
|
|
|
|
const testDeparturesInDirection = require('./lib/departures-in-direction')
|
2018-06-26 17:30:46 +02:00
|
|
|
|
const testArrivals = require('./lib/arrivals')
|
2018-08-27 12:04:14 +02:00
|
|
|
|
const testReachableFrom = require('./lib/reachable-from')
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
2022-05-03 17:16:17 +02:00
|
|
|
|
const T_MOCK = 1657618200 * 1000 // 2022-07-12T11:30+02:00
|
2022-04-23 14:40:51 +02:00
|
|
|
|
const when = createWhen(nahshProfile.timezone, nahshProfile.locale, T_MOCK)
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
2018-04-19 18:14:10 +02:00
|
|
|
|
const cfg = {
|
|
|
|
|
when,
|
|
|
|
|
stationCoordsOptional: false,
|
2019-02-15 14:53:01 +01:00
|
|
|
|
products,
|
|
|
|
|
maxLatitude: 55.15,
|
|
|
|
|
minLongitude: 7.5,
|
|
|
|
|
minLatitude: 53.15,
|
|
|
|
|
maxLongitude: 11.6
|
2018-03-14 14:54:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-19 18:14:10 +02:00
|
|
|
|
const _validateLine = createValidateLine(cfg)
|
|
|
|
|
const validateLine = (validate, l, name) => {
|
|
|
|
|
if (l && l.product === 'onCall') {
|
|
|
|
|
// skip line validation
|
|
|
|
|
// https://github.com/derhuerst/hafas-client/issues/8#issuecomment-355839965
|
|
|
|
|
l = Object.assign({}, l)
|
|
|
|
|
l.mode = 'taxi'
|
|
|
|
|
}
|
|
|
|
|
_validateLine(validate, l, name)
|
2018-03-14 14:54:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-19 18:14:10 +02:00
|
|
|
|
const validate = createValidate(cfg, {
|
|
|
|
|
line: validateLine
|
|
|
|
|
})
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
|
|
|
|
const assertValidPrice = (t, p) => {
|
|
|
|
|
t.ok(p)
|
|
|
|
|
if (p.amount !== null) {
|
|
|
|
|
t.equal(typeof p.amount, 'number')
|
|
|
|
|
t.ok(p.amount > 0)
|
|
|
|
|
}
|
|
|
|
|
if (p.hint !== null) {
|
|
|
|
|
t.equal(typeof p.hint, 'string')
|
|
|
|
|
t.ok(p.hint)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-19 21:55:54 +02:00
|
|
|
|
const client = createClient(nahshProfile, 'public-transport/hafas-client:test')
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
2018-07-11 13:43:36 +02:00
|
|
|
|
const kielHbf = '9049079'
|
|
|
|
|
const flensburg = '9027253'
|
|
|
|
|
const luebeckHbf = '9057819'
|
|
|
|
|
const husum = '9044660'
|
|
|
|
|
const schleswig = '9081683'
|
2018-07-07 21:26:40 +02:00
|
|
|
|
const ellerbekerMarkt = '9049027'
|
|
|
|
|
const seefischmarkt = '9049245'
|
2018-07-11 13:43:36 +02:00
|
|
|
|
const kielRaeucherei = '9049217'
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('journeys – Kiel Hbf to Flensburg', async (t) => {
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(kielHbf, flensburg, {
|
2019-02-01 15:35:18 +01:00
|
|
|
|
results: 4,
|
2018-05-31 13:42:54 +02:00
|
|
|
|
departure: when,
|
2018-06-13 20:39:33 +02:00
|
|
|
|
stopovers: true
|
2018-04-23 13:56:00 +02:00
|
|
|
|
})
|
|
|
|
|
|
2020-07-19 16:59:38 +02:00
|
|
|
|
const kaistr = '9049113'
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToStation({
|
2018-04-23 13:56:00 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-04-23 13:56:00 +02:00
|
|
|
|
validate,
|
2020-07-19 16:59:38 +02:00
|
|
|
|
fromIds: [kielHbf, kaistr],
|
2018-04-23 13:56:00 +02:00
|
|
|
|
toId: flensburg
|
2018-03-14 14:54:08 +01:00
|
|
|
|
})
|
|
|
|
|
|
2019-01-16 21:41:17 +08:00
|
|
|
|
for (let i = 0; i < res.journeys.length; i++) {
|
|
|
|
|
const j = res.journeys[i]
|
2018-04-19 18:14:10 +02:00
|
|
|
|
// todo: find a journey where there pricing info is always available
|
2019-01-16 21:41:17 +08:00
|
|
|
|
if (j.price) assertValidPrice(t, j.price, `res.journeys[${i}].price`)
|
2018-04-19 18:14:10 +02:00
|
|
|
|
}
|
2018-04-23 13:56:00 +02:00
|
|
|
|
|
2018-03-14 14:54:08 +01:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
2018-04-19 18:14:10 +02:00
|
|
|
|
// todo: journeys, only one product
|
2018-04-25 13:07:31 +02:00
|
|
|
|
|
2021-12-29 18:53:50 +01:00
|
|
|
|
tap.test('journeys – fails with no product', async (t) => {
|
|
|
|
|
await journeysFailsWithNoProduct({
|
2018-04-25 13:07:31 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
fromId: kielHbf,
|
|
|
|
|
toId: flensburg,
|
|
|
|
|
when,
|
|
|
|
|
products
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
2018-04-19 18:14:10 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('Kiel Hbf to Berliner Str. 80, Husum', async (t) => {
|
2018-07-16 12:15:52 +02:00
|
|
|
|
const berlinerStr = {
|
2018-03-14 14:54:08 +01:00
|
|
|
|
type: 'location',
|
2018-07-16 12:15:52 +02:00
|
|
|
|
address: 'Husum, Berliner Straße 80',
|
|
|
|
|
latitude: 54.488995,
|
|
|
|
|
longitude: 9.056263
|
2018-03-14 14:54:08 +01:00
|
|
|
|
}
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(kielHbf, berlinerStr, {
|
2018-05-31 13:42:54 +02:00
|
|
|
|
results: 3,
|
|
|
|
|
departure: when
|
2018-04-24 15:42:53 +02:00
|
|
|
|
})
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToAddress({
|
2018-04-24 15:42:53 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-04-24 15:42:53 +02:00
|
|
|
|
validate,
|
|
|
|
|
fromId: kielHbf,
|
2018-07-16 12:15:52 +02:00
|
|
|
|
to: berlinerStr
|
2018-04-24 15:42:53 +02:00
|
|
|
|
})
|
2018-03-14 14:54:08 +01:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('Kiel Hbf to Holstentor', async (t) => {
|
2018-04-24 16:10:56 +02:00
|
|
|
|
const holstentor = {
|
2018-03-14 14:54:08 +01:00
|
|
|
|
type: 'location',
|
2020-05-22 01:36:04 +02:00
|
|
|
|
id: '970003168',
|
2019-02-07 17:47:50 +01:00
|
|
|
|
poi: true,
|
2018-04-24 16:10:56 +02:00
|
|
|
|
name: 'Hansestadt Lübeck, Holstentor (Denkmal)',
|
|
|
|
|
latitude: 53.866321,
|
|
|
|
|
longitude: 10.679976
|
|
|
|
|
}
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(kielHbf, holstentor, {
|
2018-05-31 13:42:54 +02:00
|
|
|
|
results: 3,
|
|
|
|
|
departure: when
|
2018-04-24 16:10:56 +02:00
|
|
|
|
})
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToPoi({
|
2018-04-24 16:10:56 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-04-24 16:10:56 +02:00
|
|
|
|
validate,
|
|
|
|
|
fromId: kielHbf,
|
|
|
|
|
to: holstentor
|
|
|
|
|
})
|
2018-03-14 14:54:08 +01:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('Husum to Lübeck Hbf with stopover at Kiel Hbf', async (t) => {
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(husum, luebeckHbf, {
|
2018-03-14 14:54:08 +01:00
|
|
|
|
via: kielHbf,
|
|
|
|
|
results: 1,
|
2018-05-31 13:42:54 +02:00
|
|
|
|
departure: when,
|
2018-06-13 20:39:33 +02:00
|
|
|
|
stopovers: true
|
2018-03-14 14:54:08 +01:00
|
|
|
|
})
|
|
|
|
|
|
2019-01-16 21:41:17 +08:00
|
|
|
|
validate(t, res, 'journeysResult', 'res')
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const leg = res.journeys[0].legs.some((leg) => {
|
2018-06-13 20:35:06 +02:00
|
|
|
|
return leg.stopovers && leg.stopovers.some((stopover) => {
|
2018-07-11 13:25:22 +02:00
|
|
|
|
const s = stopover.stop
|
|
|
|
|
return s.station && s.station.id === kielHbf || s.id === kielHbf
|
2018-04-19 18:14:10 +02:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
t.ok(leg, 'Kiel Hbf is not being passed')
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('earlier/later journeys, Kiel Hbf -> Flensburg', async (t) => {
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testEarlierLaterJourneys({
|
2018-04-24 15:24:59 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: kielHbf,
|
2018-11-20 18:38:48 +01:00
|
|
|
|
toId: flensburg,
|
|
|
|
|
when
|
2018-03-14 14:54:08 +01:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('refreshJourney', async (t) => {
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testRefreshJourney({
|
2018-07-24 18:16:46 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
refreshJourney: client.refreshJourney,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: kielHbf,
|
|
|
|
|
toId: flensburg,
|
|
|
|
|
when
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-07-24 18:16:46 +02:00
|
|
|
|
|
2018-04-25 13:24:27 +02:00
|
|
|
|
// todo: with detour test
|
|
|
|
|
// todo: without detour test
|
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('trip details', async (t) => {
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(flensburg, husum, {
|
2018-05-28 20:35:01 +02:00
|
|
|
|
results: 1, departure: when
|
2018-03-14 14:54:08 +01:00
|
|
|
|
})
|
|
|
|
|
|
2020-04-09 14:53:28 +02:00
|
|
|
|
const p = res.journeys[0].legs.find(l => !l.walking)
|
2018-11-22 00:17:28 +01:00
|
|
|
|
t.ok(p.tripId, 'precondition failed')
|
2018-03-14 14:54:08 +01:00
|
|
|
|
t.ok(p.line.name, 'precondition failed')
|
|
|
|
|
|
2021-12-29 21:23:28 +01:00
|
|
|
|
const tripRes = await client.trip(p.tripId, p.line.name, {when})
|
|
|
|
|
|
|
|
|
|
validate(t, tripRes, 'tripResult', 'res')
|
2018-03-14 14:54:08 +01:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('departures at Kiel Räucherei', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.departures(kielRaeucherei, {
|
2018-12-28 21:17:03 +01:00
|
|
|
|
duration: 30, when,
|
2018-03-14 14:54:08 +01:00
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testDepartures({
|
2018-04-24 16:58:17 +02:00
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2018-04-24 16:58:17 +02:00
|
|
|
|
validate,
|
2018-05-30 15:51:58 +02:00
|
|
|
|
id: kielRaeucherei
|
2018-04-24 16:58:17 +02:00
|
|
|
|
})
|
2018-03-14 14:54:08 +01:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('departures with station object', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.departures({
|
2018-04-19 18:14:10 +02:00
|
|
|
|
type: 'station',
|
|
|
|
|
id: kielHbf,
|
|
|
|
|
name: 'Kiel Hbf',
|
|
|
|
|
location: {
|
|
|
|
|
type: 'location',
|
|
|
|
|
latitude: 1.23,
|
|
|
|
|
longitude: 2.34
|
|
|
|
|
}
|
|
|
|
|
}, {when})
|
|
|
|
|
|
2021-12-29 21:11:07 +01:00
|
|
|
|
validate(t, res, 'departuresResponse', 'res')
|
2018-04-19 18:14:10 +02:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-04-19 18:14:10 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('departures at Berlin Hbf in direction of Berlin Ostbahnhof', async (t) => {
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testDeparturesInDirection({
|
2018-07-07 21:26:40 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchDepartures: client.departures,
|
|
|
|
|
fetchTrip: client.trip,
|
|
|
|
|
id: ellerbekerMarkt,
|
|
|
|
|
directionIds: [seefischmarkt, '710102'],
|
|
|
|
|
when,
|
|
|
|
|
validate
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-07-07 21:26:40 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('arrivals at Kiel Räucherei', async (t) => {
|
2021-12-29 21:11:07 +01:00
|
|
|
|
const res = await client.arrivals(kielRaeucherei, {
|
2018-06-26 17:30:46 +02:00
|
|
|
|
duration: 30, when
|
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testArrivals({
|
2018-06-26 17:30:46 +02:00
|
|
|
|
test: t,
|
2021-12-29 21:11:07 +01:00
|
|
|
|
res,
|
2018-06-26 17:30:46 +02:00
|
|
|
|
validate,
|
|
|
|
|
id: kielRaeucherei
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-06-26 17:30:46 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('nearby Kiel Hbf', async (t) => {
|
2018-03-14 14:54:08 +01:00
|
|
|
|
const kielHbfPosition = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
latitude: 54.314982,
|
|
|
|
|
longitude: 10.131976
|
|
|
|
|
}
|
2018-11-21 19:07:37 +01:00
|
|
|
|
const nearby = await client.nearby(kielHbfPosition, {
|
2018-03-14 14:54:08 +01:00
|
|
|
|
results: 2, distance: 400
|
|
|
|
|
})
|
|
|
|
|
|
2018-04-19 18:14:10 +02:00
|
|
|
|
validate(t, nearby, 'locations', 'nearby')
|
|
|
|
|
|
2018-03-14 14:54:08 +01:00
|
|
|
|
t.ok(Array.isArray(nearby))
|
|
|
|
|
t.equal(nearby.length, 2)
|
|
|
|
|
|
2018-07-11 13:43:36 +02:00
|
|
|
|
t.ok(nearby[0].id === kielHbf || nearby[0].id === '8000199')
|
2018-04-19 18:14:10 +02:00
|
|
|
|
t.equal(nearby[0].name, 'Kiel Hbf')
|
2018-03-14 14:54:08 +01:00
|
|
|
|
t.ok(nearby[0].distance >= 0)
|
|
|
|
|
t.ok(nearby[0].distance <= 100)
|
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('locations named "Kiel Rathaus"', async (t) => {
|
2019-02-15 14:53:01 +01:00
|
|
|
|
const kielRathaus = '9049200'
|
2018-11-21 19:07:37 +01:00
|
|
|
|
const locations = await client.locations('Kiel Rathaus', {
|
2019-02-15 14:53:01 +01:00
|
|
|
|
results: 15
|
2018-03-14 14:54:08 +01:00
|
|
|
|
})
|
|
|
|
|
|
2018-04-19 18:14:10 +02:00
|
|
|
|
validate(t, locations, 'locations', 'locations')
|
2019-02-15 14:53:01 +01:00
|
|
|
|
t.ok(locations.length <= 15)
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
2018-11-13 20:34:12 +01:00
|
|
|
|
t.ok(locations.find(l => l.type === 'stop' || l.type === 'station'))
|
2019-02-07 17:47:50 +01:00
|
|
|
|
t.ok(locations.find(l => l.poi)) // POIs
|
2019-02-15 14:53:01 +01:00
|
|
|
|
t.ok(locations.some(l => l.station && l.station.id === kielRathaus || l.id === kielRathaus))
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('stop', async (t) => {
|
2018-11-21 19:55:37 +01:00
|
|
|
|
const s = await client.stop(kielHbf)
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
2018-11-21 19:55:37 +01:00
|
|
|
|
validate(t, s, ['stop', 'station'], 'stop')
|
2018-04-19 18:14:10 +02:00
|
|
|
|
t.equal(s.id, kielHbf)
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-03-14 14:54:08 +01:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('radar', async (t) => {
|
2021-12-29 21:24:07 +01:00
|
|
|
|
const res = await client.radar({
|
2018-04-19 18:14:10 +02:00
|
|
|
|
north: 54.4,
|
|
|
|
|
west: 10.0,
|
|
|
|
|
south: 54.2,
|
|
|
|
|
east: 10.2
|
|
|
|
|
}, {
|
2018-03-17 17:27:43 +01:00
|
|
|
|
duration: 5 * 60, when
|
|
|
|
|
})
|
|
|
|
|
|
2018-04-20 11:04:54 +02:00
|
|
|
|
// todo: cfg.stationProductsOptional option
|
2018-04-19 18:14:10 +02:00
|
|
|
|
const allProducts = products.reduce((acc, p) => (acc[p.id] = true, acc), {})
|
|
|
|
|
const validateStation = createValidateStation(cfg)
|
|
|
|
|
const validate = createValidate(cfg, {
|
|
|
|
|
station: (validate, s, name) => {
|
|
|
|
|
s = Object.assign({
|
|
|
|
|
products: allProducts // todo: fix station.products
|
|
|
|
|
}, s)
|
|
|
|
|
if (!s.name) s.name = 'foo' // todo, see #34
|
|
|
|
|
validateStation(validate, s, name)
|
2018-03-17 17:27:43 +01:00
|
|
|
|
}
|
2018-04-19 18:14:10 +02:00
|
|
|
|
})
|
2021-12-29 21:24:07 +01:00
|
|
|
|
validate(t, res, 'radarResult', 'res')
|
2018-03-17 17:27:43 +01:00
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-08-27 12:04:14 +02:00
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
|
tap.test('reachableFrom', async (t) => {
|
2018-08-27 12:04:14 +02:00
|
|
|
|
const berlinerStr = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
address: 'Husum, Berliner Straße 80',
|
|
|
|
|
latitude: 54.488995,
|
|
|
|
|
longitude: 9.056263
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testReachableFrom({
|
2018-08-27 12:04:14 +02:00
|
|
|
|
test: t,
|
|
|
|
|
reachableFrom: client.reachableFrom,
|
2018-08-27 12:06:14 +02:00
|
|
|
|
address: berlinerStr,
|
2018-08-27 12:04:14 +02:00
|
|
|
|
when,
|
|
|
|
|
maxDuration: 60,
|
|
|
|
|
validate
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|