fix tests 💚

This commit is contained in:
Jannis R 2018-09-03 15:55:09 +02:00
parent ccfee97e4b
commit 5cb2b4f049
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5

View file

@ -260,7 +260,9 @@ const validateJourneys = (val, js, name = 'journeys') => {
} }
} }
const createValidateArrivalOrDeparture = (cfg) => { const createValidateArrivalOrDeparture = (type, cfg) => {
if (type !== 'arrival' && type !== 'departure') throw new Error('invalid type')
const validateArrivalOrDeparture = (val, dep, name = 'arrOrDep') => { const validateArrivalOrDeparture = (val, dep, name = 'arrOrDep') => {
a.ok(isObj(dep), name + ' must be an object') a.ok(isObj(dep), name + ' must be an object')
// todo: let hafas-client add a .type field // todo: let hafas-client add a .type field
@ -284,12 +286,18 @@ const createValidateArrivalOrDeparture = (cfg) => {
} }
val.line(val, dep.line, name + '.line') val.line(val, dep.line, name + '.line')
a.strictEqual(typeof dep.direction, 'string', name + '.direction must be a string') if (type === 'departure') {
a.ok(dep.direction, name + '.direction must not be empty') const n = name + '.direction'
a.strictEqual(typeof dep.direction, 'string', n + ' must be a string')
a.ok(dep.direction, n + ' must not be empty')
}
} }
return validateArrivalOrDeparture return validateArrivalOrDeparture
} }
const createValidateArrival = cfg => createValidateArrivalOrDeparture('arrival', cfg)
const createValidateDeparture = cfg => createValidateArrivalOrDeparture('departure', cfg)
const validateArrivals = (val, deps, name = 'arrivals') => { const validateArrivals = (val, deps, name = 'arrivals') => {
a.ok(Array.isArray(deps), name + ' must be an array') a.ok(Array.isArray(deps), name + ' must be an array')
a.ok(deps.length > 0, name + ' must not be empty') a.ok(deps.length > 0, name + ' must not be empty')
@ -362,8 +370,8 @@ module.exports = {
journeyLeg: createValidateJourneyLeg, journeyLeg: createValidateJourneyLeg,
journey: () => validateJourney, journey: () => validateJourney,
journeys: () => validateJourneys, journeys: () => validateJourneys,
arrival: createValidateArrivalOrDeparture, arrival: createValidateArrival,
departure: createValidateArrivalOrDeparture, departure: createValidateDeparture,
departures: () => validateDepartures, departures: () => validateDepartures,
arrivals: () => validateArrivals, arrivals: () => validateArrivals,
movement: () => validateMovement, movement: () => validateMovement,