import tap from 'tap'; import {createClient} from '../../index.js'; import {profile as rawProfile} from '../../p/db/index.js'; import {data as loyaltyCards} from '../../p/db/loyalty-cards.js'; const client = createClient(rawProfile, 'public-transport/hafas-client:test'); const {profile} = client; const opt = { results: null, via: null, stopovers: false, transfers: -1, transferTime: 0, 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, age: 24, loyaltyCard: { type: loyaltyCards.BAHNCARD, discount: 25, }, }; const berlinWienQuery0 = Object.freeze( { 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', ], schnelleVerbindungen: true, sitzplatzOnly: false, bikeCarriage: false, reservierungsKontingenteVorhanden: false, nurDeutschlandTicketVerbindungen: false, deutschlandTicketVorhanden: false, }); tap.test('formats a journeys() request correctly (DB)', (t) => { const _opt = {...opt}; delete _opt.loyaltyCard; delete _opt.age; const ctx = {profile, opt: _opt}; // transformJourneysQuery() mutates its 2nd argument! const query = {...berlinWienQuery0}; const req = profile.transformJourneysQuery(ctx, query); t.same(req.body, { ...berlinWienQuery0, reisende: [ { typ: 'ERWACHSENER', ermaessigungen: [ { art: 'KEINE_ERMAESSIGUNG', klasse: 'KLASSENLOS', }, ], alter: [], anzahl: 1, }, ], }); t.end(); }); tap.test('formats a journeys() request with BC correctly (DB)', (t) => { const ctx = {profile, opt}; // transformJourneysQuery() mutates its 2nd argument! const query = {...berlinWienQuery0}; const req = profile.transformJourneysQuery(ctx, query); t.same(req.body, { ...berlinWienQuery0, reisende: [ { typ: 'JUGENDLICHER', ermaessigungen: [ { art: 'BAHNCARD25', klasse: 'KLASSE_2', }, ], alter: ['24'], anzahl: 1, }, ], }); t.end(); });