Skip to content

Commit 6211c10

Browse files
authored
Merge pull request #156 from kuzzleio/newRequestModel
Adapt from & size to be part of the query instead of the body
2 parents a7dfef1 + e885e40 commit 6211c10

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

src/kuzzle.js

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

1260+
if (options.from) {
1261+
object.from = options.from;
1262+
}
1263+
1264+
if (options.size) {
1265+
object.size = options.size;
1266+
}
1267+
12601268
if (options.metadata) {
12611269
Object.keys(options.metadata).forEach(function (meta) {
12621270
object.metadata[meta] = options.metadata[meta];

src/kuzzleDataCollection.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -339,17 +339,6 @@ KuzzleDataCollection.prototype.fetchAllDocuments = function (options, cb) {
339339
options = null;
340340
}
341341

342-
// copying pagination options to the search filter
343-
if (options) {
344-
if (options.from) {
345-
filters.from = options.from;
346-
}
347-
348-
if (options.size) {
349-
filters.size = options.size;
350-
}
351-
}
352-
353342
this.kuzzle.callbackRequired('KuzzleDataCollection.fetchAll', cb);
354343

355344
this.advancedSearch(filters, options, cb);

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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,13 @@ describe('KuzzleDataCollection methods', function () {
507507
beforeEach(function () {
508508
kuzzle = new Kuzzle('foo', {defaultIndex: 'bar'});
509509
emitted = false;
510+
expectedQuery = {
511+
index: 'bar',
512+
collection: 'foo',
513+
action: 'get',
514+
controller: 'document',
515+
body: {}
516+
};
510517
});
511518

512519
it('should forward the query to the advancedSearch method', function () {
@@ -549,7 +556,7 @@ describe('KuzzleDataCollection methods', function () {
549556

550557
collection.fetchAllDocuments({from: 123, size: 456}, function () {});
551558
should(stub.calledOnce).be.true();
552-
should(stub.calledWithMatch({from: 123, size: 456})).be.true();
559+
should(stub.calledWithMatch({}, {from: 123, size: 456})).be.true();
553560
stub.restore();
554561
});
555562
});

0 commit comments

Comments
 (0)