DB: add test for profile.transformJourneysQuery()

This commit is contained in:
Jannis R 2023-09-03 13:51:33 +02:00
parent 45610fc951
commit a8401f36e1
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5

View file

@ -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()
})