Skip to content

Commit 82694ba

Browse files
Merge pull request #172 from kuzzleio/topic-fix-scroll-and-next
Fix scroll action and next on searchResult
2 parents 32587ae + 1bc0dbd commit 82694ba

File tree

5 files changed

+32
-33
lines changed

5 files changed

+32
-33
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kuzzle-sdk",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "Official Javascript SDK for Kuzzle",
55
"author": "The Kuzzle Team <support@kuzzle.io>",
66
"repository": {

src/Collection.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,11 @@ Collection.prototype.search = function (filters, options, cb) {
490490
*/
491491
Collection.prototype.scroll = function (scrollId, options, filters, cb) {
492492
var
493-
request = {body: {}},
493+
request = {body:{}},
494494
self = this;
495495

496496
if (!scrollId) {
497-
throw new Error('Collection.scroll: scrollId required');
497+
throw new Error('Collection.scroll: scrollId is required');
498498
}
499499

500500
if (!cb) {
@@ -511,6 +511,10 @@ Collection.prototype.scroll = function (scrollId, options, filters, cb) {
511511
options = {};
512512
}
513513

514+
if (!options.scroll) {
515+
throw new Error('Collection.scroll: scroll is required');
516+
}
517+
514518
options.scrollId = scrollId;
515519

516520
this.kuzzle.callbackRequired('Collection.scroll', cb);

src/Kuzzle.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,14 +1283,22 @@ Kuzzle.prototype.query = function (queryArgs, query, options, cb) {
12831283
object.refresh = options.refresh;
12841284
}
12851285

1286-
if (options.from) {
1286+
if (typeof options.from !== 'undefined' && options.from !== null) {
12871287
object.from = options.from;
12881288
}
12891289

12901290
if (options.size) {
12911291
object.size = options.size;
12921292
}
12931293

1294+
if (options.scroll) {
1295+
object.scroll = options.scroll;
1296+
}
1297+
1298+
if (options.scrollId) {
1299+
object.scrollId = options.scrollId;
1300+
}
1301+
12941302
if (options.metadata) {
12951303
Object.keys(options.metadata).forEach(function (meta) {
12961304
object.metadata[meta] = options.metadata[meta];

src/SearchResult.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ KuzzleSearchResult.prototype.next = function (cb) {
9494
return;
9595
}
9696

97+
// from and size parameters are not valid for a scroll action
98+
if (options.from) {
99+
delete options.from;
100+
}
101+
102+
if (options.size) {
103+
delete options.size;
104+
}
105+
97106
this.dataCollection.scroll(
98107
options.scrollId,
99108
options,

test/kuzzleDataCollection/methods.test.js

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,17 @@ describe('Collection methods', function () {
146146

147147
it('should throw an error if no scrollId is set', () => {
148148
var collection = kuzzle.collection(expectedQuery.collection);
149-
should(() => { collection.scroll(); }).throw('Collection.scroll: scrollId required');
149+
should(() => { collection.scroll(); }).throw('Collection.scroll: scrollId is required');
150+
});
151+
152+
it('should throw an error if no scroll is provided', () => {
153+
var collection = kuzzle.collection(expectedQuery.collection);
154+
should(() => { collection.scroll('scrollId'); }).throw('Collection.scroll: scroll is required');
150155
});
151156

152157
it('should throw an error if no callback is given', () => {
153158
var collection = kuzzle.collection(expectedQuery.collection);
154-
should(() => { collection.scroll('scrollId'); }).throw('Collection.scroll: a callback argument is required for read queries');
159+
should(() => { collection.scroll('scrollId', {scroll: '1m'}); }).throw('Collection.scroll: a callback argument is required for read queries');
155160
});
156161

157162
it('should parse the given parameters', done => {
@@ -189,33 +194,6 @@ describe('Collection methods', function () {
189194

190195
collection.scroll(scrollId, options, filters, cb);
191196
});
192-
193-
it('should parse the given parameters even if no options is given', done => {
194-
var
195-
queryScrollStub,
196-
collection = kuzzle.collection(expectedQuery.collection),
197-
scrollId = 'scrollId',
198-
cb = () => {
199-
done();
200-
};
201-
202-
queryScrollStub = function (args, query, opts, callback) {
203-
should(args.controller).be.exactly('document');
204-
should(args.action).be.exactly('scroll');
205-
should(opts.scrollId).be.exactly(scrollId);
206-
207-
callback(null, {
208-
result: {
209-
total: 0,
210-
hits: []
211-
}
212-
});
213-
};
214-
215-
kuzzle.query = queryScrollStub;
216-
217-
collection.scroll(scrollId, cb);
218-
});
219197
});
220198

221199
describe('#count', function () {

0 commit comments

Comments
 (0)