Merge pull request #39 from public-transport/remove-journey-shorthands

remove journey shorthands
This commit is contained in:
Julius Tens 2018-03-21 21:40:05 +01:00 committed by GitHub
commit fe8f9c29f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 127 deletions

View file

@ -157,7 +157,7 @@ const createClient = (profile, request = _request) => {
journeys.laterRef = d.outCtxScrF journeys.laterRef = d.outCtxScrF
return journeys return journeys
} }
const dep = +new Date(j.departure) const dep = +new Date(j.legs[0].departure)
if (dep > latestDep) latestDep = dep if (dep > latestDep) latestDep = dep
} }

View file

@ -8,31 +8,13 @@ const createParseJourney = (profile, stations, lines, remarks) => {
const parseLeg = createParseJourneyLeg(profile, stations, lines, remarks) const parseLeg = createParseJourneyLeg(profile, stations, lines, remarks)
// todo: c.sDays // todo: c.sDays
// todo: c.dep.dProgType, c.arr.dProgType
// todo: c.conSubscr // todo: c.conSubscr
// todo: c.trfRes x vbb-parse-ticket // todo: c.trfRes x vbb-parse-ticket
const parseJourney = (j) => { const parseJourney = (j) => {
const legs = j.secL.map(leg => parseLeg(j, leg)) const legs = j.secL.map(leg => parseLeg(j, leg))
const res = { const res = {
type: 'journey', type: 'journey',
legs, 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()
} }
return res return res

View file

@ -109,29 +109,9 @@ test('Berlin Jungfernheide to München Hbf', co(function* (t) {
for (let journey of journeys) { for (let journey of journeys) {
t.equal(journey.type, 'journey') 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(Array.isArray(journey.legs))
t.ok(journey.legs.length > 0, 'no 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) assertValidStation(t, leg.origin)
assertValidStationProducts(t, leg.origin.products) 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 let earliestDep = Infinity, latestDep = -Infinity
for (let j of model) { for (let j of model) {
const dep = +new Date(j.departure) const dep = +new Date(j.legs[0].departure)
if (dep < earliestDep) earliestDep = dep if (dep < earliestDep) earliestDep = dep
else if (dep > latestDep) latestDep = 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 earlierThan: model.earlierRef
}) })
for (let j of earlier) { 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, { 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 laterThan: model.laterRef
}) })
for (let j of later) { for (let j of later) {
t.ok(new Date(j.departure) > latestDep) t.ok(new Date(j.legs[0].departure) > latestDep)
} }
t.end() t.end()

View file

@ -77,23 +77,9 @@ test('Magdeburg Hbf to Magdeburg-Buckau', co(function*(t) {
t.ok(Array.isArray(journeys)) t.ok(Array.isArray(journeys))
t.ok(journeys.length > 0, 'no journeys') t.ok(journeys.length > 0, 'no journeys')
for (let journey of 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(Array.isArray(journey.legs))
t.ok(journey.legs.length > 0, 'no 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) assertValidStation(t, leg.origin)
assertValidStationProducts(t, leg.origin.products) assertValidStationProducts(t, leg.origin.products)

View file

@ -12,7 +12,7 @@ const validateLineWithoutMode = require('./validate-line-without-mode')
const co = require('./co') const co = require('./co')
const createClient = require('..') const createClient = require('..')
const nahshProfile = require('../p/nahsh') const nahshProfile = require('../p/nahsh')
const {allProducts} = require('../p/nahsh/products') const allProducts = require('../p/nahsh/products')
const { const {
assertValidStation, assertValidStation,
assertValidPoi, assertValidPoi,
@ -108,31 +108,9 @@ test('Kiel Hbf to Flensburg', co(function* (t) {
for (let journey of journeys) { for (let journey of journeys) {
t.equal(journey.type, 'journey') 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(Array.isArray(journey.legs))
t.ok(journey.legs.length > 0, 'no 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) assertValidStation(t, leg.origin)
assertValidStationProducts(t, leg.origin.products) assertValidStationProducts(t, leg.origin.products)
@ -279,7 +257,7 @@ test('earlier/later journeys, Kiel Hbf -> Flensburg', co(function* (t) {
let earliestDep = Infinity, latestDep = -Infinity let earliestDep = Infinity, latestDep = -Infinity
for (let j of model) { for (let j of model) {
const dep = +new Date(j.departure) const dep = +new Date(j.legs[0].departure)
if (dep < earliestDep) earliestDep = dep if (dep < earliestDep) earliestDep = dep
else if (dep > latestDep) latestDep = dep else if (dep > latestDep) latestDep = dep
} }
@ -290,7 +268,7 @@ test('earlier/later journeys, Kiel Hbf -> Flensburg', co(function* (t) {
earlierThan: model.earlierRef earlierThan: model.earlierRef
}) })
for (let j of earlier) { 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, { const later = yield client.journeys(kielHbf, flensburg, {
@ -299,7 +277,7 @@ test('earlier/later journeys, Kiel Hbf -> Flensburg', co(function* (t) {
laterThan: model.laterRef laterThan: model.laterRef
}) })
for (let j of later) { for (let j of later) {
t.ok(new Date(j.departure) > latestDep) t.ok(new Date(j.legs[0].departure) > latestDep)
} }
t.end() t.end()

View file

@ -128,31 +128,9 @@ test('Salzburg Hbf to Wien Westbahnhof', co(function* (t) {
for (let journey of journeys) { for (let journey of journeys) {
t.equal(journey.type, 'journey') 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(Array.isArray(journey.legs))
t.ok(journey.legs.length > 0, 'no 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) assertValidStation(t, leg.origin)
assertValidStationProducts(t, leg.origin.products) 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 let earliestDep = Infinity, latestDep = -Infinity
for (let j of model) { for (let j of model) {
const dep = +new Date(j.departure) const dep = +new Date(j.legs[0].departure)
if (dep < earliestDep) earliestDep = dep if (dep < earliestDep) earliestDep = dep
else if (dep > latestDep) latestDep = 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 earlierThan: model.earlierRef
}) })
for (let j of earlier) { 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, { 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 laterThan: model.laterRef
}) })
for (let j of later) { for (let j of later) {
t.ok(new Date(j.departure) > latestDep) t.ok(new Date(j.legs[0].departure) > latestDep)
} }
t.end() t.end()

View file

@ -69,20 +69,9 @@ test('journeys  station to station', co(function* (t) {
for (let journey of journeys) { for (let journey of journeys) {
t.equal(journey.type, 'journey') 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.ok(Array.isArray(journey.legs))
t.strictEqual(journey.legs.length, 1) 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.equal(typeof leg.id, 'string')
t.ok(leg.id) t.ok(leg.id)
@ -192,7 +181,7 @@ test('earlier/later journeys', co(function* (t) {
let earliestDep = Infinity, latestDep = -Infinity let earliestDep = Infinity, latestDep = -Infinity
for (let j of model) { for (let j of model) {
const dep = +new Date(j.departure) const dep = +new Date(j.legs[0].departure)
if (dep < earliestDep) earliestDep = dep if (dep < earliestDep) earliestDep = dep
else if (dep > latestDep) latestDep = dep else if (dep > latestDep) latestDep = dep
} }
@ -203,7 +192,7 @@ test('earlier/later journeys', co(function* (t) {
earlierThan: model.earlierRef earlierThan: model.earlierRef
}) })
for (let j of earlier) { 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, { const later = yield client.journeys(spichernstr, bismarckstr, {
@ -212,7 +201,7 @@ test('earlier/later journeys', co(function* (t) {
laterThan: model.laterRef laterThan: model.laterRef
}) })
for (let j of later) { for (let j of later) {
t.ok(new Date(j.departure) > latestDep) t.ok(new Date(j.legs[0].departure) > latestDep)
} }
t.end() t.end()