tests: trip validator

This commit is contained in:
Jannis R 2018-11-22 00:15:59 +01:00
parent 0daa1c5fef
commit 0fa9610b30
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
10 changed files with 23 additions and 14 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -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,

View file

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

View file

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

View file

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

View file

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

View file

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