mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
beforeJourneys -> earlierThan, afterJourneys -> laterThan
This commit is contained in:
parent
88c511da27
commit
c835467d85
4 changed files with 54 additions and 18 deletions
24
index.js
24
index.js
|
@ -52,27 +52,27 @@ const createClient = (profile, request = _request) => {
|
|||
from = profile.formatLocation(profile, from)
|
||||
to = profile.formatLocation(profile, to)
|
||||
|
||||
if (('beforeJourneys' in opt) && ('afterJourneys' in opt)) {
|
||||
throw new Error('opt.afterJourneys and opt.afterJourneys are mutually exclusive.')
|
||||
if (('earlierThan' in opt) && ('laterThan' in opt)) {
|
||||
throw new Error('opt.laterThan and opt.laterThan are mutually exclusive.')
|
||||
}
|
||||
let journeysRef = null
|
||||
if ('beforeJourneys' in opt) {
|
||||
if (!isNonEmptyString(opt.beforeJourneys)) {
|
||||
throw new Error('opt.beforeJourneys must be a non-empty string.')
|
||||
if ('earlierThan' in opt) {
|
||||
if (!isNonEmptyString(opt.earlierThan)) {
|
||||
throw new Error('opt.earlierThan must be a non-empty string.')
|
||||
}
|
||||
if ('when' in opt) {
|
||||
throw new Error('opt.beforeJourneys and opt.when are mutually exclusive.')
|
||||
throw new Error('opt.earlierThan and opt.when are mutually exclusive.')
|
||||
}
|
||||
journeysRef = opt.beforeJourneys
|
||||
journeysRef = opt.earlierThan
|
||||
}
|
||||
if ('afterJourneys' in opt) {
|
||||
if (!isNonEmptyString(opt.afterJourneys)) {
|
||||
throw new Error('opt.afterJourneys must be a non-empty string.')
|
||||
if ('laterThan' in opt) {
|
||||
if (!isNonEmptyString(opt.laterThan)) {
|
||||
throw new Error('opt.laterThan must be a non-empty string.')
|
||||
}
|
||||
if ('when' in opt) {
|
||||
throw new Error('opt.afterJourneys and opt.when are mutually exclusive.')
|
||||
throw new Error('opt.laterThan and opt.when are mutually exclusive.')
|
||||
}
|
||||
journeysRef = opt.afterJourneys
|
||||
journeysRef = opt.laterThan
|
||||
}
|
||||
|
||||
opt = Object.assign({
|
||||
|
|
16
test/db.js
16
test/db.js
|
@ -243,6 +243,18 @@ test('earlier/later journeys, Jungfernheide -> München Hbf', co(function* (t) {
|
|||
t.equal(typeof model.laterRef, 'string')
|
||||
t.ok(model.laterRef)
|
||||
|
||||
// when and earlierThan/laterThan should be mutually exclusive
|
||||
t.throws(() => {
|
||||
client.journeys(jungfernh, münchenHbf, {
|
||||
when, earlierThan: model.earlierRef
|
||||
})
|
||||
})
|
||||
t.throws(() => {
|
||||
client.journeys(jungfernh, münchenHbf, {
|
||||
when, laterThan: model.laterRef
|
||||
})
|
||||
})
|
||||
|
||||
let earliestDep = Infinity, latestDep = -Infinity
|
||||
for (let j of model) {
|
||||
const dep = +new Date(j.departure)
|
||||
|
@ -253,7 +265,7 @@ test('earlier/later journeys, Jungfernheide -> München Hbf', co(function* (t) {
|
|||
const earlier = yield client.journeys(jungfernh, münchenHbf, {
|
||||
results: 3,
|
||||
// todo: single journey ref?
|
||||
beforeJourneys: model.earlierRef
|
||||
earlierThan: model.earlierRef
|
||||
})
|
||||
for (let j of earlier) {
|
||||
t.ok(new Date(j.departure) < earliestDep)
|
||||
|
@ -262,7 +274,7 @@ test('earlier/later journeys, Jungfernheide -> München Hbf', co(function* (t) {
|
|||
const later = yield client.journeys(jungfernh, münchenHbf, {
|
||||
results: 3,
|
||||
// todo: single journey ref?
|
||||
afterJourneys: model.laterRef
|
||||
laterThan: model.laterRef
|
||||
})
|
||||
for (let j of later) {
|
||||
t.ok(new Date(j.departure) > latestDep)
|
||||
|
|
16
test/oebb.js
16
test/oebb.js
|
@ -284,6 +284,18 @@ test('earlier/later journeys, Salzburg Hbf -> Wien Westbahnhof', co(function* (t
|
|||
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
|
||||
})
|
||||
})
|
||||
t.throws(() => {
|
||||
client.journeys(salzburgHbf, wienWestbahnhof, {
|
||||
when, laterThan: model.laterRef
|
||||
})
|
||||
})
|
||||
|
||||
let earliestDep = Infinity, latestDep = -Infinity
|
||||
for (let j of model) {
|
||||
const dep = +new Date(j.departure)
|
||||
|
@ -294,7 +306,7 @@ test('earlier/later journeys, Salzburg Hbf -> Wien Westbahnhof', co(function* (t
|
|||
const earlier = yield client.journeys(salzburgHbf, wienWestbahnhof, {
|
||||
results: 3,
|
||||
// todo: single journey ref?
|
||||
beforeJourneys: model.earlierRef
|
||||
earlierThan: model.earlierRef
|
||||
})
|
||||
for (let j of earlier) {
|
||||
t.ok(new Date(j.departure) < earliestDep)
|
||||
|
@ -303,7 +315,7 @@ test('earlier/later journeys, Salzburg Hbf -> Wien Westbahnhof', co(function* (t
|
|||
const later = yield client.journeys(salzburgHbf, wienWestbahnhof, {
|
||||
results: 3,
|
||||
// todo: single journey ref?
|
||||
afterJourneys: model.laterRef
|
||||
laterThan: model.laterRef
|
||||
})
|
||||
for (let j of later) {
|
||||
t.ok(new Date(j.departure) > latestDep)
|
||||
|
|
16
test/vbb.js
16
test/vbb.js
|
@ -178,6 +178,18 @@ test('earlier/later journeys', co(function* (t) {
|
|||
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
|
||||
})
|
||||
})
|
||||
t.throws(() => {
|
||||
client.journeys(spichernstr, bismarckstr, {
|
||||
when, laterThan: model.laterRef
|
||||
})
|
||||
})
|
||||
|
||||
let earliestDep = Infinity, latestDep = -Infinity
|
||||
for (let j of model) {
|
||||
const dep = +new Date(j.departure)
|
||||
|
@ -188,7 +200,7 @@ test('earlier/later journeys', co(function* (t) {
|
|||
const earlier = yield client.journeys(spichernstr, bismarckstr, {
|
||||
results: 3,
|
||||
// todo: single journey ref?
|
||||
beforeJourneys: model.earlierRef
|
||||
earlierThan: model.earlierRef
|
||||
})
|
||||
for (let j of earlier) {
|
||||
t.ok(new Date(j.departure) < earliestDep)
|
||||
|
@ -197,7 +209,7 @@ test('earlier/later journeys', co(function* (t) {
|
|||
const later = yield client.journeys(spichernstr, bismarckstr, {
|
||||
results: 3,
|
||||
// todo: single journey ref?
|
||||
afterJourneys: model.laterRef
|
||||
laterThan: model.laterRef
|
||||
})
|
||||
for (let j of later) {
|
||||
t.ok(new Date(j.departure) > latestDep)
|
||||
|
|
Loading…
Add table
Reference in a new issue