From c835467d855fa7fa049b5c54d4fb9ce88eaae832 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Sun, 4 Mar 2018 20:41:26 +0100 Subject: [PATCH] beforeJourneys -> earlierThan, afterJourneys -> laterThan --- index.js | 24 ++++++++++++------------ test/db.js | 16 ++++++++++++++-- test/oebb.js | 16 ++++++++++++++-- test/vbb.js | 16 ++++++++++++++-- 4 files changed, 54 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 21826517..5e38e696 100644 --- a/index.js +++ b/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({ diff --git a/test/db.js b/test/db.js index 56ff0ce2..f38d2ddd 100644 --- a/test/db.js +++ b/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) diff --git a/test/oebb.js b/test/oebb.js index eb7bd7ec..178c58db 100644 --- a/test/oebb.js +++ b/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) diff --git a/test/vbb.js b/test/vbb.js index 908ae980..50a86e5f 100644 --- a/test/vbb.js +++ b/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)