employ enrichStations for board stop property

This commit is contained in:
dabund24 2025-02-07 23:17:31 +01:00
parent 73a71e0aa2
commit e145d57f9e
3 changed files with 61 additions and 41 deletions

View file

@ -11,7 +11,7 @@ const createParseArrOrDep = (prefix) => {
const cancelled = profile.parseCancelled(d); const cancelled = profile.parseCancelled(d);
const res = { const res = {
tripId: d.journeyID || d.journeyId || d.train?.journeyId || d.zuglaufId, tripId: d.journeyID || d.journeyId || d.train?.journeyId || d.zuglaufId,
stop: profile.parseLocation(ctx, d.station || d.abfrageOrt || d.bahnhofsId), stop: profile.parseLocation(ctx, d.station || d.abfrageOrt || {bahnhofsId: d.bahnhofsId}),
...profile.parseWhen( ...profile.parseWhen(
ctx, ctx,
null, null,

View file

@ -13,14 +13,10 @@ const parseLocation = (ctx, l) => {
return null; return null;
} }
if (typeof l === 'string') {
return {type: 'station', id: l};
}
const lid = parse(l.id || l.locationId, {delimiter: '@'}); const lid = parse(l.id || l.locationId, {delimiter: '@'});
const res = { const res = {
type: 'location', type: 'location',
id: (l.extId || l.evaNr || lid.L || l.evaNumber || l.evaNo || '').replace(leadingZeros, '') || null, id: (l.extId || l.evaNr || lid.L || l.evaNumber || l.evaNo || l.bahnhofsId || '').replace(leadingZeros, '') || null,
}; };
const name = l.name || lid.O; const name = l.name || lid.O;
@ -33,12 +29,14 @@ const parseLocation = (ctx, l) => {
} }
// addresses and pois might also have fake evaNr sometimes! // addresses and pois might also have fake evaNr sometimes!
if (l.type === STATION || l.extId || l.evaNumber || l.evaNo || lid.A == '1') { if (l.type === STATION || l.extId || l.evaNumber || l.evaNo || lid.A == '1' || l.bahnhofsId) {
let stop = { let stop = {
type: 'station', type: 'station',
id: res.id, id: res.id,
name: name,
}; };
if (name) {
stop.name = name;
}
if ('number' === typeof res.latitude) { if ('number' === typeof res.latitude) {
stop.location = res; // todo: remove `.id` stop.location = res; // todo: remove `.id`
} }

View file

@ -82,7 +82,7 @@ const assertValidTickets = (test, tickets) => {
} }
}; };
const client = createClient(dbProfile, 'public-transport/hafas-client:test', {enrichStations: false}); const client = createClient(dbProfile, 'public-transport/hafas-client:test', {enrichStations: true});
const berlinHbf = '8011160'; const berlinHbf = '8011160';
const münchenHbf = '8000261'; const münchenHbf = '8000261';
@ -395,47 +395,69 @@ tap.test('trip details', async (t) => {
}); });
tap.test('departures at Berlin Schwedter Str.', async (t) => { tap.test('departures at Berlin Schwedter Str.', async (t) => {
const res = await client.departures(blnSchwedterStr, { const interval = setInterval(async () => {
duration: 5, when, const res = await client.departures(blnSchwedterStr, {
}); duration: 5, when,
});
await testDepartures({ if (res.departures[0].stop.name === undefined) { // ctx.common.locations have not loaded yet
test: t, return;
res, }
validate,
id: blnSchwedterStr, clearInterval(interval);
}); await testDepartures({
t.end(); test: t,
res,
validate,
id: blnSchwedterStr,
});
t.end();
}, 4000);
}); });
tap.test('departures with station object', async (t) => { tap.test('departures with station object', async (t) => {
const res = await client.departures({ const interval = setInterval(async () => {
type: 'station', const res = await client.departures({
id: jungfernheide, type: 'station',
name: 'Berlin Jungfernheide', id: jungfernheide,
location: { name: 'Berlin Jungfernheide',
type: 'location', location: {
latitude: 1.23, type: 'location',
longitude: 2.34, latitude: 1.23,
}, longitude: 2.34,
}, {when}); },
}, {when});
validate(t, res, 'departuresResponse', 'res'); if (res.departures[0].stop.name === undefined) { // ctx.common.locations have not loaded yet
t.end(); return;
}
clearInterval(interval);
validate(t, res, 'departuresResponse', 'res');
t.end();
}, 4000);
}); });
tap.test('arrivals at Berlin Schwedter Str.', async (t) => { tap.test('arrivals at Berlin Schwedter Str.', async (t) => {
const res = await client.arrivals(blnSchwedterStr, { const interval = setInterval(async () => {
duration: 5, when, const res = await client.arrivals(blnSchwedterStr, {
}); duration: 5, when,
});
await testArrivals({ if (res.arrivals[0].stop.name === undefined) { // ctx.common.locations have not loaded yet
test: t, return;
res, }
validate,
id: blnSchwedterStr, clearInterval(interval);
}); await testArrivals({
t.end(); test: t,
res,
validate,
id: blnSchwedterStr,
});
t.end();
}, 4000);
}); });
tap.test('nearby Berlin Jungfernheide', async (t) => { tap.test('nearby Berlin Jungfernheide', async (t) => {