mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-22 22:59:35 +02:00
add attribute additional
to additional stopovers ✅
This commit is contained in:
parent
ecc8fccc54
commit
244e88dec0
3 changed files with 1345 additions and 0 deletions
|
@ -37,6 +37,10 @@ const parseStopover = (ctx, st, date) => { // st = raw stopover
|
|||
Object.defineProperty(res, 'canceled', {value: true})
|
||||
}
|
||||
|
||||
if (st.isAdd) {
|
||||
res.additional = true
|
||||
}
|
||||
|
||||
if (opt.remarks && Array.isArray(st.msgL)) {
|
||||
res.remarks = findRemarks(st.msgL).map(([remark]) => remark)
|
||||
}
|
||||
|
|
35
test/db-journey-additional-stopover.js
Normal file
35
test/db-journey-additional-stopover.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
// 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 resAdditionalStopover = require('./fixtures/db-journey-additional-stopover.json')
|
||||
|
||||
const client = createClient(rawProfile, 'public-transport/hafas-client:test')
|
||||
const {profile} = client
|
||||
|
||||
const opt = {
|
||||
results: 1,
|
||||
stopovers: true
|
||||
}
|
||||
|
||||
// https://github.com/public-transport/hafas-client/issues/303
|
||||
|
||||
tap.test('parses a journey having a leg with an additional stopover', (t) => {
|
||||
const common = profile.parseCommon({profile, opt, res: resAdditionalStopover})
|
||||
const ctx = {profile, opt, common, res: resAdditionalStopover}
|
||||
const journey = profile.parseJourney(ctx, resAdditionalStopover.outConL[0])
|
||||
const stopovers = journey.legs[0].stopovers
|
||||
|
||||
const stopoverRegular = stopovers[6]
|
||||
const stopoverAdditional = stopovers[7]
|
||||
t.notOk('additional' in stopoverRegular, 'regular stopover has attribute additional')
|
||||
t.equal(stopoverAdditional.additional, true, 'additional stopover doesn\'t have attribute additional')
|
||||
t.end()
|
||||
})
|
1306
test/fixtures/db-journey-additional-stopover.json
vendored
Normal file
1306
test/fixtures/db-journey-additional-stopover.json
vendored
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue