mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
comply with FPTF 1.0.1, using validate-fptf
This commit is contained in:
parent
e6f7a09505
commit
09fc50f5b3
6 changed files with 29 additions and 16 deletions
|
@ -47,7 +47,7 @@ const m = {
|
||||||
bitmask: 64,
|
bitmask: 64,
|
||||||
name: 'Ferry',
|
name: 'Ferry',
|
||||||
short: 'F',
|
short: 'F',
|
||||||
mode: 'ferry',
|
mode: 'watercraft',
|
||||||
product: 'ferry'
|
product: 'ferry'
|
||||||
},
|
},
|
||||||
subway: {
|
subway: {
|
||||||
|
|
|
@ -42,7 +42,7 @@ const m = {
|
||||||
category: 4,
|
category: 4,
|
||||||
bitmask: 16,
|
bitmask: 16,
|
||||||
name: 'Fähre',
|
name: 'Fähre',
|
||||||
mode: 'ferry',
|
mode: 'watercraft',
|
||||||
short: 'F',
|
short: 'F',
|
||||||
product: 'ferry'
|
product: 'ferry'
|
||||||
},
|
},
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
"tap-spec": "^4.1.1",
|
"tap-spec": "^4.1.1",
|
||||||
"tape": "^4.8.0",
|
"tape": "^4.8.0",
|
||||||
"tape-promise": "^2.0.1",
|
"tape-promise": "^2.0.1",
|
||||||
|
"validate-fptf": "^1.0.1",
|
||||||
"vbb-parse-line": "^0.2.5",
|
"vbb-parse-line": "^0.2.5",
|
||||||
"vbb-stations-autocomplete": "^2.9.0"
|
"vbb-stations-autocomplete": "^2.9.0"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,15 +1,25 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const slugg = require('slugg')
|
||||||
|
|
||||||
// todo: are p.number and p.line ever different?
|
// todo: are p.number and p.line ever different?
|
||||||
// todo: operator from p.oprX?
|
// todo: operator from p.oprX?
|
||||||
const parseLine = (profile, p) => {
|
const parseLine = (profile, p) => {
|
||||||
if (!p) return null // todo: handle this upstream
|
if (!p) return null // todo: handle this upstream
|
||||||
const res = {
|
const res = {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
|
id: null,
|
||||||
name: p.line || p.name,
|
name: p.line || p.name,
|
||||||
public: true
|
public: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We don't get a proper line id from the API, so we use the trip nr here.
|
||||||
|
// todo: find a better way
|
||||||
|
if (p.prodCtx && p.prodCtx.num) res.id = p.prodCtx.num
|
||||||
|
// This is terrible, but FPTF demands an ID. Let's pray for VBB to expose an ID.
|
||||||
|
else if (p.line) res.id = slugg(p.line.trim())
|
||||||
|
else if (p.name) res.id = slugg(p.name.trim())
|
||||||
|
|
||||||
if (p.cls) res.class = p.cls
|
if (p.cls) res.class = p.cls
|
||||||
if (p.prodCtx && p.prodCtx.catCode !== undefined) {
|
if (p.prodCtx && p.prodCtx.catCode !== undefined) {
|
||||||
res.productCode = +p.prodCtx.catCode
|
res.productCode = +p.prodCtx.catCode
|
||||||
|
|
29
test/util.js
29
test/util.js
|
@ -1,15 +1,20 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const validateFptf = require('validate-fptf')
|
||||||
const isRoughlyEqual = require('is-roughly-equal')
|
const isRoughlyEqual = require('is-roughly-equal')
|
||||||
const {DateTime} = require('luxon')
|
const {DateTime} = require('luxon')
|
||||||
const isValidWGS84 = require('is-coordinates')
|
const isValidWGS84 = require('is-coordinates')
|
||||||
|
|
||||||
|
const validateFptfWith = (t, item, allowedTypes, name) => {
|
||||||
|
try {
|
||||||
|
validateFptf.recurse(allowedTypes, item, name)
|
||||||
|
} catch (err) {
|
||||||
|
t.ifError(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const assertValidStation = (t, s, coordsOptional = false) => {
|
const assertValidStation = (t, s, coordsOptional = false) => {
|
||||||
t.equal(s.type, 'station')
|
validateFptfWith(t, s, ['station'], 'station')
|
||||||
t.equal(typeof s.id, 'string')
|
|
||||||
t.ok(s.id)
|
|
||||||
t.equal(typeof s.name, 'string')
|
|
||||||
t.ok(s.name)
|
|
||||||
|
|
||||||
if (!coordsOptional || (s.location !== null && s.location !== undefined)) {
|
if (!coordsOptional || (s.location !== null && s.location !== undefined)) {
|
||||||
t.ok(s.location)
|
t.ok(s.location)
|
||||||
|
@ -18,18 +23,20 @@ const assertValidStation = (t, s, coordsOptional = false) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const assertValidPoi = (t, p) => {
|
const assertValidPoi = (t, p) => {
|
||||||
|
assertValidLocation(t, p, true)
|
||||||
|
|
||||||
t.equal(typeof p.id, 'string')
|
t.equal(typeof p.id, 'string')
|
||||||
t.equal(typeof p.name, 'string')
|
t.equal(typeof p.name, 'string')
|
||||||
if (p.address !== null && p.address !== undefined) {
|
if (p.address !== null && p.address !== undefined) {
|
||||||
t.equal(typeof p.address, 'string')
|
t.equal(typeof p.address, 'string')
|
||||||
t.ok(p.address)
|
t.ok(p.address)
|
||||||
}
|
}
|
||||||
assertValidLocation(t, p, true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const assertValidAddress = (t, a) => {
|
const assertValidAddress = (t, a) => {
|
||||||
t.equal(typeof a.address, 'string')
|
|
||||||
assertValidLocation(t, a, true)
|
assertValidLocation(t, a, true)
|
||||||
|
|
||||||
|
t.equal(typeof a.address, 'string')
|
||||||
}
|
}
|
||||||
|
|
||||||
const assertValidLocation = (t, l, coordsOptional = false) => {
|
const assertValidLocation = (t, l, coordsOptional = false) => {
|
||||||
|
@ -59,16 +66,12 @@ const assertValidLocation = (t, l, coordsOptional = false) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const validLineModes = [
|
const validLineModes = [
|
||||||
'train', 'bus', 'ferry', 'taxi', 'gondola', 'aircraft',
|
'train', 'bus', 'watercraft', 'taxi', 'gondola', 'aircraft',
|
||||||
'car', 'bicycle', 'walking'
|
'car', 'bicycle', 'walking'
|
||||||
]
|
]
|
||||||
|
|
||||||
const assertValidLine = (t, l) => {
|
const assertValidLine = (t, l) => {
|
||||||
t.equal(l.type, 'line')
|
validateFptfWith(t, l, ['line'], 'line')
|
||||||
t.equal(typeof l.name, 'string')
|
|
||||||
t.ok(validLineModes.includes(l.mode), 'invalid mode ' + l.mode)
|
|
||||||
t.equal(typeof l.product, 'string')
|
|
||||||
t.equal(l.public, true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const isValidDateTime = (w) => {
|
const isValidDateTime = (w) => {
|
||||||
|
|
|
@ -10,7 +10,6 @@ const shorten = require('vbb-short-station-name')
|
||||||
|
|
||||||
const createClient = require('..')
|
const createClient = require('..')
|
||||||
const vbbProfile = require('../p/vbb')
|
const vbbProfile = require('../p/vbb')
|
||||||
const modes = require('../p/vbb/modes')
|
|
||||||
const {
|
const {
|
||||||
assertValidStation: _assertValidStation,
|
assertValidStation: _assertValidStation,
|
||||||
assertValidPoi,
|
assertValidPoi,
|
||||||
|
|
Loading…
Add table
Reference in a new issue