-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cb7062
commit ce4b5b5
Showing
8 changed files
with
4,835 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
const parseBestPrice = (ctx, outDaySeg, journeys) => { | ||
const {profile, res} = ctx | ||
|
||
const bpjourneys = outDaySeg.conRefL | ||
? outDaySeg.conRefL | ||
.map(i => journeys.find(j => j.refreshToken == res.outConL[i].ctxRecon)) | ||
.filter(j => !!j) | ||
: [] | ||
|
||
const amount = outDaySeg.bestPrice.amount / 100 | ||
const currency = bpjourneys?.[0]?.price?.currency; | ||
|
||
const result = { | ||
journeys: bpjourneys, | ||
fromDate: profile.parseDateTime(ctx, outDaySeg.fromDate, outDaySeg.fromTime), | ||
toDate: profile.parseDateTime(ctx, outDaySeg.toDate, outDaySeg.toTime), | ||
bestPrice: amount > 0 && currency ? { amount, currency} : undefined | ||
} | ||
|
||
return result | ||
} | ||
|
||
export { | ||
parseBestPrice, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// todo: use import assertions once they're supported by Node.js & ESLint | ||
// https://github.com/tc39/proposal-import-assertions | ||
import {createRequire} from 'module' | ||
const require = createRequire(import.meta.url) | ||
|
||
import tap from 'tap' | ||
|
||
import {createClient} from '../index.js' | ||
import {profile as rawProfile} from '../p/db/index.js' | ||
const response = require('./fixtures/db-bestprice.json') | ||
import {dbBestPrices as expected} from './fixtures/db-bestprice.js' | ||
|
||
const client = createClient(rawProfile, 'public-transport/hafas-client:test') | ||
const {profile} = client | ||
|
||
const opt = { | ||
via: null, | ||
transfers: -1, | ||
transferTime: 0, | ||
accessibility: 'none', | ||
bike: false, | ||
tickets: true, | ||
polylines: true, | ||
remarks: true, | ||
walkingSpeed: 'normal', | ||
startWithWalking: true, | ||
departure: '2023-06-15', | ||
products: {} | ||
} | ||
|
||
tap.test('parses a bestprice with a DEVI leg correctly (DB)', (t) => { | ||
const res = response.svcResL[0].res | ||
const common = profile.parseCommon({profile, opt, res}) | ||
const ctx = {profile, opt, common, res} | ||
const journeys = res.outConL.map(j => profile.parseJourney(ctx, j)) | ||
const bestPrices = res.outDaySegL.map(j => profile.parseBestPrice(ctx, j, journeys)) | ||
|
||
t.same(bestPrices, expected.bestPrices) | ||
t.end() | ||
}) |
Oops, something went wrong.