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 res = {
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(
ctx,
null,

View file

@ -13,14 +13,10 @@ const parseLocation = (ctx, l) => {
return null;
}
if (typeof l === 'string') {
return {type: 'station', id: l};
}
const lid = parse(l.id || l.locationId, {delimiter: '@'});
const res = {
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;
@ -33,12 +29,14 @@ const parseLocation = (ctx, l) => {
}
// 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 = {
type: 'station',
id: res.id,
name: name,
};
if (name) {
stop.name = name;
}
if ('number' === typeof res.latitude) {
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 münchenHbf = '8000261';
@ -395,47 +395,69 @@ tap.test('trip details', async (t) => {
});
tap.test('departures at Berlin Schwedter Str.', async (t) => {
const res = await client.departures(blnSchwedterStr, {
duration: 5, when,
});
const interval = setInterval(async () => {
const res = await client.departures(blnSchwedterStr, {
duration: 5, when,
});
await testDepartures({
test: t,
res,
validate,
id: blnSchwedterStr,
});
t.end();
if (res.departures[0].stop.name === undefined) { // ctx.common.locations have not loaded yet
return;
}
clearInterval(interval);
await testDepartures({
test: t,
res,
validate,
id: blnSchwedterStr,
});
t.end();
}, 4000);
});
tap.test('departures with station object', async (t) => {
const res = await client.departures({
type: 'station',
id: jungfernheide,
name: 'Berlin Jungfernheide',
location: {
type: 'location',
latitude: 1.23,
longitude: 2.34,
},
}, {when});
const interval = setInterval(async () => {
const res = await client.departures({
type: 'station',
id: jungfernheide,
name: 'Berlin Jungfernheide',
location: {
type: 'location',
latitude: 1.23,
longitude: 2.34,
},
}, {when});
validate(t, res, 'departuresResponse', 'res');
t.end();
if (res.departures[0].stop.name === undefined) { // ctx.common.locations have not loaded yet
return;
}
clearInterval(interval);
validate(t, res, 'departuresResponse', 'res');
t.end();
}, 4000);
});
tap.test('arrivals at Berlin Schwedter Str.', async (t) => {
const res = await client.arrivals(blnSchwedterStr, {
duration: 5, when,
});
const interval = setInterval(async () => {
const res = await client.arrivals(blnSchwedterStr, {
duration: 5, when,
});
await testArrivals({
test: t,
res,
validate,
id: blnSchwedterStr,
});
t.end();
if (res.arrivals[0].stop.name === undefined) { // ctx.common.locations have not loaded yet
return;
}
clearInterval(interval);
await testArrivals({
test: t,
res,
validate,
id: blnSchwedterStr,
});
t.end();
}, 4000);
});
tap.test('nearby Berlin Jungfernheide', async (t) => {