use promises in dbweb e2e tests when waiting for enrichStations to work

This commit is contained in:
dabund24 2025-02-08 00:39:26 +01:00
parent c285339cd9
commit a985f7423e

View file

@ -395,72 +395,74 @@ tap.test('trip details', async (t) => {
}); });
tap.test('departures at Berlin Schwedter Str.', async (t) => { tap.test('departures at Berlin Schwedter Str.', async (t) => {
let interval = setInterval(async () => { const res = await new Promise((resolve) => {
const res = await client.departures(blnSchwedterStr, { let interval = setInterval(async () => { // repeat evaluating `departures()` until stations are enriched
duration: 5, when, const res = await client.departures(blnSchwedterStr, {
}); duration: 5, when,
});
if (res.departures[0].stop.name === undefined || interval === undefined) { // ctx.common.locations have not loaded yet if (res.departures[0].stop.name !== undefined) { // ctx.common.locations have loaded
return; clearInterval(interval);
} return resolve(res);
}
}, 4000);
});
clearInterval(interval); await testDepartures({
interval = undefined; test: t,
await testDepartures({ res,
test: t, validate,
res, id: blnSchwedterStr,
validate, });
id: blnSchwedterStr, t.end();
});
t.end();
}, 4000);
}); });
tap.test('departures with station object', async (t) => { tap.test('departures with station object', async (t) => {
let interval = setInterval(async () => { const res = await new Promise((resolve) => {
const res = await client.departures({ let interval = setInterval(async () => { // repeat evaluating `departures()` until stations are enriched
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});
if (res.departures[0].stop.name === undefined || interval === undefined) { // ctx.common.locations have not loaded yet if (res.departures[0].stop.name !== undefined) { // ctx.common.locations have loaded
return; clearInterval(interval);
} return resolve(res);
}
}, 4000);
});
clearInterval(interval); validate(t, res, 'departuresResponse', 'res');
interval = undefined; t.end();
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) => {
let interval = setInterval(async () => { const res = await new Promise((resolve) => {
const res = await client.arrivals(blnSchwedterStr, { let interval = setInterval(async () => { // repeat evaluating `arrivals()` until stations are enriched
duration: 5, when, const res = await client.arrivals(blnSchwedterStr, {
}); duration: 5, when,
});
if (res.arrivals[0].stop.name === undefined || interval === undefined) { // ctx.common.locations have not loaded yet if (res.arrivals[0].stop.name !== undefined) { // ctx.common.locations have loaded
return; clearInterval(interval);
} return resolve(res);
}
}, 4000);
});
clearInterval(interval); await testArrivals({
interval = undefined; test: t,
await testArrivals({ res,
test: t, validate,
res, id: blnSchwedterStr,
validate, });
id: blnSchwedterStr, t.end();
});
t.end();
}, 4000);
}); });
tap.test('nearby Berlin Jungfernheide', async (t) => { tap.test('nearby Berlin Jungfernheide', async (t) => {