2024-02-06 22:58:49 +01:00
|
|
|
import tap from 'tap';
|
2023-09-03 13:51:33 +02:00
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
import {createClient} from '../../index.js';
|
|
|
|
import {profile as rawProfile} from '../../p/db/index.js';
|
2024-12-21 15:26:49 +00:00
|
|
|
import {data as loyaltyCards} from '../../format/loyalty-cards.js';
|
2023-09-03 13:51:33 +02:00
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
const client = createClient(rawProfile, 'public-transport/hafas-client:test');
|
|
|
|
const {profile} = client;
|
2023-09-03 13:51:33 +02:00
|
|
|
|
|
|
|
const opt = {
|
|
|
|
results: null,
|
|
|
|
via: null,
|
|
|
|
stopovers: false,
|
2024-12-21 15:51:25 +00:00
|
|
|
transfers: null,
|
|
|
|
transferTime: 0,
|
2023-09-03 13:51:33 +02:00
|
|
|
accessibility: 'none',
|
|
|
|
bike: false,
|
|
|
|
walkingSpeed: 'normal',
|
|
|
|
startWithWalking: true,
|
|
|
|
tickets: false,
|
|
|
|
polylines: false,
|
|
|
|
subStops: true,
|
|
|
|
entrances: true,
|
|
|
|
remarks: true,
|
|
|
|
scheduledDays: false,
|
|
|
|
departure: '2023-09-12T08:09:10+02:00',
|
|
|
|
products: {},
|
|
|
|
|
|
|
|
firstClass: false,
|
2023-09-03 13:52:55 +02:00
|
|
|
age: 24,
|
2023-09-03 13:51:33 +02:00
|
|
|
loyaltyCard: {
|
|
|
|
type: loyaltyCards.BAHNCARD,
|
|
|
|
discount: 25,
|
|
|
|
},
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|
2023-09-03 13:51:33 +02:00
|
|
|
|
2024-12-07 23:48:08 +00:00
|
|
|
const berlinWienQuery0 = Object.freeze(
|
|
|
|
{
|
2024-12-08 21:42:57 +00:00
|
|
|
abfahrtsHalt: 'A=1@L=8098160@',
|
|
|
|
anfrageZeitpunkt: '2024-12-07T23:50:12',
|
|
|
|
ankunftsHalt: 'A=1@L=8000284@',
|
|
|
|
ankunftSuche: 'ABFAHRT',
|
|
|
|
klasse: 'KLASSE_2',
|
|
|
|
produktgattungen: [
|
|
|
|
'ICE',
|
|
|
|
'EC_IC',
|
|
|
|
'IR',
|
|
|
|
'REGIONAL',
|
|
|
|
'SBAHN',
|
|
|
|
'BUS',
|
|
|
|
'SCHIFF',
|
|
|
|
'UBAHN',
|
|
|
|
'TRAM',
|
|
|
|
'ANRUFPFLICHTIG',
|
2024-12-07 23:48:08 +00:00
|
|
|
],
|
2024-12-08 21:42:57 +00:00
|
|
|
schnelleVerbindungen: true,
|
|
|
|
sitzplatzOnly: false,
|
|
|
|
bikeCarriage: false,
|
|
|
|
reservierungsKontingenteVorhanden: false,
|
|
|
|
nurDeutschlandTicketVerbindungen: false,
|
|
|
|
deutschlandTicketVorhanden: false,
|
2024-12-21 15:51:25 +00:00
|
|
|
maxUmstiege: null,
|
|
|
|
zwischenhalte: null,
|
|
|
|
minUmstiegszeit: 0,
|
2024-12-08 21:42:57 +00:00
|
|
|
});
|
2023-09-03 13:51:33 +02:00
|
|
|
|
|
|
|
tap.test('formats a journeys() request correctly (DB)', (t) => {
|
2024-12-07 23:48:08 +00:00
|
|
|
const _opt = {...opt};
|
|
|
|
delete _opt.loyaltyCard;
|
|
|
|
delete _opt.age;
|
|
|
|
const ctx = {profile, opt: _opt};
|
2023-09-03 13:51:33 +02:00
|
|
|
|
2024-12-21 15:51:25 +00:00
|
|
|
const req = profile.formatJourneysReq(ctx, '8098160', '8000284', new Date('2024-12-07T23:50:12+01:00'), true, null);
|
2024-12-07 23:48:08 +00:00
|
|
|
t.same(req.body, {
|
2023-09-03 13:51:33 +02:00
|
|
|
...berlinWienQuery0,
|
2024-12-07 23:48:08 +00:00
|
|
|
reisende: [
|
|
|
|
{
|
2024-12-08 21:42:57 +00:00
|
|
|
typ: 'ERWACHSENER',
|
|
|
|
ermaessigungen: [
|
2024-12-07 23:48:08 +00:00
|
|
|
{
|
2024-12-08 21:42:57 +00:00
|
|
|
art: 'KEINE_ERMAESSIGUNG',
|
|
|
|
klasse: 'KLASSENLOS',
|
|
|
|
},
|
2024-12-07 23:48:08 +00:00
|
|
|
],
|
2024-12-08 21:42:57 +00:00
|
|
|
alter: [],
|
|
|
|
anzahl: 1,
|
|
|
|
},
|
|
|
|
],
|
2024-02-06 22:58:49 +01:00
|
|
|
});
|
|
|
|
t.end();
|
|
|
|
});
|
2024-12-07 23:48:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
tap.test('formats a journeys() request with BC correctly (DB)', (t) => {
|
|
|
|
const ctx = {profile, opt};
|
|
|
|
|
2024-12-21 15:51:25 +00:00
|
|
|
const req = profile.formatJourneysReq(ctx, '8098160', '8000284', new Date('2024-12-07T23:50:12+01:00'), true, null);
|
2024-12-07 23:48:08 +00:00
|
|
|
|
|
|
|
t.same(req.body, {
|
|
|
|
...berlinWienQuery0,
|
|
|
|
reisende: [
|
|
|
|
{
|
2024-12-08 21:42:57 +00:00
|
|
|
typ: 'JUGENDLICHER',
|
|
|
|
ermaessigungen: [
|
2024-12-07 23:48:08 +00:00
|
|
|
{
|
2024-12-08 21:42:57 +00:00
|
|
|
art: 'BAHNCARD25',
|
|
|
|
klasse: 'KLASSE_2',
|
|
|
|
},
|
2024-12-07 23:48:08 +00:00
|
|
|
],
|
2024-12-08 21:42:57 +00:00
|
|
|
alter: ['24'],
|
|
|
|
anzahl: 1,
|
|
|
|
},
|
|
|
|
],
|
2024-12-07 23:48:08 +00:00
|
|
|
});
|
|
|
|
t.end();
|
2024-12-08 21:42:57 +00:00
|
|
|
});
|