From 5cb2b4f049335b04758aeb1a0b01f033f7909559 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Mon, 3 Sep 2018 15:55:09 +0200 Subject: [PATCH] fix tests :green_heart: --- test/lib/validators.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/test/lib/validators.js b/test/lib/validators.js index 9a1b4efc..34db2980 100644 --- a/test/lib/validators.js +++ b/test/lib/validators.js @@ -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') => { a.ok(isObj(dep), name + ' must be an object') // todo: let hafas-client add a .type field @@ -284,12 +286,18 @@ const createValidateArrivalOrDeparture = (cfg) => { } val.line(val, dep.line, name + '.line') - a.strictEqual(typeof dep.direction, 'string', name + '.direction must be a string') - a.ok(dep.direction, name + '.direction must not be empty') + if (type === 'departure') { + 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 } +const createValidateArrival = cfg => createValidateArrivalOrDeparture('arrival', cfg) +const createValidateDeparture = cfg => createValidateArrivalOrDeparture('departure', 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') @@ -362,8 +370,8 @@ module.exports = { journeyLeg: createValidateJourneyLeg, journey: () => validateJourney, journeys: () => validateJourneys, - arrival: createValidateArrivalOrDeparture, - departure: createValidateArrivalOrDeparture, + arrival: createValidateArrival, + departure: createValidateDeparture, departures: () => validateDepartures, arrivals: () => validateArrivals, movement: () => validateMovement,