fix DB E2E tests

This commit is contained in:
Jannis R 2019-12-27 22:17:13 +01:00
parent 4ba4cefab6
commit 655c425ecf
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5

View file

@ -1,6 +1,6 @@
'use strict' 'use strict'
const stations = require('db-stations/full.json') const {full: readStations} = require('db-stations')
const a = require('assert') const a = require('assert')
const tapePromise = require('tape-promise').default const tapePromise = require('tape-promise').default
const tape = require('tape') const tape = require('tape')
@ -29,6 +29,14 @@ const testArrivals = require('./lib/arrivals')
const testJourneysWithDetour = require('./lib/journeys-with-detour') const testJourneysWithDetour = require('./lib/journeys-with-detour')
const testReachableFrom = require('./lib/reachable-from') const testReachableFrom = require('./lib/reachable-from')
const stations = []
const pStations = new Promise((resolve, reject) => {
readStations()
.once('error', reject)
.once('end', () => resolve())
.on('data', station => stations.push(station))
})
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o) const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
const when = createWhen('Europe/Berlin', 'de-DE') const when = createWhen('Europe/Berlin', 'de-DE')
@ -88,6 +96,8 @@ const blnJannowitzbrücke = '8089019'
const potsdamHbf = '8012666' const potsdamHbf = '8012666'
test('journeys  Berlin Schwedter Str. to München Hbf', async (t) => { test('journeys  Berlin Schwedter Str. to München Hbf', async (t) => {
await pStations
const res = await client.journeys(blnSchwedterStr, münchenHbf, { const res = await client.journeys(blnSchwedterStr, münchenHbf, {
results: 4, results: 4,
departure: when, departure: when,
@ -124,6 +134,8 @@ test('journeys  fails with no product', (t) => {
}) })
test('Berlin Schwedter Str. to Torfstraße 17', async (t) => { test('Berlin Schwedter Str. to Torfstraße 17', async (t) => {
await pStations
const torfstr = { const torfstr = {
type: 'location', type: 'location',
address: 'Torfstraße 17', address: 'Torfstraße 17',
@ -146,6 +158,8 @@ test('Berlin Schwedter Str. to Torfstraße 17', async (t) => {
}) })
test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => { test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => {
await pStations
const atze = { const atze = {
type: 'location', type: 'location',
id: '991598902', id: '991598902',
@ -170,6 +184,8 @@ test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => {
}) })
test('journeys: via works with detour', async (t) => { test('journeys: via works with detour', async (t) => {
await pStations
// Going from Westhafen to Wedding via Württembergalle without detour // Going from Westhafen to Wedding via Württembergalle without detour
// is currently impossible. We check if the routing engine computes a detour. // is currently impossible. We check if the routing engine computes a detour.
const res = await client.journeys(westhafen, wedding, { const res = await client.journeys(westhafen, wedding, {
@ -192,6 +208,8 @@ test('journeys: via works with detour', async (t) => {
// todo: without detour // todo: without detour
test('earlier/later journeys, Jungfernheide -> München Hbf', async (t) => { test('earlier/later journeys, Jungfernheide -> München Hbf', async (t) => {
await pStations
await testEarlierLaterJourneys({ await testEarlierLaterJourneys({
test: t, test: t,
fetchJourneys: client.journeys, fetchJourneys: client.journeys,
@ -205,6 +223,8 @@ test('earlier/later journeys, Jungfernheide -> München Hbf', async (t) => {
}) })
test.skip('journeys  leg cycle & alternatives', async (t) => { test.skip('journeys  leg cycle & alternatives', async (t) => {
await pStations
await testLegCycleAlternatives({ await testLegCycleAlternatives({
test: t, test: t,
fetchJourneys: client.journeys, fetchJourneys: client.journeys,
@ -215,6 +235,8 @@ test.skip('journeys  leg cycle & alternatives', async (t) => {
}) })
test('refreshJourney', async (t) => { test('refreshJourney', async (t) => {
await pStations
await testRefreshJourney({ await testRefreshJourney({
test: t, test: t,
fetchJourneys: client.journeys, fetchJourneys: client.journeys,
@ -228,6 +250,8 @@ test('refreshJourney', async (t) => {
}) })
test('trip details', async (t) => { test('trip details', async (t) => {
await pStations
const res = await client.journeys(berlinHbf, münchenHbf, { const res = await client.journeys(berlinHbf, münchenHbf, {
results: 1, departure: when results: 1, departure: when
}) })
@ -251,6 +275,8 @@ test('trip details', async (t) => {
}) })
test('departures at Berlin Schwedter Str.', async (t) => { test('departures at Berlin Schwedter Str.', async (t) => {
await pStations
const departures = await client.departures(blnSchwedterStr, { const departures = await client.departures(blnSchwedterStr, {
duration: 5, when, duration: 5, when,
stopovers: true stopovers: true
@ -266,6 +292,8 @@ test('departures at Berlin Schwedter Str.', async (t) => {
}) })
test('departures with station object', async (t) => { test('departures with station object', async (t) => {
await pStations
const deps = await client.departures({ const deps = await client.departures({
type: 'station', type: 'station',
id: jungfernheide, id: jungfernheide,
@ -282,6 +310,8 @@ test('departures with station object', async (t) => {
}) })
test('departures at Berlin Hbf in direction of Berlin Ostbahnhof', async (t) => { test('departures at Berlin Hbf in direction of Berlin Ostbahnhof', async (t) => {
await pStations
await testDeparturesInDirection({ await testDeparturesInDirection({
test: t, test: t,
fetchDepartures: client.departures, fetchDepartures: client.departures,
@ -295,6 +325,8 @@ test('departures at Berlin Hbf in direction of Berlin Ostbahnhof', async (t) =>
}) })
test('departures without related stations', async (t) => { test('departures without related stations', async (t) => {
await pStations
await testDeparturesWithoutRelatedStations({ await testDeparturesWithoutRelatedStations({
test: t, test: t,
fetchDepartures: client.departures, fetchDepartures: client.departures,
@ -307,6 +339,8 @@ test('departures without related stations', async (t) => {
}) })
test('arrivals at Berlin Schwedter Str.', async (t) => { test('arrivals at Berlin Schwedter Str.', async (t) => {
await pStations
const arrivals = await client.arrivals(blnSchwedterStr, { const arrivals = await client.arrivals(blnSchwedterStr, {
duration: 5, when, duration: 5, when,
stopovers: true stopovers: true
@ -322,6 +356,8 @@ test('arrivals at Berlin Schwedter Str.', async (t) => {
}) })
test('nearby Berlin Jungfernheide', async (t) => { test('nearby Berlin Jungfernheide', async (t) => {
await pStations
const nearby = await client.nearby({ const nearby = await client.nearby({
type: 'location', type: 'location',
latitude: 52.530273, latitude: 52.530273,
@ -346,6 +382,8 @@ test('nearby Berlin Jungfernheide', async (t) => {
}) })
test('locations named Jungfernheide', async (t) => { test('locations named Jungfernheide', async (t) => {
await pStations
const locations = await client.locations('Jungfernheide', { const locations = await client.locations('Jungfernheide', {
results: 10 results: 10
}) })
@ -360,6 +398,8 @@ test('locations named Jungfernheide', async (t) => {
}) })
test('stop', async (t) => { test('stop', async (t) => {
await pStations
const s = await client.stop(regensburgHbf) const s = await client.stop(regensburgHbf)
validate(t, s, ['stop', 'station'], 'stop') validate(t, s, ['stop', 'station'], 'stop')
@ -378,6 +418,8 @@ test('line with additionalName', async (t) => {
}) })
test.skip('radar', async (t) => { test.skip('radar', async (t) => {
await pStations
const vehicles = await client.radar({ const vehicles = await client.radar({
north: 52.52411, north: 52.52411,
west: 13.41002, west: 13.41002,
@ -392,6 +434,8 @@ test.skip('radar', async (t) => {
}) })
test('reachableFrom', async (t) => { test('reachableFrom', async (t) => {
await pStations
const torfstr17 = { const torfstr17 = {
type: 'location', type: 'location',
address: 'Torfstraße 17', address: 'Torfstraße 17',