db-vendo-client/test/parse/line.js

143 lines
2.7 KiB
JavaScript
Raw Normal View History

import tap from 'tap';
import {parseLine as parse} from '../../parse/line.js';
2019-09-03 15:35:12 +02:00
const profile = {
products: [
2024-12-07 16:16:31 +00:00
{
id: 'nationalExpress',
mode: 'train',
name: 'InterCityExpress',
short: 'ICE',
vendo: 'ICE',
default: true,
},
{
id: 'bus',
mode: 'bus',
name: 'Bus',
short: 'B',
vendo: 'BUS',
default: true,
},
],
2024-12-07 16:16:31 +00:00
parseOperator: _ => null
};
const ctx = {
data: {},
opt: {},
profile,
};
2019-09-03 15:35:12 +02:00
2024-12-07 16:16:31 +00:00
tap.test('parses ICE leg correctly', (t) => {
2019-09-03 15:35:12 +02:00
const input = {
2024-12-07 16:16:31 +00:00
"journeyId": "foo",
"verkehrsmittel": {
"produktGattung": "ICE",
"kategorie": "ICE",
"name": "ICE 229",
"nummer": "229",
"richtung": "Wien Hbf",
"typ": "PUBLICTRANSPORT",
"zugattribute": [{
"kategorie": "BEFÖRDERER",
"key": "BEF",
"value": "DB Fernverkehr AG, Österreichische Bundesbahnen"
},{
"kategorie": "FAHRRADMITNAHME",
"key": "FR",
"value": "Bicycles conveyed - subject to reservation",
"teilstreckenHinweis": "(Mainz Hbf - Wien Meidling)"
}],
"kurzText": "ICE",
"mittelText": "ICE 229",
"langText": "ICE 229"
}
};
2019-09-03 15:35:12 +02:00
const expected = {
type: 'line',
id: 'foo',
2024-12-07 16:16:31 +00:00
fahrtNr: 229,
name: 'ICE 229',
public: true,
product: 'nationalExpress',
productName: 'ICE',
mode: 'train',
operator: null,
};
t.same(parse(ctx, input), expected);
t.end();
});
tap.test('parses Bus trip correctly', (t) => {
const input = {
"reisetag": "2024-12-07",
"regulaereVerkehrstage": "not every day",
"irregulaereVerkehrstage": "7., 14. Dec 2024",
"zugName": "Bus 807",
"zugattribute": [
{
"kategorie": "INFORMATION",
"key": "cB",
"value": "Tel. 0981-9714925, Anmeldung bis 90 Min. vor Abfahrt (Mo-So: 9-15 Uhr)"
}
],
"cancelled": false,
};
const expected = {
type: 'line',
id: undefined,
fahrtNr: undefined,
name: 'Bus 807',
public: true,
2024-12-07 16:16:31 +00:00
product: undefined,
productName: undefined,
mode: undefined,
operator: null
};
2019-09-03 15:35:12 +02:00
t.same(parse(ctx, input), expected);
2024-12-07 16:16:31 +00:00
t.end();
});
2019-09-03 15:35:12 +02:00
2024-12-07 16:16:31 +00:00
tap.test('parses Bus leg correctly', (t) => {
const input = {
"journeyId": "foo",
"verkehrsmittel": {
"produktGattung": "BUS",
"kategorie": "Bus",
"linienNummer": "807",
"name": "Bus 807",
"nummer": "807",
"richtung": "Bahnhof, Dombühl",
"typ": "PUBLICTRANSPORT",
"zugattribute": [
{
"kategorie": "INFORMATION",
"key": "cB",
"value": "Tel. 0981-9714925, Anmeldung bis 90 Min. vor Abfahrt (Mo-So: 9-15 Uhr)"
}
],
"kurzText": "Bus",
"mittelText": "Bus 807",
"langText": "Bus 807"
}
};
const expected = {
type: 'line',
id: 'foo',
fahrtNr: '807',
name: 'Bus 807',
public: true,
product: 'bus',
productName: 'Bus',
mode: 'bus',
operator: null
};
t.same(parse(ctx, input), expected);
t.end();
});