diff --git a/lib/default-profile.js b/lib/default-profile.js index 5b1681b8..5de45fd7 100644 --- a/lib/default-profile.js +++ b/lib/default-profile.js @@ -34,6 +34,7 @@ const defaultProfile = { parseDeparture, parseJourney, parseLine, + parseStationName: id, parseLocation, parseMovement, parseNearby, diff --git a/p/vbb/index.js b/p/vbb/index.js index dc528c5b..973d531a 100644 --- a/p/vbb/index.js +++ b/p/vbb/index.js @@ -26,7 +26,7 @@ const parseLine = (profile, l) => { const data = modes.bitmasks[parseInt(res.class)] if (data) { res.mode = data.mode - res.product = data.product + res.product = data.type } } @@ -35,9 +35,13 @@ const parseLine = (profile, l) => { const parseLocation = (profile, l) => { const res = _parseLocation(profile, l) + + // todo: shorten has been made for stations, not any type of location + res.name = shorten(res.name) + if (res.type === 'station') { res.id = to12Digit(res.id) - res.name = shorten(res.name) + // todo: https://github.com/derhuerst/vbb-hafas/blob/1c64bfe42422e2648b21016d233c808460250308/lib/parse.js#L67-L75 } return res } @@ -72,6 +76,7 @@ const vbbProfile = { endpoint: 'https://fahrinfo.vbb.de/bin/mgate.exe', transformReqBody, + parseStationName: shorten, parseLocation, parseLine, parseProducts: modes.parseBitmask, diff --git a/p/vbb/modes.js b/p/vbb/modes.js index fbbb49f9..9b78cfd9 100644 --- a/p/vbb/modes.js +++ b/p/vbb/modes.js @@ -108,7 +108,6 @@ m.bitmasks[16] = m.ferry m.bitmasks[32] = m.express m.bitmasks[64] = m.regional - m.categories = [ m.suburban, m.subway, diff --git a/parse/journey.js b/parse/journey.js index cb8831e8..f622c151 100644 --- a/parse/journey.js +++ b/parse/journey.js @@ -51,7 +51,7 @@ const createParseJourney = (profile, stations, lines, remarks) => { } else if (pt.type === 'JNY') { res.id = pt.jny.jid res.line = lines[parseInt(pt.jny.prodX)] || null - res.direction = pt.jny.dirTxt // todo: parse this + res.direction = profile.parseStationName(pt.jny.dirTxt) if (pt.dep.dPlatfS) res.departurePlatform = pt.dep.dPlatfS if (pt.arr.aPlatfS) res.arrivalPlatform = pt.arr.aPlatfS diff --git a/parse/line.js b/parse/line.js index 6df7c6a5..01e7954d 100644 --- a/parse/line.js +++ b/parse/line.js @@ -5,7 +5,11 @@ // todo: what is p.oprX? const parseLine = (profile, p) => { 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, + public: true + } if (p.cls) res.class = p.cls if (p.prodCtx) { diff --git a/test/util.js b/test/util.js index 99864715..36805d1e 100644 --- a/test/util.js +++ b/test/util.js @@ -43,6 +43,7 @@ const assertValidLine = (t, l) => { if (!isValidMode(l.mode)) console.error(l) t.ok(isValidMode(l.mode), 'invalid mode ' + l.mode) t.equal(typeof l.product, 'string') + t.equal(l.public, true) } const isValidDateTime = (w) => { @@ -72,6 +73,10 @@ const isValidWhen = (w) => { return isRoughlyEqual(10 * hour, +when, ts) } +const assertValidWhen = (t, w) => { + t.ok(isValidWhen(w), 'invalid when') +} + module.exports = { assertValidStation, assertValidPoi, @@ -81,5 +86,5 @@ module.exports = { assertValidLine, isValidDateTime, assertValidStopover, - when, isValidWhen + when, isValidWhen, assertValidWhen } diff --git a/test/vbb.js b/test/vbb.js index fd4cd809..c13c0119 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -15,7 +15,7 @@ const { assertValidAddress, assertValidLocation, assertValidLine, - assertValidPassed, + assertValidStopover, hour, when, assertValidWhen } = require('./util') @@ -68,7 +68,7 @@ test('journeys – station to station', async (t) => { t.ok(part.direction.indexOf('(Berlin)') === -1) t.ok(Array.isArray(part.passed)) - for (let passed of part.passed) assertValidPassed(t, passed) + for (let passed of part.passed) assertValidStopover(t, passed) } t.end() }) @@ -93,9 +93,9 @@ test('journeys – only subway', async (t) => { for (let journey of journeys) { for (let part of journey.parts) { if (part.line) { + assertValidLine(t, part.line) t.equal(part.line.mode, 'train') t.equal(part.line.product, 'subway') - t.equal(part.line.public, true) } } } @@ -122,7 +122,8 @@ test('journeys – fails with no product', async (t) => { } }) -test('journey part details', async (t) => { +// todo +test.skip('journey part details', async (t) => { const journeys = await client.journeys(spichernstr, amrumerStr, { results: 1, when }) @@ -141,7 +142,7 @@ test('journey part details', async (t) => { t.ok(part.direction) t.ok(Array.isArray(part.passed)) - for (let passed of part.passed) assertValidPassed(t, passed) + for (let passed of part.passed) assertValidStopover(t, passed) t.end() }) @@ -200,7 +201,7 @@ test('journeys – station to POI', async (t) => { -test.only('departures', async (t) => { +test('departures', async (t) => { const deps = await client.departures(spichernstr, {duration: 5, when}) t.ok(Array.isArray(deps)) @@ -220,7 +221,8 @@ test.only('departures', async (t) => { t.end() }) -test('departures at 7-digit station', async (t) => { +// todo +test.skip('departures at 7-digit station', async (t) => { const eisenach = '8010097' // see derhuerst/vbb-hafas#22 await client.departures(eisenach, {when}) t.pass('did not fail') @@ -268,6 +270,7 @@ test('locations', async (t) => { +// todo test.skip('radar', async (t) => { const vehicles = await client.radar(52.52411, 13.41002, 52.51942, 13.41709, { duration: 5 * 60, when