mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
more bugfixes 🐛
This commit is contained in:
parent
608a91989f
commit
a2fa56edc1
5 changed files with 28 additions and 11 deletions
|
@ -15,7 +15,7 @@ const createParseDeparture = (profile, stations, lines, remarks) => {
|
||||||
const res = {
|
const res = {
|
||||||
journeyId: d.jid,
|
journeyId: d.jid,
|
||||||
station: stations[parseInt(d.stbStop.locX)] || null,
|
station: stations[parseInt(d.stbStop.locX)] || null,
|
||||||
when: when.format(),
|
when: when.toISO(),
|
||||||
direction: profile.parseStationName(d.dirTxt),
|
direction: profile.parseStationName(d.dirTxt),
|
||||||
line: lines[parseInt(d.prodX)] || null,
|
line: lines[parseInt(d.prodX)] || null,
|
||||||
remarks: d.remL ? d.remL.map(findRemark) : [],
|
remarks: d.remL ? d.remL.map(findRemark) : [],
|
||||||
|
|
|
@ -24,9 +24,9 @@ const parseLocation = (profile, l) => {
|
||||||
return station
|
return station
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l.type === POI) res.id = l.extId
|
if (l.type === ADDRESS) res.address = l.name
|
||||||
else if (l.type === ADDRESS) res.address = l.name
|
|
||||||
else res.name = l.name
|
else res.name = l.name
|
||||||
|
if (l.type === POI) res.id = l.extId
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
10
test/db.js
10
test/db.js
|
@ -238,6 +238,11 @@ test('nearby Berlin Jungfernheide', co.wrap(function* (t) {
|
||||||
t.ok(nearby[0].distance >= 0)
|
t.ok(nearby[0].distance >= 0)
|
||||||
t.ok(nearby[0].distance <= 100)
|
t.ok(nearby[0].distance <= 100)
|
||||||
|
|
||||||
|
for (let n of nearby) {
|
||||||
|
if (n.type === 'station') assertValidStation(t, n)
|
||||||
|
else assertValidLocation(t, n)
|
||||||
|
}
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
@ -250,7 +255,10 @@ test('locations named Jungfernheide', co.wrap(function* (t) {
|
||||||
t.ok(locations.length > 0)
|
t.ok(locations.length > 0)
|
||||||
t.ok(locations.length <= 10)
|
t.ok(locations.length <= 10)
|
||||||
|
|
||||||
for (let location of locations) assertValidLocation(t, location)
|
for (let l of locations) {
|
||||||
|
if (l.type === 'station') assertValidStation(t, l)
|
||||||
|
else assertValidLocation(t, l)
|
||||||
|
}
|
||||||
t.ok(locations.some(isJungfernheide))
|
t.ok(locations.some(isJungfernheide))
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
|
|
|
@ -20,8 +20,11 @@ const assertValidStation = (t, s, coordsOptional = false) => {
|
||||||
const assertValidPoi = (t, p) => {
|
const assertValidPoi = (t, p) => {
|
||||||
t.equal(typeof p.id, 'string')
|
t.equal(typeof p.id, 'string')
|
||||||
t.equal(typeof p.name, 'string')
|
t.equal(typeof p.name, 'string')
|
||||||
t.equal(typeof a.address, 'string') // todo: do POIs always have an address?
|
if (p.address !== null && p.address !== undefined) {
|
||||||
assertValidLocation(t, a, true) // todo: do POIs always have coords?
|
t.equal(typeof p.address, 'string')
|
||||||
|
t.ok(p.address)
|
||||||
|
}
|
||||||
|
assertValidLocation(t, p, true) // todo: do POIs always have coords?
|
||||||
}
|
}
|
||||||
|
|
||||||
const assertValidAddress = (t, a) => {
|
const assertValidAddress = (t, a) => {
|
||||||
|
|
16
test/vbb.js
16
test/vbb.js
|
@ -277,7 +277,10 @@ test('nearby', co.wrap(function* (t) {
|
||||||
const nearby = yield client.nearby(52.4873452, 13.3310411, {distance: 200})
|
const nearby = yield client.nearby(52.4873452, 13.3310411, {distance: 200})
|
||||||
|
|
||||||
t.ok(Array.isArray(nearby))
|
t.ok(Array.isArray(nearby))
|
||||||
for (let n of nearby) assertValidLocation(t, n, false)
|
for (let n of nearby) {
|
||||||
|
if (n.type === 'station') assertValidStation(t, n)
|
||||||
|
else assertValidLocation(t, n, false)
|
||||||
|
}
|
||||||
|
|
||||||
t.equal(nearby[0].id, '900000044201')
|
t.equal(nearby[0].id, '900000044201')
|
||||||
t.equal(nearby[0].name, 'U Berliner Str.')
|
t.equal(nearby[0].name, 'U Berliner Str.')
|
||||||
|
@ -300,10 +303,13 @@ test('locations', co.wrap(function* (t) {
|
||||||
t.ok(Array.isArray(locations))
|
t.ok(Array.isArray(locations))
|
||||||
t.ok(locations.length > 0)
|
t.ok(locations.length > 0)
|
||||||
t.ok(locations.length <= 10)
|
t.ok(locations.length <= 10)
|
||||||
for (let l of locations) assertValidLocation(t, l)
|
for (let l of locations) {
|
||||||
t.ok(locations.find((s) => s.type === 'station'))
|
if (l.type === 'station') assertValidStation(t, l)
|
||||||
t.ok(locations.find((s) => s.type === 'poi'))
|
else assertValidLocation(t, l)
|
||||||
t.ok(locations.find((s) => s.type === 'address'))
|
}
|
||||||
|
t.ok(locations.find(s => s.type === 'station'))
|
||||||
|
t.ok(locations.find(s => s.id && s.name)) // POIs
|
||||||
|
t.ok(locations.find(s => !s.name && s.address)) // addresses
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
Loading…
Add table
Reference in a new issue