From 1eeb0d7bd772c39f3c00924a4e27a16bac976216 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Fri, 15 Feb 2019 14:53:01 +0100 Subject: [PATCH] make tests more reliable :green_heart: --- test/cmta.js | 26 ++++++-------------------- test/db.js | 6 +++++- test/insa.js | 13 +++++++++---- test/nahsh.js | 17 +++++++++++------ test/oebb.js | 6 +++++- test/sbahn-muenchen.js | 6 +++++- test/vbn.js | 6 +++++- 7 files changed, 46 insertions(+), 34 deletions(-) diff --git a/test/cmta.js b/test/cmta.js index 205b1988..d8e79f91 100644 --- a/test/cmta.js +++ b/test/cmta.js @@ -9,7 +9,6 @@ const co = require('./lib/co') const createClient = require('..') const cmtaProfile = require('../p/cmta') const products = require('../p/cmta/products') -const {movement: _validateMovement} = require('./lib/validators') const createValidate = require('./lib/validate-fptf-with') const testJourneysStationToStation = require('./lib/journeys-station-to-station') const testJourneysStationToAddress = require('./lib/journeys-station-to-address') @@ -27,27 +26,14 @@ const when = createWhen(cmtaProfile.timezone, cmtaProfile.locale) const cfg = { when, stationCoordsOptional: false, - products + products, + minLatitude: 26, + maxLatitude: 33, + minLongitude: -100, + maxLongitude: -95 } -const validateMovement = (val, m, name = 'movement') => { - // todo: fix this upstream - const withFakeLocation = Object.assign({}, m) - withFakeLocation.location = Object.assign({}, m.location, { - latitude: 50, - longitude: 12 - }) - _validateMovement(val, withFakeLocation, name) - - assert.ok(m.location.latitude <= 33, name + '.location.latitude is too small') - assert.ok(m.location.latitude >= 26, name + '.location.latitude is too large') - assert.ok(m.location.longitude >= -100, name + '.location.longitude is too small') - assert.ok(m.location.longitude <= -95, name + '.location.longitude is too small') -} - -const validate = createValidate(cfg, { - movement: validateMovement -}) +const validate = createValidate(cfg) const test = tapePromise(tape) const client = createClient(cmtaProfile, 'public-transport/hafas-client:test') diff --git a/test/db.js b/test/db.js index f2b2aaa3..f87c2e27 100644 --- a/test/db.js +++ b/test/db.js @@ -37,7 +37,11 @@ const when = createWhen('Europe/Berlin', 'de-DE') const cfg = { when, stationCoordsOptional: false, - products + products, + minLatitude: 46.673100, + maxLatitude: 55.030671, + minLongitude: 6.896517, + maxLongitude: 16.180237 } const _validateStation = createValidateStation(cfg) diff --git a/test/insa.js b/test/insa.js index da169295..742839d7 100644 --- a/test/insa.js +++ b/test/insa.js @@ -27,7 +27,11 @@ const when = createWhen('Europe/Berlin', 'de-DE') const cfg = { when, stationCoordsOptional: false, - products + products, + minLatitude: 50.7, + maxLatitude: 53.2, + minLongitude: 10.25, + maxLongitude: 13.4 } const validate = createValidate(cfg, {}) @@ -230,7 +234,8 @@ test('arrivals at Magdeburg Leiterstr.', co(function*(t) { // todo: nearby test('locations named Magdeburg', co(function*(t) { - const locations = yield client.locations('Magdeburg', { + const nordpark = '7480' + const locations = yield client.locations('nordpark', { results: 20 }) @@ -242,9 +247,9 @@ test('locations named Magdeburg', co(function*(t) { t.ok(locations.some((l) => { // todo: trim IDs if (l.station) { - if (l.station.id === '008010224' || l.station.id === magdeburgHbf) return true + if (l.station.id === '000007480' || l.station.id === nordpark) return true } - return l.id === '008010224' || l.id === magdeburgHbf + return l.id === '000007480' || l.id === nordpark })) t.end() diff --git a/test/nahsh.js b/test/nahsh.js index 66c25eda..9c50c59d 100644 --- a/test/nahsh.js +++ b/test/nahsh.js @@ -30,7 +30,11 @@ const when = createWhen('Europe/Berlin', 'de-DE') const cfg = { when, stationCoordsOptional: false, - products + products, + maxLatitude: 55.15, + minLongitude: 7.5, + minLatitude: 53.15, + maxLongitude: 11.6 } const _validateLine = createValidateLine(cfg) @@ -300,17 +304,18 @@ test('nearby Kiel Hbf', co(function* (t) { t.end() })) -test('locations named Kiel', co(function* (t) { - const locations = yield client.locations('Kiel', { - results: 20 +test('locations named "Kiel Rathaus"', co(function* (t) { + const kielRathaus = '9049200' + const locations = yield client.locations('Kiel Rathaus', { + results: 15 }) validate(t, locations, 'locations', 'locations') - t.ok(locations.length <= 20) + t.ok(locations.length <= 15) t.ok(locations.find(l => l.type === 'stop' || l.type === 'station')) t.ok(locations.find(l => l.id && l.name)) // POIs - t.ok(locations.some(l => l.station && l.station.id === kielHbf || l.id === kielHbf)) + t.ok(locations.some(l => l.station && l.station.id === kielRathaus || l.id === kielRathaus)) t.end() })) diff --git a/test/oebb.js b/test/oebb.js index 1b248c62..2f309495 100644 --- a/test/oebb.js +++ b/test/oebb.js @@ -29,7 +29,11 @@ const when = createWhen('Europe/Vienna', 'de-AT') const cfg = { when, stationCoordsOptional: false, - products + products, + minLatitude: 45.992803, + maxLatitude: 49.453517, + minLongitude: 8.787557, + maxLongitude: 17.491275 } // todo validateDirection: search list of stations for direction diff --git a/test/sbahn-muenchen.js b/test/sbahn-muenchen.js index 68bfc185..b2c5aebe 100644 --- a/test/sbahn-muenchen.js +++ b/test/sbahn-muenchen.js @@ -27,7 +27,11 @@ const when = createWhen(sMunichProfile.timezone, sMunichProfile.locale) const cfg = { when, stationCoordsOptional: false, - products + products, + minLatitude: 48, + maxLatitude: 48.3, + minLongitude: 11.3, + maxLongitude: 11.8 } const validateMovement = (val, m, name = 'movement') => { diff --git a/test/vbn.js b/test/vbn.js index 72cbc3ea..67e97764 100644 --- a/test/vbn.js +++ b/test/vbn.js @@ -25,7 +25,11 @@ const when = createWhen('Europe/Berlin', 'de-DE') const cfg = { when, stationCoordsOptional: false, - products + products, + minLatitude: 52.559311, + maxLatitude: 53.948075, + minLongitude: 7.622917, + maxLongitude: 9.984605 } const validate = createValidate(cfg, {})