From a2fa56edc1faccc1cf466eb413837737ef819df6 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Mon, 11 Dec 2017 19:53:26 +0100 Subject: [PATCH] more bugfixes :bug: --- parse/departure.js | 2 +- parse/location.js | 4 ++-- test/db.js | 10 +++++++++- test/util.js | 7 +++++-- test/vbb.js | 16 +++++++++++----- 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/parse/departure.js b/parse/departure.js index 7ded8c06..c9d6c298 100644 --- a/parse/departure.js +++ b/parse/departure.js @@ -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) : [], diff --git a/parse/location.js b/parse/location.js index 1c8d37b7..b776b920 100644 --- a/parse/location.js +++ b/parse/location.js @@ -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 } diff --git a/test/db.js b/test/db.js index a40a6ad3..340373f2 100644 --- a/test/db.js +++ b/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 <= 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() diff --git a/test/util.js b/test/util.js index d7b73170..343a1f36 100644 --- a/test/util.js +++ b/test/util.js @@ -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) => { diff --git a/test/vbb.js b/test/vbb.js index 86369d34..04682321 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -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() }))