mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09: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 testRefreshJourney = require('./lib/refresh-journey')
|
||||
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
||||
const testDepartures = require('./lib/departures')
|
||||
const testArrivals = require('./lib/arrivals')
|
||||
|
||||
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
|
||||
})
|
||||
|
||||
validate(t, deps, 'departures', 'departures')
|
||||
t.ok(deps.length > 0, 'must be >0 departures')
|
||||
// todo: move into deps validator
|
||||
t.same(deps, deps.sort((a, b) => t.when > b.when))
|
||||
|
||||
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`)
|
||||
}
|
||||
|
||||
await testDepartures({
|
||||
test: t,
|
||||
departures: deps,
|
||||
validate,
|
||||
ids,
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
@ -224,16 +221,12 @@ tap.test('arrivals at Ingolstadt Hbf', async (t) => {
|
|||
duration: 10, when
|
||||
})
|
||||
|
||||
validate(t, arrs, 'arrivals', 'arrivals')
|
||||
t.ok(arrs.length > 0, 'must be >0 arrivals')
|
||||
// todo: move into arrs validator
|
||||
t.same(arrs, arrs.sort((a, b) => t.when > b.when))
|
||||
|
||||
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`)
|
||||
}
|
||||
|
||||
await testArrivals({
|
||||
test: t,
|
||||
arrivals: arrs,
|
||||
validate,
|
||||
ids,
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ const testArrivals = async (cfg) => {
|
|||
}
|
||||
|
||||
// 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
|
||||
|
|
|
@ -22,7 +22,7 @@ const testDepartures = async (cfg) => {
|
|||
}
|
||||
|
||||
// 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
|
||||
|
|
|
@ -491,19 +491,21 @@ const createValidateDeparture = (cfg) => {
|
|||
}
|
||||
}
|
||||
|
||||
const validateArrivals = (val, deps, name = 'arrivals') => {
|
||||
a.ok(Array.isArray(deps), name + ' must be an array')
|
||||
a.ok(deps.length > 0, name + ' must not be empty')
|
||||
for (let i = 0; i < deps.length; i++) {
|
||||
val.arrival(val, deps[i], name + `[${i}]`)
|
||||
const _createValidateStationBoardResults = (cfg, validatorsKey) => {
|
||||
const validateStationBoardResults = (val, arrsOrDeps, name) => {
|
||||
a.ok(Array.isArray(arrsOrDeps), name + ' must be an array')
|
||||
a.ok(arrsOrDeps.length > 0, name + ' must not be empty')
|
||||
for (let i = 0; i < arrsOrDeps.length; i++) {
|
||||
val[validatorsKey](val, arrsOrDeps[i], name + `[${i}]`)
|
||||
}
|
||||
}
|
||||
const validateDepartures = (val, deps, name = 'departures') => {
|
||||
a.ok(Array.isArray(deps), name + ' must be an array')
|
||||
a.ok(deps.length > 0, name + ' must not be empty')
|
||||
for (let i = 0; i < deps.length; i++) {
|
||||
val.departure(val, deps[i], name + `[${i}]`)
|
||||
return validateStationBoardResults
|
||||
}
|
||||
const createValidateArrivals = (cfg) => {
|
||||
return _createValidateStationBoardResults(cfg, 'arrival')
|
||||
}
|
||||
const createValidateDepartures = (cfg) => {
|
||||
return _createValidateStationBoardResults(cfg, 'departure')
|
||||
}
|
||||
|
||||
const createValidateMovement = (cfg) => {
|
||||
|
@ -582,8 +584,8 @@ module.exports = {
|
|||
trip: () => validateTrip,
|
||||
arrival: createValidateArrival,
|
||||
departure: createValidateDeparture,
|
||||
departures: () => validateDepartures,
|
||||
arrivals: () => validateArrivals,
|
||||
arrivals: createValidateArrivals,
|
||||
departures: createValidateDepartures,
|
||||
movement: createValidateMovement,
|
||||
movements: () => validateMovements
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
|||
const testRefreshJourney = require('./lib/refresh-journey')
|
||||
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
||||
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
||||
const testDepartures = require('./lib/departures')
|
||||
const testDeparturesInDirection = require('./lib/departures-in-direction')
|
||||
|
||||
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,
|
||||
})
|
||||
|
||||
validate(t, deps, 'departures', 'departures')
|
||||
t.ok(deps.length > 0, 'must be >0 departures')
|
||||
// todo: move into deps validator
|
||||
t.same(deps, deps.sort((a, b) => t.when > b.when))
|
||||
|
||||
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`)
|
||||
}
|
||||
|
||||
await testDepartures({
|
||||
test: t,
|
||||
departures: deps,
|
||||
validate,
|
||||
ids,
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ const rmvProfile = require('../../p/rmv')
|
|||
const products = require('../../p/rmv/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')
|
||||
|
||||
|
@ -71,9 +70,12 @@ tap.test('arrivals at Wiesbaden Hbf', async (t) => {
|
|||
duration: 10, when
|
||||
})
|
||||
|
||||
validate(t, arrivals, 'arrivals', 'arrivals')
|
||||
t.ok(arrivals.length > 0, 'must be >0 arrivals')
|
||||
t.same(arrivals, arrivals.sort((a, b) => t.when > b.when))
|
||||
await testArrivals({
|
||||
test: t,
|
||||
arrivals,
|
||||
validate,
|
||||
id: wiesbadenHbf,
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
|
@ -85,9 +85,15 @@ tap.test('arrivals at Platz der Jugend', async (t) => {
|
|||
duration: 30, when
|
||||
})
|
||||
|
||||
validate(t, arrivals, 'arrivals', 'arrivals')
|
||||
t.ok(arrivals.length > 0, 'must be >0 arrivals')
|
||||
t.same(arrivals, arrivals.sort((a, b) => t.when > b.when))
|
||||
await testArrivals({
|
||||
test: t,
|
||||
arrivals,
|
||||
validate,
|
||||
ids: [
|
||||
sternwarte,
|
||||
'708539', // Rostock Sternwarte
|
||||
],
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ const testJourneysStationToStation = require('./lib/journeys-station-to-station'
|
|||
const testJourneysStationToAddress = require('./lib/journeys-station-to-address')
|
||||
const testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
|
||||
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||
const testRefreshJourney = require('./lib/refresh-journey')
|
||||
const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product')
|
||||
const testJourneysWithDetour = require('./lib/journeys-with-detour')
|
||||
const testDepartures = require('./lib/departures')
|
||||
|
@ -177,21 +176,12 @@ tap.test('departures', async (t) => {
|
|||
duration: 5, when
|
||||
})
|
||||
|
||||
validate(t, departures, 'departures', 'departures')
|
||||
t.ok(departures.length > 0, 'must be >0 departures')
|
||||
for (let i = 0; i < departures.length; i++) {
|
||||
let stop = departures[i].stop
|
||||
let name = `departures[${i}].stop`
|
||||
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))
|
||||
await testDepartures({
|
||||
test: t,
|
||||
departures,
|
||||
validate,
|
||||
id: saarbrueckenUhlandstr,
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ const sncbProfile = require('../../p/sncb')
|
|||
const products = require('../../p/sncb/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')
|
||||
|
||||
|
@ -76,9 +75,12 @@ tap.test('arrivals at Bruxelles Midi', async (t) => {
|
|||
duration: 10, when
|
||||
})
|
||||
|
||||
validate(t, arrivals, 'arrivals', 'arrivals')
|
||||
t.ok(arrivals.length > 0, 'must be >0 arrivals')
|
||||
t.same(arrivals, arrivals.sort((a, b) => t.when > b.when))
|
||||
await testArrivals({
|
||||
test: t,
|
||||
arrivals,
|
||||
validate,
|
||||
id: bruxellesMidi,
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ 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 testServerInfo = require('./lib/server-info')
|
||||
|
@ -78,9 +77,12 @@ tap.test('arrivals at Volksgarten', async (t) => {
|
|||
duration: 10, when
|
||||
})
|
||||
|
||||
validate(t, arrivals, 'arrivals', 'arrivals')
|
||||
t.ok(arrivals.length > 0, 'must be >0 arrivals')
|
||||
t.same(arrivals, arrivals.sort((a, b) => t.when > b.when))
|
||||
await testArrivals({
|
||||
test: t,
|
||||
arrivals,
|
||||
validate,
|
||||
id: volksgarten,
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
|
@ -70,9 +70,12 @@ tap.test('arrivals at Bremen Humboldtstr.', async (t) => {
|
|||
duration: 10, when
|
||||
})
|
||||
|
||||
validate(t, arrivals, 'arrivals', 'arrivals')
|
||||
t.ok(arrivals.length > 0, 'must be >0 arrivals')
|
||||
t.same(arrivals, arrivals.sort((a, b) => t.when > b.when))
|
||||
await testArrivals({
|
||||
test: t,
|
||||
arrivals,
|
||||
validate,
|
||||
id: bremenHumboldtstr,
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ const zvvProfile = require('../../p/zvv')
|
|||
const products = require('../../p/zvv/products')
|
||||
const createValidate = require('./lib/validate-fptf-with')
|
||||
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 testJourneysStationToPoi = require('./lib/journeys-station-to-poi')
|
||||
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||
|
|
Loading…
Add table
Reference in a new issue