From 522248b9080e4c1047d1f2a2945e3444d0ade357 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Tue, 10 Mar 2020 23:48:01 +0100 Subject: [PATCH] add RSAG E2E tests :white_check_mark: --- test/e2e/index.js | 1 + test/e2e/rsag.js | 127 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 test/e2e/rsag.js diff --git a/test/e2e/index.js b/test/e2e/index.js index e97a3cb9..f4f8563c 100644 --- a/test/e2e/index.js +++ b/test/e2e/index.js @@ -16,6 +16,7 @@ require('./hvv') require('./vsn') require('./vbn') require('./rmv') +require('./rsag') require('./db-busradar-nrw') require('./invg') require('./pkp') diff --git a/test/e2e/rsag.js b/test/e2e/rsag.js new file mode 100644 index 00000000..7997419c --- /dev/null +++ b/test/e2e/rsag.js @@ -0,0 +1,127 @@ +'use strict' + +const assert = require('assert') +const tapePromise = require('tape-promise').default +const tape = require('tape') + +const {createWhen} = require('./lib/util') +const createClient = require('../..') +const rsagProfile = require('../../p/rsag') +const products = require('../../p/rsag/products') +const createValidate = require('./lib/validate-fptf-with') +const testJourneysStationToStation = require('./lib/journeys-station-to-station') +const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') +const testRefreshJourney = require('./lib/refresh-journey') +const testArrivals = require('./lib/arrivals') +const testReachableFrom = require('./lib/reachable-from') + +const when = createWhen(rsagProfile.timezone, rsagProfile.locale) + +const cfg = { + when, + // stationCoordsOptional: false, + products, + minLatitude: 52.299, + maxLatitude: 54.862, + minLongitude: 9.121, + maxLongitude: 14.824, +} + +const validate = createValidate(cfg) + +const test = tapePromise(tape) +const client = createClient(rsagProfile, 'public-transport/hafas-client:test') + +const sternwarte = '704956' +const sternwarte2 = '708539' +const weißesKreuz = '708573' + +test('journeys – Platz der Jugend to Weißes Kreuz', async (t) => { + const res = await client.journeys(sternwarte, weißesKreuz, { + results: 4, + departure: when, + stopovers: true + }) + + await testJourneysStationToStation({ + test: t, + res, + validate, + fromId: sternwarte, + toId: weißesKreuz + }) + t.end() +}) + +// todo: journeys, walkingSpeed +// todo: via works – with detour + +test('earlier/later journeys', async (t) => { + await testEarlierLaterJourneys({ + test: t, + fetchJourneys: client.journeys, + validate, + fromId: sternwarte, + toId: weißesKreuz, + when + }) + + t.end() +}) + +test.skip('refreshJourney', async (t) => { + await testRefreshJourney({ + test: t, + fetchJourneys: client.journeys, + refreshJourney: client.refreshJourney, + validate, + fromId: sternwarte, + toId: weißesKreuz, + when + }) + t.end() +}) + +test('arrivals at Platz der Jugend', async (t) => { + const arrivals = await client.arrivals(sternwarte, { + duration: 30, when + }) + + validate(t, arrivals, 'arrivals', 'arrivals') + t.ok(arrivals.length > 0, 'must be >0 arrivals') + t.deepEqual(arrivals, arrivals.sort((a, b) => t.when > b.when)) + t.end() +}) + +// todo: nearby + +test.skip('radar', async (t) => { + const vehicles = await client.radar({ + north: 54.116968, + west: 12.029738, + south: 54.060517, + east: 12.203261 + }, { + duration: 5 * 60, when, results: 10 + }) + + validate(t, vehicles, 'movements', 'vehicles') + t.end() +}) + +test('reachableFrom', async (t) => { + await testReachableFrom({ + test: t, + reachableFrom: client.reachableFrom, + address: { + type: 'location', + id: '990004158', + address: 'Rostock - Stadtmitte, Pläterstraße 2', + latitude: 54.091285, longitude: 12.13648 + }, + when, + maxDuration: 15, + validate + }) + t.end() +})