Skip to content

Commit

Permalink
E2E/integration tests: DRY & tweak assertions ✅
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Jun 18, 2022
1 parent bdf933f commit 2ed2f38
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 80 deletions.
33 changes: 13 additions & 20 deletions test/e2e/invg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
})

Expand Down Expand Up @@ -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()
})

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/lib/arrivals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/e2e/lib/departures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 15 additions & 13 deletions test/e2e/lib/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}]`)
}
}
return validateStationBoardResults
}
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}]`)
}
const createValidateArrivals = (cfg) => {
return _createValidateStationBoardResults(cfg, 'arrival')
}
const createValidateDepartures = (cfg) => {
return _createValidateStationBoardResults(cfg, 'departure')
}

const createValidateMovement = (cfg) => {
Expand Down Expand Up @@ -582,8 +584,8 @@ module.exports = {
trip: () => validateTrip,
arrival: createValidateArrival,
departure: createValidateDeparture,
departures: () => validateDepartures,
arrivals: () => validateArrivals,
arrivals: createValidateArrivals,
departures: createValidateDepartures,
movement: createValidateMovement,
movements: () => validateMovements
}
17 changes: 7 additions & 10 deletions test/e2e/oebb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
})

Expand Down
10 changes: 6 additions & 4 deletions test/e2e/rmv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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()
})

Expand Down
12 changes: 9 additions & 3 deletions test/e2e/rsag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

Expand Down
22 changes: 6 additions & 16 deletions test/e2e/saarfahrplan.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()
})

Expand Down
10 changes: 6 additions & 4 deletions test/e2e/sncb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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()
})

Expand Down
10 changes: 6 additions & 4 deletions test/e2e/svv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()
})

Expand Down
9 changes: 6 additions & 3 deletions test/e2e/vbn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

Expand Down
1 change: 0 additions & 1 deletion test/e2e/zvv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 2ed2f38

Please sign in to comment.