mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09: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,
|
||||
name: 'Ferry',
|
||||
short: 'F',
|
||||
mode: 'ferry',
|
||||
mode: 'watercraft',
|
||||
product: 'ferry'
|
||||
},
|
||||
subway: {
|
||||
|
|
|
@ -42,7 +42,7 @@ const m = {
|
|||
category: 4,
|
||||
bitmask: 16,
|
||||
name: 'Fähre',
|
||||
mode: 'ferry',
|
||||
mode: 'watercraft',
|
||||
short: 'F',
|
||||
product: 'ferry'
|
||||
},
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
"tap-spec": "^4.1.1",
|
||||
"tape": "^4.8.0",
|
||||
"tape-promise": "^2.0.1",
|
||||
"validate-fptf": "^1.0.1",
|
||||
"vbb-parse-line": "^0.2.5",
|
||||
"vbb-stations-autocomplete": "^2.9.0"
|
||||
},
|
||||
|
|
|
@ -1,15 +1,25 @@
|
|||
'use strict'
|
||||
|
||||
const slugg = require('slugg')
|
||||
|
||||
// todo: are p.number and p.line ever different?
|
||||
// todo: operator from p.oprX?
|
||||
const parseLine = (profile, p) => {
|
||||
if (!p) return null // todo: handle this upstream
|
||||
const res = {
|
||||
type: 'line',
|
||||
id: null,
|
||||
name: p.line || p.name,
|
||||
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.prodCtx && p.prodCtx.catCode !== undefined) {
|
||||
res.productCode = +p.prodCtx.catCode
|
||||
|
|
29
test/util.js
29
test/util.js
|
@ -1,15 +1,20 @@
|
|||
'use strict'
|
||||
|
||||
const validateFptf = require('validate-fptf')
|
||||
const isRoughlyEqual = require('is-roughly-equal')
|
||||
const {DateTime} = require('luxon')
|
||||
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) => {
|
||||
t.equal(s.type, 'station')
|
||||
t.equal(typeof s.id, 'string')
|
||||
t.ok(s.id)
|
||||
t.equal(typeof s.name, 'string')
|
||||
t.ok(s.name)
|
||||
validateFptfWith(t, s, ['station'], 'station')
|
||||
|
||||
if (!coordsOptional || (s.location !== null && s.location !== undefined)) {
|
||||
t.ok(s.location)
|
||||
|
@ -18,18 +23,20 @@ const assertValidStation = (t, s, coordsOptional = false) => {
|
|||
}
|
||||
|
||||
const assertValidPoi = (t, p) => {
|
||||
assertValidLocation(t, p, true)
|
||||
|
||||
t.equal(typeof p.id, 'string')
|
||||
t.equal(typeof p.name, 'string')
|
||||
if (p.address !== null && p.address !== undefined) {
|
||||
t.equal(typeof p.address, 'string')
|
||||
t.ok(p.address)
|
||||
}
|
||||
assertValidLocation(t, p, true)
|
||||
}
|
||||
|
||||
const assertValidAddress = (t, a) => {
|
||||
t.equal(typeof a.address, 'string')
|
||||
assertValidLocation(t, a, true)
|
||||
|
||||
t.equal(typeof a.address, 'string')
|
||||
}
|
||||
|
||||
const assertValidLocation = (t, l, coordsOptional = false) => {
|
||||
|
@ -59,16 +66,12 @@ const assertValidLocation = (t, l, coordsOptional = false) => {
|
|||
}
|
||||
|
||||
const validLineModes = [
|
||||
'train', 'bus', 'ferry', 'taxi', 'gondola', 'aircraft',
|
||||
'train', 'bus', 'watercraft', 'taxi', 'gondola', 'aircraft',
|
||||
'car', 'bicycle', 'walking'
|
||||
]
|
||||
|
||||
const assertValidLine = (t, l) => {
|
||||
t.equal(l.type, '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)
|
||||
validateFptfWith(t, l, ['line'], 'line')
|
||||
}
|
||||
|
||||
const isValidDateTime = (w) => {
|
||||
|
|
|
@ -10,7 +10,6 @@ const shorten = require('vbb-short-station-name')
|
|||
|
||||
const createClient = require('..')
|
||||
const vbbProfile = require('../p/vbb')
|
||||
const modes = require('../p/vbb/modes')
|
||||
const {
|
||||
assertValidStation: _assertValidStation,
|
||||
assertValidPoi,
|
||||
|
|
Loading…
Add table
Reference in a new issue