move check for transfers set to -1 to index.js

This commit is contained in:
dabund24 2025-01-08 22:07:47 +01:00
parent ef99283e02
commit 2535bb630e
4 changed files with 5 additions and 22 deletions

View file

@ -146,6 +146,9 @@ const createClient = (profile, userAgent, opt = {}) => {
}
journeysRef = opt.laterThan;
}
if (opt?.transfers === -1) { // having `transfers` set to -1 may not be allowed, see https://github.com/public-transport/db-vendo-client/issues/5
opt.transfers = null;
}
opt = Object.assign({
results: null, // number of journeys `null` means "whatever HAFAS returns"

View file

@ -7,7 +7,7 @@ const formatJourneysReq = (ctx, from, to, when, outFrwd, journeysRef) => {
// TODO opt.accessibility
// TODO routingMode
let query = {
maxUmstiege: opt.transfers === -1 ? undefined : opt.transfers, // setting `maxUmstiege` to -1 is not allowed, see https://github.com/public-transport/db-vendo-client/issues/5
maxUmstiege: opt.transfers,
minUmstiegszeit: opt.transferTime,
deutschlandTicketVorhanden: false,
nurDeutschlandTicketVerbindungen: false,

View file

@ -46,7 +46,7 @@ const formatJourneysReq = (ctx, from, to, when, outFrwd, journeysRef) => {
? [{locationId: profile.formatLocation(profile, opt.via, 'opt.via').lid}]
: undefined,
zielLocationId: to.lid,
maxUmstiege: opt.transfers === -1 ? undefined : opt.transfers, // setting `maxUmstiege` to -1 is not allowed, see https://github.com/public-transport/db-vendo-client/issues/5
maxUmstiege: opt.transfers ?? undefined,
minUmstiegsdauer: opt.transferTime || undefined,
fahrradmitnahme: opt.bike,
},

View file

@ -114,23 +114,3 @@ tap.test('formats a journeys() request with BC correctly (DB)', (t) => {
});
t.end();
});
tap.test('formats a journeys() request with unlimited transfers (DB)', (t) => {
const _opt = {...opt};
const ctx = {profile, opt: _opt};
ctx.opt.transfers = 0; // no transfers
const reqZeroTransfers = profile.formatJourneysReq(ctx, '8098160', '8000284', new Date('2024-12-07T23:50:12+01:00'), true, null);
t.same(reqZeroTransfers.body.maxUmstiege, 0);
ctx.opt.transfers = null; // unconstrained transfers implicit
const reqUnlimitedTransfersImplicit = profile.formatJourneysReq(ctx, '8098160', '8000284', new Date('2024-12-07T23:50:12+01:00'), true, null);
t.same(reqUnlimitedTransfersImplicit.body.maxUmstiege, undefined);
ctx.opt.transfers = -1; // unconstrained transfers explicit
const reqUnlimitedTransfersExplicit = profile.formatJourneysReq(ctx, '8098160', '8000284', new Date('2024-12-07T23:50:12+01:00'), true, null);
t.same(reqUnlimitedTransfersExplicit.body.maxUmstiege, undefined);
t.end();
});