merge next into tests-rewrite

This commit is contained in:
Jannis R 2018-05-31 13:42:54 +02:00
commit 938195753c
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
9 changed files with 93 additions and 42 deletions

View file

@ -40,7 +40,10 @@ With `opt`, you can override the default options, which look like this:
```js ```js
{ {
when: new Date(), // Use either `departure` or `arrival` to specify a date/time.
departure: new Date(),
arrival: null,
earlierThan: null, // ref to get journeys earlier than the last query earlierThan: null, // ref to get journeys earlier than the last query
laterThan: null, // ref to get journeys later than the last query laterThan: null, // ref to get journeys later than the last query
results: 5, // how many journeys? results: 5, // how many journeys?

View file

@ -62,15 +62,18 @@ const createClient = (profile, request = _request) => {
to = profile.formatLocation(profile, to, 'to') to = profile.formatLocation(profile, to, 'to')
if (('earlierThan' in opt) && ('laterThan' in opt)) { if (('earlierThan' in opt) && ('laterThan' in opt)) {
throw new Error('opt.laterThan and opt.laterThan are mutually exclusive.') throw new Error('opt.earlierThan and opt.laterThan are mutually exclusive.')
}
if (('departure' in opt) && ('arrival' in opt)) {
throw new Error('opt.departure and opt.arrival are mutually exclusive.')
} }
let journeysRef = null let journeysRef = null
if ('earlierThan' in opt) { if ('earlierThan' in opt) {
if (!isNonEmptyString(opt.earlierThan)) { if (!isNonEmptyString(opt.earlierThan)) {
throw new Error('opt.earlierThan must be a non-empty string.') throw new Error('opt.earlierThan must be a non-empty string.')
} }
if ('when' in opt) { if (('departure' in opt) || ('arrival' in opt)) {
throw new Error('opt.earlierThan and opt.when are mutually exclusive.') throw new Error('opt.earlierThan and opt.departure/opt.arrival are mutually exclusive.')
} }
journeysRef = opt.earlierThan journeysRef = opt.earlierThan
} }
@ -78,8 +81,8 @@ const createClient = (profile, request = _request) => {
if (!isNonEmptyString(opt.laterThan)) { if (!isNonEmptyString(opt.laterThan)) {
throw new Error('opt.laterThan must be a non-empty string.') throw new Error('opt.laterThan must be a non-empty string.')
} }
if ('when' in opt) { if (('departure' in opt) || ('arrival' in opt)) {
throw new Error('opt.laterThan and opt.when are mutually exclusive.') throw new Error('opt.laterThan and opt.departure/opt.arrival are mutually exclusive.')
} }
journeysRef = opt.laterThan journeysRef = opt.laterThan
} }
@ -97,8 +100,19 @@ const createClient = (profile, request = _request) => {
polylines: false // return leg shapes? polylines: false // return leg shapes?
}, opt) }, opt)
if (opt.via) opt.via = profile.formatLocation(profile, opt.via, 'opt.via') if (opt.via) opt.via = profile.formatLocation(profile, opt.via, 'opt.via')
opt.when = new Date(opt.when || Date.now())
if (Number.isNaN(+opt.when)) throw new Error('opt.when is invalid') if (opt.when !== undefined) {
throw new Error('opt.when is not supported anymore. Use opt.departure/opt.arrival.')
}
let when = new Date(), outFrwd = true
if (opt.departure !== undefined && opt.departure !== null) {
when = new Date(opt.departure)
if (Number.isNaN(+when)) throw new Error('opt.departure is invalid')
} else if (opt.arrival !== undefined && opt.arrival !== null) {
when = new Date(opt.arrival)
if (Number.isNaN(+when)) throw new Error('opt.arrival is invalid')
outFrwd = false
}
const filters = [ const filters = [
profile.formatProductsFilter(opt.products || {}) profile.formatProductsFilter(opt.products || {})
@ -132,10 +146,10 @@ const createClient = (profile, request = _request) => {
arrLocL: [to], arrLocL: [to],
jnyFltrL: filters, jnyFltrL: filters,
getTariff: !!opt.tickets, getTariff: !!opt.tickets,
outFrwd,
// todo: what is req.gisFltrL? // todo: what is req.gisFltrL?
getPT: true, // todo: what is this? getPT: true, // todo: what is this?
outFrwd: true, // todo: what is this?
getIV: false, // todo: walk & bike as alternatives? getIV: false, // todo: walk & bike as alternatives?
getPolyline: !!opt.polylines getPolyline: !!opt.polylines
} }
@ -172,7 +186,7 @@ const createClient = (profile, request = _request) => {
}) })
} }
return more(opt.when, journeysRef) return more(when, journeysRef)
} }
const locations = (query, opt = {}) => { const locations = (query, opt = {}) => {

View file

@ -76,7 +76,7 @@ const regensburgHbf = '8000309'
test('journeys  Berlin Schwedter Str. to München Hbf', co(function* (t) { test('journeys  Berlin Schwedter Str. to München Hbf', co(function* (t) {
const journeys = yield client.journeys(blnSchwedterStr, münchenHbf, { const journeys = yield client.journeys(blnSchwedterStr, münchenHbf, {
results: 3, when, passedStations: true results: 3, departure: when, passedStations: true
}) })
yield testJourneysStationToStation({ yield testJourneysStationToStation({
@ -116,7 +116,8 @@ test('Berlin Schwedter Str. to Torfstraße 17', co(function* (t) {
longitude: 13.3491223 longitude: 13.3491223
} }
const journeys = yield client.journeys(blnSchwedterStr, torfstr, { const journeys = yield client.journeys(blnSchwedterStr, torfstr, {
results: 3, when results: 3,
departure: when
}) })
yield testJourneysStationToAddress({ yield testJourneysStationToAddress({
@ -138,7 +139,8 @@ test('Berlin Schwedter Str. to ATZE Musiktheater', co(function* (t) {
longitude: 13.350437 longitude: 13.350437
} }
const journeys = yield client.journeys(blnSchwedterStr, atze, { const journeys = yield client.journeys(blnSchwedterStr, atze, {
results: 3, when results: 3,
departure: when
}) })
yield testJourneysStationToPoi({ yield testJourneysStationToPoi({
@ -157,7 +159,7 @@ test('journeys: via works with detour', co(function* (t) {
const journeys = yield client.journeys(westhafen, wedding, { const journeys = yield client.journeys(westhafen, wedding, {
via: württembergallee, via: württembergallee,
results: 1, results: 1,
when, departure: when,
passedStations: true passedStations: true
}) })
@ -186,7 +188,7 @@ test('earlier/later journeys, Jungfernheide -> München Hbf', co(function* (t) {
test('journey leg details', co(function* (t) { test('journey leg details', co(function* (t) {
const journeys = yield client.journeys(berlinHbf, münchenHbf, { const journeys = yield client.journeys(berlinHbf, münchenHbf, {
results: 1, when results: 1, departure: when
}) })
const p = journeys[0].legs[0] const p = journeys[0].legs[0]

View file

@ -42,7 +42,9 @@ const dessau = '008010077'
test('journeys  Magdeburg Hbf to Magdeburg-Buckau', co(function* (t) { test('journeys  Magdeburg Hbf to Magdeburg-Buckau', co(function* (t) {
const journeys = yield client.journeys(magdeburgHbf, magdeburgBuckau, { const journeys = yield client.journeys(magdeburgHbf, magdeburgBuckau, {
results: 3, when, passedStations: true results: 3,
departure: when,
passedStations: true
}) })
yield testJourneysStationToStation({ yield testJourneysStationToStation({
@ -78,7 +80,8 @@ test('Magdeburg Hbf to 39104 Magdeburg, Sternstr. 10', co(function*(t) {
} }
const journeys = yield client.journeys(magdeburgHbf, sternStr, { const journeys = yield client.journeys(magdeburgHbf, sternStr, {
results: 3, when results: 3,
departure: when
}) })
yield testJourneysStationToAddress({ yield testJourneysStationToAddress({
@ -100,7 +103,8 @@ test('Magdeburg Hbf to Kloster Unser Lieben Frauen', co(function*(t) {
longitude: 11.636437 longitude: 11.636437
} }
const journeys = yield client.journeys(magdeburgHbf, kloster, { const journeys = yield client.journeys(magdeburgHbf, kloster, {
results: 3, when results: 3,
departure: when
}) })
yield testJourneysStationToPoi({ yield testJourneysStationToPoi({
@ -120,7 +124,7 @@ test('journeys: via works with detour', co(function* (t) {
const journeys = yield client.journeys(hasselbachplatzSternstrasse, stendal, { const journeys = yield client.journeys(hasselbachplatzSternstrasse, stendal, {
via: dessau, via: dessau,
results: 1, results: 1,
when, departure: when,
passedStations: true passedStations: true
}) })
@ -149,7 +153,7 @@ test('earlier/later journeys', co(function* (t) {
test('journey leg details', co(function* (t) { test('journey leg details', co(function* (t) {
const journeys = yield client.journeys(magdeburgHbf, magdeburgBuckau, { const journeys = yield client.journeys(magdeburgHbf, magdeburgBuckau, {
results: 1, when results: 1, departure: when
}) })
const p = journeys[0].legs[0] const p = journeys[0].legs[0]

View file

@ -13,7 +13,7 @@ const testEarlierLaterJourneys = co(function* (cfg) {
} = cfg } = cfg
const model = yield fetchJourneys(fromId, toId, { const model = yield fetchJourneys(fromId, toId, {
results: 3, when results: 3, departure: when
}) })
// todo: move to journeys validator? // todo: move to journeys validator?
@ -22,17 +22,31 @@ const testEarlierLaterJourneys = co(function* (cfg) {
t.equal(typeof model.laterRef, 'string') t.equal(typeof model.laterRef, 'string')
t.ok(model.laterRef) t.ok(model.laterRef)
// when and earlierThan/laterThan should be mutually exclusive // departure/arrival and earlierThan/laterThan should be mutually exclusive
t.throws(() => { t.throws(() => {
fetchJourneys(fromId, toId, { fetchJourneys(fromId, toId, {
when, earlierThan: model.earlierRef departure: when, earlierThan: model.earlierRef
}) })
// silence rejections, we're only interested in exceptions // silence rejections, we're only interested in exceptions
.catch(() => {}) .catch(() => {})
}) })
t.throws(() => { t.throws(() => {
fetchJourneys(fromId, toId, { fetchJourneys(fromId, toId, {
when, laterThan: model.laterRef departure: when, laterThan: model.laterRef
})
// silence rejections, we're only interested in exceptions
.catch(() => {})
})
t.throws(() => {
fetchJourneys(fromId, toId, {
arrival: when, earlierThan: model.earlierRef
})
// silence rejections, we're only interested in exceptions
.catch(() => {})
})
t.throws(() => {
fetchJourneys(fromId, toId, {
arrival: when, laterThan: model.laterRef
}) })
// silence rejections, we're only interested in exceptions // silence rejections, we're only interested in exceptions
.catch(() => {}) .catch(() => {})

View file

@ -14,7 +14,7 @@ const journeysFailsWithNoProduct = (cfg) => {
for (let p of products) productsObj[p.id] = false for (let p of products) productsObj[p.id] = false
t.throws(() => { t.throws(() => {
client.journeys(fromId, toId, {when, products}) client.journeys(fromId, toId, {departure: when, products})
// silence rejections, we're only interested in exceptions // silence rejections, we're only interested in exceptions
.catch(() => {}) .catch(() => {})
}) })

View file

@ -67,7 +67,9 @@ const schleswig = '8005362'
test('journeys  Kiel Hbf to Flensburg', co(function* (t) { test('journeys  Kiel Hbf to Flensburg', co(function* (t) {
const journeys = yield client.journeys(kielHbf, flensburg, { const journeys = yield client.journeys(kielHbf, flensburg, {
results: 3, when, passedStations: true results: 3,
departure: when,
passedStations: true
}) })
yield testJourneysStationToStation({ yield testJourneysStationToStation({
@ -109,7 +111,8 @@ test('Kiel Hbf to Husum, Zingel 10', co(function* (t) {
longitude: 9.050798 longitude: 9.050798
} }
const journeys = yield client.journeys(kielHbf, zingel, { const journeys = yield client.journeys(kielHbf, zingel, {
results: 3, when results: 3,
departure: when
}) })
yield testJourneysStationToAddress({ yield testJourneysStationToAddress({
@ -131,7 +134,8 @@ test('Kiel Hbf to Holstentor', co(function* (t) {
longitude: 10.679976 longitude: 10.679976
} }
const journeys = yield client.journeys(kielHbf, holstentor, { const journeys = yield client.journeys(kielHbf, holstentor, {
results: 3, when results: 3,
departure: when
}) })
yield testJourneysStationToPoi({ yield testJourneysStationToPoi({
@ -147,7 +151,9 @@ test('Kiel Hbf to Holstentor', co(function* (t) {
test('Husum to Lübeck Hbf with stopover at Kiel Hbf', co(function* (t) { test('Husum to Lübeck Hbf with stopover at Kiel Hbf', co(function* (t) {
const journeys = yield client.journeys(husum, luebeckHbf, { const journeys = yield client.journeys(husum, luebeckHbf, {
via: kielHbf, via: kielHbf,
results: 1, when, passedStations: true results: 1,
departure: when,
passedStations: true
}) })
validate(t, journeys, 'journeys', 'journeys') validate(t, journeys, 'journeys', 'journeys')
@ -179,7 +185,7 @@ test('earlier/later journeys, Kiel Hbf -> Flensburg', co(function* (t) {
test('journey leg details for Flensburg to Husum', co(function* (t) { test('journey leg details for Flensburg to Husum', co(function* (t) {
const journeys = yield client.journeys(flensburg, husum, { const journeys = yield client.journeys(flensburg, husum, {
results: 1, when results: 1, departure: when
}) })
const p = journeys[0].legs[0] const p = journeys[0].legs[0]

View file

@ -60,7 +60,9 @@ const wienRenngasse = '1390186'
test.skip('journeys  Salzburg Hbf to Wien Westbahnhof', co(function* (t) { test.skip('journeys  Salzburg Hbf to Wien Westbahnhof', co(function* (t) {
const journeys = yield client.journeys(salzburgHbf, wienFickeystr, { const journeys = yield client.journeys(salzburgHbf, wienFickeystr, {
results: 3, when, passedStations: true results: 3,
departure: when,
passedStations: true
}) })
yield testJourneysStationToStation({ yield testJourneysStationToStation({
@ -101,7 +103,8 @@ test('Salzburg Hbf to 1220 Wien, Wagramer Straße 5', co(function* (t) {
longitude: 16.425863 longitude: 16.425863
} }
const journeys = yield client.journeys(salzburgHbf, wagramerStr, { const journeys = yield client.journeys(salzburgHbf, wagramerStr, {
results: 3, when results: 3,
departure: when
}) })
yield testJourneysStationToAddress({ yield testJourneysStationToAddress({
@ -123,7 +126,7 @@ test('Salzburg Hbf to Albertina', co(function* (t) {
longitude: 16.368404 longitude: 16.368404
} }
const journeys = yield client.journeys(salzburgHbf, albertina, { const journeys = yield client.journeys(salzburgHbf, albertina, {
results: 3, when results: 3, departure: when
}) })
yield testJourneysStationToPoi({ yield testJourneysStationToPoi({
@ -146,7 +149,7 @@ test('journeys: via works with detour', co(function* (t) {
const journeys = yield client.journeys(stephansplatz, schottenring, { const journeys = yield client.journeys(stephansplatz, schottenring, {
via: donauinsel, via: donauinsel,
results: 1, results: 1,
when, departure: when,
passedStations: true passedStations: true
}) })
@ -170,7 +173,7 @@ test('journeys: via works without detour', co(function* (t) {
const journeys = yield client.journeys(karlsplatz, praterstern, { const journeys = yield client.journeys(karlsplatz, praterstern, {
via: museumsquartier, via: museumsquartier,
results: 1, results: 1,
when, departure: when,
passedStations: true passedStations: true
}) })
@ -208,7 +211,7 @@ test('earlier/later journeys, Salzburg Hbf -> Wien Westbahnhof', co(function* (t
test('leg details for Wien Westbahnhof to München Hbf', co(function* (t) { test('leg details for Wien Westbahnhof to München Hbf', co(function* (t) {
const journeys = yield client.journeys(wienWestbahnhof, muenchenHbf, { const journeys = yield client.journeys(wienWestbahnhof, muenchenHbf, {
results: 1, when results: 1, departure: when
}) })
const p = journeys[0].legs[0] const p = journeys[0].legs[0]

View file

@ -111,7 +111,9 @@ const württembergallee = '900000026153'
test('journeys  Spichernstr. to Bismarckstr.', co(function* (t) { test('journeys  Spichernstr. to Bismarckstr.', co(function* (t) {
const journeys = yield client.journeys(spichernstr, bismarckstr, { const journeys = yield client.journeys(spichernstr, bismarckstr, {
results: 3, when, passedStations: true results: 3,
departure: when,
passedStations: true
}) })
yield testJourneysStationToStation({ yield testJourneysStationToStation({
@ -128,7 +130,8 @@ test('journeys  Spichernstr. to Bismarckstr.', co(function* (t) {
test('journeys  only subway', co(function* (t) { test('journeys  only subway', co(function* (t) {
const journeys = yield client.journeys(spichernstr, bismarckstr, { const journeys = yield client.journeys(spichernstr, bismarckstr, {
results: 20, when, results: 20,
departure: when,
products: { products: {
suburban: false, suburban: false,
subway: true, subway: true,
@ -185,7 +188,7 @@ test('earlier/later journeys', co(function* (t) {
test('journey leg details', co(function* (t) { test('journey leg details', co(function* (t) {
const journeys = yield client.journeys(spichernstr, amrumerStr, { const journeys = yield client.journeys(spichernstr, amrumerStr, {
results: 1, when results: 1, departure: when
}) })
const p = journeys[0].legs[0] const p = journeys[0].legs[0]
@ -205,7 +208,8 @@ test('journeys  station to address', co(function* (t) {
longitude: 13.350042 longitude: 13.350042
} }
const journeys = yield client.journeys(spichernstr, torfstr, { const journeys = yield client.journeys(spichernstr, torfstr, {
results: 3, when results: 3,
departure: when
}) })
yield testJourneysStationToAddress({ yield testJourneysStationToAddress({
@ -227,7 +231,8 @@ test('journeys  station to POI', co(function* (t) {
longitude: 13.351686 longitude: 13.351686
} }
const journeys = yield client.journeys(spichernstr, atze, { const journeys = yield client.journeys(spichernstr, atze, {
results: 3, when results: 3,
departure: when
}) })
yield testJourneysStationToPoi({ yield testJourneysStationToPoi({
@ -246,7 +251,7 @@ test('journeys: via works with detour', co(function* (t) {
const journeys = yield client.journeys(westhafen, wedding, { const journeys = yield client.journeys(westhafen, wedding, {
via: württembergallee, via: württembergallee,
results: 1, results: 1,
when, departure: when,
passedStations: true passedStations: true
}) })