From de16802a16faf56fedb95e1b8a9b3d80bd8cbc18 Mon Sep 17 00:00:00 2001 From: Patrick Mooney Date: Fri, 25 Jul 2014 14:16:31 -0500 Subject: [PATCH] Fix SearchPager bugs, improve test coverage --- lib/client/search_pager.js | 7 +------ test/client.test.js | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/lib/client/search_pager.js b/lib/client/search_pager.js index 9eb87ca..2e1088f 100644 --- a/lib/client/search_pager.js +++ b/lib/client/search_pager.js @@ -73,11 +73,6 @@ SearchPager.prototype.begin = function begin() { this._nextPage(null); }; - -SearchPager.prototype._onEntry = function _onEntry(entry) { - this.emit('searchEntry', entry); -}; - SearchPager.prototype._onEnd = function _onEnd(res) { var self = this; var cookie = null; @@ -95,7 +90,7 @@ SearchPager.prototype._onEnd = function _onEnd(res) { this.emit('page', res, nullCb); var err = new Error('missing paged control'); err.name = 'PagedError'; - if (this.listeners('pageError') > 0) { + if (this.listeners('pageError').length > 0) { this.emit('pageError', err); // If the consumer as subscribed to pageError, SearchPager is absolved // from deliverying the fault via the 'error' event. Emitting an 'end' diff --git a/test/client.test.js b/test/client.test.js index 14f6e89..b9fcab1 100644 --- a/test/client.test.js +++ b/test/client.test.js @@ -627,6 +627,46 @@ test('search paged', function (t) { }); }); + t.test('paged - no support (err handled)', function (t2) { + client.search(SUFFIX, { + paged: { pageSize: 100 } + }, function (err, res) { + t2.ifError(err); + res.on('pageError', t2.ok.bind(t2)); + res.on('end', function () { + t2.pass(); + t2.end(); + }); + }); + }); + + t.test('paged - no support (err not handled)', function (t2) { + client.search(SUFFIX, { + paged: { pageSize: 100 } + }, function (err, res) { + t2.ifError(err); + res.on('end', t2.fail.bind(t2)); + res.on('error', function (error) { + t2.ok(error); + t2.end(); + }); + }); + }); + + t.test('paged - redundant control', function (t2) { + try { + client.search(SUFFIX, { + paged: { pageSize: 100 }, + }, new ldap.PagedResultsControl(), + function (err, res) { + t2.fail(); + }); + } catch (e) { + t2.ok(e); + t2.end(); + } + }); + t.end(); });