mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-05-05 22:19:59 +03:00
bugfixes 🐛
This commit is contained in:
parent
0a5b1a0c68
commit
47b5ef7ed5
3 changed files with 26 additions and 37 deletions
|
@ -3,7 +3,6 @@
|
||||||
// todo: what is p.number vs p.line?
|
// todo: what is p.number vs p.line?
|
||||||
// todo: what is p.icoX?
|
// todo: what is p.icoX?
|
||||||
// todo: what is p.oprX?
|
// todo: what is p.oprX?
|
||||||
// todo: is passing in profile necessary?
|
|
||||||
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 = {type: 'line', name: p.line || p.name}
|
const res = {type: 'line', name: p.line || p.name}
|
||||||
|
@ -14,6 +13,8 @@ const parseLine = (profile, p) => {
|
||||||
res.productName = p.prodCtx.catOutS
|
res.productName = p.prodCtx.catOutS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: parse mode, remove from profiles
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
21
test/db.js
21
test/db.js
|
@ -13,10 +13,27 @@ const {
|
||||||
assertValidLocation,
|
assertValidLocation,
|
||||||
assertValidLine,
|
assertValidLine,
|
||||||
assertValidStopover,
|
assertValidStopover,
|
||||||
isJungfernheide, assertIsJungfernheide,
|
|
||||||
when, isValidWhen
|
when, isValidWhen
|
||||||
} = require('./util.js')
|
} = require('./util.js')
|
||||||
|
|
||||||
|
const isJungfernheide = (s) => {
|
||||||
|
return s.type === 'station' &&
|
||||||
|
(s.id === '008011167' || s.id === '8011167') &&
|
||||||
|
s.name === 'Berlin Jungfernheide' &&
|
||||||
|
s.coordinates &&
|
||||||
|
isRoughlyEqual(s.coordinates.latitude, 52.530408, .0005) &&
|
||||||
|
isRoughlyEqual(s.coordinates.longitude, 13.299424, .0005)
|
||||||
|
}
|
||||||
|
|
||||||
|
const assertIsJungfernheide = (t, s) => {
|
||||||
|
t.equal(s.type, 'station')
|
||||||
|
t.ok(s.id === '008011167' || s.id === '8011167', 'id should be 8011167')
|
||||||
|
t.equal(s.name, 'Berlin Jungfernheide')
|
||||||
|
t.ok(s.coordinates)
|
||||||
|
t.ok(isRoughlyEqual(s.coordinates.latitude, 52.530408, .0005))
|
||||||
|
t.ok(isRoughlyEqual(s.coordinates.longitude, 13.299424, .0005))
|
||||||
|
}
|
||||||
|
|
||||||
const test = tapePromise(tape)
|
const test = tapePromise(tape)
|
||||||
const client = createClient(dbProfile)
|
const client = createClient(dbProfile)
|
||||||
|
|
||||||
|
@ -163,7 +180,7 @@ test('locations named Jungfernheide', async (t) => {
|
||||||
t.ok(locations.length <= 10)
|
t.ok(locations.length <= 10)
|
||||||
|
|
||||||
for (let location of locations) assertValidLocation(t, location)
|
for (let location of locations) assertValidLocation(t, location)
|
||||||
t.ok(locations.find(isJungfernheide))
|
t.ok(locations.some(isJungfernheide))
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
39
test/util.js
39
test/util.js
|
@ -41,10 +41,10 @@ const assertValidLocation = (t, l) => {
|
||||||
else if (l.type === 'address') assertValidAddress(t, l)
|
else if (l.type === 'address') assertValidAddress(t, l)
|
||||||
else t.fail('invalid type ' + l.type)
|
else t.fail('invalid type ' + l.type)
|
||||||
|
|
||||||
t.equal(typeof s.name, 'string')
|
t.equal(typeof l.name, 'string')
|
||||||
t.ok(s.coordinates)
|
t.ok(l.coordinates)
|
||||||
t.equal(typeof s.coordinates.latitude, 'number')
|
t.equal(typeof l.coordinates.latitude, 'number')
|
||||||
t.equal(typeof s.coordinates.longitude, 'number')
|
t.equal(typeof l.coordinates.longitude, 'number')
|
||||||
}
|
}
|
||||||
|
|
||||||
const isValidMode = (m) => {
|
const isValidMode = (m) => {
|
||||||
|
@ -57,7 +57,7 @@ const isValidMode = (m) => {
|
||||||
const assertValidLine = (t, l) => {
|
const assertValidLine = (t, l) => {
|
||||||
t.equal(l.type, 'line')
|
t.equal(l.type, 'line')
|
||||||
t.equal(typeof l.name, 'string')
|
t.equal(typeof l.name, 'string')
|
||||||
t.ok(isValidMode(l.mode))
|
t.ok(isValidMode(l.mode), 'invalid mode ' + l.mode)
|
||||||
t.equal(typeof l.product, 'string')
|
t.equal(typeof l.product, 'string')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,33 +75,6 @@ const assertValidStopover = (t, s) => {
|
||||||
assertValidStation(t, s.station)
|
assertValidStation(t, s.station)
|
||||||
}
|
}
|
||||||
|
|
||||||
const isJungfernheide = (s) => {
|
|
||||||
return s.type === 'station' &&
|
|
||||||
s.id === '8011167' &&
|
|
||||||
s.name === 'Berlin Jungfernheide' &&
|
|
||||||
s.coordinates &&
|
|
||||||
isRoughlyEqual(s.coordinates.latitude, 52.530408, .0005) &&
|
|
||||||
isRoughlyEqual(s.coordinates.longitude, 13.299424, .0005)
|
|
||||||
}
|
|
||||||
|
|
||||||
const assertIsJungfernheide = (t, s) => {
|
|
||||||
t.equal(s.type, 'station')
|
|
||||||
t.equal(s.id, '8011167')
|
|
||||||
t.equal(s.name, 'Berlin Jungfernheide')
|
|
||||||
t.ok(s.coordinates)
|
|
||||||
t.ok(isRoughlyEqual(s.coordinates.latitude, 52.530408, .0005))
|
|
||||||
t.ok(isRoughlyEqual(s.coordinates.longitude, 13.299424, .0005))
|
|
||||||
}
|
|
||||||
|
|
||||||
const assertIsMünchenHbf = (s) => {
|
|
||||||
t.equal(s.type, 'station')
|
|
||||||
t.equal(s.id, '8000261')
|
|
||||||
t.equal(s.name, 'München Hbf')
|
|
||||||
t.ok(s.coordinates)
|
|
||||||
t.equal(s.coordinates.latitude, 48.140229)
|
|
||||||
t.equal(s.coordinates.longitude, 11.558339)
|
|
||||||
}
|
|
||||||
|
|
||||||
const minute = 60 * 1000
|
const minute = 60 * 1000
|
||||||
const hour = 60 * minute
|
const hour = 60 * minute
|
||||||
const day = 24 * hour
|
const day = 24 * hour
|
||||||
|
@ -125,7 +98,5 @@ module.exports = {
|
||||||
assertValidLine,
|
assertValidLine,
|
||||||
isValidDateTime,
|
isValidDateTime,
|
||||||
assertValidStopover,
|
assertValidStopover,
|
||||||
isJungfernheide, assertIsJungfernheide,
|
|
||||||
assertIsMünchenHbf,
|
|
||||||
when, isValidWhen
|
when, isValidWhen
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue