mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
add missing test helper fn, add todos, clean up
This commit is contained in:
parent
fecd2aefc0
commit
c769638005
6 changed files with 40 additions and 38 deletions
|
@ -171,6 +171,8 @@ test('journeys: via works – with detour', co(function* (t) {
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// todo: without detour
|
||||||
|
|
||||||
test('earlier/later journeys, Jungfernheide -> München Hbf', co(function* (t) {
|
test('earlier/later journeys, Jungfernheide -> München Hbf', co(function* (t) {
|
||||||
yield testEarlierLaterJourneys({
|
yield testEarlierLaterJourneys({
|
||||||
test: t,
|
test: t,
|
||||||
|
|
|
@ -138,6 +138,8 @@ test('journeys: via works – with detour', co(function* (t) {
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// todo: without detour
|
||||||
|
|
||||||
test('earlier/later journeys', co(function* (t) {
|
test('earlier/later journeys', co(function* (t) {
|
||||||
yield testEarlierLaterJourneys({
|
yield testEarlierLaterJourneys({
|
||||||
test: t,
|
test: t,
|
||||||
|
|
30
test/lib/journeys-station-to-poi.js
Normal file
30
test/lib/journeys-station-to-poi.js
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const isRoughlyEqual = require('is-roughly-equal')
|
||||||
|
|
||||||
|
const co = require('./co')
|
||||||
|
|
||||||
|
const testJourneysStationToPoi = co(function* (cfg) {
|
||||||
|
const {test: t, journeys, validate, fromId} = cfg
|
||||||
|
const {id, name, latitude, longitude} = cfg.to
|
||||||
|
|
||||||
|
validate(t, journeys, 'journeys', 'journeys')
|
||||||
|
t.strictEqual(journeys.length, 3)
|
||||||
|
for (let i = 0; i < journeys.length; i++) {
|
||||||
|
const j = journeys[i]
|
||||||
|
|
||||||
|
const firstLeg = j.legs[0]
|
||||||
|
t.strictEqual(firstLeg.origin.id, fromId)
|
||||||
|
|
||||||
|
const d = j.legs[j.legs.length - 1].destination
|
||||||
|
const n = `journeys[0].legs[${i}].destination`
|
||||||
|
|
||||||
|
t.strictEqual(d.type, 'location', n + '.type is invalid')
|
||||||
|
t.strictEqual(d.id, id, n + '.id is invalid')
|
||||||
|
t.strictEqual(d.name, name, n + '.name is invalid')
|
||||||
|
t.ok(isRoughlyEqual(.0001, d.latitude, latitude), n + '.latitude is invalid')
|
||||||
|
t.ok(isRoughlyEqual(.0001, d.longitude, longitude), n + '.longitude is invalid')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = testJourneysStationToPoi
|
|
@ -1,38 +0,0 @@
|
||||||
'use strict'
|
|
||||||
|
|
||||||
const a = require('assert')
|
|
||||||
const is = require('@sindresorhus/is')
|
|
||||||
|
|
||||||
const validateItem = require('validate-fptf/lib/item')
|
|
||||||
const validateReference = require('validate-fptf/lib/reference')
|
|
||||||
|
|
||||||
// todo: this is copied code, DRY this up!
|
|
||||||
// see https://github.com/public-transport/validate-fptf/blob/373b4847ec9668c4a9ec9b0dbd50f8a70ffbe127/line.js
|
|
||||||
const validateLineWithoutMode = (validate, line, name) => {
|
|
||||||
validateItem(line, name)
|
|
||||||
|
|
||||||
a.strictEqual(line.type, 'line', name + '.type must be `line`')
|
|
||||||
|
|
||||||
validateReference(line.id, name + '.id')
|
|
||||||
|
|
||||||
a.strictEqual(typeof line.name, 'string', name + '.name must be a string')
|
|
||||||
a.ok(line.name.length > 0, name + '.name can\'t be empty')
|
|
||||||
|
|
||||||
// skipping line validation here
|
|
||||||
// see https://github.com/derhuerst/hafas-client/issues/8#issuecomment-355839965
|
|
||||||
if (is.undefined(line.mode) || is.null(line.mode)) {
|
|
||||||
console.error(`ÖBB: Missing \`mode\` for line ${line.name} (at ${name}).`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is.undefined(line.subMode)) {
|
|
||||||
a.fail(name + '.subMode is reserved an should not be used for now')
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo: routes
|
|
||||||
|
|
||||||
if (!is.null(line.operator) && !is.undefined(line.operator)) {
|
|
||||||
validate(['operator'], line.operator, name + '.operator')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = validateLineWithoutMode
|
|
|
@ -174,6 +174,9 @@ test('earlier/later journeys, Kiel Hbf -> Flensburg', co(function* (t) {
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// todo: with detour test
|
||||||
|
// todo: without detour test
|
||||||
|
|
||||||
test('journey leg details for Flensburg to Husum', co(function* (t) {
|
test('journey leg details for Flensburg to Husum', co(function* (t) {
|
||||||
const journeys = yield client.journeys(flensburg, husum, {
|
const journeys = yield client.journeys(flensburg, husum, {
|
||||||
results: 1, when
|
results: 1, when
|
||||||
|
|
|
@ -45,6 +45,7 @@ const validateDirection = (dir, name) => {
|
||||||
const _validateStation = createValidateStation(cfg)
|
const _validateStation = createValidateStation(cfg)
|
||||||
const validateStation = (validate, s, name) => {
|
const validateStation = (validate, s, name) => {
|
||||||
_validateStation(validate, s, name)
|
_validateStation(validate, s, name)
|
||||||
|
// todo: find station by ID
|
||||||
a.equal(s.name, shorten(s.name), name + '.name must be shortened')
|
a.equal(s.name, shorten(s.name), name + '.name must be shortened')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,6 +263,8 @@ test('journeys: via works – with detour', co(function* (t) {
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// todo: without detour test
|
||||||
|
|
||||||
test('departures', co(function* (t) {
|
test('departures', co(function* (t) {
|
||||||
const departures = yield client.departures(spichernstr, {
|
const departures = yield client.departures(spichernstr, {
|
||||||
duration: 5, when
|
duration: 5, when
|
||||||
|
|
Loading…
Add table
Reference in a new issue