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

149 lines
2.8 KiB
JavaScript
Raw Normal View History

import tap from 'tap';
import {parseLocation as parse} from '../../parse/location.js';
2024-12-21 15:26:49 +00:00
import {parseProducts} from '../../parse/products.js';
2019-09-03 15:35:12 +02:00
const profile = {
parseLocation: parse,
enrichStation: (ctx, stop) => stop,
parseStationName: (_, name) => name.toLowerCase(),
2024-12-21 15:26:49 +00:00
parseProducts,
2024-12-07 16:16:31 +00:00
products: [{
id: 'nationalExpress',
vendo: 'ICE',
},
{
id: 'national',
vendo: 'IC',
},
{
id: 'regional',
vendo: 'REGIONAL',
},
{
id: 'bus',
vendo: 'BUS',
},
{
id: 'taxi',
vendo: 'ANRUFPFLICHTIG',
2024-12-08 21:42:57 +00:00
}],
};
const ctx = {
data: {},
opt: {
linesOfStops: false,
subStops: true,
entrances: true,
},
profile,
};
2019-09-03 15:35:12 +02:00
2021-05-20 16:42:43 +01:00
tap.test('parses an address correctly', (t) => {
2019-09-03 15:35:12 +02:00
const input = {
2024-12-08 21:42:57 +00:00
id: 'A=2@O=Würzburg - Heuchelhof, Pergamonweg@X=9952209@Y=49736794@U=92@b=981423354@B=1@p=1706613073@',
lat: 49.736794,
lon: 9.952209,
name: 'Würzburg - Heuchelhof, Pergamonweg',
products: [],
type: 'ADR',
};
2019-09-03 15:35:12 +02:00
const address = parse(ctx, input);
2021-05-20 16:42:43 +01:00
t.same(address, {
2019-09-03 15:35:12 +02:00
type: 'location',
2024-12-07 16:16:31 +00:00
id: null,
2024-12-17 19:41:00 +00:00
name: 'Würzburg - Heuchelhof, Pergamonweg',
2024-12-07 16:16:31 +00:00
address: 'Würzburg - Heuchelhof, Pergamonweg',
latitude: 49.736794,
longitude: 9.952209,
});
2019-09-03 15:35:12 +02:00
t.end();
});
2019-09-03 15:35:12 +02:00
2021-05-20 16:42:43 +01:00
tap.test('parses a POI correctly', (t) => {
2019-09-03 15:35:12 +02:00
const input = {
2024-12-08 21:42:57 +00:00
id: 'A=4@O=Berlin, Pergamonkeller (Gastronomie)@X=13395473@Y=52520223@U=91@L=991526508@B=1@p=1732715706@',
lat: 52.52022,
lon: 13.395473,
name: 'Berlin, Pergamonkeller (Gastronomie)',
products: [],
type: 'POI',
};
2019-09-03 15:35:12 +02:00
const poi = parse(ctx, input);
2021-05-20 16:42:43 +01:00
t.same(poi, {
2019-09-03 15:35:12 +02:00
type: 'location',
poi: true,
2024-12-07 16:16:31 +00:00
id: '991526508',
name: 'Berlin, Pergamonkeller (Gastronomie)',
latitude: 52.52022,
longitude: 13.395473,
});
t.end();
});
2019-09-03 15:35:12 +02:00
2021-05-20 16:42:43 +01:00
tap.test('parses a stop correctly', (t) => {
2024-12-07 16:16:31 +00:00
const input = {
2024-12-08 21:42:57 +00:00
extId: '8012622',
id: 'A=1@O=Perleberg@X=11852322@Y=53071252@U=81@L=8012622@B=1@p=1733173731@i=U×008027183@',
lat: 53.07068,
lon: 11.85039,
name: 'Perleberg',
products: [
'REGIONAL',
'BUS',
'ANRUFPFLICHTIG',
2024-12-07 16:16:31 +00:00
],
2024-12-08 21:42:57 +00:00
type: 'ST',
};
2024-12-07 16:16:31 +00:00
const stop = parse(ctx, input);
2021-05-20 16:42:43 +01:00
t.same(stop, {
2024-12-18 00:08:52 +00:00
type: 'station',
2024-12-07 16:16:31 +00:00
id: '8012622',
name: 'Perleberg',
2019-09-03 15:35:12 +02:00
location: {
type: 'location',
2024-12-07 16:16:31 +00:00
id: '8012622',
latitude: 53.07068,
longitude: 11.85039,
2019-09-03 15:35:12 +02:00
},
2024-12-07 16:16:31 +00:00
products: {
2024-12-08 21:42:57 +00:00
nationalExpress: false,
national: false,
regional: true,
bus: true,
taxi: true,
},
});
t.end();
});
2024-12-07 16:16:31 +00:00
tap.test('falls back to coordinates from `lid', (t) => {
const input = {
2024-12-08 21:42:57 +00:00
id: 'A=1@O=Bahnhof, Rothenburg ob der Tauber@X=10190711@Y=49377180@U=80@L=683407@',
name: 'Bahnhof, Rothenburg ob der Tauber',
bahnhofsInfoId: '5393',
extId: '683407',
adminID: 'vgn063',
kategorie: 'Bus',
nummer: '2524',
};
2024-12-07 16:16:31 +00:00
const stop = parse(ctx, input);
t.same(stop, {
2024-12-18 00:08:52 +00:00
type: 'station',
2024-12-07 16:16:31 +00:00
id: '683407',
name: 'Bahnhof, Rothenburg ob der Tauber',
location: {
type: 'location',
2024-12-07 16:16:31 +00:00
id: '683407',
latitude: 49.377180,
longitude: 10.190711,
2024-12-08 21:42:57 +00:00
},
});
t.end();
});