From 9501dab9f4a8dadf49543c4ee2ef54b199ef20fb Mon Sep 17 00:00:00 2001 From: Jannis R Date: Tue, 24 Apr 2018 16:10:56 +0200 Subject: [PATCH] journeys from station to POI tests: use helper fn --- test/db.js | 36 +++++++++++++++++++----------------- test/insa.js | 22 ++++++++++------------ test/nahsh.js | 37 +++++++++++++++++-------------------- test/oebb.js | 26 +++++++++++++------------- test/vbb.js | 34 ++++++++++++++++------------------ 5 files changed, 75 insertions(+), 80 deletions(-) diff --git a/test/db.js b/test/db.js index 10461cb9..5041ea99 100644 --- a/test/db.js +++ b/test/db.js @@ -17,6 +17,7 @@ const { 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 isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o) @@ -64,7 +65,6 @@ const berlinHbf = '8011160' const münchenHbf = '8000261' const jungfernheide = '8011167' const blnSchwedterStr = '732652' -const atze = '991598902' const westhafen = '008089116' const wedding = '008089131' const württembergallee = '731084' @@ -114,23 +114,25 @@ test('Berlin Schwedter Str. to Torfstraße 17', co(function* (t) { t.end() })) -test('Berlin Jungfernheide to ATZE Musiktheater', co(function* (t) { - const latitude = 52.542417 - const longitude = 13.350437 - const journeys = yield client.journeys(jungfernheide, { - type: 'location', id: atze, name: 'ATZE Musiktheater', - latitude, longitude - }, {when}) - - validate(t, journeys, 'journeys', 'journeys') - - const i = journeys[0].legs.length - 1 - const d = journeys[0].legs[i].destination - const name = `journeys[0].legs[${i}].destination` - t.equal(d.name, 'ATZE Musiktheater', name + '.name is invalid') - t.ok(isRoughlyEqual(.0001, d.latitude, latitude), name + '.latitude is invalid') - t.ok(isRoughlyEqual(.0001, d.longitude, longitude), name + '.longitude is invalid') +test('Berlin Schwedter Str. to ATZE Musiktheater', co(function* (t) { + const atze = { + type: 'location', + id: '991598902', + name: 'ATZE Musiktheater', + latitude: 52.542417, + longitude: 13.350437 + } + const journeys = yield client.journeys(blnSchwedterStr, atze, { + results: 3, when + }) + yield testJourneysStationToPoi({ + test: t, + journeys, + validate, + fromId: blnSchwedterStr, + to: atze + }) t.end() })) diff --git a/test/insa.js b/test/insa.js index 271a1389..0f2072c0 100644 --- a/test/insa.js +++ b/test/insa.js @@ -12,6 +12,7 @@ const products = require('../p/insa/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 isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o) @@ -75,7 +76,7 @@ test('Magdeburg Hbf to 39104 Magdeburg, Sternstr. 10', co(function*(t) { t.end() })) -test('Kloster Unser Lieben Frauen to Magdeburg Hbf', co(function*(t) { +test('Magdeburg Hbf to Kloster Unser Lieben Frauen', co(function*(t) { const kloster = { type: 'location', id: '970012223', @@ -83,20 +84,17 @@ test('Kloster Unser Lieben Frauen to Magdeburg Hbf', co(function*(t) { latitude: 52.127601, longitude: 11.636437 } - const journeys = yield client.journeys(magdeburgHbf, kloster, { - when + results: 3, when }) - validate(t, journeys, 'journeys', 'journeys') - for (let journey of journeys) { - const i = journey.legs.length - 1 - const d = journey.legs[i].destination - t.equal(d.id, kloster.id) - t.equal(d.name, kloster.name) - t.ok(isRoughlyEqual(0.0001, d.latitude, kloster.latitude)) - t.ok(isRoughlyEqual(0.0001, d.longitude, kloster.longitude)) - } + yield testJourneysStationToPoi({ + test: t, + journeys, + validate, + fromId: magdeburgHbf, + to: kloster + }) t.end() })) diff --git a/test/nahsh.js b/test/nahsh.js index 6cf62138..12756e03 100644 --- a/test/nahsh.js +++ b/test/nahsh.js @@ -16,6 +16,7 @@ const { 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 when = createWhen('Europe/Berlin', 'de-DE') @@ -58,7 +59,6 @@ const client = createClient(nahshProfile) const kielHbf = '8000199' const flensburg = '8000103' -const holstentor = '970003547' const luebeckHbf = '8000237' const husum = '8000181' const schleswig = '8005362' @@ -110,27 +110,24 @@ test('Kiel Hbf to Husum, Zingel 10', co(function* (t) { })) test('Kiel Hbf to Holstentor', co(function* (t) { - const latitude = 53.866321 - const longitude = 10.679976 - const name = 'Hansestadt Lübeck, Holstentor (Denkmal)' - const journeys = yield client.journeys(kielHbf, { + const holstentor = { type: 'location', - id: holstentor, - name, - latitude, longitude - }, {when}) - - validate(t, journeys, 'journeys', 'journeys') - - const i = journeys[0].legs.length - 1 - const d = journeys[0].legs[i].destination - const k = `journeys[0].legs[${i}].destination` - - t.strictEqual(d.id, holstentor, k + '.id is invalid') - t.strictEqual(d.name, name, k + '.name is invalid') - t.ok(isRoughlyEqual(.0001, d.latitude, latitude), k + '.latitude is invalid') - t.ok(isRoughlyEqual(.0001, d.longitude, longitude), k + '.longitude is invalid') + id: '970003547', + name: 'Hansestadt Lübeck, Holstentor (Denkmal)', + latitude: 53.866321, + longitude: 10.679976 + } + const journeys = yield client.journeys(kielHbf, holstentor, { + results: 3, when + }) + yield testJourneysStationToPoi({ + test: t, + journeys, + validate, + fromId: kielHbf, + to: holstentor + }) t.end() })) diff --git a/test/oebb.js b/test/oebb.js index e4ceb148..9a0480f2 100644 --- a/test/oebb.js +++ b/test/oebb.js @@ -16,6 +16,7 @@ const { 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 when = createWhen('Europe/Vienna', 'de-AT') @@ -101,25 +102,24 @@ test('Salzburg Hbf to 1220 Wien, Wagramer Straße 5', co(function* (t) { })) test('Salzburg Hbf to Albertina', co(function* (t) { - const latitude = 48.204699 - const longitude = 16.368404 const albertina = { type: 'location', id: '975900003', name: 'Albertina', - latitude, longitude + latitude: 48.204699, + longitude: 16.368404 } - const journeys = yield client.journeys(salzburgHbf, albertina, {when}) - - validate(t, journeys, 'journeys', 'journeys') - - const i = journeys[0].legs.length - 1 - const d = journeys[0].legs[i].destination - const k = `journeys[0].legs[${i}].destination` - t.equal(d.name, 'Albertina', k + '.name is invalid') - t.ok(isRoughlyEqual(.0001, d.latitude, latitude), k + '.latitude is invalid') - t.ok(isRoughlyEqual(.0001, d.longitude, longitude), k + '.longitude is invalid') + const journeys = yield client.journeys(salzburgHbf, albertina, { + results: 3, when + }) + yield testJourneysStationToPoi({ + test: t, + journeys, + validate, + fromId: salzburgHbf, + to: albertina + }) t.end() })) diff --git a/test/vbb.js b/test/vbb.js index 95195d38..a34c05bc 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -22,6 +22,7 @@ const { 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 when = createWhen('Europe/Berlin', 'de-DE') @@ -100,7 +101,6 @@ const client = createClient(vbbProfile) const amrumerStr = '900000009101' const spichernstr = '900000042101' const bismarckstr = '900000024201' -const atze = '900980720' const westhafen = '900000001201' const wedding = '900000009104' const württembergallee = '900000026153' @@ -229,26 +229,24 @@ test('journeys – station to address', co(function* (t) { })) test('journeys – station to POI', co(function* (t) { - const latitude = 52.543333 - const longitude = 13.351686 - const journeys = yield client.journeys(spichernstr, { + const atze = { type: 'location', - id: atze, + id: '900980720', name: 'Berlin, Atze Musiktheater für Kinder', - latitude, longitude - }, {results: 1, when}) - - validate(t, journeys, 'journeys', 'journeys') - - const i = journeys[0].legs.length - 1 - const d = journeys[0].legs[i].destination - const name = `journeys[0].legs[${i}].destination` - - t.strictEqual(d.id, atze, name + '.id is invalid') - t.strictEqual(d.name, 'Berlin, Atze Musiktheater für Kinder', name + '.name is invalid') - t.ok(isRoughlyEqual(.0001, d.latitude, latitude), name + '.latitude is invalid') - t.ok(isRoughlyEqual(.0001, d.longitude, longitude), name + '.longitude is invalid') + latitude: 52.543333, + longitude: 13.351686 + } + const journeys = yield client.journeys(spichernstr, atze, { + results: 3, when + }) + yield testJourneysStationToPoi({ + test: t, + journeys, + validate, + fromId: spichernstr, + to: atze + }) t.end() }))