mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-04-20 23:23:56 +03:00
dticket support
This commit is contained in:
parent
c4d0a55d41
commit
ad09f8b1be
11 changed files with 2374 additions and 10 deletions
|
@ -627,7 +627,8 @@
|
|||
"Intervalle",
|
||||
"tagesbest",
|
||||
"dbbahnhof",
|
||||
"cancelation"
|
||||
"Deutschlandticket",
|
||||
"fahrverguenstigungen"
|
||||
],
|
||||
"ignorePaths": [
|
||||
"docs/dumps/**",
|
||||
|
|
4
index.js
4
index.js
|
@ -181,6 +181,8 @@ const createClient = (profile, userAgent, opt = {}) => {
|
|||
scheduledDays: false, // parse & expose dates each journey is valid on?
|
||||
notOnlyFastRoutes: false, // if true, also show routes that are mathematically non-optimal
|
||||
bestprice: false, // search for lowest prices across the entire day
|
||||
deutschlandTicketDiscount: false,
|
||||
deutschlandTicketConnectionsOnly: false,
|
||||
}, opt);
|
||||
|
||||
if (opt.when !== undefined) {
|
||||
|
@ -239,6 +241,8 @@ const createClient = (profile, userAgent, opt = {}) => {
|
|||
entrances: true, // parse & expose entrances of stops/stations?
|
||||
remarks: true, // parse & expose hints & warnings?
|
||||
scheduledDays: false, // parse & expose dates the journey is valid on?
|
||||
deutschlandTicketDiscount: false,
|
||||
deutschlandTicketConnectionsOnly: false,
|
||||
}, opt);
|
||||
|
||||
const req = profile.formatRefreshJourneyReq({profile, opt}, refreshToken);
|
||||
|
|
|
@ -76,6 +76,18 @@ const mapRouteParsers = (route, parsers) => {
|
|||
default: false,
|
||||
parse: parseBoolean,
|
||||
},
|
||||
deutschlandTicketDiscount: {
|
||||
description: 'Calculate ticket prices assuming Deutschlandticket is present',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
parse: parseBoolean,
|
||||
},
|
||||
deutschlandTicketConnectionsOnly: {
|
||||
description: 'Only return journeys that can be used with the Deutschlandticket',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
parse: parseBoolean,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (route.includes('departures') || route.includes('arrivals')) {
|
||||
|
|
|
@ -105,7 +105,6 @@ const request = async (ctx, userAgent, reqData) => {
|
|||
if (reqOptions.query) {
|
||||
url += '?' + stringify(reqOptions.query, {arrayFormat: 'brackets', encodeValuesOnly: true});
|
||||
}
|
||||
console.log(url);
|
||||
const reqId = randomBytesHexString(6);
|
||||
const fetchReq = new Request(url, reqOptions);
|
||||
profile.logRequest(ctx, fetchReq, reqId);
|
||||
|
@ -122,6 +121,7 @@ const request = async (ctx, userAgent, reqData) => {
|
|||
|
||||
if (!res.ok) {
|
||||
// todo [breaking]: make this a FetchError or a HafasClientError?
|
||||
console.log(JSON.stringify(res), await res.text());
|
||||
const err = new Error(res.statusText);
|
||||
Object.assign(err, errProps);
|
||||
throw err;
|
||||
|
|
|
@ -9,6 +9,10 @@ const formatBaseJourneysReq = (ctx) => {
|
|||
einstiegsTypList: [
|
||||
'STANDARD',
|
||||
],
|
||||
fahrverguenstigungen: {
|
||||
deutschlandTicketVorhanden: ctx.opt.deutschlandTicketDiscount,
|
||||
nurDeutschlandTicketVerbindungen: ctx.opt.deutschlandTicketConnectionsOnly,
|
||||
},
|
||||
klasse: travellers.klasse,
|
||||
reisendenProfil: {
|
||||
reisende: travellers.reisende.map(t => {
|
||||
|
|
|
@ -10,8 +10,8 @@ const formatJourneysReq = (ctx, from, to, when, outFrwd, journeysRef) => {
|
|||
let query = {
|
||||
maxUmstiege: transfers,
|
||||
minUmstiegszeit: opt.transferTime,
|
||||
deutschlandTicketVorhanden: false,
|
||||
nurDeutschlandTicketVerbindungen: false,
|
||||
deutschlandTicketVorhanden: opt.deutschlandTicketDiscount,
|
||||
nurDeutschlandTicketVerbindungen: opt.deutschlandTicketConnectionsOnly,
|
||||
reservierungsKontingenteVorhanden: false,
|
||||
schnelleVerbindungen: !opt.notOnlyFastRoutes,
|
||||
sitzplatzOnly: false,
|
||||
|
|
|
@ -127,7 +127,7 @@ if (!process.env.VCR_OFF) {
|
|||
});
|
||||
|
||||
tap.test('refreshJourney – valid tickets', async (t) => {
|
||||
const T_MOCK = 1710831600 * 1000; // 2024-03-19T08:00:00+01:00
|
||||
const T_MOCK = 1758279600 * 1000;
|
||||
const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK);
|
||||
|
||||
const journeysRes = await client.journeys(berlinHbf, münchenHbf, {
|
||||
|
@ -261,7 +261,7 @@ if (!process.env.VCR_MODE) {
|
|||
}
|
||||
|
||||
tap.test('refreshJourney', async (t) => {
|
||||
const T_MOCK = 1710831600 * 1000; // 2024-03-19T08:00:00+01:00
|
||||
const T_MOCK = 1763542800 * 1000;
|
||||
const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK);
|
||||
const validate = createValidate({...cfg, when});
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ tap.test('journeys – Berlin Schwedter Str. to München Hbf', async (t) => {
|
|||
});
|
||||
|
||||
tap.test('refreshJourney – valid tickets', async (t) => {
|
||||
const T_MOCK = 1710831600 * 1000; // 2024-03-19T08:00:00+01:00
|
||||
const T_MOCK = 1758279600 * 1000;
|
||||
const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK);
|
||||
|
||||
const journeysRes = await client.journeys(berlinHbf, münchenHbf, {
|
||||
|
@ -261,7 +261,7 @@ if (!process.env.VCR_OFF) {
|
|||
}
|
||||
|
||||
tap.test('refreshJourney', async (t) => {
|
||||
const T_MOCK = 1710831600 * 1000; // 2024-03-19T08:00:00+01:00
|
||||
const T_MOCK = 1763542800 * 1000;
|
||||
const when = createWhen(dbProfile.timezone, dbProfile.locale, T_MOCK);
|
||||
const validate = createValidate({...cfg, when});
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -41,6 +41,10 @@ const berlinWienQuery0 = Object.freeze(
|
|||
einstiegsTypList: [
|
||||
'STANDARD',
|
||||
],
|
||||
fahrverguenstigungen: {
|
||||
deutschlandTicketVorhanden: undefined,
|
||||
nurDeutschlandTicketVerbindungen: undefined,
|
||||
},
|
||||
klasse: 'KLASSE_2',
|
||||
reiseHin: {
|
||||
wunsch: {
|
||||
|
|
|
@ -57,8 +57,8 @@ const berlinWienQuery0 = Object.freeze(
|
|||
sitzplatzOnly: false,
|
||||
bikeCarriage: false,
|
||||
reservierungsKontingenteVorhanden: false,
|
||||
nurDeutschlandTicketVerbindungen: false,
|
||||
deutschlandTicketVorhanden: false,
|
||||
nurDeutschlandTicketVerbindungen: undefined,
|
||||
deutschlandTicketVorhanden: undefined,
|
||||
maxUmstiege: null,
|
||||
zwischenhalte: null,
|
||||
minUmstiegszeit: 0,
|
||||
|
|
Loading…
Add table
Reference in a new issue