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

148 lines
2.9 KiB
JavaScript
Raw Normal View History

import tap from 'tap';
import omit from 'lodash/omit.js';
import {parseLocation as parse} from '../../parse/location.js';
2024-12-07 16:16:31 +00:00
import {parseBitmask as parseProductsBitmask} from '../../parse/products-bitmask.js'
2019-09-03 15:35:12 +02:00
const profile = {
parseLocation: parse,
parseStationName: (_, name) => name.toLowerCase(),
2024-12-07 16:16:31 +00:00
parseProductsBitmask,
products: [{
id: 'nationalExpress',
vendo: 'ICE',
},
{
id: 'national',
vendo: 'IC',
},
{
id: 'regional',
vendo: 'REGIONAL',
},
{
id: 'bus',
vendo: 'BUS',
},
{
id: 'taxi',
vendo: 'ANRUFPFLICHTIG',
}]
};
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-07 16:16:31 +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,
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-07 16:16:31 +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 = {
"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"
],
"type": "ST"
};
const stop = parse(ctx, input);
2021-05-20 16:42:43 +01:00
t.same(stop, {
2019-09-03 15:35:12 +02:00
type: 'stop',
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: {
"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 = {
"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, {
type: 'stop',
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,
}
});
t.end();
});