mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-06-19 10:42:33 +03:00
Compare commits
2 commits
6c2081c14e
...
b3e0e764e2
Author | SHA1 | Date | |
---|---|---|---|
|
b3e0e764e2 | ||
|
2ea47f7792 |
6 changed files with 268 additions and 263 deletions
19
index.js
19
index.js
|
@ -27,25 +27,18 @@ const validateLocation = (loc, name = 'location') => {
|
|||
}
|
||||
};
|
||||
|
||||
const loadEnrichedStationData = (profile) => new Promise((resolve, reject) => {
|
||||
import('db-hafas-stations').then(m => {
|
||||
const loadEnrichedStationData = async (profile) => {
|
||||
const dbHafasStations = await import('db-hafas-stations');
|
||||
const items = {};
|
||||
m.default.full()
|
||||
.on('data', (station) => {
|
||||
for await (const station of dbHafasStations.readFullStations()) {
|
||||
items[station.id] = station;
|
||||
items[station.name] = station;
|
||||
})
|
||||
.once('end', () => {
|
||||
}
|
||||
if (profile.DEBUG) {
|
||||
console.log('Loaded station index.');
|
||||
}
|
||||
resolve(items);
|
||||
})
|
||||
.once('error', (err) => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
return items;
|
||||
};
|
||||
|
||||
const applyEnrichedStationData = async (ctx, shouldLoadEnrichedStationData) => {
|
||||
const {profile, common} = ctx;
|
||||
|
|
17
package-lock.json
generated
17
package-lock.json
generated
|
@ -1,17 +1,17 @@
|
|||
{
|
||||
"name": "db-vendo-client",
|
||||
"version": "6.6.2",
|
||||
"version": "6.7.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "db-vendo-client",
|
||||
"version": "6.6.2",
|
||||
"version": "6.7.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"content-type": "^1.0.5",
|
||||
"cross-fetch": "^4.1.0",
|
||||
"db-hafas-stations": "^1.1.0",
|
||||
"db-hafas-stations": "2.0.0",
|
||||
"gps-distance": "0.0.4",
|
||||
"https-proxy-agent": "^7.0.6",
|
||||
"luxon": "^3.5.0",
|
||||
|
@ -3447,14 +3447,15 @@
|
|||
}
|
||||
},
|
||||
"node_modules/db-hafas-stations": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/db-hafas-stations/-/db-hafas-stations-1.1.0.tgz",
|
||||
"integrity": "sha512-o6NhX3YExhdxd8IA1cfWf1px5nJTym/2hXcnnINgXjSCBmD4ujv/pCUcXZcj8ucozhk5koR2SBgdKhWJpM39pw==",
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/db-hafas-stations/-/db-hafas-stations-2.0.0.tgz",
|
||||
"integrity": "sha512-GjcqpZhs+HeOvc2dnAJs2Uy3/b8zRNlvTfLCvqFe9J2JYOlQVyuYCjjdsPBTOmJol42sPToPs71wr03kTMVJDw==",
|
||||
"dependencies": {
|
||||
"ndjson": "^2.0.0"
|
||||
"ndjson": "^2.0.0",
|
||||
"qs": "^6.14.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/db-rest": {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "db-vendo-client",
|
||||
"description": "Client for bahn.de public transport APIs.",
|
||||
"version": "6.6.2",
|
||||
"version": "6.7.0",
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
"files": [
|
||||
|
@ -60,7 +60,7 @@
|
|||
"dependencies": {
|
||||
"content-type": "^1.0.5",
|
||||
"cross-fetch": "^4.1.0",
|
||||
"db-hafas-stations": "^1.1.0",
|
||||
"db-hafas-stations": "2.0.0",
|
||||
"gps-distance": "0.0.4",
|
||||
"https-proxy-agent": "^7.0.6",
|
||||
"luxon": "^3.5.0",
|
||||
|
|
|
@ -78,6 +78,14 @@ const enrichStation = (ctx, stop, locations) => {
|
|||
...stop,
|
||||
};
|
||||
delete stop.lines;
|
||||
delete stop.facilities;
|
||||
delete stop.reisezentrumOpeningHours;
|
||||
if (stop.station) {
|
||||
stop.station = {...stop.station};
|
||||
delete stop.station.lines;
|
||||
delete stop.station.facilities;
|
||||
delete stop.station.reisezentrumOpeningHours;
|
||||
}
|
||||
}
|
||||
return stop;
|
||||
};
|
||||
|
|
|
@ -99,7 +99,8 @@ const potsdamHbf = '8012666';
|
|||
const berlinSüdkreuz = '8011113';
|
||||
const kölnHbf = '8000207';
|
||||
|
||||
tap.test('journeys – Berlin Schwedter Str. to München Hbf', async (t) => {
|
||||
if (!process.env.VCR_OFF) {
|
||||
tap.test('journeys – Berlin Schwedter Str. to München Hbf', async (t) => {
|
||||
const res = await client.journeys(blnSchwedterStr, münchenHbf, {
|
||||
results: 4,
|
||||
departure: when,
|
||||
|
@ -123,9 +124,9 @@ tap.test('journeys – Berlin Schwedter Str. to München Hbf', async (t) => {
|
|||
}
|
||||
}
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('refreshJourney – valid tickets', async (t) => {
|
||||
tap.test('refreshJourney – valid tickets', async (t) => {
|
||||
const T_MOCK = 1710831600 * 1000; // 2024-03-19T08:00:00+01:00
|
||||
const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK);
|
||||
|
||||
|
@ -147,11 +148,11 @@ tap.test('refreshJourney – valid tickets', async (t) => {
|
|||
}
|
||||
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
// todo: journeys, only one product
|
||||
// todo: journeys, only one product
|
||||
|
||||
tap.test('journeys – fails with no product', async (t) => {
|
||||
tap.test('journeys – fails with no product', async (t) => {
|
||||
await journeysFailsWithNoProduct({
|
||||
test: t,
|
||||
fetchJourneys: client.journeys,
|
||||
|
@ -161,9 +162,9 @@ tap.test('journeys – fails with no product', async (t) => {
|
|||
products: dbProfile.products,
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('Berlin Schwedter Str. to Torfstraße 17', async (t) => {
|
||||
tap.test('Berlin Schwedter Str. to Torfstraße 17', async (t) => {
|
||||
const torfstr = {
|
||||
type: 'location',
|
||||
address: 'Torfstraße 17',
|
||||
|
@ -183,9 +184,9 @@ tap.test('Berlin Schwedter Str. to Torfstraße 17', async (t) => {
|
|||
to: torfstr,
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => {
|
||||
tap.test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => {
|
||||
const atze = {
|
||||
type: 'location',
|
||||
id: '991598902',
|
||||
|
@ -207,9 +208,9 @@ tap.test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => {
|
|||
to: atze,
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('journeys: via works – with detour', async (t) => {
|
||||
tap.test('journeys: via works – with detour', async (t) => {
|
||||
// Going from Westhafen to Wedding via Württembergallee without detour
|
||||
// is currently impossible. We check if the routing engine computes a detour.
|
||||
const res = await client.journeys(westhafen, wedding, {
|
||||
|
@ -226,11 +227,11 @@ tap.test('journeys: via works – with detour', async (t) => {
|
|||
detourIds: [württembergallee],
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
// todo: walkingSpeed "Berlin - Charlottenburg, Hallerstraße" -> jungfernheide
|
||||
// todo: without detour
|
||||
});
|
||||
|
||||
// todo: walkingSpeed "Berlin - Charlottenburg, Hallerstraße" -> jungfernheide
|
||||
// todo: without detour
|
||||
}
|
||||
|
||||
// todo: with the DB endpoint, earlierRef/laterRef is missing queries many days in the future
|
||||
tap.skip('earlier/later journeys, Jungfernheide -> München Hbf', async (t) => {
|
||||
|
|
|
@ -151,7 +151,8 @@ tap.test('refreshJourney – valid tickets', async (t) => {
|
|||
|
||||
// todo: journeys, only one product
|
||||
|
||||
tap.test('journeys – fails with no product', async (t) => {
|
||||
if (!process.env.VCR_OFF) {
|
||||
tap.test('journeys – fails with no product', async (t) => {
|
||||
await journeysFailsWithNoProduct({
|
||||
test: t,
|
||||
fetchJourneys: client.journeys,
|
||||
|
@ -161,9 +162,9 @@ tap.test('journeys – fails with no product', async (t) => {
|
|||
products: dbProfile.products,
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('Berlin Schwedter Str. to Torfstraße 17', async (t) => {
|
||||
tap.test('Berlin Schwedter Str. to Torfstraße 17', async (t) => {
|
||||
const torfstr = {
|
||||
type: 'location',
|
||||
address: 'Torfstraße 17',
|
||||
|
@ -183,9 +184,9 @@ tap.test('Berlin Schwedter Str. to Torfstraße 17', async (t) => {
|
|||
to: torfstr,
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => {
|
||||
tap.test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => {
|
||||
const atze = {
|
||||
type: 'location',
|
||||
id: '991598902',
|
||||
|
@ -207,9 +208,9 @@ tap.test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => {
|
|||
to: atze,
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('journeys: via works – with detour', async (t) => {
|
||||
tap.test('journeys: via works – with detour', async (t) => {
|
||||
// Going from Westhafen to Wedding via Württembergallee without detour
|
||||
// is currently impossible. We check if the routing engine computes a detour.
|
||||
const res = await client.journeys(westhafen, wedding, {
|
||||
|
@ -226,14 +227,14 @@ tap.test('journeys: via works – with detour', async (t) => {
|
|||
detourIds: [württembergallee],
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
// todo: walkingSpeed "Berlin - Charlottenburg, Hallerstraße" -> jungfernheide
|
||||
// todo: without detour
|
||||
// todo: walkingSpeed "Berlin - Charlottenburg, Hallerstraße" -> jungfernheide
|
||||
// todo: without detour
|
||||
|
||||
|
||||
// todo: with the DB endpoint, earlierRef/laterRef is missing queries many days in the future
|
||||
tap.skip('earlier/later journeys, Jungfernheide -> München Hbf', async (t) => {
|
||||
// todo: with the DB endpoint, earlierRef/laterRef is missing queries many days in the future
|
||||
tap.skip('earlier/later journeys, Jungfernheide -> München Hbf', async (t) => {
|
||||
await testEarlierLaterJourneys({
|
||||
test: t,
|
||||
fetchJourneys: client.journeys,
|
||||
|
@ -244,9 +245,9 @@ tap.skip('earlier/later journeys, Jungfernheide -> München Hbf', async (t) => {
|
|||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
if (!process.env.VCR_MODE) {
|
||||
if (!process.env.VCR_MODE) {
|
||||
tap.test('journeys – leg cycle & alternatives', async (t) => {
|
||||
await testLegCycleAlternatives({
|
||||
test: t,
|
||||
|
@ -257,9 +258,9 @@ if (!process.env.VCR_MODE) {
|
|||
});
|
||||
t.end();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
tap.test('refreshJourney', async (t) => {
|
||||
tap.test('refreshJourney', async (t) => {
|
||||
const T_MOCK = 1710831600 * 1000; // 2024-03-19T08:00:00+01:00
|
||||
const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK);
|
||||
const validate = createValidate({...cfg, when});
|
||||
|
@ -274,7 +275,8 @@ tap.test('refreshJourney', async (t) => {
|
|||
when,
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
tap.skip('journeysFromTrip – U Mehringdamm to U Naturkundemuseum, reroute to Spittelmarkt.', async (t) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue