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