mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
tests: trip validator ✅
This commit is contained in:
parent
0daa1c5fef
commit
0fa9610b30
10 changed files with 23 additions and 14 deletions
|
@ -175,7 +175,7 @@ test('trip details', async (t) => {
|
||||||
t.ok(p.line.name, 'precondition failed')
|
t.ok(p.line.name, 'precondition failed')
|
||||||
const trip = await client.trip(p.id, p.line.name, {when})
|
const trip = await client.trip(p.id, p.line.name, {when})
|
||||||
|
|
||||||
validate(t, trip, 'journeyLeg', 'trip')
|
validate(t, trip, 'trip', 'trip')
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,7 @@ test('trip details', async (t) => {
|
||||||
t.ok(p.line.name, 'precondition failed')
|
t.ok(p.line.name, 'precondition failed')
|
||||||
const trip = await client.trip(p.id, p.line.name, {when})
|
const trip = await client.trip(p.id, p.line.name, {when})
|
||||||
|
|
||||||
validate(t, trip, 'journeyLeg', 'trip')
|
validate(t, trip, 'trip', 'trip')
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
13
test/db.js
13
test/db.js
|
@ -12,7 +12,7 @@ const dbProfile = require('../p/db')
|
||||||
const products = require('../p/db/products')
|
const products = require('../p/db/products')
|
||||||
const {
|
const {
|
||||||
station: createValidateStation,
|
station: createValidateStation,
|
||||||
journeyLeg: createValidateJourneyLeg
|
trip: createValidateTrip
|
||||||
} = require('./lib/validators')
|
} = require('./lib/validators')
|
||||||
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')
|
||||||
|
@ -235,14 +235,15 @@ test('trip details', async (t) => {
|
||||||
t.ok(p.line.name, 'precondition failed')
|
t.ok(p.line.name, 'precondition failed')
|
||||||
const trip = await client.trip(p.id, p.line.name, {when})
|
const trip = await client.trip(p.id, p.line.name, {when})
|
||||||
|
|
||||||
const validateJourneyLeg = createValidateJourneyLeg(cfg)
|
const validateTrip = createValidateTrip(cfg)
|
||||||
const validate = createValidate(cfg, {
|
const validate = createValidate(cfg, {
|
||||||
journeyLeg: (validate, leg, name) => {
|
trip: (validate, trip, name) => {
|
||||||
if (!leg.direction) leg.direction = 'foo' // todo, see #49
|
trip = Object.assign({}, trip)
|
||||||
validateJourneyLeg(validate, leg, name)
|
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()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
|
@ -168,7 +168,7 @@ test('trip details', async (t) => {
|
||||||
t.ok(p.line.name, 'precondition failed')
|
t.ok(p.line.name, 'precondition failed')
|
||||||
const trip = await client.trip(p.id, p.line.name, {when})
|
const trip = await client.trip(p.id, p.line.name, {when})
|
||||||
|
|
||||||
validate(t, trip, 'journeyLeg', 'trip')
|
validate(t, trip, 'trip', 'trip')
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -228,6 +228,9 @@ const createValidateJourneyLeg = (cfg) => {
|
||||||
a.ok(leg.distance > 0, msg + '> 0')
|
a.ok(leg.distance > 0, msg + '> 0')
|
||||||
}
|
}
|
||||||
} else {
|
} 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'
|
const msg = name + '.direction must be a string'
|
||||||
a.strictEqual(typeof leg.direction, 'string', msg)
|
a.strictEqual(typeof leg.direction, 'string', msg)
|
||||||
a.ok(leg.direction, name + '.direction must not be empty')
|
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) => {
|
const createValidateArrivalOrDeparture = (type, cfg) => {
|
||||||
if (type !== 'arrival' && type !== 'departure') throw new Error('invalid type')
|
if (type !== 'arrival' && type !== 'departure') throw new Error('invalid type')
|
||||||
|
|
||||||
|
@ -447,6 +454,7 @@ module.exports = {
|
||||||
journeyLeg: createValidateJourneyLeg,
|
journeyLeg: createValidateJourneyLeg,
|
||||||
journey: () => validateJourney,
|
journey: () => validateJourney,
|
||||||
journeys: () => validateJourneys,
|
journeys: () => validateJourneys,
|
||||||
|
trip: () => validateTrip,
|
||||||
arrival: createValidateArrival,
|
arrival: createValidateArrival,
|
||||||
departure: createValidateDeparture,
|
departure: createValidateDeparture,
|
||||||
departures: () => validateDepartures,
|
departures: () => validateDepartures,
|
||||||
|
|
|
@ -218,7 +218,7 @@ test('trip details', async (t) => {
|
||||||
t.ok(p.line.name, 'precondition failed')
|
t.ok(p.line.name, 'precondition failed')
|
||||||
const trip = await client.trip(p.id, p.line.name, {when})
|
const trip = await client.trip(p.id, p.line.name, {when})
|
||||||
|
|
||||||
validate(t, trip, 'journeyLeg', 'trip')
|
validate(t, trip, 'trip', 'trip')
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -241,7 +241,7 @@ test('trip details', async (t) => {
|
||||||
t.ok(p.line.name, 'precondition failed')
|
t.ok(p.line.name, 'precondition failed')
|
||||||
const trip = await client.trip(p.id, p.line.name, {when})
|
const trip = await client.trip(p.id, p.line.name, {when})
|
||||||
|
|
||||||
validate(t, trip, 'journeyLeg', 'trip')
|
validate(t, trip, 'trip', 'trip')
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -171,7 +171,7 @@ test('trip details', async (t) => {
|
||||||
t.ok(p.line.name, 'precondition failed')
|
t.ok(p.line.name, 'precondition failed')
|
||||||
const trip = await client.trip(p.id, p.line.name, {when})
|
const trip = await client.trip(p.id, p.line.name, {when})
|
||||||
|
|
||||||
validate(t, trip, 'journeyLeg', 'trip')
|
validate(t, trip, 'trip', 'trip')
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -155,7 +155,7 @@ test('trip details', async (t) => {
|
||||||
t.ok(p.line.name, 'precondition failed')
|
t.ok(p.line.name, 'precondition failed')
|
||||||
const trip = await client.trip(p.id, p.line.name, {when})
|
const trip = await client.trip(p.id, p.line.name, {when})
|
||||||
|
|
||||||
validate(t, trip, 'journeyLeg', 'trip')
|
validate(t, trip, 'trip', 'trip')
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -174,7 +174,7 @@ test.skip('trip details', async (t) => {
|
||||||
t.ok(p.line.name, 'precondition failed')
|
t.ok(p.line.name, 'precondition failed')
|
||||||
const trip = await client.trip(p.tripId, p.line.name, {when})
|
const trip = await client.trip(p.tripId, p.line.name, {when})
|
||||||
|
|
||||||
validate(t, trip, 'journeyLeg', 'trip')
|
validate(t, trip, 'trip', 'trip')
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue