Fix SearchPager bugs, improve test coverage

This commit is contained in:
Patrick Mooney 2014-07-25 14:16:31 -05:00
parent 8fd16ee255
commit de16802a16
2 changed files with 41 additions and 6 deletions

View File

@ -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'

View File

@ -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();
});