2018-08-24 20:09:16 +02:00
|
|
|
|
'use strict'
|
|
|
|
|
|
|
|
|
|
const assert = require('assert')
|
|
|
|
|
const tapePromise = require('tape-promise').default
|
|
|
|
|
const tape = require('tape')
|
|
|
|
|
|
|
|
|
|
const {createWhen} = require('./lib/util')
|
|
|
|
|
const createClient = require('..')
|
|
|
|
|
const cmtaProfile = require('../p/cmta')
|
|
|
|
|
const products = require('../p/cmta/products')
|
|
|
|
|
const createValidate = require('./lib/validate-fptf-with')
|
|
|
|
|
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
|
|
|
|
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
|
|
|
|
|
const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
|
|
|
|
|
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
|
|
|
|
const testRefreshJourney = require('./lib/refresh-journey')
|
|
|
|
|
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')
|
2018-08-27 12:04:14 +02:00
|
|
|
|
const testReachableFrom = require('./lib/reachable-from')
|
2018-08-24 20:09:16 +02:00
|
|
|
|
|
|
|
|
|
const when = createWhen(cmtaProfile.timezone, cmtaProfile.locale)
|
|
|
|
|
|
|
|
|
|
const cfg = {
|
|
|
|
|
when,
|
|
|
|
|
stationCoordsOptional: false,
|
2019-02-15 14:53:01 +01:00
|
|
|
|
products,
|
|
|
|
|
minLatitude: 26,
|
|
|
|
|
maxLatitude: 33,
|
|
|
|
|
minLongitude: -100,
|
|
|
|
|
maxLongitude: -95
|
2018-08-24 20:09:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-15 14:53:01 +01:00
|
|
|
|
const validate = createValidate(cfg)
|
2018-08-24 20:09:16 +02:00
|
|
|
|
|
|
|
|
|
const test = tapePromise(tape)
|
|
|
|
|
const client = createClient(cmtaProfile, 'public-transport/hafas-client:test')
|
|
|
|
|
|
|
|
|
|
const broadieOaks = '2370'
|
|
|
|
|
const domain = '5919'
|
|
|
|
|
const capitol591 = '591'
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('journeys – Broadie Oaks to Domain', async (t) => {
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(broadieOaks, domain, {
|
2019-02-01 15:35:18 +01:00
|
|
|
|
results: 4,
|
2018-08-24 20:09:16 +02:00
|
|
|
|
departure: when,
|
|
|
|
|
stopovers: true
|
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToStation({
|
2018-08-24 20:09:16 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-08-24 20:09:16 +02:00
|
|
|
|
validate,
|
|
|
|
|
fromId: broadieOaks,
|
|
|
|
|
toId: domain
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-08-24 20:09:16 +02:00
|
|
|
|
|
|
|
|
|
// todo: journeys, only one product
|
|
|
|
|
|
|
|
|
|
test('journeys – fails with no product', (t) => {
|
|
|
|
|
journeysFailsWithNoProduct({
|
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
fromId: broadieOaks,
|
|
|
|
|
toId: domain,
|
|
|
|
|
when,
|
|
|
|
|
products
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('Domain to 1104 Elm Street, Austin, TX 78703', async (t) => {
|
2018-08-24 20:09:16 +02:00
|
|
|
|
const someAddress = {
|
|
|
|
|
type: 'location',
|
|
|
|
|
address: '1104 ELM ST, Austin, TX 78703',
|
|
|
|
|
latitude: 30.279220,
|
|
|
|
|
longitude: -97.758292
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(domain, someAddress, {
|
2018-08-24 20:09:16 +02:00
|
|
|
|
results: 3,
|
|
|
|
|
departure: when
|
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToAddress({
|
2018-08-24 20:09:16 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-08-24 20:09:16 +02:00
|
|
|
|
validate,
|
|
|
|
|
fromId: domain,
|
|
|
|
|
to: someAddress
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-08-24 20:09:16 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('Domain to Whole Foods Market - North Lamar Blvd', async (t) => {
|
2018-08-24 20:09:16 +02:00
|
|
|
|
const wholeFoodsMarket = {
|
|
|
|
|
type: 'location',
|
2019-02-07 18:06:15 +01:00
|
|
|
|
id: '9845565', // or `9871373`
|
2019-02-07 17:47:50 +01:00
|
|
|
|
poi: true,
|
2018-08-24 20:09:16 +02:00
|
|
|
|
name: 'Whole Foods Market - N Lamar Blvd',
|
|
|
|
|
latitude: 30.270653,
|
|
|
|
|
longitude: -97.753564
|
|
|
|
|
}
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(domain, wholeFoodsMarket, {
|
2018-08-24 20:09:16 +02:00
|
|
|
|
results: 3,
|
|
|
|
|
departure: when
|
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testJourneysStationToPoi({
|
2018-08-24 20:09:16 +02:00
|
|
|
|
test: t,
|
2019-01-16 21:41:17 +08:00
|
|
|
|
res,
|
2018-08-24 20:09:16 +02:00
|
|
|
|
validate,
|
|
|
|
|
fromId: domain,
|
|
|
|
|
to: wholeFoodsMarket
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-08-24 20:09:16 +02:00
|
|
|
|
|
2018-10-29 22:11:08 +01:00
|
|
|
|
// todo: walkingSpeed "2107 MELRIDGE PL" -> 000002148
|
2018-08-24 20:09:16 +02:00
|
|
|
|
// todo: via works – with detour
|
|
|
|
|
// todo: without detour
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('earlier/later journeys', async (t) => {
|
|
|
|
|
await testEarlierLaterJourneys({
|
2018-08-24 20:09:16 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: broadieOaks,
|
2018-11-20 18:38:48 +01:00
|
|
|
|
toId: domain,
|
|
|
|
|
when
|
2018-08-24 20:09:16 +02:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-08-24 20:09:16 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('refreshJourney', async (t) => {
|
|
|
|
|
await testRefreshJourney({
|
2018-08-24 20:09:16 +02:00
|
|
|
|
test: t,
|
|
|
|
|
fetchJourneys: client.journeys,
|
|
|
|
|
refreshJourney: client.refreshJourney,
|
|
|
|
|
validate,
|
|
|
|
|
fromId: broadieOaks,
|
|
|
|
|
toId: domain,
|
|
|
|
|
when
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-08-24 20:09:16 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('trip details', async (t) => {
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const res = await client.journeys(broadieOaks, domain, {
|
2018-08-24 20:09:16 +02:00
|
|
|
|
results: 1, departure: when
|
|
|
|
|
})
|
|
|
|
|
|
2019-01-16 21:41:17 +08:00
|
|
|
|
const p = res.journeys[0].legs[0]
|
2018-11-22 00:17:28 +01:00
|
|
|
|
t.ok(p.tripId, 'precondition failed')
|
2018-08-24 20:09:16 +02:00
|
|
|
|
t.ok(p.line.name, 'precondition failed')
|
2018-11-22 00:17:28 +01:00
|
|
|
|
const trip = await client.trip(p.tripId, p.line.name, {when})
|
2018-08-24 20:09:16 +02:00
|
|
|
|
|
2018-11-22 00:15:59 +01:00
|
|
|
|
validate(t, trip, 'trip', 'trip')
|
2018-08-24 20:09:16 +02:00
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-08-24 20:09:16 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('departures at Broadie Oaks', async (t) => {
|
|
|
|
|
const departures = await client.departures(broadieOaks, {
|
2018-12-28 21:17:03 +01:00
|
|
|
|
duration: 10, when,
|
|
|
|
|
stopovers: true
|
2018-08-24 20:09:16 +02:00
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testDepartures({
|
2018-08-24 20:09:16 +02:00
|
|
|
|
test: t,
|
|
|
|
|
departures,
|
|
|
|
|
validate,
|
|
|
|
|
id: broadieOaks
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-08-24 20:09:16 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('departures with station object', async (t) => {
|
|
|
|
|
const deps = await client.departures({
|
2018-08-24 20:09:16 +02:00
|
|
|
|
type: 'station',
|
|
|
|
|
id: broadieOaks,
|
|
|
|
|
name: 'Magdeburg Hbf',
|
|
|
|
|
location: {
|
|
|
|
|
type: 'location',
|
|
|
|
|
latitude: 1.23,
|
|
|
|
|
longitude: 2.34
|
|
|
|
|
}
|
|
|
|
|
}, {when})
|
|
|
|
|
|
|
|
|
|
validate(t, deps, 'departures', 'departures')
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-08-24 20:09:16 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('arrivals at Broadie Oaks', async (t) => {
|
|
|
|
|
const arrivals = await client.arrivals(broadieOaks, {
|
2018-08-24 20:09:16 +02:00
|
|
|
|
duration: 10, when
|
|
|
|
|
})
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
await testArrivals({
|
2018-08-24 20:09:16 +02:00
|
|
|
|
test: t,
|
|
|
|
|
arrivals,
|
|
|
|
|
validate,
|
|
|
|
|
id: broadieOaks
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-08-24 20:09:16 +02:00
|
|
|
|
|
|
|
|
|
// todo: nearby
|
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('locations named "Capitol"', async (t) => {
|
|
|
|
|
const locations = await client.locations('Capitol', {
|
2018-08-24 20:09:16 +02:00
|
|
|
|
results: 10
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
validate(t, locations, 'locations', 'locations')
|
|
|
|
|
t.ok(locations.length <= 10)
|
|
|
|
|
|
|
|
|
|
t.ok(locations.find(s => s.type === 'stop' || s.type === 'station'))
|
2019-02-07 17:47:50 +01:00
|
|
|
|
t.ok(locations.find(s => s.poi)) // POIs
|
2018-08-24 20:09:16 +02:00
|
|
|
|
t.ok(locations.some((l) => {
|
2019-01-16 22:05:21 +08:00
|
|
|
|
return l.station && l.station.id === capitol591 || l.id === capitol591
|
2018-08-24 20:09:16 +02:00
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-08-24 20:09:16 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('station Domain', async (t) => {
|
2018-11-21 19:55:37 +01:00
|
|
|
|
const s = await client.stop(domain)
|
2018-08-24 20:09:16 +02:00
|
|
|
|
|
|
|
|
|
validate(t, s, ['stop', 'station'], 'station')
|
|
|
|
|
t.equal(s.id, domain)
|
|
|
|
|
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-08-24 20:09:16 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('radar', async (t) => {
|
|
|
|
|
const vehicles = await client.radar({
|
2018-08-24 20:09:16 +02:00
|
|
|
|
north: 30.240877,
|
|
|
|
|
west: -97.804588,
|
|
|
|
|
south: 30.225378,
|
|
|
|
|
east: -97.786692
|
|
|
|
|
}, {
|
|
|
|
|
duration: 5 * 60, when, results: 10
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
validate(t, vehicles, 'movements', 'vehicles')
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|
2018-08-27 12:04:14 +02:00
|
|
|
|
|
2018-11-21 19:07:37 +01:00
|
|
|
|
test('reachableFrom', async (t) => {
|
|
|
|
|
await testReachableFrom({
|
2018-08-27 12:04:14 +02:00
|
|
|
|
test: t,
|
|
|
|
|
reachableFrom: client.reachableFrom,
|
2018-08-27 12:06:14 +02:00
|
|
|
|
address: {
|
2018-08-27 12:04:14 +02:00
|
|
|
|
type: 'location',
|
|
|
|
|
address: '604 W 9TH ST, Austin, TX 78701',
|
|
|
|
|
latitude: 30.272910,
|
|
|
|
|
longitude: -97.747883
|
|
|
|
|
},
|
|
|
|
|
when,
|
|
|
|
|
maxDuration: 15,
|
|
|
|
|
validate
|
|
|
|
|
})
|
|
|
|
|
t.end()
|
2018-11-21 19:07:37 +01:00
|
|
|
|
})
|