add tests for arrival parsing (db)

This commit is contained in:
Julius Tens 2020-06-09 17:14:26 +02:00 committed by Jannis Redmann
parent 3ca4a0c2b2
commit 57fc610a5f
4 changed files with 595 additions and 0 deletions

33
test/db-arrivals.js Normal file
View file

@ -0,0 +1,33 @@
'use strict'
const tapePromise = require('tape-promise').default
const tape = require('tape')
const createClient = require('..')
const rawProfile = require('../p/db')
const res = require('./fixtures/db-arrivals.json')
const expected = require('./fixtures/db-arrivals.js')
const test = tapePromise(tape)
const client = createClient(rawProfile, 'public-transport/hafas-client:test')
const {profile} = client
const opt = {
direction: null,
duration: 10,
linesOfStops: true,
remarks: true,
stopovers: true,
includeRelatedStations: true,
when: '2019-08-19T20:30:00+02:00',
products: {}
}
test('parses an arrival correctly (DB)', (t) => {
const common = profile.parseCommon({profile, opt, res})
const ctx = {profile, opt, common, res}
const arrivals = res.jnyL.map(d => profile.parseArrival(ctx, d))
t.deepEqual(arrivals, expected)
t.end()
})

265
test/fixtures/db-arrivals.js vendored Normal file
View file

@ -0,0 +1,265 @@
'use strict'
module.exports = [
{
tripId: '1|1144239|52|80|9062020',
stop: {
type: 'stop',
id: '730985',
name: 'Jungfernheide Bahnhof (S+U), Berlin',
location: {
type: 'location',
id: '730985',
latitude: 52.530866,
longitude: 13.300781
},
products: {
nationalExpress: false,
national: false,
regionalExp: false,
regional: true,
suburban: true,
bus: true,
ferry: false,
subway: true,
tram: false,
taxi: false
},
station: {
type: 'station',
id: '8011167',
name: 'Berlin Jungfernheide',
location: {
type: 'location',
id: '8011167',
latitude: 52.530291,
longitude: 13.299451
},
products: {
nationalExpress: false,
national: false,
regionalExp: false,
regional: true,
suburban: true,
bus: true,
ferry: false,
subway: true,
tram: false,
taxi: false
},
lines: [
{
type: 'line',
id: '3-bb-re6',
fahrtNr: null,
name: 'Bus RE6',
public: true,
mode: 'train',
product: 'regional'
},
{
type: 'line',
id: '3-08-sev-1491900-5842741',
fahrtNr: null,
name: 'Bus SEV',
public: true,
mode: 'train',
product: 'regional'
},
{
type: 'line',
id: 'rb',
fahrtNr: null,
name: 'RB',
public: true,
mode: 'train',
product: 'regional'
},
{
type: 'line',
id: 're',
fahrtNr: null,
name: 'RE',
public: true,
mode: 'train',
product: 'regional'
},
{
type: 'line',
id: 're',
fahrtNr: null,
name: 'RE',
public: true,
mode: 'train',
product: 'regional'
},
{
type: 'line',
id: '4-08-2',
fahrtNr: null,
name: 'S 2',
public: true,
mode: 'train',
product: 'suburban'
},
{
type: 'line',
id: '4-08-25',
fahrtNr: null,
name: 'S 25',
public: true,
mode: 'train',
product: 'suburban'
},
{
type: 'line',
id: '4-08-41',
fahrtNr: null,
name: 'S 41',
public: true,
mode: 'train',
product: 'suburban'
},
{
type: 'line',
id: '4-08-42',
fahrtNr: null,
name: 'S 42',
public: true,
mode: 'train',
product: 'suburban'
},
{
type: 'line',
id: '4-08-46',
fahrtNr: null,
name: 'S 46',
public: true,
mode: 'train',
product: 'suburban'
},
{
type: 'line',
id: '5-vbbbvb-n7',
fahrtNr: null,
name: 'Bus N7',
public: true,
mode: 'bus',
product: 'bus'
},
{
type: 'line',
id: '5-vbbbvb-x9',
fahrtNr: null,
name: 'Bus X9',
public: true,
mode: 'bus',
product: 'bus'
},
{
type: 'line',
id: '5-vbbbvb-109',
fahrtNr: null,
name: 'Bus 109',
public: true,
mode: 'bus',
product: 'bus'
},
{
type: 'line',
id: '5-vbbbvb-m21',
fahrtNr: null,
name: 'Bus M21',
public: true,
mode: 'bus',
product: 'bus'
},
{
type: 'line',
id: '5-vbbbvb-m27',
fahrtNr: null,
name: 'Bus M27',
public: true,
mode: 'bus',
product: 'bus'
},
{
type: 'line',
id: '7-vbbbvu-7',
fahrtNr: null,
name: 'U 7',
public: true,
mode: 'train',
product: 'subway'
}
]
},
lines: [
{
type: 'line',
id: '5-vbbbvb-n7',
fahrtNr: null,
name: 'Bus N7',
public: true,
mode: 'bus',
product: 'bus'
},
{
type: 'line',
id: '5-vbbbvb-x9',
fahrtNr: null,
name: 'Bus X9',
public: true,
mode: 'bus',
product: 'bus'
},
{
type: 'line',
id: '5-vbbbvb-m21',
fahrtNr: null,
name: 'Bus M21',
public: true,
mode: 'bus',
product: 'bus'
},
{
type: 'line',
id: '5-vbbbvb-m27',
fahrtNr: null,
name: 'Bus M27',
public: true,
mode: 'bus',
product: 'bus'
},
{
type: 'line',
id: '7-vbbbvu-7',
fahrtNr: null,
name: 'U 7',
public: true,
mode: 'train',
product: 'subway'
}
]
},
when: '2020-06-09T17:21:00+02:00',
plannedWhen: '2020-06-09T17:04:00+02:00',
delay: 1020,
platform: null,
plannedPlatform: null,
direction: null,
provenance: 'Rathaus Spandau (S+U), Berlin',
line: {
type: 'line',
id: '7-vbbbvu-7',
fahrtNr: '19245',
name: 'U 7',
public: true,
adminCode: 'vbbBVU',
mode: 'train',
product: 'subway',
operator: { type: 'operator', id: 'nahreisezug', name: 'Nahreisezug' }
},
remarks: []
}
]

296
test/fixtures/db-arrivals.json vendored Normal file
View file

@ -0,0 +1,296 @@
{
"common": {
"locL": [
{
"lid": "A=1@O=Jungfernheide Bahnhof (S+U), Berlin@X=13300781@Y=52530866@U=80@L=730985@",
"type": "S",
"name": "Jungfernheide Bahnhof (S+U), Berlin",
"icoX": 2,
"extId": "730985",
"state": "F",
"crd": {
"x": 13300781,
"y": 52530866,
"type": "WGS84",
"layerX": 0,
"crdSysX": 0
},
"pCls": 184,
"pRefL": [
1,
2,
3,
4,
5
],
"mMastLocX": 1
},
{
"lid": "A=1@O=Berlin Jungfernheide@X=13299433@Y=52530273@U=80@L=8011167@",
"type": "S",
"name": "Berlin Jungfernheide",
"icoX": 2,
"extId": "8011167",
"state": "F",
"crd": {
"x": 13299451,
"y": 52530291,
"z": 0,
"type": "WGS84",
"layerX": 0,
"crdSysX": 0
},
"pCls": 184,
"pRefL": [
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
1,
2,
16,
3,
4,
5
]
}
],
"prodL": [
{
"name": "U 7",
"nameS": "7",
"number": "7",
"icoX": 0,
"cls": 128,
"oprX": 0,
"prodCtx": {
"name": "U 7",
"num": "19245",
"line": "7",
"lineId": "7_vbbBVU_7",
"matchId": "",
"catOut": "U",
"catOutS": "U",
"catOutL": "U-Bahn",
"catIn": "U",
"catCode": "7",
"admin": "vbbBVU"
}
},
{
"name": "Bus N7",
"nameS": "N7",
"icoX": 2,
"cls": 32,
"prodCtx": {
"lineId": "5_vbbBVB_N7"
}
},
{
"name": "Bus X9",
"nameS": "X9",
"icoX": 2,
"cls": 32,
"prodCtx": {
"lineId": "5_vbbBVB_X9"
}
},
{
"name": "Bus M21",
"nameS": "M21",
"icoX": 2,
"cls": 32,
"prodCtx": {
"lineId": "5_vbbBVB_M21"
}
},
{
"name": "Bus M27",
"nameS": "M27",
"icoX": 2,
"cls": 32,
"prodCtx": {
"lineId": "5_vbbBVB_M27"
}
},
{
"name": "U 7",
"nameS": "7",
"icoX": 0,
"cls": 128,
"prodCtx": {
"lineId": "7_vbbBVU_7"
}
},
{
"name": "Bus RE6",
"nameS": "RE6",
"icoX": 2,
"cls": 8,
"prodCtx": {
"lineId": "3_BB_____RE6"
}
},
{
"name": "Bus SEV",
"nameS": "SEV",
"icoX": 2,
"cls": 8,
"prodCtx": {
"lineId": "3_08_____SEV!!1491900!!5842741"
}
},
{
"name": "RB",
"icoX": 3,
"cls": 8
},
{
"name": "RE",
"icoX": 4,
"cls": 8
},
{
"name": "RE",
"icoX": 5,
"cls": 8
},
{
"name": "S 2",
"nameS": "2",
"icoX": 6,
"cls": 16,
"prodCtx": {
"lineId": "4_08_____2"
}
},
{
"name": "S 25",
"nameS": "25",
"icoX": 6,
"cls": 16,
"prodCtx": {
"lineId": "4_08_____25"
}
},
{
"name": "S 41",
"nameS": "41",
"icoX": 6,
"cls": 16,
"prodCtx": {
"lineId": "4_08_____41"
}
},
{
"name": "S 42",
"nameS": "42",
"icoX": 6,
"cls": 16,
"prodCtx": {
"lineId": "4_08_____42"
}
},
{
"name": "S 46",
"nameS": "46",
"icoX": 6,
"cls": 16,
"prodCtx": {
"lineId": "4_08_____46"
}
},
{
"name": "Bus 109",
"nameS": "109",
"icoX": 2,
"cls": 32,
"prodCtx": {
"lineId": "5_vbbBVB_109"
}
}
],
"polyL": [],
"layerL": [
{
"id": "standard",
"name": "standard",
"index": 0,
"annoCnt": 0
}
],
"crdSysL": [
{
"id": "standard",
"index": 0,
"type": "WGS84",
"dim": 3
}
],
"opL": [
{
"name": "Nahreisezug",
"icoX": 1
}
],
"remL": [],
"icoL": [
{
"res": "U"
},
{
"res": "DPN",
"txt": "Nahreisezug"
},
{
"res": "Bus"
},
{
"res": "RB"
},
{
"res": "DPN"
},
{
"res": "RE"
},
{
"res": "S"
}
]
},
"type": "ARR",
"jnyL": [
{
"jid": "1|1144239|52|80|9062020",
"date": "20200609",
"prodX": 0,
"dirTxt": "Rathaus Spandau (S+U), Berlin",
"status": "P",
"isRchbl": true,
"stbStop": {
"locX": 0,
"idx": 9,
"aProdX": 0,
"aOutR": true,
"aTimeS": "170400",
"aTimeR": "172100",
"aProgType": "PROGNOSED",
"aTZOffset": 120,
"type": "N"
},
"subscr": "F"
}
],
"fpB": "20191215",
"fpE": "20201212",
"planrtTS": "1591715437",
"sD": "20200609",
"sT": "171108"
}

View file

@ -7,6 +7,7 @@ require('./db-stop')
require('./insa-stop') require('./insa-stop')
require('./bvg-journey') require('./bvg-journey')
require('./db-journey') require('./db-journey')
require('./db-arrivals')
require('./vbb-departures') require('./vbb-departures')
require('./bvg-radar') require('./bvg-radar')
require('./db-netz-remarks') require('./db-netz-remarks')