From 817f44ea392056c8865cccdd5723adb7277b90c7 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Wed, 29 Nov 2017 02:27:31 +0100 Subject: [PATCH] =?UTF-8?q?Node=206=20=F0=9F=92=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + test/db.js | 51 +++++++++++++++++++------------------- test/vbb.js | 69 ++++++++++++++++++++++++++-------------------------- 3 files changed, 62 insertions(+), 59 deletions(-) diff --git a/package.json b/package.json index 7c4e25bf..6f570e43 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "vbb-translate-ids": "^3.1.0" }, "devDependencies": { + "co": "^4.6.0", "db-stations": "^1.25.0", "floordate": "^3.0.0", "is-roughly-equal": "^0.1.0", diff --git a/test/db.js b/test/db.js index 03ca7ef8..9b7b927b 100644 --- a/test/db.js +++ b/test/db.js @@ -3,6 +3,7 @@ const getStations = require('db-stations').full const tapePromise = require('tape-promise').default const tape = require('tape') +const co = require('co') const isRoughlyEqual = require('is-roughly-equal') const createClient = require('..') @@ -61,8 +62,8 @@ const assertValidProducts = (t, p) => { const test = tapePromise(tape) const client = createClient(dbProfile) -test('Berlin Jungfernheide to München Hbf', async (t) => { - const journeys = await client.journeys('8011167', '8000261', { +test('Berlin Jungfernheide to München Hbf', co.wrap(function* (t) { + const journeys = yield client.journeys('8011167', '8000261', { when, passedStations: true }) @@ -70,7 +71,7 @@ test('Berlin Jungfernheide to München Hbf', async (t) => { t.ok(journeys.length > 0, 'no journeys') for (let journey of journeys) { assertValidStation(t, journey.origin) - if (!await findStation(journey.origin.id)) { + if (!(yield findStation(journey.origin.id))) { console.error('unknown station', journey.origin.id, journey.origin.name) } if (journey.origin.products) { @@ -79,7 +80,7 @@ test('Berlin Jungfernheide to München Hbf', async (t) => { t.ok(isValidWhen(journey.departure)) assertValidStation(t, journey.destination) - if (!await findStation(journey.origin.id)) { + if (!(yield findStation(journey.origin.id))) { console.error('unknown station', journey.destination.id, journey.destination.name) } if (journey.destination.products) { @@ -92,14 +93,14 @@ test('Berlin Jungfernheide to München Hbf', async (t) => { const part = journey.parts[0] assertValidStation(t, part.origin) - if (!await findStation(part.origin.id)) { + if (!(yield 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)) { + if (!(yield findStation(part.destination.id))) { console.error('unknown station', part.destination.id, part.destination.name) } t.ok(isValidWhen(part.arrival)) @@ -112,10 +113,10 @@ test('Berlin Jungfernheide to München Hbf', async (t) => { } t.end() -}) +})) -test('Berlin Jungfernheide to Torfstraße 17', async (t) => { - const journeys = await client.journeys('8011167', { +test('Berlin Jungfernheide to Torfstraße 17', co.wrap(function* (t) { + const journeys = yield client.journeys('8011167', { type: 'address', name: 'Torfstraße 17', latitude: 52.5416823, longitude: 13.3491223 }, {when}) @@ -126,7 +127,7 @@ test('Berlin Jungfernheide to Torfstraße 17', async (t) => { const part = journey.parts[journey.parts.length - 1] assertValidStation(t, part.origin) - if (!await findStation(part.origin.id)) { + if (!(yield findStation(part.origin.id))) { console.error('unknown station', part.origin.id, part.origin.name) } if (part.origin.products) assertValidProducts(t, part.origin.products) @@ -140,10 +141,10 @@ test('Berlin Jungfernheide to Torfstraße 17', async (t) => { 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', { +test('Berlin Jungfernheide to ATZE Musiktheater', co.wrap(function* (t) { + const journeys = yield client.journeys('8011167', { type: 'poi', name: 'ATZE Musiktheater', id: '991598902', latitude: 52.542417, longitude: 13.350437 }, {when}) @@ -154,7 +155,7 @@ test('Berlin Jungfernheide to ATZE Musiktheater', async (t) => { const part = journey.parts[journey.parts.length - 1] assertValidStation(t, part.origin) - if (!await findStation(part.origin.id)) { + if (!(yield findStation(part.origin.id))) { console.error('unknown station', part.origin.id, part.origin.name) } if (part.origin.products) assertValidProducts(t, part.origin.products) @@ -168,17 +169,17 @@ test('Berlin Jungfernheide to ATZE Musiktheater', async (t) => { t.ok(isRoughlyEqual(.0001, d.coordinates.longitude, 13.350402)) t.end() -}) +})) -test('departures at Berlin Jungfernheide', async (t) => { - const deps = await client.departures('8011167', { +test('departures at Berlin Jungfernheide', co.wrap(function* (t) { + const deps = yield 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)) { + if (!(yield findStation(dep.station.id))) { console.error('unknown station', dep.station.id, dep.station.name) } if (dep.station.products) assertValidProducts(t, dep.station.products) @@ -186,10 +187,10 @@ test('departures at Berlin Jungfernheide', async (t) => { } t.end() -}) +})) -test('nearby Berlin Jungfernheide', async (t) => { - const nearby = await client.nearby(52.530273, 13.299433, { +test('nearby Berlin Jungfernheide', co.wrap(function* (t) { + const nearby = yield client.nearby(52.530273, 13.299433, { results: 2, distance: 400 }) @@ -201,10 +202,10 @@ test('nearby Berlin Jungfernheide', async (t) => { t.ok(nearby[0].distance <= 100) t.end() -}) +})) -test('locations named Jungfernheide', async (t) => { - const locations = await client.locations('Jungfernheide', { +test('locations named Jungfernheide', co.wrap(function* (t) { + const locations = yield client.locations('Jungfernheide', { results: 10 }) @@ -216,4 +217,4 @@ test('locations named Jungfernheide', async (t) => { t.ok(locations.some(isJungfernheide)) t.end() -}) +})) diff --git a/test/vbb.js b/test/vbb.js index 0bbd9331..53b8de79 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -5,6 +5,7 @@ const isRoughlyEqual = require('is-roughly-equal') const stations = require('vbb-stations-autocomplete') const tapePromise = require('tape-promise').default const tape = require('tape') +const co = require('co') const createClient = require('..') const vbbProfile = require('../p/vbb') @@ -30,8 +31,8 @@ const amrumerStr = '900000009101' const spichernstr = '900000042101' const bismarckstr = '900000024201' -test('journeys – station to station', async (t) => { - const journeys = await client.journeys(spichernstr, amrumerStr, { +test('journeys – station to station', co.wrap(function* (t) { + const journeys = yield client.journeys(spichernstr, amrumerStr, { results: 3, when, passedStations: true }) @@ -71,10 +72,10 @@ test('journeys – station to station', async (t) => { for (let passed of part.passed) assertValidStopover(t, passed) } t.end() -}) +})) -test('journeys – only subway', async (t) => { - const journeys = await client.journeys(spichernstr, bismarckstr, { +test('journeys – only subway', co.wrap(function* (t) { + const journeys = yield client.journeys(spichernstr, bismarckstr, { results: 20, when, products: { suburban: false, @@ -100,11 +101,11 @@ test('journeys – only subway', async (t) => { } } t.end() -}) +})) -test('journeys – fails with no product', async (t) => { +test('journeys – fails with no product', co.wrap(function* (t) { try { - await client.journeys(spichernstr, bismarckstr, { + yield client.journeys(spichernstr, bismarckstr, { when, products: { suburban: false, @@ -120,17 +121,17 @@ test('journeys – fails with no product', async (t) => { t.ok(err, 'error thrown') t.end() } -}) +})) -test('journey part details', async (t) => { - const journeys = await client.journeys(spichernstr, amrumerStr, { +test('journey part details', co.wrap(function* (t) { + const journeys = yield client.journeys(spichernstr, amrumerStr, { results: 1, when }) const p = journeys[0].parts[0] t.ok(p.id, 'precondition failed') t.ok(p.line.name, 'precondition failed') - const part = await client.journeyPart(p.id, p.line.name, {when}) + const part = yield client.journeyPart(p.id, p.line.name, {when}) t.equal(typeof part.id, 'string') t.ok(part.id) @@ -144,12 +145,12 @@ test('journey part details', async (t) => { for (let passed of part.passed) assertValidStopover(t, passed) t.end() -}) +})) -test('journeys – station to address', async (t) => { - const journeys = await client.journeys(spichernstr, { +test('journeys – station to address', co.wrap(function* (t) { + const journeys = yield client.journeys(spichernstr, { type: 'address', name: 'Torfstraße 17', latitude: 52.5416823, longitude: 13.3491223 }, {results: 1, when}) @@ -170,12 +171,12 @@ test('journeys – station to address', async (t) => { assertValidWhen(t, part.arrival) t.end() -}) +})) -test('journeys – station to POI', async (t) => { - const journeys = await client.journeys(spichernstr, { +test('journeys – station to POI', co.wrap(function* (t) { + const journeys = yield client.journeys(spichernstr, { type: 'poi', name: 'ATZE Musiktheater', id: 9980720, latitude: 52.543333, longitude: 13.351686 }, {results: 1, when}) @@ -196,12 +197,12 @@ test('journeys – station to POI', async (t) => { assertValidWhen(t, part.arrival) t.end() -}) +})) -test('departures', async (t) => { - const deps = await client.departures(spichernstr, {duration: 5, when}) +test('departures', co.wrap(function* (t) { + const deps = yield client.departures(spichernstr, {duration: 5, when}) t.ok(Array.isArray(deps)) t.deepEqual(deps, deps.sort((a, b) => t.when > b.when)) @@ -218,22 +219,22 @@ test('departures', async (t) => { assertValidLine(t, dep.line) } t.end() -}) +})) // todo -test.skip('departures at 7-digit station', async (t) => { +test.skip('departures at 7-digit station', co.wrap(function* (t) { const eisenach = '8010097' // see derhuerst/vbb-hafas#22 - await client.departures(eisenach, {when}) + yield client.departures(eisenach, {when}) t.pass('did not fail') t.end() -}) +})) -test('nearby', async (t) => { +test('nearby', co.wrap(function* (t) { // Berliner Str./Bundesallee - const nearby = await client.nearby(52.4873452, 13.3310411, {distance: 200}) + const nearby = yield client.nearby(52.4873452, 13.3310411, {distance: 200}) t.ok(Array.isArray(nearby)) for (let n of nearby) assertValidLocation(t, n, false) @@ -249,12 +250,12 @@ test('nearby', async (t) => { t.ok(nearby[1].distance < 200) t.end() -}) +})) -test('locations', async (t) => { - const locations = await client.locations('Alexanderplatz', {results: 10}) +test('locations', co.wrap(function* (t) { + const locations = yield client.locations('Alexanderplatz', {results: 10}) t.ok(Array.isArray(locations)) t.ok(locations.length > 0) @@ -265,12 +266,12 @@ test('locations', async (t) => { t.ok(locations.find((s) => s.type === 'address')) t.end() -}) +})) -test('radar', async (t) => { - const vehicles = await client.radar(52.52411, 13.41002, 52.51942, 13.41709, { +test('radar', co.wrap(function* (t) { + const vehicles = yield client.radar(52.52411, 13.41002, 52.51942, 13.41709, { duration: 5 * 60, when }) @@ -317,4 +318,4 @@ test('radar', async (t) => { } } t.end() -}) +}))