From 7b903d5ca6830cd8bf67c60249b86abec19bd9cc Mon Sep 17 00:00:00 2001 From: Jeff McAffer Date: Sat, 12 Nov 2016 09:46:00 -0800 Subject: [PATCH] fix event tests --- lib/eventFinder.js | 17 +++++++++++------ test/eventFinderTests.js | 7 ++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/eventFinder.js b/lib/eventFinder.js index 03da1e3..026488d 100644 --- a/lib/eventFinder.js +++ b/lib/eventFinder.js @@ -25,15 +25,20 @@ class EventFinder { } getNewEvents(eventSource) { - const self = this; - return this.requestor.getAll(eventSource).then(self._findNew.bind(self)); + return this.requestor.getAll(eventSource).then(this._findNew.bind(this)); } + // Find the events for which we do NOT have a document. _findNew(events) { - const limit = qlimit(10); - return Q.all(events.filter(limit(event => { - return !this.eventStore.etag('event', event.url, (err, tag)); - }))); + const self = this; + return Q.all(events.map(qlimit(10)(event => { + return self.eventStore.etag('event', event.url).then(etag => { + return etag ? null : event; + }); + }))).then(events => { + return events.filter(event =>event); + }); } } + module.exports = EventFinder; \ No newline at end of file diff --git a/test/eventFinderTests.js b/test/eventFinderTests.js index b09d669..d7de2fa 100644 --- a/test/eventFinderTests.js +++ b/test/eventFinderTests.js @@ -18,6 +18,7 @@ describe('Event Finder', () => { expect(found[0].url).to.be.equal('http://test1'); }); }); + it('will not find any documents', () => { const events = [ [{ url: 'http://test1' }, { url: 'http://test2' }] @@ -29,6 +30,7 @@ describe('Event Finder', () => { expect(found.length).to.be.equal(0); }); }); + it('will stop not finding at first found document', () => { const events = [ [{ url: 'http://test1' }, { url: 'http://test2' }, { url: 'http://test3' }] @@ -64,10 +66,9 @@ function createStore(documents) { extend(collection, document); return collection; }, {}); - result.etag = (type, url, callback) => { + result.etag = (type, url) => { let result = hash[url]; - result = result ? result.etag : null; - return callback ? callback(null, result) : Q(result); + return Q(result ? result.etag : null); }; return result; } \ No newline at end of file