mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-06-07 04:42:34 +03:00
move check for transfers set to -1 to index.js
This commit is contained in:
parent
ef99283e02
commit
2535bb630e
4 changed files with 5 additions and 22 deletions
3
index.js
3
index.js
|
@ -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"
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
|
|
|
@ -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();
|
||||
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue