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
4 changes: 2 additions & 2 deletions features/steps/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ Then('the document is successfully deleted', function (cb) {

Then(/^the document is (successfully|not) found$/, function (yesno) {
should(this.error).be.null();
should(this.content.constructor.name).eql('DocumentsSearchResult');
should(this.content.constructor.name).eql('DocumentSearchResult');
should(this.content.total).eql(yesno === 'successfully' ? 1 : 0);
});

Expand Down Expand Up @@ -386,7 +386,7 @@ Then('the documents should be retrieved', function () {
});

Then(/^The search result should have (fetched|a total of) (\d+) documents$/, function (what, number) {
should(this.content.constructor.name).eql('DocumentsSearchResult');
should(this.content.constructor.name).eql('DocumentSearchResult');

let field;
switch (what) {
Expand Down
20 changes: 10 additions & 10 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ if (typeof window !== 'undefined' && typeof BUILT === 'undefined') {

import { Kuzzle } from './src/Kuzzle';
import { Http, WebSocket } from './src/protocols';
import * as BaseController from './src/controllers/Base';
import * as KuzzleAbstractProtocol from './src/protocols/abstract/Base';
import * as KuzzleEventEmitter from './src/core/KuzzleEventEmitter';
import { BaseController } from './src/controllers/Base';
import { KuzzleAbstractProtocol } from './src/protocols/abstract/Base';
import { KuzzleEventEmitter } from './src/core/KuzzleEventEmitter';

import * as SearchResultBase from './src/core/searchResult/SearchResultBase';
import * as DocumentSearchResult from './src/core/searchResult/Document';
import * as ProfileSearchResult from './src/core/searchResult/Profile';
import * as RoleSearchResult from './src/core/searchResult/Role';
import * as SpecificationSearchResult from './src/core/searchResult/Specifications';
import * as UserSearchResult from './src/core/searchResult/User';
import { SearchResultBase } from './src/core/searchResult/SearchResultBase';
import { DocumentSearchResult } from './src/core/searchResult/Document';
import { ProfileSearchResult } from './src/core/searchResult/Profile';
import { RoleSearchResult } from './src/core/searchResult/Role';
import { SpecificationSearchResult } from './src/core/searchResult/Specifications';
import { UserSearchResult } from './src/core/searchResult/User';

const exported = {
Kuzzle,
Expand All @@ -38,4 +38,4 @@ const exported = {

export default exported;

module.exports = exported;
module.exports = exported;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"scripts": {
"prepublishOnly": "npm run build",
"test": "npm run --silent lint && npm run unit-testing && npm run functional-testing",
"test": "npm run test:lint && npm run test:unit && npm run test:functional",
"test:unit": "nyc --reporter=text-summary --reporter=lcov mocha",
"test:functional": "cucumber-js --exit --fail-fast",
"test:lint": "npm run test:lint:js && npm run test:lint:ts",
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/Document.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseController } from './Base';
import { SearchResult } from '../core/searchResult/SearchResultBase';
import { DocumentsSearchResult } from '../core/searchResult/Document';
import { DocumentSearchResult } from '../core/searchResult/Document';
import { JSONObject, Document, DocumentHit } from '../utils/interfaces';

export class DocumentController extends BaseController {
Expand Down Expand Up @@ -640,7 +640,7 @@ export class DocumentController extends BaseController {
): Promise<SearchResult<DocumentHit>> {
return this._search(index, collection, query, options)
.then(({ response, request, opts }) => (
new DocumentsSearchResult(this.kuzzle, request, opts, response.result)
new DocumentSearchResult(this.kuzzle, request, opts, response.result)
));
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/searchResult/Document.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SearchResultBase } from './SearchResultBase';
import { DocumentHit } from '../../utils/interfaces';

export class DocumentsSearchResult extends SearchResultBase<DocumentHit> {
export class DocumentSearchResult extends SearchResultBase<DocumentHit> {
/**
* @param {Kuzzle} kuzzle
* @param {object} query
Expand All @@ -16,4 +16,4 @@ export class DocumentsSearchResult extends SearchResultBase<DocumentHit> {
}
}

module.exports = { DocumentsSearchResult };
module.exports = { DocumentSearchResult };
12 changes: 7 additions & 5 deletions src/protocols/Http.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class HttpProtocol extends KuzzleAbstractProtocol {
return;
}

url = url.replace(regex, '/' + data[ matches[1] ]);
url = url.replace(regex, `/${encodeURIComponent(data[matches[1]])}`);

delete(queryArgs[ matches[1] ]);

Expand All @@ -212,22 +212,24 @@ class HttpProtocol extends KuzzleAbstractProtocol {
const queryString = [];

for (const key of Object.keys(queryArgs)) {
const value = queryArgs[key];
let value = queryArgs[key];
const encodedKey = encodeURIComponent(key);

if (Array.isArray(value)) {
queryString.push(`${key}=${value.join()}`);
queryString.push(`${encodedKey}=${encodeURIComponent(value.join())}`);
}
else if (typeof value === 'boolean') {
// In Kuzzle, an optional boolean option is set to true if present in
// the querystring, and false if absent.
// As there is no boolean type in querystrings, encoding a boolean
// option "foo=false" in it will make Kuzzle consider it as truthy.
if (value === true) {
queryString.push(key);
queryString.push(encodedKey);
}
}
else {
queryString.push(`${key}=${typeof value === 'object' ? JSON.stringify(value) : value}`);
value = typeof value === 'object' ? JSON.stringify(value) : value;
queryString.push(`${encodedKey}=${encodeURIComponent(value)}`);
}
}

Expand Down
12 changes: 6 additions & 6 deletions test/controllers/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const sinon = require('sinon');
const should = require('should');

const { DocumentController } = require('../../src/controllers/Document');
const { DocumentsSearchResult } = require('../../src/core/searchResult/Document');
const { DocumentSearchResult } = require('../../src/core/searchResult/Document');

describe('Document Controller', () => {
const options = {opt: 'in'};
Expand Down Expand Up @@ -366,7 +366,7 @@ describe('Document Controller', () => {
});

describe('search', () => {
it('should call document/search query and return a Promise which resolves a DocumentsSearchResult instance', () => {
it('should call document/search query and return a Promise which resolves a DocumentSearchResult instance', () => {
const result = {
scrollId: 'scroll-id',
hits: [
Expand Down Expand Up @@ -394,7 +394,7 @@ describe('Document Controller', () => {
scroll: undefined
}, options);

should(res).be.an.instanceOf(DocumentsSearchResult);
should(res).be.an.instanceOf(DocumentSearchResult);
should(res._options).match(options);
should(res._options.verb).be.eql('POST');
should(res._response).be.equal(result);
Expand All @@ -403,7 +403,7 @@ describe('Document Controller', () => {
});
});

it('should call document/search query and return a Promise which resolves a DocumentsSearchResult instance', () => {
it('should call document/search query and return a Promise which resolves a DocumentSearchResult instance', () => {
const result = {
scrollId: 'scroll-id',
hits: [
Expand Down Expand Up @@ -433,7 +433,7 @@ describe('Document Controller', () => {
scroll: undefined
}, options);

should(res).be.an.instanceOf(DocumentsSearchResult);
should(res).be.an.instanceOf(DocumentSearchResult);
should(res._options).match(options);
should(res._options.verb).be.eql('GET');
should(res._response).be.equal(result);
Expand Down Expand Up @@ -469,7 +469,7 @@ describe('Document Controller', () => {
scroll: '10s'
}, {});

should(res).be.an.instanceOf(DocumentsSearchResult);
should(res).be.an.instanceOf(DocumentSearchResult);
should(res._options).match({ verb: 'POST' });
should(res._response).be.equal(result);
should(res.fetched).be.equal(2);
Expand Down
34 changes: 17 additions & 17 deletions test/core/searchResult/document.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const sinon = require('sinon');
const should = require('should');

const { DocumentsSearchResult } = require('../../../src/core/searchResult/Document');
const { DocumentSearchResult } = require('../../../src/core/searchResult/Document');

describe('DocumentsSearchResult', () => {
describe('DocumentSearchResult', () => {
const options = {opt: 'in'};

let
Expand Down Expand Up @@ -31,7 +31,7 @@ describe('DocumentsSearchResult', () => {
});

describe('constructor', () => {
it('should create a DocumentsSearchResult instance with good properties', () => {
it('should create a DocumentSearchResult instance with good properties', () => {
response = {
hits: [
{_id: 'document1', _score: 0.9876, _source: {foo: 'bar'}},
Expand All @@ -40,7 +40,7 @@ describe('DocumentsSearchResult', () => {
total: 3
};

searchResult = new DocumentsSearchResult(kuzzle, request, options, response);
searchResult = new DocumentSearchResult(kuzzle, request, options, response);

should(searchResult._request).be.equal(request);
should(searchResult._options).be.equal(options);
Expand All @@ -67,7 +67,7 @@ describe('DocumentsSearchResult', () => {
total: 2
};

searchResult = new DocumentsSearchResult(kuzzle, request, options, response);
searchResult = new DocumentSearchResult(kuzzle, request, options, response);

return searchResult.next()
.then(result => {
Expand All @@ -87,7 +87,7 @@ describe('DocumentsSearchResult', () => {
total: 30
};

searchResult = new DocumentsSearchResult(kuzzle, request, options, response);
searchResult = new DocumentSearchResult(kuzzle, request, options, response);

return should(searchResult.next())
.be.rejectedWith('Unable to retrieve next results from search: missing scrollId, from/sort, or from/size params');
Expand Down Expand Up @@ -116,12 +116,12 @@ describe('DocumentsSearchResult', () => {
aggregations: 'aggregations',
total: 30
};
searchResult = new DocumentsSearchResult(kuzzle, request, options, response);
searchResult = new DocumentSearchResult(kuzzle, request, options, response);

kuzzle.query.resolves({result: nextResponse});
});

it('should call document/scroll action with scrollId parameter and resolve to a new DocumentsSearchResult', () => {
it('should call document/scroll action with scrollId parameter and resolve to a new DocumentSearchResult', () => {
return searchResult.next()
.then(nextSearchResult => {
should(kuzzle.query)
Expand All @@ -133,7 +133,7 @@ describe('DocumentsSearchResult', () => {
scrollId: 'scroll-id'
}, options);
should(nextSearchResult).not.be.equal(searchResult);
should(nextSearchResult).be.instanceOf(DocumentsSearchResult);
should(nextSearchResult).be.instanceOf(DocumentSearchResult);
});
});

Expand Down Expand Up @@ -175,12 +175,12 @@ describe('DocumentsSearchResult', () => {
aggregations: 'aggregations',
total: 30
};
searchResult = new DocumentsSearchResult(kuzzle, request, options, response);
searchResult = new DocumentSearchResult(kuzzle, request, options, response);

kuzzle.query.resolves({result: nextResponse});
});

it('should call document/search action with search_after parameter and resolve to a new DocumentsSearchResult', () => {
it('should call document/search action with search_after parameter and resolve to a new DocumentSearchResult', () => {
return searchResult.next()
.then(nextSearchResult => {
should(kuzzle.query)
Expand All @@ -200,7 +200,7 @@ describe('DocumentsSearchResult', () => {
size: 2
}, options);
should(nextSearchResult).not.be.equal(searchResult);
should(nextSearchResult).be.instanceOf(DocumentsSearchResult);
should(nextSearchResult).be.instanceOf(DocumentSearchResult);
});
});

Expand All @@ -219,15 +219,15 @@ describe('DocumentsSearchResult', () => {

it('should reject with an error if the sort is invalid', () => {
request.body.sort = [];
searchResult = new DocumentsSearchResult(kuzzle, request, options, response);
searchResult = new DocumentSearchResult(kuzzle, request, options, response);

return should(searchResult.next())
.be.rejected();
});

it('should reject if the sort combination does not allow to retrieve all the documents', () => {
response.hits = [];
searchResult = new DocumentsSearchResult(kuzzle, request, options, response);
searchResult = new DocumentSearchResult(kuzzle, request, options, response);

return should(searchResult.next())
.be.rejected();
Expand Down Expand Up @@ -256,7 +256,7 @@ describe('DocumentsSearchResult', () => {
aggregations: 'aggregations',
total: 30
};
searchResult = new DocumentsSearchResult(kuzzle, request, options, response);
searchResult = new DocumentSearchResult(kuzzle, request, options, response);

kuzzle.query.resolves({result: nextResponse});
});
Expand All @@ -273,7 +273,7 @@ describe('DocumentsSearchResult', () => {
});


it('should call document/search action with from/size parameters and resolve to a new DocumentsSearchResult', () => {
it('should call document/search action with from/size parameters and resolve to a new DocumentSearchResult', () => {
return searchResult.next()
.then(nextSearchResult => {
should(kuzzle.query)
Expand All @@ -288,7 +288,7 @@ describe('DocumentsSearchResult', () => {
from: 2
}, options);
should(nextSearchResult).not.be.equal(searchResult);
should(nextSearchResult).be.instanceOf(DocumentsSearchResult);
should(nextSearchResult).be.instanceOf(DocumentSearchResult);
});
});

Expand Down
Loading