From ef9e3765ee24ea16579f52a6401b903104279f40 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Tue, 4 Jan 2022 15:31:40 +0100 Subject: [PATCH] =?UTF-8?q?parseLine:=20don't=20trim=20adminCode=20?= =?UTF-8?q?=F0=9F=92=A5=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parse/line.js | 3 +- test/fixtures/bvg-arrivals.js | 48 ++++++++++++------------ test/fixtures/bvg-journey.js | 2 +- test/fixtures/bvg-trip-with-occupancy.js | 2 +- test/fixtures/vbb-departures.js | 24 ++++++------ test/fixtures/vbb-journeys.js | 14 +++---- test/mobiliteit-lu-line.js | 2 +- test/parse/line.js | 14 +++++-- 8 files changed, 58 insertions(+), 51 deletions(-) diff --git a/parse/line.js b/parse/line.js index a78e97e2..e21bd5fd 100644 --- a/parse/line.js +++ b/parse/line.js @@ -22,8 +22,7 @@ const parseLine = ({profile}, p) => { // todo: what is p.prodCtx.catCode? if (p.prodCtx && 'string' === typeof p.prodCtx.admin) { - // todo [breaking]: don't trim - res.adminCode = p.prodCtx.admin.replace(/-+$/, '') + res.adminCode = p.prodCtx.admin } if (p.prodCtx && 'string' === typeof p.prodCtx.catOut) { diff --git a/test/fixtures/bvg-arrivals.js b/test/fixtures/bvg-arrivals.js index 771e26cc..28906532 100644 --- a/test/fixtures/bvg-arrivals.js +++ b/test/fixtures/bvg-arrivals.js @@ -311,7 +311,7 @@ module.exports = [ fahrtNr: '2780', name: 'M5', public: true, - adminCode: 'BVT', + adminCode: 'BVT---', productName: 'Tram', mode: 'train', product: 'tram', @@ -348,7 +348,7 @@ module.exports = [ fahrtNr: '3085', name: 'M8', public: true, - adminCode: 'BVT', + adminCode: 'BVT---', productName: 'Tram', mode: 'train', product: 'tram', @@ -385,7 +385,7 @@ module.exports = [ fahrtNr: '3151', name: 'M8', public: true, - adminCode: 'BVT', + adminCode: 'BVT---', productName: 'Tram', mode: 'train', product: 'tram', @@ -422,7 +422,7 @@ module.exports = [ fahrtNr: '3255', name: '56', public: true, - adminCode: 'BVT', + adminCode: 'BVT---', productName: 'Tram', mode: 'train', product: 'tram', @@ -459,7 +459,7 @@ module.exports = [ fahrtNr: '25595', name: 'S8', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', @@ -497,7 +497,7 @@ module.exports = [ fahrtNr: '893', name: 'S41', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', @@ -536,7 +536,7 @@ module.exports = [ fahrtNr: '1710', name: 'S42', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', @@ -575,7 +575,7 @@ module.exports = [ fahrtNr: '3304', name: '56', public: true, - adminCode: 'BVT', + adminCode: 'BVT---', productName: 'Tram', mode: 'train', product: 'tram', @@ -612,7 +612,7 @@ module.exports = [ fahrtNr: '1344', name: 'S42', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', @@ -651,7 +651,7 @@ module.exports = [ fahrtNr: '2643', name: 'M5', public: true, - adminCode: 'BVT', + adminCode: 'BVT---', productName: 'Tram', mode: 'train', product: 'tram', @@ -688,7 +688,7 @@ module.exports = [ fahrtNr: '654', name: 'S41', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', @@ -725,7 +725,7 @@ module.exports = [ fahrtNr: '1357', name: 'S42', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', @@ -762,7 +762,7 @@ module.exports = [ fahrtNr: '2780', name: 'M5', public: true, - adminCode: 'BVT', + adminCode: 'BVT---', productName: 'Tram', mode: 'train', product: 'tram', @@ -801,7 +801,7 @@ module.exports = [ fahrtNr: '25467', name: 'S8', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', @@ -849,7 +849,7 @@ module.exports = [ fahrtNr: '3085', name: 'M8', public: true, - adminCode: 'BVT', + adminCode: 'BVT---', productName: 'Tram', mode: 'train', product: 'tram', @@ -886,7 +886,7 @@ module.exports = [ fahrtNr: '3151', name: 'M8', public: true, - adminCode: 'BVT', + adminCode: 'BVT---', productName: 'Tram', mode: 'train', product: 'tram', @@ -923,7 +923,7 @@ module.exports = [ fahrtNr: '3255', name: '56', public: true, - adminCode: 'BVT', + adminCode: 'BVT---', productName: 'Tram', mode: 'train', product: 'tram', @@ -962,7 +962,7 @@ module.exports = [ fahrtNr: '26542', name: 'S85', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', @@ -1032,7 +1032,7 @@ module.exports = [ fahrtNr: '889', name: 'S41', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', @@ -1071,7 +1071,7 @@ module.exports = [ fahrtNr: '1706', name: 'S42', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', @@ -1110,7 +1110,7 @@ module.exports = [ fahrtNr: '1704', name: 'S42', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', @@ -1149,7 +1149,7 @@ module.exports = [ fahrtNr: '1702', name: 'S42', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', @@ -1188,7 +1188,7 @@ module.exports = [ fahrtNr: '1700', name: 'S42', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', @@ -1227,7 +1227,7 @@ module.exports = [ fahrtNr: '1698', name: 'S42', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', diff --git a/test/fixtures/bvg-journey.js b/test/fixtures/bvg-journey.js index 73793e5a..c2ae3513 100644 --- a/test/fixtures/bvg-journey.js +++ b/test/fixtures/bvg-journey.js @@ -697,7 +697,7 @@ module.exports = { fahrtNr: '14825', name: 'S2', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', diff --git a/test/fixtures/bvg-trip-with-occupancy.js b/test/fixtures/bvg-trip-with-occupancy.js index 6a16a9f5..7cf12075 100644 --- a/test/fixtures/bvg-trip-with-occupancy.js +++ b/test/fixtures/bvg-trip-with-occupancy.js @@ -9,7 +9,7 @@ module.exports = { fahrtNr: '7070', name: '147', public: true, - adminCode: 'BVB', + adminCode: 'BVB---', productName: 'Bus', mode: 'bus', product: 'bus', diff --git a/test/fixtures/vbb-departures.js b/test/fixtures/vbb-departures.js index 24d6642c..3b3c40d9 100644 --- a/test/fixtures/vbb-departures.js +++ b/test/fixtures/vbb-departures.js @@ -172,7 +172,7 @@ module.exports = [ fahrtNr: '10541', name: 'S3', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', @@ -365,7 +365,7 @@ module.exports = [ fahrtNr: '33695', name: '300', public: true, - adminCode: 'BVB', + adminCode: 'BVB---', productName: 'Bus', mode: 'bus', product: 'bus', @@ -579,7 +579,7 @@ module.exports = [ fahrtNr: '17590', name: 'U8', public: true, - adminCode: 'BVU', + adminCode: 'BVU---', productName: 'U', mode: 'train', product: 'subway', @@ -794,7 +794,7 @@ module.exports = [ fahrtNr: '17227', name: 'U8', public: true, - adminCode: 'BVU', + adminCode: 'BVU---', productName: 'U', mode: 'train', product: 'subway', @@ -1009,7 +1009,7 @@ module.exports = [ fahrtNr: '15359', name: 'S5', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', @@ -1224,7 +1224,7 @@ module.exports = [ fahrtNr: '17258', name: 'S7', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', @@ -1439,7 +1439,7 @@ module.exports = [ fahrtNr: '17985', name: 'S7', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', @@ -1654,7 +1654,7 @@ module.exports = [ fahrtNr: '14839', name: 'S5', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', @@ -1869,7 +1869,7 @@ module.exports = [ fahrtNr: '17589', name: 'U8', public: true, - adminCode: 'BVU', + adminCode: 'BVU---', productName: 'U', mode: 'train', product: 'subway', @@ -2084,7 +2084,7 @@ module.exports = [ fahrtNr: '17229', name: 'U8', public: true, - adminCode: 'BVU', + adminCode: 'BVU---', productName: 'U', mode: 'train', product: 'subway', @@ -2299,7 +2299,7 @@ module.exports = [ fahrtNr: '33624', name: '300', public: true, - adminCode: 'BVB', + adminCode: 'BVB---', productName: 'Bus', mode: 'bus', product: 'bus', @@ -2513,7 +2513,7 @@ module.exports = [ fahrtNr: '20512', name: 'S9', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', diff --git a/test/fixtures/vbb-journeys.js b/test/fixtures/vbb-journeys.js index 2859d2e5..d6a71a6b 100644 --- a/test/fixtures/vbb-journeys.js +++ b/test/fixtures/vbb-journeys.js @@ -59,7 +59,7 @@ module.exports = [{ fahrtNr: '24005', name: 'U9', public: true, - adminCode: 'BVU', + adminCode: 'BVU---', productName: 'U', mode: 'train', product: 'subway', @@ -132,7 +132,7 @@ module.exports = [{ fahrtNr: '2568', name: 'S41', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', @@ -205,7 +205,7 @@ module.exports = [{ fahrtNr: '1710', name: 'ICE 1710', public: true, - adminCode: 'N80', + adminCode: 'N80---', productName: 'ICE', mode: 'train', product: 'express', @@ -225,7 +225,7 @@ module.exports = [{ fahrtNr: '2457', name: 'IC 2457', public: true, - adminCode: 'N80', + adminCode: 'N80---', productName: 'IC', mode: 'train', product: 'express', @@ -247,7 +247,7 @@ module.exports = [{ fahrtNr: '2055', name: 'IC 2055', public: true, - adminCode: 'N80', + adminCode: 'N80---', productName: 'IC', mode: 'train', product: 'express', @@ -334,7 +334,7 @@ module.exports = [{ fahrtNr: '24006', name: 'U9', public: true, - adminCode: 'BVU', + adminCode: 'BVU---', productName: 'U', mode: 'train', product: 'subway', @@ -407,7 +407,7 @@ module.exports = [{ fahrtNr: '2723', name: 'S41', public: true, - adminCode: 'DBS', + adminCode: 'DBS---', productName: 'S', mode: 'train', product: 'suburban', diff --git a/test/mobiliteit-lu-line.js b/test/mobiliteit-lu-line.js index f93b297c..913d5490 100644 --- a/test/mobiliteit-lu-line.js +++ b/test/mobiliteit-lu-line.js @@ -43,7 +43,7 @@ tap.test('parses a line correctly (mobiliteit.lu)', (t) => { fahrtNr: '108', name: 'IC 108', public: true, - adminCode: 'C88', + adminCode: 'C88---', productName: 'IC', mode: 'train', product: 'national-train', diff --git a/test/parse/line.js b/test/parse/line.js index 7db47812..9b63c327 100644 --- a/test/parse/line.js +++ b/test/parse/line.js @@ -1,6 +1,7 @@ 'use strict' const tap = require('tap') +const omit = require('lodash/omit') const parse = require('../../parse/line') const profile = { @@ -21,7 +22,9 @@ tap.test('parses lines correctly', (t) => { line: 'foo line', prodCtx: { lineId: 'Foo ', - num: 123 + num: 123, + // HAFAS endpoints commonly have these padded admin codes. + admin: 'foo---', } } const expected = { @@ -29,7 +32,8 @@ tap.test('parses lines correctly', (t) => { id: 'foo', fahrtNr: 123, name: 'foo line', - public: true + public: true, + adminCode: 'foo---', } t.same(parse(ctx, input), expected) @@ -51,7 +55,11 @@ tap.test('parses lines correctly', (t) => { t.same(parse(ctx, { ...input, prodCtx: undefined }), { - ...expected, id: 'foo-line', fahrtNr: null + ...omit(expected, [ + 'adminCode', + ]), + id: 'foo-line', + fahrtNr: null, }) t.end() })