Compare commits

...

2 commits

Author SHA1 Message Date
Traines
b3e0e764e2 update db-hafas-stations
Some checks failed
test / lint-and-spellcheck (push) Has been cancelled
test / unit-tests (18.x) (push) Has been cancelled
test / unit-tests (20.x) (push) Has been cancelled
test / unit-tests (22.x) (push) Has been cancelled
test / integration-tests (18.x) (push) Has been cancelled
test / integration-tests (20.x) (push) Has been cancelled
test / integration-tests (22.x) (push) Has been cancelled
test / e2e-tests (18.x) (push) Has been cancelled
2025-03-19 00:39:01 +00:00
Traines
2ea47f7792 disable some more live e2e tests 2025-03-19 00:38:48 +00:00
6 changed files with 268 additions and 263 deletions

View file

@ -27,25 +27,18 @@ const validateLocation = (loc, name = 'location') => {
} }
}; };
const loadEnrichedStationData = (profile) => new Promise((resolve, reject) => { const loadEnrichedStationData = async (profile) => {
import('db-hafas-stations').then(m => { const dbHafasStations = await import('db-hafas-stations');
const items = {}; const items = {};
m.default.full() for await (const station of dbHafasStations.readFullStations()) {
.on('data', (station) => { items[station.id] = station;
items[station.id] = station; items[station.name] = station;
items[station.name] = station; }
}) if (profile.DEBUG) {
.once('end', () => { console.log('Loaded station index.');
if (profile.DEBUG) { }
console.log('Loaded station index.'); return items;
} };
resolve(items);
})
.once('error', (err) => {
reject(err);
});
});
});
const applyEnrichedStationData = async (ctx, shouldLoadEnrichedStationData) => { const applyEnrichedStationData = async (ctx, shouldLoadEnrichedStationData) => {
const {profile, common} = ctx; const {profile, common} = ctx;

17
package-lock.json generated
View file

@ -1,17 +1,17 @@
{ {
"name": "db-vendo-client", "name": "db-vendo-client",
"version": "6.6.2", "version": "6.7.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "db-vendo-client", "name": "db-vendo-client",
"version": "6.6.2", "version": "6.7.0",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"content-type": "^1.0.5", "content-type": "^1.0.5",
"cross-fetch": "^4.1.0", "cross-fetch": "^4.1.0",
"db-hafas-stations": "^1.1.0", "db-hafas-stations": "2.0.0",
"gps-distance": "0.0.4", "gps-distance": "0.0.4",
"https-proxy-agent": "^7.0.6", "https-proxy-agent": "^7.0.6",
"luxon": "^3.5.0", "luxon": "^3.5.0",
@ -3447,14 +3447,15 @@
} }
}, },
"node_modules/db-hafas-stations": { "node_modules/db-hafas-stations": {
"version": "1.1.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/db-hafas-stations/-/db-hafas-stations-1.1.0.tgz", "resolved": "https://registry.npmjs.org/db-hafas-stations/-/db-hafas-stations-2.0.0.tgz",
"integrity": "sha512-o6NhX3YExhdxd8IA1cfWf1px5nJTym/2hXcnnINgXjSCBmD4ujv/pCUcXZcj8ucozhk5koR2SBgdKhWJpM39pw==", "integrity": "sha512-GjcqpZhs+HeOvc2dnAJs2Uy3/b8zRNlvTfLCvqFe9J2JYOlQVyuYCjjdsPBTOmJol42sPToPs71wr03kTMVJDw==",
"dependencies": { "dependencies": {
"ndjson": "^2.0.0" "ndjson": "^2.0.0",
"qs": "^6.14.0"
}, },
"engines": { "engines": {
"node": ">=14" "node": ">=18"
} }
}, },
"node_modules/db-rest": { "node_modules/db-rest": {

View file

@ -1,7 +1,7 @@
{ {
"name": "db-vendo-client", "name": "db-vendo-client",
"description": "Client for bahn.de public transport APIs.", "description": "Client for bahn.de public transport APIs.",
"version": "6.6.2", "version": "6.7.0",
"type": "module", "type": "module",
"main": "index.js", "main": "index.js",
"files": [ "files": [
@ -60,7 +60,7 @@
"dependencies": { "dependencies": {
"content-type": "^1.0.5", "content-type": "^1.0.5",
"cross-fetch": "^4.1.0", "cross-fetch": "^4.1.0",
"db-hafas-stations": "^1.1.0", "db-hafas-stations": "2.0.0",
"gps-distance": "0.0.4", "gps-distance": "0.0.4",
"https-proxy-agent": "^7.0.6", "https-proxy-agent": "^7.0.6",
"luxon": "^3.5.0", "luxon": "^3.5.0",

View file

@ -78,6 +78,14 @@ const enrichStation = (ctx, stop, locations) => {
...stop, ...stop,
}; };
delete stop.lines; 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; return stop;
}; };

View file

@ -99,138 +99,139 @@ const potsdamHbf = '8012666';
const berlinSüdkreuz = '8011113'; const berlinSüdkreuz = '8011113';
const kölnHbf = '8000207'; const kölnHbf = '8000207';
tap.test('journeys  Berlin Schwedter Str. to München Hbf', async (t) => { if (!process.env.VCR_OFF) {
const res = await client.journeys(blnSchwedterStr, münchenHbf, { tap.test('journeys  Berlin Schwedter Str. to München Hbf', async (t) => {
results: 4, const res = await client.journeys(blnSchwedterStr, münchenHbf, {
departure: when, results: 4,
stopovers: true, departure: when,
}); stopovers: true,
});
await testJourneysStationToStation({ await testJourneysStationToStation({
test: t, test: t,
res, res,
validate, validate,
fromId: blnSchwedterStr, fromId: blnSchwedterStr,
toId: münchenHbf, toId: münchenHbf,
}); });
// todo: find a journey where there pricing info is always available // todo: find a journey where there pricing info is always available
for (let journey of res.journeys) { for (let journey of res.journeys) {
if (journey.price) { if (journey.price) {
assertValidPrice(t, journey.price); assertValidPrice(t, journey.price);
}
if (journey.tickets) {
assertValidTickets(t, journey.tickets);
}
} }
if (journey.tickets) { t.end();
assertValidTickets(t, journey.tickets); });
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);
const journeysRes = await client.journeys(berlinHbf, münchenHbf, {
results: 4,
departure: when,
stopovers: true,
});
const refreshWithoutTicketsRes = await client.refreshJourney(journeysRes.journeys[0].refreshToken, {
tickets: false,
});
const refreshWithTicketsRes = await client.refreshJourney(journeysRes.journeys[0].refreshToken, {
tickets: true,
});
for (let res of [refreshWithoutTicketsRes, refreshWithTicketsRes]) {
if (res.journey.tickets !== undefined) {
assertValidTickets(t, res.journey.tickets);
}
} }
}
t.end();
});
tap.test('refreshJourney valid tickets', async (t) => { t.end();
const T_MOCK = 1710831600 * 1000; // 2024-03-19T08:00:00+01:00
const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK);
const journeysRes = await client.journeys(berlinHbf, münchenHbf, {
results: 4,
departure: when,
stopovers: true,
});
const refreshWithoutTicketsRes = await client.refreshJourney(journeysRes.journeys[0].refreshToken, {
tickets: false,
});
const refreshWithTicketsRes = await client.refreshJourney(journeysRes.journeys[0].refreshToken, {
tickets: true,
});
for (let res of [refreshWithoutTicketsRes, refreshWithTicketsRes]) {
if (res.journey.tickets !== undefined) {
assertValidTickets(t, res.journey.tickets);
}
}
t.end();
});
// todo: journeys, only one product
tap.test('journeys fails with no product', async (t) => {
await journeysFailsWithNoProduct({
test: t,
fetchJourneys: client.journeys,
fromId: blnSchwedterStr,
toId: münchenHbf,
when,
products: dbProfile.products,
});
t.end();
});
tap.test('Berlin Schwedter Str. to Torfstraße 17', async (t) => {
const torfstr = {
type: 'location',
address: 'Torfstraße 17',
latitude: 52.5416823,
longitude: 13.3491223,
};
const res = await client.journeys(blnSchwedterStr, torfstr, {
results: 3,
departure: when,
}); });
await testJourneysStationToAddress({ // todo: journeys, only one product
test: t,
res,
validate,
fromId: blnSchwedterStr,
to: torfstr,
});
t.end();
});
tap.test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => { tap.test('journeys fails with no product', async (t) => {
const atze = { await journeysFailsWithNoProduct({
type: 'location', test: t,
id: '991598902', fetchJourneys: client.journeys,
poi: true, fromId: blnSchwedterStr,
name: 'Berlin, Atze Musiktheater für Kinder (Kultur und U', toId: münchenHbf,
latitude: 52.542417, when,
longitude: 13.350437, products: dbProfile.products,
}; });
const res = await client.journeys(blnSchwedterStr, atze, { t.end();
results: 3,
departure: when,
}); });
await testJourneysStationToPoi({ tap.test('Berlin Schwedter Str. to Torfstraße 17', async (t) => {
test: t, const torfstr = {
res, type: 'location',
validate, address: 'Torfstraße 17',
fromId: blnSchwedterStr, latitude: 52.5416823,
to: atze, longitude: 13.3491223,
}); };
t.end(); const res = await client.journeys(blnSchwedterStr, torfstr, {
}); results: 3,
departure: when,
});
tap.test('journeys: via works with detour', async (t) => { await testJourneysStationToAddress({
// Going from Westhafen to Wedding via Württembergallee without detour test: t,
// is currently impossible. We check if the routing engine computes a detour. res,
const res = await client.journeys(westhafen, wedding, { validate,
via: württembergallee, fromId: blnSchwedterStr,
results: 1, to: torfstr,
departure: when, });
stopovers: true, t.end();
}); });
await testJourneysWithDetour({ tap.test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => {
test: t, const atze = {
res, type: 'location',
validate, id: '991598902',
detourIds: [württembergallee], poi: true,
name: 'Berlin, Atze Musiktheater für Kinder (Kultur und U',
latitude: 52.542417,
longitude: 13.350437,
};
const res = await client.journeys(blnSchwedterStr, atze, {
results: 3,
departure: when,
});
await testJourneysStationToPoi({
test: t,
res,
validate,
fromId: blnSchwedterStr,
to: atze,
});
t.end();
}); });
t.end();
});
// todo: walkingSpeed "Berlin - Charlottenburg, Hallerstraße" -> jungfernheide tap.test('journeys: via works with detour', async (t) => {
// todo: without detour // 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, {
via: württembergallee,
results: 1,
departure: when,
stopovers: true,
});
await testJourneysWithDetour({
test: t,
res,
validate,
detourIds: [württembergallee],
});
t.end();
});
// 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 // 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) => { tap.skip('earlier/later journeys, Jungfernheide -> München Hbf', async (t) => {

View file

@ -151,131 +151,133 @@ tap.test('refreshJourney valid tickets', async (t) => {
// todo: journeys, only one product // todo: journeys, only one product
tap.test('journeys fails with no product', async (t) => { if (!process.env.VCR_OFF) {
await journeysFailsWithNoProduct({ tap.test('journeys fails with no product', async (t) => {
test: t, await journeysFailsWithNoProduct({
fetchJourneys: client.journeys,
fromId: blnSchwedterStr,
toId: münchenHbf,
when,
products: dbProfile.products,
});
t.end();
});
tap.test('Berlin Schwedter Str. to Torfstraße 17', async (t) => {
const torfstr = {
type: 'location',
address: 'Torfstraße 17',
latitude: 52.5416823,
longitude: 13.3491223,
};
const res = await client.journeys(blnSchwedterStr, torfstr, {
results: 3,
departure: when,
});
await testJourneysStationToAddress({
test: t,
res,
validate,
fromId: blnSchwedterStr,
to: torfstr,
});
t.end();
});
tap.test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => {
const atze = {
type: 'location',
id: '991598902',
poi: true,
name: 'Berlin, Atze Musiktheater für Kinder (Kultur und U',
latitude: 52.542417,
longitude: 13.350437,
};
const res = await client.journeys(blnSchwedterStr, atze, {
results: 3,
departure: when,
});
await testJourneysStationToPoi({
test: t,
res,
validate,
fromId: blnSchwedterStr,
to: atze,
});
t.end();
});
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, {
via: württembergallee,
results: 1,
departure: when,
stopovers: true,
});
await testJourneysWithDetour({
test: t,
res,
validate,
detourIds: [württembergallee],
});
t.end();
});
// 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) => {
await testEarlierLaterJourneys({
test: t,
fetchJourneys: client.journeys,
validate,
fromId: jungfernheide,
toId: münchenHbf,
when,
});
t.end();
});
if (!process.env.VCR_MODE) {
tap.test('journeys leg cycle & alternatives', async (t) => {
await testLegCycleAlternatives({
test: t, test: t,
fetchJourneys: client.journeys, fetchJourneys: client.journeys,
fromId: blnTiergarten, fromId: blnSchwedterStr,
toId: blnJannowitzbrücke, toId: münchenHbf,
when,
products: dbProfile.products,
});
t.end();
});
tap.test('Berlin Schwedter Str. to Torfstraße 17', async (t) => {
const torfstr = {
type: 'location',
address: 'Torfstraße 17',
latitude: 52.5416823,
longitude: 13.3491223,
};
const res = await client.journeys(blnSchwedterStr, torfstr, {
results: 3,
departure: when,
});
await testJourneysStationToAddress({
test: t,
res,
validate,
fromId: blnSchwedterStr,
to: torfstr,
});
t.end();
});
tap.test('Berlin Schwedter Str. to ATZE Musiktheater', async (t) => {
const atze = {
type: 'location',
id: '991598902',
poi: true,
name: 'Berlin, Atze Musiktheater für Kinder (Kultur und U',
latitude: 52.542417,
longitude: 13.350437,
};
const res = await client.journeys(blnSchwedterStr, atze, {
results: 3,
departure: when,
});
await testJourneysStationToPoi({
test: t,
res,
validate,
fromId: blnSchwedterStr,
to: atze,
});
t.end();
});
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, {
via: württembergallee,
results: 1,
departure: when,
stopovers: true,
});
await testJourneysWithDetour({
test: t,
res,
validate,
detourIds: [württembergallee],
});
t.end();
});
// 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) => {
await testEarlierLaterJourneys({
test: t,
fetchJourneys: client.journeys,
validate,
fromId: jungfernheide,
toId: münchenHbf,
when,
});
t.end();
});
if (!process.env.VCR_MODE) {
tap.test('journeys leg cycle & alternatives', async (t) => {
await testLegCycleAlternatives({
test: t,
fetchJourneys: client.journeys,
fromId: blnTiergarten,
toId: blnJannowitzbrücke,
when,
});
t.end();
});
}
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});
await testRefreshJourney({
test: t,
fetchJourneys: client.journeys,
refreshJourney: client.refreshJourney,
validate,
fromId: jungfernheide,
toId: münchenHbf,
when, when,
}); });
t.end(); t.end();
}); });
} }
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});
await testRefreshJourney({
test: t,
fetchJourneys: client.journeys,
refreshJourney: client.refreshJourney,
validate,
fromId: jungfernheide,
toId: münchenHbf,
when,
});
t.end();
});
/* /*
tap.skip('journeysFromTrip U Mehringdamm to U Naturkundemuseum, reroute to Spittelmarkt.', async (t) => { tap.skip('journeysFromTrip U Mehringdamm to U Naturkundemuseum, reroute to Spittelmarkt.', async (t) => {
const blnMehringdamm = '730939'; const blnMehringdamm = '730939';