mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
E2E/integration tests: DRY & tweak assertions ✅
This commit is contained in:
parent
bdf933f806
commit
2ed2f38195
12 changed files with 76 additions and 80 deletions
|
@ -18,6 +18,7 @@ const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
|
||||||
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||||
const testRefreshJourney = require('./lib/refresh-journey')
|
const testRefreshJourney = require('./lib/refresh-journey')
|
||||||
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
||||||
|
const testDepartures = require('./lib/departures')
|
||||||
const testArrivals = require('./lib/arrivals')
|
const testArrivals = require('./lib/arrivals')
|
||||||
|
|
||||||
const T_MOCK = 1641897000 * 1000 // 2022-01-11T11:30:00+01
|
const T_MOCK = 1641897000 * 1000 // 2022-01-11T11:30:00+01
|
||||||
|
@ -184,16 +185,12 @@ tap.test('departures at Ingolstadt Hbf', async (t) => {
|
||||||
duration: 10, when
|
duration: 10, when
|
||||||
})
|
})
|
||||||
|
|
||||||
validate(t, deps, 'departures', 'departures')
|
await testDepartures({
|
||||||
t.ok(deps.length > 0, 'must be >0 departures')
|
test: t,
|
||||||
// todo: move into deps validator
|
departures: deps,
|
||||||
t.same(deps, deps.sort((a, b) => t.when > b.when))
|
validate,
|
||||||
|
ids,
|
||||||
for (let i = 0; i < deps.length; i++) {
|
})
|
||||||
const dep = deps[i]
|
|
||||||
t.ok(ids.includes(dep.stop.id), `deps[${i}].stop.id ("${dep.stop.id}") is invalid`)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -224,16 +221,12 @@ tap.test('arrivals at Ingolstadt Hbf', async (t) => {
|
||||||
duration: 10, when
|
duration: 10, when
|
||||||
})
|
})
|
||||||
|
|
||||||
validate(t, arrs, 'arrivals', 'arrivals')
|
await testArrivals({
|
||||||
t.ok(arrs.length > 0, 'must be >0 arrivals')
|
test: t,
|
||||||
// todo: move into arrs validator
|
arrivals: arrs,
|
||||||
t.same(arrs, arrs.sort((a, b) => t.when > b.when))
|
validate,
|
||||||
|
ids,
|
||||||
for (let i = 0; i < arrs.length; i++) {
|
})
|
||||||
const arr = arrs[i]
|
|
||||||
t.ok(ids.includes(arr.stop.id), `arrs[${i}].stop.id ("${arr.stop.id}") is invalid`)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ const testArrivals = async (cfg) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: move into arrivals validator
|
// todo: move into arrivals validator
|
||||||
t.same(arrs, arrs.sort((a, b) => t.when > b.when))
|
t.same(arrs, arrs.sort((a, b) => t.when > b.when), 'arrivals must be sorted by .when')
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = testArrivals
|
module.exports = testArrivals
|
||||||
|
|
|
@ -22,7 +22,7 @@ const testDepartures = async (cfg) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: move into deps validator
|
// todo: move into deps validator
|
||||||
t.same(deps, deps.sort((a, b) => t.when > b.when))
|
t.same(deps, deps.sort((a, b) => t.when > b.when), 'departures must be sorted by .when')
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = testDepartures
|
module.exports = testDepartures
|
||||||
|
|
|
@ -491,19 +491,21 @@ const createValidateDeparture = (cfg) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const validateArrivals = (val, deps, name = 'arrivals') => {
|
const _createValidateStationBoardResults = (cfg, validatorsKey) => {
|
||||||
a.ok(Array.isArray(deps), name + ' must be an array')
|
const validateStationBoardResults = (val, arrsOrDeps, name) => {
|
||||||
a.ok(deps.length > 0, name + ' must not be empty')
|
a.ok(Array.isArray(arrsOrDeps), name + ' must be an array')
|
||||||
for (let i = 0; i < deps.length; i++) {
|
a.ok(arrsOrDeps.length > 0, name + ' must not be empty')
|
||||||
val.arrival(val, deps[i], name + `[${i}]`)
|
for (let i = 0; i < arrsOrDeps.length; i++) {
|
||||||
|
val[validatorsKey](val, arrsOrDeps[i], name + `[${i}]`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return validateStationBoardResults
|
||||||
}
|
}
|
||||||
const validateDepartures = (val, deps, name = 'departures') => {
|
const createValidateArrivals = (cfg) => {
|
||||||
a.ok(Array.isArray(deps), name + ' must be an array')
|
return _createValidateStationBoardResults(cfg, 'arrival')
|
||||||
a.ok(deps.length > 0, name + ' must not be empty')
|
}
|
||||||
for (let i = 0; i < deps.length; i++) {
|
const createValidateDepartures = (cfg) => {
|
||||||
val.departure(val, deps[i], name + `[${i}]`)
|
return _createValidateStationBoardResults(cfg, 'departure')
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const createValidateMovement = (cfg) => {
|
const createValidateMovement = (cfg) => {
|
||||||
|
@ -582,8 +584,8 @@ module.exports = {
|
||||||
trip: () => validateTrip,
|
trip: () => validateTrip,
|
||||||
arrival: createValidateArrival,
|
arrival: createValidateArrival,
|
||||||
departure: createValidateDeparture,
|
departure: createValidateDeparture,
|
||||||
departures: () => validateDepartures,
|
arrivals: createValidateArrivals,
|
||||||
arrivals: () => validateArrivals,
|
departures: createValidateDepartures,
|
||||||
movement: createValidateMovement,
|
movement: createValidateMovement,
|
||||||
movements: () => validateMovements
|
movements: () => validateMovements
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||||
const testRefreshJourney = require('./lib/refresh-journey')
|
const testRefreshJourney = require('./lib/refresh-journey')
|
||||||
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
||||||
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
||||||
|
const testDepartures = require('./lib/departures')
|
||||||
const testDeparturesInDirection = require('./lib/departures-in-direction')
|
const testDeparturesInDirection = require('./lib/departures-in-direction')
|
||||||
|
|
||||||
const T_MOCK = 1641897000 * 1000 // 2022-01-11T11:30:00+01
|
const T_MOCK = 1641897000 * 1000 // 2022-01-11T11:30:00+01
|
||||||
|
@ -254,16 +255,12 @@ tap.test('departures at Wien Leibenfrostgasse', async (t) => {
|
||||||
duration: 15, when,
|
duration: 15, when,
|
||||||
})
|
})
|
||||||
|
|
||||||
validate(t, deps, 'departures', 'departures')
|
await testDepartures({
|
||||||
t.ok(deps.length > 0, 'must be >0 departures')
|
test: t,
|
||||||
// todo: move into deps validator
|
departures: deps,
|
||||||
t.same(deps, deps.sort((a, b) => t.when > b.when))
|
validate,
|
||||||
|
ids,
|
||||||
for (let i = 0; i < deps.length; i++) {
|
})
|
||||||
const dep = deps[i]
|
|
||||||
t.ok(ids.includes(dep.stop.id), `deps[${i}].stop.id ("${dep.stop.id}") is invalid`)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ const rmvProfile = require('../../p/rmv')
|
||||||
const products = require('../../p/rmv/products')
|
const products = require('../../p/rmv/products')
|
||||||
const createValidate = require('./lib/validate-fptf-with')
|
const createValidate = require('./lib/validate-fptf-with')
|
||||||
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
||||||
const testRefreshJourney = require('./lib/refresh-journey')
|
|
||||||
const testArrivals = require('./lib/arrivals')
|
const testArrivals = require('./lib/arrivals')
|
||||||
const testReachableFrom = require('./lib/reachable-from')
|
const testReachableFrom = require('./lib/reachable-from')
|
||||||
|
|
||||||
|
@ -71,9 +70,12 @@ tap.test('arrivals at Wiesbaden Hbf', async (t) => {
|
||||||
duration: 10, when
|
duration: 10, when
|
||||||
})
|
})
|
||||||
|
|
||||||
validate(t, arrivals, 'arrivals', 'arrivals')
|
await testArrivals({
|
||||||
t.ok(arrivals.length > 0, 'must be >0 arrivals')
|
test: t,
|
||||||
t.same(arrivals, arrivals.sort((a, b) => t.when > b.when))
|
arrivals,
|
||||||
|
validate,
|
||||||
|
id: wiesbadenHbf,
|
||||||
|
})
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -85,9 +85,15 @@ tap.test('arrivals at Platz der Jugend', async (t) => {
|
||||||
duration: 30, when
|
duration: 30, when
|
||||||
})
|
})
|
||||||
|
|
||||||
validate(t, arrivals, 'arrivals', 'arrivals')
|
await testArrivals({
|
||||||
t.ok(arrivals.length > 0, 'must be >0 arrivals')
|
test: t,
|
||||||
t.same(arrivals, arrivals.sort((a, b) => t.when > b.when))
|
arrivals,
|
||||||
|
validate,
|
||||||
|
ids: [
|
||||||
|
sternwarte,
|
||||||
|
'708539', // Rostock Sternwarte
|
||||||
|
],
|
||||||
|
})
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ const testJourneysStationToStation = require('./lib/journeys-station-to-station'
|
||||||
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
|
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
|
||||||
const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
|
const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
|
||||||
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||||
const testRefreshJourney = require('./lib/refresh-journey')
|
|
||||||
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
||||||
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
||||||
const testDepartures = require('./lib/departures')
|
const testDepartures = require('./lib/departures')
|
||||||
|
@ -177,21 +176,12 @@ tap.test('departures', async (t) => {
|
||||||
duration: 5, when
|
duration: 5, when
|
||||||
})
|
})
|
||||||
|
|
||||||
validate(t, departures, 'departures', 'departures')
|
await testDepartures({
|
||||||
t.ok(departures.length > 0, 'must be >0 departures')
|
test: t,
|
||||||
for (let i = 0; i < departures.length; i++) {
|
departures,
|
||||||
let stop = departures[i].stop
|
validate,
|
||||||
let name = `departures[${i}].stop`
|
id: saarbrueckenUhlandstr,
|
||||||
if (stop.station) {
|
})
|
||||||
stop = stop.station
|
|
||||||
name += '.station'
|
|
||||||
}
|
|
||||||
|
|
||||||
t.equal(stop.id, saarbrueckenUhlandstr, name + '.id is invalid')
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo: move into deps validator
|
|
||||||
t.same(departures, departures.sort((a, b) => t.when > b.when))
|
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ const sncbProfile = require('../../p/sncb')
|
||||||
const products = require('../../p/sncb/products')
|
const products = require('../../p/sncb/products')
|
||||||
const createValidate = require('./lib/validate-fptf-with')
|
const createValidate = require('./lib/validate-fptf-with')
|
||||||
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
||||||
const testRefreshJourney = require('./lib/refresh-journey')
|
|
||||||
const testArrivals = require('./lib/arrivals')
|
const testArrivals = require('./lib/arrivals')
|
||||||
const testReachableFrom = require('./lib/reachable-from')
|
const testReachableFrom = require('./lib/reachable-from')
|
||||||
|
|
||||||
|
@ -76,9 +75,12 @@ tap.test('arrivals at Bruxelles Midi', async (t) => {
|
||||||
duration: 10, when
|
duration: 10, when
|
||||||
})
|
})
|
||||||
|
|
||||||
validate(t, arrivals, 'arrivals', 'arrivals')
|
await testArrivals({
|
||||||
t.ok(arrivals.length > 0, 'must be >0 arrivals')
|
test: t,
|
||||||
t.same(arrivals, arrivals.sort((a, b) => t.when > b.when))
|
arrivals,
|
||||||
|
validate,
|
||||||
|
id: bruxellesMidi,
|
||||||
|
})
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ const svvProfile = require('../../p/svv')
|
||||||
const products = require('../../p/svv/products')
|
const products = require('../../p/svv/products')
|
||||||
const createValidate = require('./lib/validate-fptf-with')
|
const createValidate = require('./lib/validate-fptf-with')
|
||||||
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
||||||
const testRefreshJourney = require('./lib/refresh-journey')
|
|
||||||
const testArrivals = require('./lib/arrivals')
|
const testArrivals = require('./lib/arrivals')
|
||||||
const testReachableFrom = require('./lib/reachable-from')
|
const testReachableFrom = require('./lib/reachable-from')
|
||||||
const testServerInfo = require('./lib/server-info')
|
const testServerInfo = require('./lib/server-info')
|
||||||
|
@ -78,9 +77,12 @@ tap.test('arrivals at Volksgarten', async (t) => {
|
||||||
duration: 10, when
|
duration: 10, when
|
||||||
})
|
})
|
||||||
|
|
||||||
validate(t, arrivals, 'arrivals', 'arrivals')
|
await testArrivals({
|
||||||
t.ok(arrivals.length > 0, 'must be >0 arrivals')
|
test: t,
|
||||||
t.same(arrivals, arrivals.sort((a, b) => t.when > b.when))
|
arrivals,
|
||||||
|
validate,
|
||||||
|
id: volksgarten,
|
||||||
|
})
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -70,9 +70,12 @@ tap.test('arrivals at Bremen Humboldtstr.', async (t) => {
|
||||||
duration: 10, when
|
duration: 10, when
|
||||||
})
|
})
|
||||||
|
|
||||||
validate(t, arrivals, 'arrivals', 'arrivals')
|
await testArrivals({
|
||||||
t.ok(arrivals.length > 0, 'must be >0 arrivals')
|
test: t,
|
||||||
t.same(arrivals, arrivals.sort((a, b) => t.when > b.when))
|
arrivals,
|
||||||
|
validate,
|
||||||
|
id: bremenHumboldtstr,
|
||||||
|
})
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ const zvvProfile = require('../../p/zvv')
|
||||||
const products = require('../../p/zvv/products')
|
const products = require('../../p/zvv/products')
|
||||||
const createValidate = require('./lib/validate-fptf-with')
|
const createValidate = require('./lib/validate-fptf-with')
|
||||||
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
||||||
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
|
||||||
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
|
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
|
||||||
const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
|
const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
|
||||||
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||||
|
|
Loading…
Add table
Reference in a new issue