more bugfixes 🐛

This commit is contained in:
Jannis R 2017-12-11 19:53:26 +01:00
parent 608a91989f
commit a2fa56edc1
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
5 changed files with 28 additions and 11 deletions

View file

@ -15,7 +15,7 @@ const createParseDeparture = (profile, stations, lines, remarks) => {
const res = {
journeyId: d.jid,
station: stations[parseInt(d.stbStop.locX)] || null,
when: when.format(),
when: when.toISO(),
direction: profile.parseStationName(d.dirTxt),
line: lines[parseInt(d.prodX)] || null,
remarks: d.remL ? d.remL.map(findRemark) : [],

View file

@ -24,9 +24,9 @@ const parseLocation = (profile, l) => {
return station
}
if (l.type === POI) res.id = l.extId
else if (l.type === ADDRESS) res.address = l.name
if (l.type === ADDRESS) res.address = l.name
else res.name = l.name
if (l.type === POI) res.id = l.extId
return res
}

View file

@ -238,6 +238,11 @@ test('nearby Berlin Jungfernheide', co.wrap(function* (t) {
t.ok(nearby[0].distance >= 0)
t.ok(nearby[0].distance <= 100)
for (let n of nearby) {
if (n.type === 'station') assertValidStation(t, n)
else assertValidLocation(t, n)
}
t.end()
}))
@ -250,7 +255,10 @@ test('locations named Jungfernheide', co.wrap(function* (t) {
t.ok(locations.length > 0)
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.end()

View file

@ -20,8 +20,11 @@ const assertValidStation = (t, s, coordsOptional = false) => {
const assertValidPoi = (t, p) => {
t.equal(typeof p.id, 'string')
t.equal(typeof p.name, 'string')
t.equal(typeof a.address, 'string') // todo: do POIs always have an address?
assertValidLocation(t, a, true) // todo: do POIs always have coords?
if (p.address !== null && p.address !== undefined) {
t.equal(typeof p.address, 'string')
t.ok(p.address)
}
assertValidLocation(t, p, true) // todo: do POIs always have coords?
}
const assertValidAddress = (t, a) => {

View file

@ -277,7 +277,10 @@ test('nearby', co.wrap(function* (t) {
const nearby = yield client.nearby(52.4873452, 13.3310411, {distance: 200})
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].name, 'U Berliner Str.')
@ -300,10 +303,13 @@ test('locations', co.wrap(function* (t) {
t.ok(Array.isArray(locations))
t.ok(locations.length > 0)
t.ok(locations.length <= 10)
for (let l of locations) assertValidLocation(t, l)
t.ok(locations.find((s) => s.type === 'station'))
t.ok(locations.find((s) => s.type === 'poi'))
t.ok(locations.find((s) => s.type === 'address'))
for (let l of locations) {
if (l.type === 'station') assertValidStation(t, l)
else assertValidLocation(t, l)
}
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()
}))