From a8401f36e145a44c498961c4b20d0dcf237160d7 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Sun, 3 Sep 2023 13:51:33 +0200 Subject: [PATCH] =?UTF-8?q?DB:=20add=20test=20for=20profile.transformJourn?= =?UTF-8?q?eysQuery()=20=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/format/db-journeys-query.js | 83 ++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 test/format/db-journeys-query.js diff --git a/test/format/db-journeys-query.js b/test/format/db-journeys-query.js new file mode 100644 index 00000000..6177e146 --- /dev/null +++ b/test/format/db-journeys-query.js @@ -0,0 +1,83 @@ +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, + loyaltyCard: { + type: loyaltyCards.BAHNCARD, + discount: 25, + }, +} + +const berlinWienQuery0 = Object.freeze({ + getPasslist: false, + maxChg: -1, + minChgTime: 0, + depLocL: [{ + type: 'S', + lid: 'A=1@L=8098160@', + }], + viaLocL: [], + arrLocL: [{ + type: 'S', + lid: 'A=1@L=8000284@', + }], + jnyFltrL: [ + {type: 'PROD', mode: 'INC', value: '1023'}, + {type: 'META', mode: 'INC', meta: 'notBarrierfree'}, + ], + gisFltrL: [], + getTariff: false, + ushrp: true, + getPT: true, + getIV: false, + getPolyline: false, + outDate: '20230912', + outTime: '080910', + outFrwd: true, +}) + +tap.test('formats a journeys() request correctly (DB)', (t) => { + const ctx = {profile, opt} + + // transformJourneysQuery() mutates its 2nd argument! + const query = {...berlinWienQuery0} + const req = profile.transformJourneysQuery(ctx, query) + + t.same(req, { + ...berlinWienQuery0, + trfReq: { + jnyCl: 2, + tvlrProf: [{ + type: 'E', // "adult" + redtnCard: 2, // BahnCard 25 + }], + cType: 'PK', + }, + }) + t.end() +})