mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-04-20 23:23:56 +03:00
employ enrichStations for board stop property
This commit is contained in:
parent
73a71e0aa2
commit
e145d57f9e
3 changed files with 61 additions and 41 deletions
|
@ -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,
|
||||
|
|
|
@ -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`
|
||||
}
|
||||
|
|
|
@ -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,10 +395,16 @@ tap.test('trip details', async (t) => {
|
|||
});
|
||||
|
||||
tap.test('departures at Berlin Schwedter Str.', async (t) => {
|
||||
const interval = setInterval(async () => {
|
||||
const res = await client.departures(blnSchwedterStr, {
|
||||
duration: 5, when,
|
||||
});
|
||||
|
||||
if (res.departures[0].stop.name === undefined) { // ctx.common.locations have not loaded yet
|
||||
return;
|
||||
}
|
||||
|
||||
clearInterval(interval);
|
||||
await testDepartures({
|
||||
test: t,
|
||||
res,
|
||||
|
@ -406,9 +412,11 @@ tap.test('departures at Berlin Schwedter Str.', async (t) => {
|
|||
id: blnSchwedterStr,
|
||||
});
|
||||
t.end();
|
||||
}, 4000);
|
||||
});
|
||||
|
||||
tap.test('departures with station object', async (t) => {
|
||||
const interval = setInterval(async () => {
|
||||
const res = await client.departures({
|
||||
type: 'station',
|
||||
id: jungfernheide,
|
||||
|
@ -420,15 +428,28 @@ tap.test('departures with station object', async (t) => {
|
|||
},
|
||||
}, {when});
|
||||
|
||||
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 interval = setInterval(async () => {
|
||||
const res = await client.arrivals(blnSchwedterStr, {
|
||||
duration: 5, when,
|
||||
});
|
||||
|
||||
if (res.arrivals[0].stop.name === undefined) { // ctx.common.locations have not loaded yet
|
||||
return;
|
||||
}
|
||||
|
||||
clearInterval(interval);
|
||||
await testArrivals({
|
||||
test: t,
|
||||
res,
|
||||
|
@ -436,6 +457,7 @@ tap.test('arrivals at Berlin Schwedter Str.', async (t) => {
|
|||
id: blnSchwedterStr,
|
||||
});
|
||||
t.end();
|
||||
}, 4000);
|
||||
});
|
||||
|
||||
tap.test('nearby Berlin Jungfernheide', async (t) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue