From c7696380057021492c8b977125116a2b2b7789eb Mon Sep 17 00:00:00 2001 From: Jannis R Date: Wed, 25 Apr 2018 13:24:27 +0200 Subject: [PATCH] add missing test helper fn, add todos, clean up --- test/db.js | 2 ++ test/insa.js | 2 ++ test/lib/journeys-station-to-poi.js | 30 ++++++++++++++++++++ test/lib/validate-line-without-mode.js | 38 -------------------------- test/nahsh.js | 3 ++ test/vbb.js | 3 ++ 6 files changed, 40 insertions(+), 38 deletions(-) create mode 100644 test/lib/journeys-station-to-poi.js delete mode 100644 test/lib/validate-line-without-mode.js diff --git a/test/db.js b/test/db.js index e6db740a..2c963efd 100644 --- a/test/db.js +++ b/test/db.js @@ -171,6 +171,8 @@ test('journeys: via works – with detour', co(function* (t) { t.end() })) +// todo: without detour + test('earlier/later journeys, Jungfernheide -> München Hbf', co(function* (t) { yield testEarlierLaterJourneys({ test: t, diff --git a/test/insa.js b/test/insa.js index 70e68e37..6387bd0b 100644 --- a/test/insa.js +++ b/test/insa.js @@ -138,6 +138,8 @@ test('journeys: via works – with detour', co(function* (t) { t.end() })) +// todo: without detour + test('earlier/later journeys', co(function* (t) { yield testEarlierLaterJourneys({ test: t, diff --git a/test/lib/journeys-station-to-poi.js b/test/lib/journeys-station-to-poi.js new file mode 100644 index 00000000..e996dc37 --- /dev/null +++ b/test/lib/journeys-station-to-poi.js @@ -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 diff --git a/test/lib/validate-line-without-mode.js b/test/lib/validate-line-without-mode.js deleted file mode 100644 index 71068e32..00000000 --- a/test/lib/validate-line-without-mode.js +++ /dev/null @@ -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 diff --git a/test/nahsh.js b/test/nahsh.js index 34f816be..cb3cf021 100644 --- a/test/nahsh.js +++ b/test/nahsh.js @@ -174,6 +174,9 @@ test('earlier/later journeys, Kiel Hbf -> Flensburg', co(function* (t) { t.end() })) +// todo: with detour test +// todo: without detour test + test('journey leg details for Flensburg to Husum', co(function* (t) { const journeys = yield client.journeys(flensburg, husum, { results: 1, when diff --git a/test/vbb.js b/test/vbb.js index 23574746..b9751308 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -45,6 +45,7 @@ const validateDirection = (dir, name) => { const _validateStation = createValidateStation(cfg) const 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') } @@ -262,6 +263,8 @@ test('journeys: via works – with detour', co(function* (t) { t.end() })) +// todo: without detour test + test('departures', co(function* (t) { const departures = yield client.departures(spichernstr, { duration: 5, when