mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
Merge pull request #39 from public-transport/remove-journey-shorthands
remove journey shorthands
This commit is contained in:
commit
fe8f9c29f9
7 changed files with 20 additions and 127 deletions
2
index.js
2
index.js
|
@ -157,7 +157,7 @@ const createClient = (profile, request = _request) => {
|
|||
journeys.laterRef = d.outCtxScrF
|
||||
return journeys
|
||||
}
|
||||
const dep = +new Date(j.departure)
|
||||
const dep = +new Date(j.legs[0].departure)
|
||||
if (dep > latestDep) latestDep = dep
|
||||
}
|
||||
|
||||
|
|
|
@ -8,31 +8,13 @@ const createParseJourney = (profile, stations, lines, remarks) => {
|
|||
const parseLeg = createParseJourneyLeg(profile, stations, lines, remarks)
|
||||
|
||||
// todo: c.sDays
|
||||
// todo: c.dep.dProgType, c.arr.dProgType
|
||||
// todo: c.conSubscr
|
||||
// todo: c.trfRes x vbb-parse-ticket
|
||||
const parseJourney = (j) => {
|
||||
const legs = j.secL.map(leg => parseLeg(j, leg))
|
||||
const res = {
|
||||
type: 'journey',
|
||||
legs,
|
||||
origin: legs[0].origin,
|
||||
destination: legs[legs.length - 1].destination,
|
||||
departure: legs[0].departure,
|
||||
arrival: legs[legs.length - 1].arrival
|
||||
}
|
||||
if (legs.some(p => p.cancelled)) {
|
||||
res.cancelled = true
|
||||
Object.defineProperty(res, 'canceled', {value: true})
|
||||
res.departure = res.arrival = null
|
||||
|
||||
const firstLeg = j.secL[0]
|
||||
const dep = profile.parseDateTime(profile, j.date, firstLeg.dep.dTimeS)
|
||||
res.formerScheduledDeparture = dep.toISO()
|
||||
|
||||
const lastLeg = j.secL[j.secL.length - 1]
|
||||
const arr = profile.parseDateTime(profile, j.date, lastLeg.arr.aTimeS)
|
||||
res.formerScheduledArrival = arr.toISO()
|
||||
legs
|
||||
}
|
||||
|
||||
return res
|
||||
|
|
28
test/db.js
28
test/db.js
|
@ -109,29 +109,9 @@ test('Berlin Jungfernheide to München Hbf', co(function* (t) {
|
|||
for (let journey of journeys) {
|
||||
t.equal(journey.type, 'journey')
|
||||
|
||||
assertValidStation(t, journey.origin)
|
||||
assertValidStationProducts(t, journey.origin.products)
|
||||
if (!(yield findStation(journey.origin.id))) {
|
||||
console.error('unknown station', journey.origin.id, journey.origin.name)
|
||||
}
|
||||
if (journey.origin.products) {
|
||||
assertValidProducts(t, journey.origin.products)
|
||||
}
|
||||
assertValidWhen(t, journey.departure, when)
|
||||
|
||||
assertValidStation(t, journey.destination)
|
||||
assertValidStationProducts(t, journey.origin.products)
|
||||
if (!(yield findStation(journey.origin.id))) {
|
||||
console.error('unknown station', journey.destination.id, journey.destination.name)
|
||||
}
|
||||
if (journey.destination.products) {
|
||||
assertValidProducts(t, journey.destination.products)
|
||||
}
|
||||
assertValidWhen(t, journey.arrival, when)
|
||||
|
||||
t.ok(Array.isArray(journey.legs))
|
||||
t.ok(journey.legs.length > 0, 'no legs')
|
||||
const leg = journey.legs[0]
|
||||
const leg = journey.legs[0] // todo: all legs
|
||||
|
||||
assertValidStation(t, leg.origin)
|
||||
assertValidStationProducts(t, leg.origin.products)
|
||||
|
@ -284,7 +264,7 @@ test('earlier/later journeys, Jungfernheide -> München Hbf', co(function* (t) {
|
|||
|
||||
let earliestDep = Infinity, latestDep = -Infinity
|
||||
for (let j of model) {
|
||||
const dep = +new Date(j.departure)
|
||||
const dep = +new Date(j.legs[0].departure)
|
||||
if (dep < earliestDep) earliestDep = dep
|
||||
else if (dep > latestDep) latestDep = dep
|
||||
}
|
||||
|
@ -295,7 +275,7 @@ test('earlier/later journeys, Jungfernheide -> München Hbf', co(function* (t) {
|
|||
earlierThan: model.earlierRef
|
||||
})
|
||||
for (let j of earlier) {
|
||||
t.ok(new Date(j.departure) < earliestDep)
|
||||
t.ok(new Date(j.legs[0].departure) < earliestDep)
|
||||
}
|
||||
|
||||
const later = yield client.journeys(jungfernh, münchenHbf, {
|
||||
|
@ -304,7 +284,7 @@ test('earlier/later journeys, Jungfernheide -> München Hbf', co(function* (t) {
|
|||
laterThan: model.laterRef
|
||||
})
|
||||
for (let j of later) {
|
||||
t.ok(new Date(j.departure) > latestDep)
|
||||
t.ok(new Date(j.legs[0].departure) > latestDep)
|
||||
}
|
||||
|
||||
t.end()
|
||||
|
|
16
test/insa.js
16
test/insa.js
|
@ -77,23 +77,9 @@ test('Magdeburg Hbf to Magdeburg-Buckau', co(function*(t) {
|
|||
t.ok(Array.isArray(journeys))
|
||||
t.ok(journeys.length > 0, 'no journeys')
|
||||
for (let journey of journeys) {
|
||||
assertValidStation(t, journey.origin)
|
||||
assertValidStationProducts(t, journey.origin.products)
|
||||
if (journey.origin.products) {
|
||||
assertValidProducts(t, journey.origin.products)
|
||||
}
|
||||
assertValidWhen(t, journey.departure, when)
|
||||
|
||||
assertValidStation(t, journey.destination)
|
||||
assertValidStationProducts(t, journey.origin.products)
|
||||
if (journey.destination.products) {
|
||||
assertValidProducts(t, journey.destination.products)
|
||||
}
|
||||
assertValidWhen(t, journey.arrival, when)
|
||||
|
||||
t.ok(Array.isArray(journey.legs))
|
||||
t.ok(journey.legs.length > 0, 'no legs')
|
||||
const leg = journey.legs[0]
|
||||
const leg = journey.legs[0] // todo: all legs
|
||||
|
||||
assertValidStation(t, leg.origin)
|
||||
assertValidStationProducts(t, leg.origin.products)
|
||||
|
|
|
@ -12,7 +12,7 @@ const validateLineWithoutMode = require('./validate-line-without-mode')
|
|||
const co = require('./co')
|
||||
const createClient = require('..')
|
||||
const nahshProfile = require('../p/nahsh')
|
||||
const {allProducts} = require('../p/nahsh/products')
|
||||
const allProducts = require('../p/nahsh/products')
|
||||
const {
|
||||
assertValidStation,
|
||||
assertValidPoi,
|
||||
|
@ -108,31 +108,9 @@ test('Kiel Hbf to Flensburg', co(function* (t) {
|
|||
for (let journey of journeys) {
|
||||
t.equal(journey.type, 'journey')
|
||||
|
||||
assertValidStation(t, journey.origin)
|
||||
assertValidStationProducts(t, journey.origin.products)
|
||||
// todo
|
||||
// if (!(yield findStation(journey.origin.id))) {
|
||||
// console.error('unknown station', journey.origin.id, journey.origin.name)
|
||||
// }
|
||||
if (journey.origin.products) {
|
||||
assertValidProducts(t, journey.origin.products)
|
||||
}
|
||||
assertValidWhen(t, journey.departure, when)
|
||||
|
||||
assertValidStation(t, journey.destination)
|
||||
assertValidStationProducts(t, journey.origin.products)
|
||||
// todo
|
||||
// if (!(yield findStation(journey.origin.id))) {
|
||||
// console.error('unknown station', journey.destination.id, journey.destination.name)
|
||||
// }
|
||||
if (journey.destination.products) {
|
||||
assertValidProducts(t, journey.destination.products)
|
||||
}
|
||||
assertValidWhen(t, journey.arrival, when)
|
||||
|
||||
t.ok(Array.isArray(journey.legs))
|
||||
t.ok(journey.legs.length > 0, 'no legs')
|
||||
const leg = journey.legs[0]
|
||||
const leg = journey.legs[0] // todo: all legs
|
||||
|
||||
assertValidStation(t, leg.origin)
|
||||
assertValidStationProducts(t, leg.origin.products)
|
||||
|
@ -279,7 +257,7 @@ test('earlier/later journeys, Kiel Hbf -> Flensburg', co(function* (t) {
|
|||
|
||||
let earliestDep = Infinity, latestDep = -Infinity
|
||||
for (let j of model) {
|
||||
const dep = +new Date(j.departure)
|
||||
const dep = +new Date(j.legs[0].departure)
|
||||
if (dep < earliestDep) earliestDep = dep
|
||||
else if (dep > latestDep) latestDep = dep
|
||||
}
|
||||
|
@ -290,7 +268,7 @@ test('earlier/later journeys, Kiel Hbf -> Flensburg', co(function* (t) {
|
|||
earlierThan: model.earlierRef
|
||||
})
|
||||
for (let j of earlier) {
|
||||
t.ok(new Date(j.departure) < earliestDep)
|
||||
t.ok(new Date(j.legs[0].departure) < earliestDep)
|
||||
}
|
||||
|
||||
const later = yield client.journeys(kielHbf, flensburg, {
|
||||
|
@ -299,7 +277,7 @@ test('earlier/later journeys, Kiel Hbf -> Flensburg', co(function* (t) {
|
|||
laterThan: model.laterRef
|
||||
})
|
||||
for (let j of later) {
|
||||
t.ok(new Date(j.departure) > latestDep)
|
||||
t.ok(new Date(j.legs[0].departure) > latestDep)
|
||||
}
|
||||
|
||||
t.end()
|
||||
|
|
30
test/oebb.js
30
test/oebb.js
|
@ -128,31 +128,9 @@ test('Salzburg Hbf to Wien Westbahnhof', co(function* (t) {
|
|||
for (let journey of journeys) {
|
||||
t.equal(journey.type, 'journey')
|
||||
|
||||
assertValidStation(t, journey.origin)
|
||||
assertValidStationProducts(t, journey.origin.products)
|
||||
// todo
|
||||
// if (!(yield findStation(journey.origin.id))) {
|
||||
// console.error('unknown station', journey.origin.id, journey.origin.name)
|
||||
// }
|
||||
if (journey.origin.products) {
|
||||
assertValidProducts(t, journey.origin.products)
|
||||
}
|
||||
assertValidWhen(t, journey.departure, when)
|
||||
|
||||
assertValidStation(t, journey.destination)
|
||||
assertValidStationProducts(t, journey.origin.products)
|
||||
// todo
|
||||
// if (!(yield findStation(journey.origin.id))) {
|
||||
// console.error('unknown station', journey.destination.id, journey.destination.name)
|
||||
// }
|
||||
if (journey.destination.products) {
|
||||
assertValidProducts(t, journey.destination.products)
|
||||
}
|
||||
assertValidWhen(t, journey.arrival, when)
|
||||
|
||||
t.ok(Array.isArray(journey.legs))
|
||||
t.ok(journey.legs.length > 0, 'no legs')
|
||||
const leg = journey.legs[0]
|
||||
const leg = journey.legs[0] // todo: all legs
|
||||
|
||||
assertValidStation(t, leg.origin)
|
||||
assertValidStationProducts(t, leg.origin.products)
|
||||
|
@ -327,7 +305,7 @@ test('earlier/later journeys, Salzburg Hbf -> Wien Westbahnhof', co(function* (t
|
|||
|
||||
let earliestDep = Infinity, latestDep = -Infinity
|
||||
for (let j of model) {
|
||||
const dep = +new Date(j.departure)
|
||||
const dep = +new Date(j.legs[0].departure)
|
||||
if (dep < earliestDep) earliestDep = dep
|
||||
else if (dep > latestDep) latestDep = dep
|
||||
}
|
||||
|
@ -338,7 +316,7 @@ test('earlier/later journeys, Salzburg Hbf -> Wien Westbahnhof', co(function* (t
|
|||
earlierThan: model.earlierRef
|
||||
})
|
||||
for (let j of earlier) {
|
||||
t.ok(new Date(j.departure) < earliestDep)
|
||||
t.ok(new Date(j.legs[0].departure) < earliestDep)
|
||||
}
|
||||
|
||||
const later = yield client.journeys(salzburgHbf, wienWestbahnhof, {
|
||||
|
@ -347,7 +325,7 @@ test('earlier/later journeys, Salzburg Hbf -> Wien Westbahnhof', co(function* (t
|
|||
laterThan: model.laterRef
|
||||
})
|
||||
for (let j of later) {
|
||||
t.ok(new Date(j.departure) > latestDep)
|
||||
t.ok(new Date(j.legs[0].departure) > latestDep)
|
||||
}
|
||||
|
||||
t.end()
|
||||
|
|
19
test/vbb.js
19
test/vbb.js
|
@ -69,20 +69,9 @@ test('journeys – station to station', co(function* (t) {
|
|||
for (let journey of journeys) {
|
||||
t.equal(journey.type, 'journey')
|
||||
|
||||
assertValidStation(t, journey.origin)
|
||||
assertValidStationProducts(t, journey.origin.products)
|
||||
t.ok(journey.origin.name.indexOf('(Berlin)') === -1)
|
||||
t.strictEqual(journey.origin.id, spichernstr)
|
||||
assertValidWhen(t, journey.departure, when)
|
||||
|
||||
assertValidStation(t, journey.destination)
|
||||
assertValidStationProducts(t, journey.destination.products)
|
||||
t.strictEqual(journey.destination.id, amrumerStr)
|
||||
assertValidWhen(t, journey.arrival, when)
|
||||
|
||||
t.ok(Array.isArray(journey.legs))
|
||||
t.strictEqual(journey.legs.length, 1)
|
||||
const leg = journey.legs[0]
|
||||
const leg = journey.legs[0] // todo: all legs
|
||||
|
||||
t.equal(typeof leg.id, 'string')
|
||||
t.ok(leg.id)
|
||||
|
@ -192,7 +181,7 @@ test('earlier/later journeys', co(function* (t) {
|
|||
|
||||
let earliestDep = Infinity, latestDep = -Infinity
|
||||
for (let j of model) {
|
||||
const dep = +new Date(j.departure)
|
||||
const dep = +new Date(j.legs[0].departure)
|
||||
if (dep < earliestDep) earliestDep = dep
|
||||
else if (dep > latestDep) latestDep = dep
|
||||
}
|
||||
|
@ -203,7 +192,7 @@ test('earlier/later journeys', co(function* (t) {
|
|||
earlierThan: model.earlierRef
|
||||
})
|
||||
for (let j of earlier) {
|
||||
t.ok(new Date(j.departure) < earliestDep)
|
||||
t.ok(new Date(j.legs[0].departure) < earliestDep)
|
||||
}
|
||||
|
||||
const later = yield client.journeys(spichernstr, bismarckstr, {
|
||||
|
@ -212,7 +201,7 @@ test('earlier/later journeys', co(function* (t) {
|
|||
laterThan: model.laterRef
|
||||
})
|
||||
for (let j of later) {
|
||||
t.ok(new Date(j.departure) > latestDep)
|
||||
t.ok(new Date(j.legs[0].departure) > latestDep)
|
||||
}
|
||||
|
||||
t.end()
|
||||
|
|
Loading…
Add table
Reference in a new issue