mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
E2E/integration tests: validate remarks ✅
This commit is contained in:
parent
dda36c2da0
commit
38cc9e9af8
1 changed files with 63 additions and 5 deletions
|
@ -9,6 +9,17 @@ const {assertValidWhen} = require('./util')
|
||||||
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
|
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
|
||||||
const is = val => val !== null && val !== undefined
|
const is = val => val !== null && val !== undefined
|
||||||
|
|
||||||
|
const createValidateProducts = (cfg) => {
|
||||||
|
const validateProducts = (val, p, name = 'products') => {
|
||||||
|
a.ok(isObj(p), name + ' must be an object')
|
||||||
|
for (let product of cfg.products) {
|
||||||
|
const msg = `${name}[${product.id}] must be a boolean`
|
||||||
|
a.strictEqual(typeof p[product.id], 'boolean', msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return validateProducts
|
||||||
|
}
|
||||||
|
|
||||||
const createValidateStation = (cfg) => {
|
const createValidateStation = (cfg) => {
|
||||||
const validateStation = (val, s, name = 'station') => {
|
const validateStation = (val, s, name = 'station') => {
|
||||||
defaultValidators.station(val, s, name)
|
defaultValidators.station(val, s, name)
|
||||||
|
@ -16,11 +27,7 @@ const createValidateStation = (cfg) => {
|
||||||
if (!cfg.stationCoordsOptional) {
|
if (!cfg.stationCoordsOptional) {
|
||||||
a.ok(is(s.location), `missing ${name}.location`)
|
a.ok(is(s.location), `missing ${name}.location`)
|
||||||
}
|
}
|
||||||
a.ok(isObj(s.products), name + '.products must be an object')
|
val.products(val, s.products, name + '.products')
|
||||||
for (let product of cfg.products) {
|
|
||||||
const msg = name + `.products[${product.id}] must be a boolean`
|
|
||||||
a.strictEqual(typeof s.products[product.id], 'boolean', msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('lines' in s) {
|
if ('lines' in s) {
|
||||||
a.ok(Array.isArray(s.lines), name + `.lines must be an array`)
|
a.ok(Array.isArray(s.lines), name + `.lines must be an array`)
|
||||||
|
@ -98,6 +105,55 @@ const createValidateLine = (cfg) => {
|
||||||
return validateLine
|
return validateLine
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const validateRemark = (val, rem, name = 'remark') => {
|
||||||
|
a.ok(isObj(rem), name + ' must be an object')
|
||||||
|
a.strictEqual(typeof rem.id, 'string', name + '.id must be a string')
|
||||||
|
a.ok(rem.id, name + '.id must not be empty')
|
||||||
|
if (rem.summary !== null) {
|
||||||
|
a.strictEqual(typeof rem.summary, 'string', name + '.summary must be a string')
|
||||||
|
a.ok(rem.summary, name + '.summary must not be empty')
|
||||||
|
}
|
||||||
|
if (rem.text !== null) {
|
||||||
|
a.strictEqual(typeof rem.text, 'string', name + '.text must be a string')
|
||||||
|
a.ok(rem.text, name + '.text must not be empty')
|
||||||
|
}
|
||||||
|
if ('validFrom' in rem) {
|
||||||
|
a.strictEqual(typeof rem.validFrom, 'string', name + '.validFrom must be a string')
|
||||||
|
a.ok(Number.isInteger(Date.parse(rem.validFrom)), name + '.validFrom must be ISO 8601')
|
||||||
|
}
|
||||||
|
if ('validUntil' in rem) {
|
||||||
|
a.strictEqual(typeof rem.validUntil, 'string', name + '.validUntil must be a string')
|
||||||
|
a.ok(Number.isInteger(Date.parse(rem.validUntil)), name + '.validUntil must be ISO 8601')
|
||||||
|
}
|
||||||
|
if ('modified' in rem) {
|
||||||
|
a.strictEqual(typeof rem.modified, 'string', name + '.modified must be a string')
|
||||||
|
a.ok(Number.isInteger(Date.parse(rem.modified)), name + '.modified must be ISO 8601')
|
||||||
|
}
|
||||||
|
if ('products' in rem) {
|
||||||
|
val.products(val, rem.products, name + '.products')
|
||||||
|
}
|
||||||
|
if ('edges' in rem) {
|
||||||
|
a.ok(Array.isArray(rem.edges), name + '.edges must be an array')
|
||||||
|
for (let i = 0; i < rem.edges.length; i++) {
|
||||||
|
const e = rem.edges[i]
|
||||||
|
const n = `${name}.edges[${i}]`
|
||||||
|
a.ok(isObj(e), n + ' must be an object')
|
||||||
|
if (e.fromLocation !== null) {
|
||||||
|
val.location(val, e.fromLocation, n + '.fromLocation')
|
||||||
|
}
|
||||||
|
if (e.toLocation !== null) {
|
||||||
|
val.location(val, e.toLocation, n + '.toLocation')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ('affectedLines' in rem) {
|
||||||
|
a.ok(Array.isArray(rem.affectedLines), name + '.affectedLines must be an array')
|
||||||
|
for (let i = 0; i < rem.affectedLines.length; i++) {
|
||||||
|
val.line(val, rem.affectedLines[i], `${name}.affectedLines[${i}]`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const createValidateStopover = (cfg) => {
|
const createValidateStopover = (cfg) => {
|
||||||
const validateStopover = (val, s, name = 'stopover') => {
|
const validateStopover = (val, s, name = 'stopover') => {
|
||||||
if (
|
if (
|
||||||
|
@ -508,6 +564,7 @@ const validateMovements = (val, ms, name = 'movements') => {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
products: createValidateProducts,
|
||||||
station: createValidateStation,
|
station: createValidateStation,
|
||||||
stop: () => validateStop,
|
stop: () => validateStop,
|
||||||
location: () => validateLocation,
|
location: () => validateLocation,
|
||||||
|
@ -515,6 +572,7 @@ module.exports = {
|
||||||
poi: () => validatePoi,
|
poi: () => validatePoi,
|
||||||
address: () => validateAddress,
|
address: () => validateAddress,
|
||||||
line: createValidateLine,
|
line: createValidateLine,
|
||||||
|
remark: () => validateRemark,
|
||||||
stopover: createValidateStopover,
|
stopover: createValidateStopover,
|
||||||
ticket: () => validateTicket,
|
ticket: () => validateTicket,
|
||||||
journeyLeg: createValidateJourneyLeg,
|
journeyLeg: createValidateJourneyLeg,
|
||||||
|
|
Loading…
Add table
Reference in a new issue