mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 23:29:35 +02:00
add E2E tests for SVV ✅
This commit is contained in:
parent
fa3146d706
commit
9c4189a874
3 changed files with 103 additions and 0 deletions
|
@ -6,6 +6,8 @@ const NOT_FOUND = 'NOT_FOUND'
|
||||||
const SERVER_ERROR = 'SERVER_ERROR'
|
const SERVER_ERROR = 'SERVER_ERROR'
|
||||||
|
|
||||||
// https://gist.github.com/derhuerst/79d49c0f04c1c192a5d15756e5af575f/edit
|
// https://gist.github.com/derhuerst/79d49c0f04c1c192a5d15756e5af575f/edit
|
||||||
|
// todo:
|
||||||
|
// `code: 'METHOD_NA', message: 'HCI Service: service method disabled'`
|
||||||
const byErrorCode = Object.assign(Object.create(null), {
|
const byErrorCode = Object.assign(Object.create(null), {
|
||||||
H_UNKNOWN: {
|
H_UNKNOWN: {
|
||||||
isServer: false,
|
isServer: false,
|
||||||
|
|
|
@ -21,3 +21,4 @@ require('./db-busradar-nrw')
|
||||||
require('./invg')
|
require('./invg')
|
||||||
require('./pkp')
|
require('./pkp')
|
||||||
require('./sncb')
|
require('./sncb')
|
||||||
|
require('./svv')
|
||||||
|
|
100
test/e2e/svv.js
Normal file
100
test/e2e/svv.js
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
'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 svvProfile = require('../../p/svv')
|
||||||
|
const products = require('../../p/svv/products')
|
||||||
|
const createValidate = require('./lib/validate-fptf-with')
|
||||||
|
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
||||||
|
const testRefreshJourney = require('./lib/refresh-journey')
|
||||||
|
const testArrivals = require('./lib/arrivals')
|
||||||
|
const testReachableFrom = require('./lib/reachable-from')
|
||||||
|
|
||||||
|
const when = createWhen(svvProfile.timezone, svvProfile.locale)
|
||||||
|
|
||||||
|
const cfg = {
|
||||||
|
when,
|
||||||
|
stationCoordsOptional: false,
|
||||||
|
products,
|
||||||
|
minLatitude: 45.742,
|
||||||
|
maxLatitude: 49.41,
|
||||||
|
minLongitude: 8.177,
|
||||||
|
maxLongitude: 18.448,
|
||||||
|
}
|
||||||
|
|
||||||
|
const validate = createValidate(cfg)
|
||||||
|
|
||||||
|
const test = tapePromise(tape)
|
||||||
|
const client = createClient(svvProfile, 'public-transport/hafas-client:test')
|
||||||
|
|
||||||
|
const sam = '455086100'
|
||||||
|
const volksgarten = '455082100'
|
||||||
|
const zillnerstr2 = {
|
||||||
|
type: 'location',
|
||||||
|
id: '980133005',
|
||||||
|
address: 'Zillnerstraße 2, 5020 Salzburg',
|
||||||
|
latitude: 47.801434, longitude: 13.031006,
|
||||||
|
}
|
||||||
|
|
||||||
|
test('journeys – Sam to Volksgarten', async (t) => {
|
||||||
|
const res = await client.journeys(sam, volksgarten, {
|
||||||
|
results: 4,
|
||||||
|
departure: when,
|
||||||
|
stopovers: true
|
||||||
|
})
|
||||||
|
|
||||||
|
await testJourneysStationToStation({
|
||||||
|
test: t,
|
||||||
|
res,
|
||||||
|
validate,
|
||||||
|
fromId: sam,
|
||||||
|
toId: volksgarten
|
||||||
|
})
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
// todo: via works – with detour
|
||||||
|
// todo: without detour
|
||||||
|
|
||||||
|
test('trip details', async (t) => {
|
||||||
|
const res = await client.journeys(sam, volksgarten, {
|
||||||
|
results: 1, departure: when
|
||||||
|
})
|
||||||
|
|
||||||
|
const p = res.journeys[0].legs[0]
|
||||||
|
t.ok(p.tripId, 'precondition failed')
|
||||||
|
t.ok(p.line.name, 'precondition failed')
|
||||||
|
const trip = await client.trip(p.tripId, p.line.name, {when})
|
||||||
|
|
||||||
|
validate(t, trip, 'trip', 'trip')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
test('arrivals at Bremen Humboldtstr.', async (t) => {
|
||||||
|
const arrivals = await client.arrivals(volksgarten, {
|
||||||
|
duration: 10, 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('reachableFrom', async (t) => {
|
||||||
|
await testReachableFrom({
|
||||||
|
test: t,
|
||||||
|
reachableFrom: client.reachableFrom,
|
||||||
|
address: zillnerstr2,
|
||||||
|
when,
|
||||||
|
maxDuration: 15,
|
||||||
|
validate
|
||||||
|
})
|
||||||
|
t.end()
|
||||||
|
})
|
Loading…
Add table
Reference in a new issue