diff --git a/test/bvg.js b/test/bvg.js index bf1d5f05..aa628e49 100644 --- a/test/bvg.js +++ b/test/bvg.js @@ -175,7 +175,7 @@ test('trip details', async (t) => { t.ok(p.line.name, 'precondition failed') const trip = await client.trip(p.id, p.line.name, {when}) - validate(t, trip, 'journeyLeg', 'trip') + validate(t, trip, 'trip', 'trip') t.end() }) diff --git a/test/cmta.js b/test/cmta.js index cfc31cce..43ec5383 100644 --- a/test/cmta.js +++ b/test/cmta.js @@ -157,7 +157,7 @@ test('trip details', async (t) => { t.ok(p.line.name, 'precondition failed') const trip = await client.trip(p.id, p.line.name, {when}) - validate(t, trip, 'journeyLeg', 'trip') + validate(t, trip, 'trip', 'trip') t.end() }) diff --git a/test/db.js b/test/db.js index e0e0153a..e307a193 100644 --- a/test/db.js +++ b/test/db.js @@ -12,7 +12,7 @@ const dbProfile = require('../p/db') const products = require('../p/db/products') const { station: createValidateStation, - journeyLeg: createValidateJourneyLeg + trip: createValidateTrip } = require('./lib/validators') const createValidate = require('./lib/validate-fptf-with') const testJourneysStationToStation = require('./lib/journeys-station-to-station') @@ -235,14 +235,15 @@ test('trip details', async (t) => { t.ok(p.line.name, 'precondition failed') const trip = await client.trip(p.id, p.line.name, {when}) - const validateJourneyLeg = createValidateJourneyLeg(cfg) + const validateTrip = createValidateTrip(cfg) const validate = createValidate(cfg, { - journeyLeg: (validate, leg, name) => { - if (!leg.direction) leg.direction = 'foo' // todo, see #49 - validateJourneyLeg(validate, leg, name) + trip: (validate, trip, name) => { + trip = Object.assign({}, trip) + if (!trip.direction) trip.direction = 'foo' // todo, see #49 + validateTrip(validate, trip, name) } }) - validate(t, trip, 'journeyLeg', 'trip') + validate(t, trip, 'trip', 'trip') t.end() }) diff --git a/test/insa.js b/test/insa.js index f1d87478..f5e5ede8 100644 --- a/test/insa.js +++ b/test/insa.js @@ -168,7 +168,7 @@ test('trip details', async (t) => { t.ok(p.line.name, 'precondition failed') const trip = await client.trip(p.id, p.line.name, {when}) - validate(t, trip, 'journeyLeg', 'trip') + validate(t, trip, 'trip', 'trip') t.end() }) diff --git a/test/lib/validators.js b/test/lib/validators.js index 6d3b21e2..a80d8ab5 100644 --- a/test/lib/validators.js +++ b/test/lib/validators.js @@ -228,6 +228,9 @@ const createValidateJourneyLeg = (cfg) => { a.ok(leg.distance > 0, msg + '> 0') } } else { + a.strictEqual(typeof leg.tripId, 'string', name + '.tripId must be a string') + a.ok(leg.tripId, name + '.tripId must not be empty') + const msg = name + '.direction must be a string' a.strictEqual(typeof leg.direction, 'string', msg) a.ok(leg.direction, name + '.direction must not be empty') @@ -301,6 +304,10 @@ const validateJourneys = (val, js, name = 'journeys') => { } } +const validateTrip = (val, trip, name = 'trip') => { + val.journeyLeg(val, trip, name) +} + const createValidateArrivalOrDeparture = (type, cfg) => { if (type !== 'arrival' && type !== 'departure') throw new Error('invalid type') @@ -447,6 +454,7 @@ module.exports = { journeyLeg: createValidateJourneyLeg, journey: () => validateJourney, journeys: () => validateJourneys, + trip: () => validateTrip, arrival: createValidateArrival, departure: createValidateDeparture, departures: () => validateDepartures, diff --git a/test/nahsh.js b/test/nahsh.js index 9e4277ea..916f2ef6 100644 --- a/test/nahsh.js +++ b/test/nahsh.js @@ -218,7 +218,7 @@ test('trip details', async (t) => { t.ok(p.line.name, 'precondition failed') const trip = await client.trip(p.id, p.line.name, {when}) - validate(t, trip, 'journeyLeg', 'trip') + validate(t, trip, 'trip', 'trip') t.end() }) diff --git a/test/oebb.js b/test/oebb.js index 5c748f25..073fc608 100644 --- a/test/oebb.js +++ b/test/oebb.js @@ -241,7 +241,7 @@ test('trip details', async (t) => { t.ok(p.line.name, 'precondition failed') const trip = await client.trip(p.id, p.line.name, {when}) - validate(t, trip, 'journeyLeg', 'trip') + validate(t, trip, 'trip', 'trip') t.end() }) diff --git a/test/sbahn-muenchen.js b/test/sbahn-muenchen.js index a6224029..11e798fa 100644 --- a/test/sbahn-muenchen.js +++ b/test/sbahn-muenchen.js @@ -171,7 +171,7 @@ test('trip details', async (t) => { t.ok(p.line.name, 'precondition failed') const trip = await client.trip(p.id, p.line.name, {when}) - validate(t, trip, 'journeyLeg', 'trip') + validate(t, trip, 'trip', 'trip') t.end() }) diff --git a/test/vbb.js b/test/vbb.js index 12976ae7..9d24a48e 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -155,7 +155,7 @@ test('trip details', async (t) => { t.ok(p.line.name, 'precondition failed') const trip = await client.trip(p.id, p.line.name, {when}) - validate(t, trip, 'journeyLeg', 'trip') + validate(t, trip, 'trip', 'trip') t.end() }) diff --git a/test/vbn.js b/test/vbn.js index dc39f64a..7dfa01c9 100644 --- a/test/vbn.js +++ b/test/vbn.js @@ -174,7 +174,7 @@ test.skip('trip details', async (t) => { t.ok(p.line.name, 'precondition failed') const trip = await client.trip(p.tripId, p.line.name, {when}) - validate(t, trip, 'journeyLeg', 'trip') + validate(t, trip, 'trip', 'trip') t.end() })