mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
earlier/later journeys test: use helper fn
This commit is contained in:
parent
b364269041
commit
6818635ee4
6 changed files with 102 additions and 245 deletions
56
test/db.js
56
test/db.js
|
@ -16,6 +16,7 @@ const {
|
||||||
} = require('./lib/validators')
|
} = require('./lib/validators')
|
||||||
const createValidate = require('./lib/validate-fptf-with')
|
const createValidate = require('./lib/validate-fptf-with')
|
||||||
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
||||||
|
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||||
|
|
||||||
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
|
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
|
||||||
|
|
||||||
|
@ -154,57 +155,14 @@ test('journeys: via works – with detour', co(function* (t) {
|
||||||
}))
|
}))
|
||||||
|
|
||||||
test('earlier/later journeys, Jungfernheide -> München Hbf', co(function* (t) {
|
test('earlier/later journeys, Jungfernheide -> München Hbf', co(function* (t) {
|
||||||
const model = yield client.journeys(jungfernheide, münchenHbf, {
|
yield testEarlierLaterJourneys({
|
||||||
results: 3, when
|
test: t,
|
||||||
|
fetchJourneys: client.journeys,
|
||||||
|
validate,
|
||||||
|
fromId: jungfernheide,
|
||||||
|
toId: münchenHbf
|
||||||
})
|
})
|
||||||
|
|
||||||
// todo: move to journeys validator?
|
|
||||||
t.equal(typeof model.earlierRef, 'string')
|
|
||||||
t.ok(model.earlierRef)
|
|
||||||
t.equal(typeof model.laterRef, 'string')
|
|
||||||
t.ok(model.laterRef)
|
|
||||||
|
|
||||||
// when and earlierThan/laterThan should be mutually exclusive
|
|
||||||
t.throws(() => {
|
|
||||||
client.journeys(jungfernheide, münchenHbf, {
|
|
||||||
when, earlierThan: model.earlierRef
|
|
||||||
})
|
|
||||||
// silence rejections, we're only interested in exceptions
|
|
||||||
.catch(() => {})
|
|
||||||
})
|
|
||||||
t.throws(() => {
|
|
||||||
client.journeys(jungfernheide, münchenHbf, {
|
|
||||||
when, laterThan: model.laterRef
|
|
||||||
})
|
|
||||||
// silence rejections, we're only interested in exceptions
|
|
||||||
.catch(() => {})
|
|
||||||
})
|
|
||||||
|
|
||||||
let earliestDep = Infinity, latestDep = -Infinity
|
|
||||||
for (let j of model) {
|
|
||||||
const dep = +new Date(j.legs[0].departure)
|
|
||||||
if (dep < earliestDep) earliestDep = dep
|
|
||||||
else if (dep > latestDep) latestDep = dep
|
|
||||||
}
|
|
||||||
|
|
||||||
const earlier = yield client.journeys(jungfernheide, münchenHbf, {
|
|
||||||
results: 3,
|
|
||||||
// todo: single journey ref?
|
|
||||||
earlierThan: model.earlierRef
|
|
||||||
})
|
|
||||||
for (let j of earlier) {
|
|
||||||
t.ok(new Date(j.legs[0].departure) < earliestDep)
|
|
||||||
}
|
|
||||||
|
|
||||||
const later = yield client.journeys(jungfernheide, münchenHbf, {
|
|
||||||
results: 3,
|
|
||||||
// todo: single journey ref?
|
|
||||||
laterThan: model.laterRef
|
|
||||||
})
|
|
||||||
for (let j of later) {
|
|
||||||
t.ok(new Date(j.legs[0].departure) > latestDep)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
56
test/insa.js
56
test/insa.js
|
@ -11,6 +11,7 @@ const insaProfile = require('../p/insa')
|
||||||
const products = require('../p/insa/products')
|
const products = require('../p/insa/products')
|
||||||
const createValidate = require('./lib/validate-fptf-with')
|
const createValidate = require('./lib/validate-fptf-with')
|
||||||
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
||||||
|
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||||
|
|
||||||
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
|
const isObj = o => o !== null && 'object' === typeof o && !Array.isArray(o)
|
||||||
|
|
||||||
|
@ -126,57 +127,14 @@ test('journeys: via works – with detour', co(function* (t) {
|
||||||
}))
|
}))
|
||||||
|
|
||||||
test('earlier/later journeys', co(function* (t) {
|
test('earlier/later journeys', co(function* (t) {
|
||||||
const model = yield client.journeys(magdeburgHbf, magdeburgBuckau, {
|
yield testEarlierLaterJourneys({
|
||||||
results: 3, when
|
test: t,
|
||||||
|
fetchJourneys: client.journeys,
|
||||||
|
validate,
|
||||||
|
fromId: magdeburgHbf,
|
||||||
|
toId: magdeburgBuckau
|
||||||
})
|
})
|
||||||
|
|
||||||
// todo: move to journeys validator?
|
|
||||||
t.equal(typeof model.earlierRef, 'string')
|
|
||||||
t.ok(model.earlierRef)
|
|
||||||
t.equal(typeof model.laterRef, 'string')
|
|
||||||
t.ok(model.laterRef)
|
|
||||||
|
|
||||||
// when and earlierThan/laterThan should be mutually exclusive
|
|
||||||
t.throws(() => {
|
|
||||||
client.journeys(magdeburgHbf, magdeburgBuckau, {
|
|
||||||
when, earlierThan: model.earlierRef
|
|
||||||
})
|
|
||||||
// silence rejections, we're only interested in exceptions
|
|
||||||
.catch(() => {})
|
|
||||||
})
|
|
||||||
t.throws(() => {
|
|
||||||
client.journeys(magdeburgHbf, magdeburgBuckau, {
|
|
||||||
when, laterThan: model.laterRef
|
|
||||||
})
|
|
||||||
// silence rejections, we're only interested in exceptions
|
|
||||||
.catch(() => {})
|
|
||||||
})
|
|
||||||
|
|
||||||
let earliestDep = Infinity, latestDep = -Infinity
|
|
||||||
for (let j of model) {
|
|
||||||
const dep = +new Date(j.legs[0].departure)
|
|
||||||
if (dep < earliestDep) earliestDep = dep
|
|
||||||
else if (dep > latestDep) latestDep = dep
|
|
||||||
}
|
|
||||||
|
|
||||||
const earlier = yield client.journeys(magdeburgHbf, magdeburgBuckau, {
|
|
||||||
results: 3,
|
|
||||||
// todo: single journey ref?
|
|
||||||
earlierThan: model.earlierRef
|
|
||||||
})
|
|
||||||
for (let j of earlier) {
|
|
||||||
t.ok(new Date(j.legs[0].departure) < earliestDep)
|
|
||||||
}
|
|
||||||
|
|
||||||
const later = yield client.journeys(magdeburgHbf, magdeburgBuckau, {
|
|
||||||
results: 3,
|
|
||||||
// todo: single journey ref?
|
|
||||||
laterThan: model.laterRef
|
|
||||||
})
|
|
||||||
for (let j of later) {
|
|
||||||
t.ok(new Date(j.legs[0].departure) > latestDep)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
67
test/lib/earlier-later-journeys.js
Normal file
67
test/lib/earlier-later-journeys.js
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const co = require('./co')
|
||||||
|
|
||||||
|
const testEarlierLaterJourneys = co(function* (cfg) {
|
||||||
|
const {
|
||||||
|
test: t,
|
||||||
|
fetchJourneys,
|
||||||
|
fromId,
|
||||||
|
toId,
|
||||||
|
when,
|
||||||
|
// todo: validate
|
||||||
|
} = cfg
|
||||||
|
|
||||||
|
const model = yield fetchJourneys(fromId, toId, {
|
||||||
|
results: 3, when
|
||||||
|
})
|
||||||
|
|
||||||
|
// todo: move to journeys validator?
|
||||||
|
t.equal(typeof model.earlierRef, 'string')
|
||||||
|
t.ok(model.earlierRef)
|
||||||
|
t.equal(typeof model.laterRef, 'string')
|
||||||
|
t.ok(model.laterRef)
|
||||||
|
|
||||||
|
// when and earlierThan/laterThan should be mutually exclusive
|
||||||
|
t.throws(() => {
|
||||||
|
fetchJourneys(fromId, toId, {
|
||||||
|
when, earlierThan: model.earlierRef
|
||||||
|
})
|
||||||
|
// silence rejections, we're only interested in exceptions
|
||||||
|
.catch(() => {})
|
||||||
|
})
|
||||||
|
t.throws(() => {
|
||||||
|
fetchJourneys(fromId, toId, {
|
||||||
|
when, laterThan: model.laterRef
|
||||||
|
})
|
||||||
|
// silence rejections, we're only interested in exceptions
|
||||||
|
.catch(() => {})
|
||||||
|
})
|
||||||
|
|
||||||
|
let earliestDep = Infinity, latestDep = -Infinity
|
||||||
|
for (let j of model) {
|
||||||
|
const dep = +new Date(j.legs[0].departure)
|
||||||
|
if (dep < earliestDep) earliestDep = dep
|
||||||
|
else if (dep > latestDep) latestDep = dep
|
||||||
|
}
|
||||||
|
|
||||||
|
const earlier = yield fetchJourneys(fromId, toId, {
|
||||||
|
results: 3,
|
||||||
|
// todo: single journey ref?
|
||||||
|
earlierThan: model.earlierRef
|
||||||
|
})
|
||||||
|
for (let j of earlier) {
|
||||||
|
t.ok(new Date(j.legs[0].departure) < earliestDep)
|
||||||
|
}
|
||||||
|
|
||||||
|
const later = yield fetchJourneys(fromId, toId, {
|
||||||
|
results: 3,
|
||||||
|
// todo: single journey ref?
|
||||||
|
laterThan: model.laterRef
|
||||||
|
})
|
||||||
|
for (let j of later) {
|
||||||
|
t.ok(new Date(j.legs[0].departure) > latestDep)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = testEarlierLaterJourneys
|
|
@ -15,6 +15,7 @@ const {
|
||||||
} = require('./lib/validators')
|
} = require('./lib/validators')
|
||||||
const createValidate = require('./lib/validate-fptf-with')
|
const createValidate = require('./lib/validate-fptf-with')
|
||||||
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
||||||
|
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||||
|
|
||||||
const when = createWhen('Europe/Berlin', 'de-DE')
|
const when = createWhen('Europe/Berlin', 'de-DE')
|
||||||
|
|
||||||
|
@ -153,57 +154,14 @@ test('Husum to Lübeck Hbf with stopover at Kiel Hbf', co(function* (t) {
|
||||||
}))
|
}))
|
||||||
|
|
||||||
test('earlier/later journeys, Kiel Hbf -> Flensburg', co(function* (t) {
|
test('earlier/later journeys, Kiel Hbf -> Flensburg', co(function* (t) {
|
||||||
const model = yield client.journeys(kielHbf, flensburg, {
|
yield testEarlierLaterJourneys({
|
||||||
results: 3, when
|
test: t,
|
||||||
|
fetchJourneys: client.journeys,
|
||||||
|
validate,
|
||||||
|
fromId: kielHbf,
|
||||||
|
toId: flensburg
|
||||||
})
|
})
|
||||||
|
|
||||||
// todo: move to journeys validator?
|
|
||||||
t.equal(typeof model.earlierRef, 'string')
|
|
||||||
t.ok(model.earlierRef)
|
|
||||||
t.equal(typeof model.laterRef, 'string')
|
|
||||||
t.ok(model.laterRef)
|
|
||||||
|
|
||||||
// when and earlierThan/laterThan should be mutually exclusive
|
|
||||||
t.throws(() => {
|
|
||||||
client.journeys(kielHbf, flensburg, {
|
|
||||||
when, earlierThan: model.earlierRef
|
|
||||||
})
|
|
||||||
// silence rejections, we're only interested in exceptions
|
|
||||||
.catch(() => {})
|
|
||||||
})
|
|
||||||
t.throws(() => {
|
|
||||||
client.journeys(kielHbf, flensburg, {
|
|
||||||
when, laterThan: model.laterRef
|
|
||||||
})
|
|
||||||
// silence rejections, we're only interested in exceptions
|
|
||||||
.catch(() => {})
|
|
||||||
})
|
|
||||||
|
|
||||||
let earliestDep = Infinity, latestDep = -Infinity
|
|
||||||
for (let j of model) {
|
|
||||||
const dep = +new Date(j.legs[0].departure)
|
|
||||||
if (dep < earliestDep) earliestDep = dep
|
|
||||||
else if (dep > latestDep) latestDep = dep
|
|
||||||
}
|
|
||||||
|
|
||||||
const earlier = yield client.journeys(kielHbf, flensburg, {
|
|
||||||
results: 3,
|
|
||||||
// todo: single journey ref?
|
|
||||||
earlierThan: model.earlierRef
|
|
||||||
})
|
|
||||||
for (let j of earlier) {
|
|
||||||
t.ok(new Date(j.legs[0].departure) < earliestDep)
|
|
||||||
}
|
|
||||||
|
|
||||||
const later = yield client.journeys(kielHbf, flensburg, {
|
|
||||||
results: 3,
|
|
||||||
// todo: single journey ref?
|
|
||||||
laterThan: model.laterRef
|
|
||||||
})
|
|
||||||
for (let j of later) {
|
|
||||||
t.ok(new Date(j.legs[0].departure) > latestDep)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
56
test/oebb.js
56
test/oebb.js
|
@ -15,6 +15,7 @@ const {
|
||||||
} = require('./lib/validators')
|
} = require('./lib/validators')
|
||||||
const createValidate = require('./lib/validate-fptf-with')
|
const createValidate = require('./lib/validate-fptf-with')
|
||||||
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
||||||
|
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||||
|
|
||||||
const when = createWhen('Europe/Vienna', 'de-AT')
|
const when = createWhen('Europe/Vienna', 'de-AT')
|
||||||
|
|
||||||
|
@ -187,57 +188,14 @@ test('journeys: via works – without detour', co(function* (t) {
|
||||||
}))
|
}))
|
||||||
|
|
||||||
test('earlier/later journeys, Salzburg Hbf -> Wien Westbahnhof', co(function* (t) {
|
test('earlier/later journeys, Salzburg Hbf -> Wien Westbahnhof', co(function* (t) {
|
||||||
const model = yield client.journeys(salzburgHbf, wienWestbahnhof, {
|
yield testEarlierLaterJourneys({
|
||||||
results: 3, when
|
test: t,
|
||||||
|
fetchJourneys: client.journeys,
|
||||||
|
validate,
|
||||||
|
fromId: salzburgHbf,
|
||||||
|
toId: wienWestbahnhof
|
||||||
})
|
})
|
||||||
|
|
||||||
// todo: move to journeys validator?
|
|
||||||
t.equal(typeof model.earlierRef, 'string')
|
|
||||||
t.ok(model.earlierRef)
|
|
||||||
t.equal(typeof model.laterRef, 'string')
|
|
||||||
t.ok(model.laterRef)
|
|
||||||
|
|
||||||
// when and earlierThan/laterThan should be mutually exclusive
|
|
||||||
t.throws(() => {
|
|
||||||
client.journeys(salzburgHbf, wienWestbahnhof, {
|
|
||||||
when, earlierThan: model.earlierRef
|
|
||||||
})
|
|
||||||
// silence rejections, we're only interested in exceptions
|
|
||||||
.catch(() => {})
|
|
||||||
})
|
|
||||||
t.throws(() => {
|
|
||||||
client.journeys(salzburgHbf, wienWestbahnhof, {
|
|
||||||
when, laterThan: model.laterRef
|
|
||||||
})
|
|
||||||
// silence rejections, we're only interested in exceptions
|
|
||||||
.catch(() => {})
|
|
||||||
})
|
|
||||||
|
|
||||||
let earliestDep = Infinity, latestDep = -Infinity
|
|
||||||
for (let j of model) {
|
|
||||||
const dep = +new Date(j.legs[0].departure)
|
|
||||||
if (dep < earliestDep) earliestDep = dep
|
|
||||||
else if (dep > latestDep) latestDep = dep
|
|
||||||
}
|
|
||||||
|
|
||||||
const earlier = yield client.journeys(salzburgHbf, wienWestbahnhof, {
|
|
||||||
results: 3,
|
|
||||||
// todo: single journey ref?
|
|
||||||
earlierThan: model.earlierRef
|
|
||||||
})
|
|
||||||
for (let j of earlier) {
|
|
||||||
t.ok(new Date(j.legs[0].departure) < earliestDep)
|
|
||||||
}
|
|
||||||
|
|
||||||
const later = yield client.journeys(salzburgHbf, wienWestbahnhof, {
|
|
||||||
results: 3,
|
|
||||||
// todo: single journey ref?
|
|
||||||
laterThan: model.laterRef
|
|
||||||
})
|
|
||||||
for (let j of later) {
|
|
||||||
t.ok(new Date(j.legs[0].departure) > latestDep)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
56
test/vbb.js
56
test/vbb.js
|
@ -21,6 +21,7 @@ const {
|
||||||
} = require('./lib/validators')
|
} = require('./lib/validators')
|
||||||
const createValidate = require('./lib/validate-fptf-with')
|
const createValidate = require('./lib/validate-fptf-with')
|
||||||
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
const testJourneysStationToStation = require('./lib/journeys-station-to-station')
|
||||||
|
const testEarlierLaterJourneys = require('./lib/earlier-later-journeys')
|
||||||
|
|
||||||
const when = createWhen('Europe/Berlin', 'de-DE')
|
const when = createWhen('Europe/Berlin', 'de-DE')
|
||||||
|
|
||||||
|
@ -180,57 +181,14 @@ test('journeys – fails with no product', (t) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test('earlier/later journeys', co(function* (t) {
|
test('earlier/later journeys', co(function* (t) {
|
||||||
const model = yield client.journeys(spichernstr, bismarckstr, {
|
yield testEarlierLaterJourneys({
|
||||||
results: 3, when
|
test: t,
|
||||||
|
fetchJourneys: client.journeys,
|
||||||
|
validate,
|
||||||
|
fromId: spichernstr,
|
||||||
|
toId: bismarckstr
|
||||||
})
|
})
|
||||||
|
|
||||||
// todo: move to journeys validator?
|
|
||||||
t.equal(typeof model.earlierRef, 'string')
|
|
||||||
t.ok(model.earlierRef)
|
|
||||||
t.equal(typeof model.laterRef, 'string')
|
|
||||||
t.ok(model.laterRef)
|
|
||||||
|
|
||||||
// when and earlierThan/laterThan should be mutually exclusive
|
|
||||||
t.throws(() => {
|
|
||||||
client.journeys(spichernstr, bismarckstr, {
|
|
||||||
when, earlierThan: model.earlierRef
|
|
||||||
})
|
|
||||||
// silence rejections, we're only interested in exceptions
|
|
||||||
.catch(() => {})
|
|
||||||
})
|
|
||||||
t.throws(() => {
|
|
||||||
client.journeys(spichernstr, bismarckstr, {
|
|
||||||
when, laterThan: model.laterRef
|
|
||||||
})
|
|
||||||
// silence rejections, we're only interested in exceptions
|
|
||||||
.catch(() => {})
|
|
||||||
})
|
|
||||||
|
|
||||||
let earliestDep = Infinity, latestDep = -Infinity
|
|
||||||
for (let j of model) {
|
|
||||||
const dep = +new Date(j.legs[0].departure)
|
|
||||||
if (dep < earliestDep) earliestDep = dep
|
|
||||||
else if (dep > latestDep) latestDep = dep
|
|
||||||
}
|
|
||||||
|
|
||||||
const earlier = yield client.journeys(spichernstr, bismarckstr, {
|
|
||||||
results: 3,
|
|
||||||
// todo: single journey ref?
|
|
||||||
earlierThan: model.earlierRef
|
|
||||||
})
|
|
||||||
for (let j of earlier) {
|
|
||||||
t.ok(new Date(j.legs[0].departure) < earliestDep)
|
|
||||||
}
|
|
||||||
|
|
||||||
const later = yield client.journeys(spichernstr, bismarckstr, {
|
|
||||||
results: 3,
|
|
||||||
// todo: single journey ref?
|
|
||||||
laterThan: model.laterRef
|
|
||||||
})
|
|
||||||
for (let j of later) {
|
|
||||||
t.ok(new Date(j.legs[0].departure) > latestDep)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue