Skip to content

Commit 2ab175a

Browse files
committed
Merge remote-tracking branch 'origin/develop' into develop-implement-scroll
2 parents 6d23b14 + 6211c10 commit 2ab175a

File tree

5 files changed

+39
-29
lines changed

5 files changed

+39
-29
lines changed

src/kuzzle.js

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

1286+
if (options.from) {
1287+
object.from = options.from;
1288+
}
1289+
1290+
if (options.size) {
1291+
object.size = options.size;
1292+
}
1293+
12861294
if (options.metadata) {
12871295
Object.keys(options.metadata).forEach(function (meta) {
12881296
object.metadata[meta] = options.metadata[meta];

src/kuzzleDataCollection.js

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -288,28 +288,6 @@ KuzzleDataCollection.prototype.fetchAllDocuments = function (options, cb) {
288288
options = null;
289289
}
290290

291-
// copying pagination options to the search filter
292-
if (options && options.scroll) {
293-
filters.scroll = options.scroll;
294-
delete options.scroll;
295-
}
296-
297-
if (options && options.from) {
298-
filters.from = options.from;
299-
delete options.from;
300-
}
301-
else {
302-
filters.from = 0;
303-
}
304-
305-
if (options && options.size) {
306-
filters.size = options.size;
307-
delete options.size;
308-
}
309-
else {
310-
filters.size = 1000;
311-
}
312-
313291
this.kuzzle.callbackRequired('KuzzleDataCollection.fetchAllDocuments', cb);
314292

315293
this.search(filters, options, function getNextDocuments (error, searchResult) {
@@ -516,7 +494,7 @@ KuzzleDataCollection.prototype.scroll = function (scrollId, options, filters, cb
516494

517495
this.kuzzle.callbackRequired('KuzzleDataCollection.scroll', cb);
518496

519-
this.kuzzle.query({controller: 'read', action: 'scroll'}, request, options, function (error, result) {
497+
this.kuzzle.query({controller: 'document', action: 'scroll'}, request, options, function (error, result) {
520498
var documents = [];
521499

522500
if (error) {

test/kuzzle/methods.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,12 @@ describe('Kuzzle methods', function () {
345345
});
346346

347347
it('should handle from option correctly', function (done) {
348-
expectedQuery.body.from = 'foobar';
348+
expectedQuery.from = 'foobar';
349349
kuzzle.listCollections('foo', {from: 'foobar'}, () => done());
350350
});
351351

352352
it('should handle size option correctly', function (done) {
353-
expectedQuery.body.size = 'foobar';
353+
expectedQuery.size = 'foobar';
354354
kuzzle.listCollections('foo', {size: 'foobar'}, () => done());
355355
});
356356

test/kuzzle/query.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,22 @@ describe('Query management', function () {
172172
should(requestObject.refresh).match(refresh);
173173
});
174174

175+
it('should handle option size properly', function () {
176+
var
177+
size = 'foo';
178+
179+
kuzzle.query(queryArgs, { body: { some: 'query'}}, {size: size});
180+
should(requestObject.size).match(size);
181+
});
182+
183+
it('should handle option from properly', function () {
184+
var
185+
from = 'foo';
186+
187+
kuzzle.query(queryArgs, { body: { some: 'query'}}, {from: from});
188+
should(requestObject.from).match(from);
189+
});
190+
175191
it('should exit early if the query is not queuable and the SDK is offline', function () {
176192
kuzzle.state = 'offline';
177193
kuzzle.query(queryArgs, { body: { some: 'query'}}, {queuable: false});

test/kuzzleDataCollection/methods.test.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ describe('KuzzleDataCollection methods', function () {
166166
};
167167

168168
queryScrollStub = function (args, query, opts, callback) {
169-
should(args.controller).be.exactly('read');
169+
should(args.controller).be.exactly('document');
170170
should(args.action).be.exactly('scroll');
171171
should(query.body.scroll).be.exactly(options.scroll);
172172
should(query.body.scrollId).be.exactly(scrollId);
@@ -201,7 +201,7 @@ describe('KuzzleDataCollection methods', function () {
201201
};
202202

203203
queryScrollStub = function (args, query, opts, callback) {
204-
should(args.controller).be.exactly('read');
204+
should(args.controller).be.exactly('document');
205205
should(args.action).be.exactly('scroll');
206206
should(query.body.scrollId).be.exactly(scrollId);
207207
should(opts).be.null();
@@ -601,6 +601,13 @@ describe('KuzzleDataCollection methods', function () {
601601
beforeEach(function () {
602602
kuzzle = new Kuzzle('foo', {defaultIndex: 'bar'});
603603
emitted = false;
604+
expectedQuery = {
605+
index: 'bar',
606+
collection: 'foo',
607+
action: 'get',
608+
controller: 'document',
609+
body: {}
610+
};
604611
});
605612

606613
it('should forward the query to the search method', function () {
@@ -652,7 +659,7 @@ describe('KuzzleDataCollection methods', function () {
652659

653660
collection.fetchAllDocuments({from: 123, size: 456}, function () {});
654661
should(stub.calledOnce).be.true();
655-
should(stub.calledWithMatch({from: 123, size: 456})).be.true();
662+
should(stub.calledWithMatch({}, {from: 123, size: 456})).be.true();
656663
stub.restore();
657664
});
658665

@@ -663,7 +670,8 @@ describe('KuzzleDataCollection methods', function () {
663670

664671
collection.fetchAllDocuments({scroll: '30s'}, function () {});
665672
should(stub.calledOnce).be.true();
666-
should(stub.calledWithMatch({from: 0, size: 1000, scroll: '30s'})).be.true();
673+
console.dir(stub.firstCall.args, {depth: null});
674+
should(stub.calledWith({}, {scroll: '30s'}, sinon.match.func)).be.true();
667675
stub.restore();
668676
});
669677

0 commit comments

Comments
 (0)