Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kuzzle-sdk",
"version": "7.1.1",
"version": "7.1.2",
"description": "Official Javascript SDK for Kuzzle",
"author": "The Kuzzle Team <support@kuzzle.io>",
"repository": {
Expand Down
8 changes: 2 additions & 6 deletions src/controllers/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,8 @@ class DocumentController extends BaseController {
delete options[opt];
}

if (request.size === undefined) {
request.size = 10;
}

if (!request.scroll && !request.body.sort && !request.from) {
request.from = 0;
if (!options.verb) {
options.verb = 'POST';
}

return this.query(request, options)
Expand Down
18 changes: 16 additions & 2 deletions src/protocols/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,19 @@ class HttpWrapper extends KuzzleAbstractProtocol {

if (http && http.length === 1) {
routes[controller][action] = http[0];
} else if (http && http.length > 1) {
routes[controller][action] = getCorrectRoute(http);
}
else if (http && http.length > 1) {
// We need this ugly fix because the document:search route can also
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it missing one word to fully understand those 2 first comment ?

// be accessed in GET with this url: "/:index/:collection"
// But to send a query, we need to pass it in the body so we need POST
// so we can change the verb but then POST on "/:index/:collection"
// is the collection:update method (document:search is "/:index/:collection/_search")
if (controller === 'document' && action === 'search') {
routes[controller][action] = getPostRoute(http);
}
else {
routes[controller][action] = getCorrectRoute(http);
}
}
}

Expand All @@ -325,7 +336,10 @@ class HttpWrapper extends KuzzleAbstractProtocol {
_warn (message) {
console.warn(message); // eslint-disable-line no-console
}
}

function getPostRoute (routes) {
return routes[0].verb === 'POST' ? routes[0] : routes[1];
}

function getCorrectRoute (routes) {
Expand Down
28 changes: 5 additions & 23 deletions test/controllers/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,14 @@ describe('Document Controller', () => {
.then(res => {
should(kuzzle.query)
.be.calledOnce()
.be.calledWith({
.be.calledWithMatch({
controller: 'document',
action: 'search',
index: 'index',
collection: 'collection',
body: {foo: 'bar'},
from: 0,
size: 10,
from: undefined,
size: undefined,
scroll: undefined
}, options);

Expand All @@ -416,7 +416,7 @@ describe('Document Controller', () => {
.then(res => {
should(kuzzle.query)
.be.calledOnce()
.be.calledWith({
.be.calledWithMatch({
controller: 'document',
action: 'search',
index: 'index',
Expand All @@ -428,30 +428,13 @@ describe('Document Controller', () => {
}, {});

should(res).be.an.instanceOf(DocumentSearchResult);
should(res._options).be.empty();
should(res._options).match({ verb: 'POST' });
should(res._response).be.equal(result);
should(res.fetched).be.equal(2);
should(res.total).be.equal(3);
});
});

it('should set default value for from and size', () => {
const result = {
hits: [],
total: 0
};
kuzzle.document.query = sinon.stub().resolves({result});

return kuzzle.document.search('index', 'collection', {})
.then(() => {
should(kuzzle.document.query).be.calledOnce();

const request = kuzzle.document.query.getCall(0).args[0];
should(request.from).be.eql(0);
should(request.size).be.eql(10);
});
});

it('should allow to set value of 0 for size', () => {
const result = {
hits: [],
Expand All @@ -464,7 +447,6 @@ describe('Document Controller', () => {
should(kuzzle.document.query).be.calledOnce();

const request = kuzzle.document.query.getCall(0).args[0];
should(request.from).be.eql(0);
should(request.size).be.eql(0);
});
});
Expand Down
12 changes: 11 additions & 1 deletion test/protocol/http.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,14 @@ describe('HTTP networking module', () => {
describe('_constructRoutes', () => {
it('should construct http routes from server:publicApi', () => {
const publicApi = {
document: {
search: {
http: [
{ verb: 'GET', url: '/:index/:collection/' },
{ verb: 'POST', url: '/:index/:collection/_search' }
]
}
},
foo: {
login: {
http: [
Expand Down Expand Up @@ -766,8 +774,10 @@ describe('HTTP networking module', () => {
// will be in the query string
should(routes.foo.create.url).be.eql('/:index/:collection/_create');

should(routes.foo.subscribe).be.undefined();
// we should choose the POST route for document:create
should(routes.document.search.url).be.eql('/:index/:collection/_search');

should(routes.foo.subscribe).be.undefined();
});

it('should overwrite kuzzle routes with custom routes', () => {
Expand Down