mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
170 lines
4.6 KiB
JavaScript
170 lines
4.6 KiB
JavaScript
|
'use strict'
|
||
|
|
||
|
const tapePromise = require('tape-promise').default
|
||
|
const tape = require('tape')
|
||
|
const isRoughlyEqual = require('is-roughly-equal')
|
||
|
|
||
|
const createClient = require('..')
|
||
|
const {
|
||
|
findStation,
|
||
|
assertValidStation,
|
||
|
assertValidPoi,
|
||
|
assertValidAddress,
|
||
|
assertValidLocation,
|
||
|
assertValidLine,
|
||
|
assertValidStopover,
|
||
|
isJungfernheide, assertIsJungfernheide,
|
||
|
when, isValidWhen
|
||
|
} = require('./util.js')
|
||
|
|
||
|
const test = tapePromise(tape)
|
||
|
const client = createClient(dbProfile)
|
||
|
|
||
|
test('Berlin Jungfernheide to München Hbf', async (t) => {
|
||
|
const journeys = await client.journeys('8011167', '8000261', {
|
||
|
when, passedStations: true
|
||
|
})
|
||
|
|
||
|
t.ok(Array.isArray(journeys))
|
||
|
t.ok(journeys.length > 0, 'no journeys')
|
||
|
for (let journey of journeys) {
|
||
|
assertValidStation(t, journey.origin)
|
||
|
if (!await findStation(journey.origin.id)) {
|
||
|
console.error('unknown station', journey.origin.id, journey.origin.name)
|
||
|
}
|
||
|
t.ok(isValidWhen(journey.departure))
|
||
|
|
||
|
assertValidStation(t, journey.destination)
|
||
|
if (!await findStation(journey.origin.id)) {
|
||
|
console.error('unknown station', journey.destination.id, journey.destination.name)
|
||
|
}
|
||
|
t.ok(isValidWhen(journey.arrival))
|
||
|
|
||
|
t.ok(Array.isArray(journey.parts))
|
||
|
t.ok(journey.parts.length > 0, 'no parts')
|
||
|
const part = journey.parts[0]
|
||
|
|
||
|
assertValidStation(t, part.origin)
|
||
|
if (!await findStation(part.origin.id)) {
|
||
|
console.error('unknown station', part.origin.id, part.origin.name)
|
||
|
}
|
||
|
t.ok(isValidWhen(part.departure))
|
||
|
t.equal(typeof part.departurePlatform, 'string')
|
||
|
|
||
|
assertValidStation(t, part.destination)
|
||
|
if (!await findStation(part.destination.id)) {
|
||
|
console.error('unknown station', part.destination.id, part.destination.name)
|
||
|
}
|
||
|
t.ok(isValidWhen(part.arrival))
|
||
|
t.equal(typeof part.arrivalPlatform, 'string')
|
||
|
|
||
|
assertValidLine(t, part.line)
|
||
|
|
||
|
t.ok(Array.isArray(part.passed))
|
||
|
for (let stopover of part.passed) assertValidStopover(t, stopover)
|
||
|
}
|
||
|
|
||
|
t.end()
|
||
|
})
|
||
|
|
||
|
test('Berlin Jungfernheide to Torfstraße 17', async (t) => {
|
||
|
const journeys = await client.journeys('8011167', {
|
||
|
type: 'address', name: 'Torfstraße 17',
|
||
|
latitude: 52.5416823, longitude: 13.3491223
|
||
|
}, {when})
|
||
|
|
||
|
t.ok(Array.isArray(journeys))
|
||
|
t.ok(journeys.length >= 1, 'no journeys')
|
||
|
const journey = journeys[0]
|
||
|
const part = journey.parts[journey.parts.length - 1]
|
||
|
|
||
|
assertValidStation(t, part.origin)
|
||
|
if (!await findStation(part.origin.id)) {
|
||
|
console.error('unknown station', part.origin.id, part.origin.name)
|
||
|
}
|
||
|
t.ok(isValidWhen(part.departure))
|
||
|
t.ok(isValidWhen(part.arrival))
|
||
|
|
||
|
const d = part.destination
|
||
|
assertValidAddress(t, d)
|
||
|
t.equal(d.name, 'Torfstraße 17')
|
||
|
t.ok(isRoughlyEqual(.0001, d.coordinates.latitude, 52.5416823))
|
||
|
t.ok(isRoughlyEqual(.0001, d.coordinates.longitude, 13.3491223))
|
||
|
|
||
|
t.end()
|
||
|
})
|
||
|
|
||
|
test('Berlin Jungfernheide to ATZE Musiktheater', async (t) => {
|
||
|
const journeys = await client.journeys('8011167', {
|
||
|
type: 'poi', name: 'ATZE Musiktheater', id: '991598902',
|
||
|
latitude: 52.542417, longitude: 13.350437
|
||
|
}, {when})
|
||
|
|
||
|
t.ok(Array.isArray(journeys))
|
||
|
t.ok(journeys.length >= 1, 'no journeys')
|
||
|
const journey = journeys[0]
|
||
|
const part = journey.parts[journey.parts.length - 1]
|
||
|
|
||
|
assertValidStation(t, part.origin)
|
||
|
if (!await findStation(part.origin.id)) {
|
||
|
console.error('unknown station', part.origin.id, part.origin.name)
|
||
|
}
|
||
|
t.ok(isValidWhen(part.departure))
|
||
|
t.ok(isValidWhen(part.arrival))
|
||
|
|
||
|
const d = part.destination
|
||
|
assertValidPoi(t, d)
|
||
|
t.equal(d.name, 'ATZE Musiktheater')
|
||
|
t.ok(isRoughlyEqual(.0001, d.coordinates.latitude, 52.542399))
|
||
|
t.ok(isRoughlyEqual(.0001, d.coordinates.longitude, 13.350402))
|
||
|
|
||
|
t.end()
|
||
|
})
|
||
|
|
||
|
test('departures at Berlin Jungfernheide', async (t) => {
|
||
|
const deps = await client.departures('8011167', {
|
||
|
duration: 5, when
|
||
|
})
|
||
|
|
||
|
t.ok(Array.isArray(deps))
|
||
|
for (let dep of deps) {
|
||
|
assertValidStation(t, dep.station)
|
||
|
if (!await findStation(dep.station.id)) {
|
||
|
console.error('unknown station', dep.station.id, dep.station.name)
|
||
|
}
|
||
|
t.ok(isValidWhen(dep.when))
|
||
|
}
|
||
|
|
||
|
t.end()
|
||
|
})
|
||
|
|
||
|
test('nearby Berlin Jungfernheide', async (t) => {
|
||
|
const nearby = await client.nearby(52.530273, 13.299433, {
|
||
|
results: 2, distance: 400
|
||
|
})
|
||
|
|
||
|
t.ok(Array.isArray(nearby))
|
||
|
t.equal(nearby.length, 2)
|
||
|
|
||
|
assertIsJungfernheide(t, nearby[0])
|
||
|
t.ok(nearby[0].distance >= 0)
|
||
|
t.ok(nearby[0].distance <= 100)
|
||
|
|
||
|
t.end()
|
||
|
})
|
||
|
|
||
|
test('locations named Jungfernheide', async (t) => {
|
||
|
const locations = await client.locations('Jungfernheide', {
|
||
|
results: 10
|
||
|
})
|
||
|
|
||
|
t.ok(Array.isArray(locations))
|
||
|
t.ok(locations.length > 0)
|
||
|
t.ok(locations.length <= 10)
|
||
|
|
||
|
for (let location of locations) assertValidLocation(t, location)
|
||
|
t.ok(locations.find(isJungfernheide))
|
||
|
|
||
|
t.end()
|
||
|
})
|