Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add attribute additional to additional stopovers with test #304

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions parse/stopover.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
35 changes: 35 additions & 0 deletions test/db-journey-additional-stopover.js
Original file line number Diff line number Diff line change
@@ -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()
})
Loading
Loading