diff --git a/.travis.yml b/.travis.yml index 87f8cd9..0de7c90 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ language: node_js node_js: - - "0.10" \ No newline at end of file + - 6.9 diff --git a/lib/client.js b/lib/client.js index e6dd5ef..ba17c60 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1,10 +1,10 @@ -var request = require('request'), - _ = require('lodash'), - _s = require('underscore.string'), - urlParser = require('url'); +const request = require('request'); +const _ = require('lodash'); +const _s = require('underscore.string'); +const urlParser = require('url'); // Avalable APIS -var apis = ['search', 'moreLikeThis', 'indexes', 'fields', 'documents', 'templates', 'replication']; +const apis = ['search', 'moreLikeThis', 'indexes', 'fields', 'documents', 'templates', 'replication']; // Build API function buildApi(name) { @@ -30,7 +30,7 @@ function Client(options) { // Make an http request to defined endpoint Client.prototype.request = function (options, callback) { - var url = urlParser.format(_(this.options) + const url = urlParser.format(_(this.options) .pick(['hostname', 'port', 'protocol', 'query']) .defaults({ protocol: 'http', @@ -41,12 +41,12 @@ Client.prototype.request = function (options, callback) { request(_(options) .defaults({ - url: url, + url, json: true }) - .value(), function (err, res, body) { + .value(), (err, res, body) => { if (err) { - var message = err.message; + let message = err.message; if (err.code === 'ECONNREFUSED') { message = 'Cannot connect to OpenSearchServer at ' + url; diff --git a/lib/documents.js b/lib/documents.js index 1169127..b186626 100644 --- a/lib/documents.js +++ b/lib/documents.js @@ -1,6 +1,6 @@ -var _ = require('lodash'); +const _ = require('lodash'); -var documents = module.exports = { +const documents = module.exports = { documents: {} }; @@ -31,4 +31,4 @@ var documents = module.exports = { }, callback); }; -}).call(documents.documents); \ No newline at end of file +}).call(documents.documents); diff --git a/lib/fields.js b/lib/fields.js index 0864f75..4f4f9aa 100644 --- a/lib/fields.js +++ b/lib/fields.js @@ -1,8 +1,6 @@ -var util = require('./util'); +const util = require('./util'); -var fields = module.exports = { - fields: {} -}; +const fields = module.exports = { fields: {} }; (function () { @@ -10,13 +8,13 @@ var fields = module.exports = { this.createOrUpdate = function (index, options, callback) { options = options || {}; - ['indexed', 'stored', 'termVector'].forEach(function (param) { + ['indexed', 'stored', 'termVector'].forEach((param) => { if (typeof options[param] !== 'undefined') options[param] = util.convertParam(options[param]); }); this.request({ - pathname: '/services/rest/index/' + index + '/field/' + options.name, + pathname: `/services/rest/index/${index}/field/${options.name}`, method: 'PUT', json: options }, callback); @@ -28,7 +26,7 @@ var fields = module.exports = { // Remove an existing field this.destroy = function (index, field, callback) { this.request({ - pathname: '/services/rest/index/' + index + '/field/' + field, + pathname: `/services/rest/index/${index}/field/${field}`, method: 'DELETE' }, callback); }; @@ -36,7 +34,7 @@ var fields = module.exports = { // Set the unique and the default fields this.setUniqueDefault = function (index, options, callback) { this.request({ - pathname: '/services/rest/index/' + index + '/field', + pathname: `/services/rest/index/${index}/field`, method: 'POST', qs: options }, callback); @@ -45,9 +43,9 @@ var fields = module.exports = { // list fields this.list = function (index, callback) { this.request({ - pathname: '/services/rest/index/' + index + '/field/', + pathname: `/services/rest/index/${index}/field/`, method: 'GET' }, callback); }; -}).call(fields.fields); \ No newline at end of file +}).call(fields.fields); diff --git a/lib/indexes.js b/lib/indexes.js index 9c891e2..c6af927 100644 --- a/lib/indexes.js +++ b/lib/indexes.js @@ -1,8 +1,6 @@ -var _ = require('lodash'); +const _ = require('lodash'); -var indexes = module.exports = { - indexes: {} -}; +const indexes = module.exports = { indexes: {} }; (function () { @@ -17,8 +15,11 @@ var indexes = module.exports = { template: '' }); + const { template } = options; + const templateQueryString = template ? '/template/' + template : ''; + this.request({ - pathname: '/services/rest/index/' + index + (options.template ? '/template/' + options.template : ''), + pathname: `/services/rest/index/${index}${templateQueryString}`, method: 'POST' }, callback); }; @@ -26,7 +27,7 @@ var indexes = module.exports = { // Test if index exists this.exists = function (index, callback) { this.request({ - pathname: '/services/rest/index/' + index, + pathname: `/services/rest/index/${index}`, method: 'GET' }, callback); }; @@ -34,9 +35,9 @@ var indexes = module.exports = { // Remove an existing index this.destroy = function (index, callback) { this.request({ - pathname: '/services/rest/index/' + index, + pathname: `/services/rest/index/${index}`, method: 'DELETE' }, callback); }; -}).call(indexes.indexes); \ No newline at end of file +}).call(indexes.indexes); diff --git a/lib/more-like-this.js b/lib/more-like-this.js index 5280bd1..5acc0fa 100644 --- a/lib/more-like-this.js +++ b/lib/more-like-this.js @@ -1,13 +1,13 @@ -var _ = require('lodash'); +const _ = require('lodash'); -var moreLikeThis = module.exports = {}; +const moreLikeThis = module.exports = {}; (function () { // More like this this.moreLikeThis = function (index, options, callback) { this.request({ - pathname: '/services/rest/index/' + index + '/morelikethis', + pathname: `/services/rest/index/${index}/morelikethis`, method: 'POST', json: _.defaults({}, options || {}, { analyzerName: 'StandardAnalyzer', @@ -25,4 +25,4 @@ var moreLikeThis = module.exports = {}; }, callback); }; -}).call(moreLikeThis); \ No newline at end of file +}).call(moreLikeThis); diff --git a/lib/oss.js b/lib/oss.js index 858d00c..1173618 100644 --- a/lib/oss.js +++ b/lib/oss.js @@ -1,5 +1,5 @@ -var Client = require('./client'); -var util = require('./util'); +const Client = require('./client'); +const util = require('./util'); // Create a new client function createClient(options) { @@ -8,4 +8,4 @@ function createClient(options) { exports.Client = Client; exports.createClient = createClient; -exports.util = util; \ No newline at end of file +exports.util = util; diff --git a/lib/replication.js b/lib/replication.js index 5df578a..4817ca6 100644 --- a/lib/replication.js +++ b/lib/replication.js @@ -1,12 +1,12 @@ -var _ = require('lodash'); +const _ = require('lodash'); -var replication = module.exports = {}; +const replication = module.exports = {}; (function () { this.createReplicationIndex = function(index, searcher, callback) { this.request({ - pathname: '/services/rest/index/' + index + '/replication', + pathname: `/services/rest/index/${index}/replication`, method: 'PUT', body: { replicationType: 'MAIN_INDEX', @@ -18,16 +18,16 @@ var replication = module.exports = {}; }; this.replicate = function(index, searcher, callback) { - var searcherUrl = buildUrl(searcher); + const searcherUrl = buildUrl(searcher); this.request({ - pathname: '/services/rest/index/' + index + '/replication/run', + pathname: `/services/rest/index/${index}/replication/run`, method: 'PUT', - search: 'name=' + searcherUrl + '/' + index + search: `name=${searcherUrl}/${index}` }, callback); }; - function buildUrl(searcher) { - return searcher.protocol || 'http' + '://' + searcher.hostname + ':' + searcher.port; + function buildUrl({ protocol = 'http', hostname, port }) { + return `${protocol}://${hostname}:${port}`; } }).call(replication); diff --git a/lib/search.js b/lib/search.js index ed02297..3a611ea 100644 --- a/lib/search.js +++ b/lib/search.js @@ -1,6 +1,6 @@ -var _ = require('lodash'); +const _ = require('lodash'); -var search = module.exports = {}; +const search = module.exports = {}; (function () { @@ -11,10 +11,10 @@ var search = module.exports = {}; }); this.request({ - pathname: '/services/rest/index/' + index + '/search/' + options.type, + pathname: `/services/rest/index/${index}/search/${options.type}`, method: 'POST', json: _.omit(options, 'type') }, callback); }; -}).call(search); \ No newline at end of file +}).call(search); diff --git a/lib/templates.js b/lib/templates.js index 9061bee..8227949 100644 --- a/lib/templates.js +++ b/lib/templates.js @@ -1,15 +1,13 @@ -var _ = require('lodash'); +const _ = require('lodash'); -var templates = module.exports = { - templates: {} -}; +const templates = module.exports = { templates: {} }; (function () { // Get a search template. this.get = function (index, name, callback) { this.request({ - pathname: '/services/rest/index/' + index + '/search/template/' + name, + pathname: `/services/rest/index/${index}/search/template/${name}`, method: 'GET' }, callback); }; @@ -17,7 +15,7 @@ var templates = module.exports = { // List all search templates. this.list = function (index, callback) { this.request({ - pathname: '/services/rest/index/' + index + '/search/template/', + pathname: `/services/rest/index/${index}/search/template/`, method: 'GET' }, callback); }; @@ -29,7 +27,7 @@ var templates = module.exports = { }); this.request({ - pathname: '/services/rest/index/' + index + '/search/' + options.type + '/' + name, + pathname: `/services/rest/index/${index}/search/${options.type}/${name}`, method: 'PUT', json: _.omit(options, 'type') }, callback); @@ -41,9 +39,9 @@ var templates = module.exports = { // Remove an existing template. this.destroy = function (index, name, callback) { this.request({ - pathname: '/services/rest/index/' + index + '/search/template/' + name, + pathname: `/services/rest/index/${index}/search/template/${name}`, method: 'DELETE' }, callback); }; -}).call(templates.templates); \ No newline at end of file +}).call(templates.templates); diff --git a/lib/util.js b/lib/util.js index b48fb64..dc62299 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1,4 +1,4 @@ -var _ = require('lodash'); +const _ = require('lodash'); function convertParam(val) { return val === true ? 'YES' : @@ -7,4 +7,4 @@ function convertParam(val) { val; } -exports.convertParam = convertParam; \ No newline at end of file +exports.convertParam = convertParam; diff --git a/test/client.js b/test/client.js index 76db8c6..d4bfe1d 100644 --- a/test/client.js +++ b/test/client.js @@ -1,31 +1,29 @@ /* globals describe, it, beforeEach */ -var expect = require('chai').expect, - nock = require('nock'), - Client = require('../lib/client'); +const expect = require('chai').expect; +const nock = require('nock'); +const Client = require('../lib/client'); - nock.enableNetConnect(); +nock.enableNetConnect(); -describe('Client', function () { +describe('Client', () => { - it('should have default options', function () { - var client = new Client(); + it('should have default options', () => { + const client = new Client(); expect(client.options).to.have.property('hostname'); expect(client.options).to.have.property('port'); }); - describe('#request', function () { - describe('without credentials', function () { - var client; + describe('#request', () => { + describe('without credentials', () => { + let client; - beforeEach(function () { + beforeEach(() => { client = new Client(); nock('http://localhost:9090') .post('/my-path') - .reply(200, { - foo: 'bar' - }); + .reply(200, { foo: 'bar' }); nock('http://localhost:9090') .post('/my-error-path') @@ -37,28 +35,19 @@ describe('Client', function () { }); - it('should be possible to make a request', function (done) { + it('should be possible to make a request', done => { - client.request({ - pathname: '/my-path', - method: 'POST' - }, function (err, res) { + client.request({ pathname: '/my-path', method: 'POST' }, (err, res) => { if (err) return done(err); - expect(res).to.deep.equal({ - foo: 'bar' - }); - + expect(res).to.deep.equal({ foo: 'bar' }); done(); }); }); - it('should handle error correctly', function (done) { + it('should handle error correctly', done => { - client.request({ - pathname: '/my-error-path', - method: 'POST' - }, function (err, res) { + client.request({ pathname: '/my-error-path', method: 'POST' }, (err, res) => { expect(err instanceof Error).to.be.true; expect(err.message).to.be.equal('My error'); expect(res).to.be.undefined; @@ -67,12 +56,9 @@ describe('Client', function () { }); }); - it('should handle OSS internal error correctly', function (done) { + it('should handle OSS internal error correctly', done => { - client.request({ - pathname: '/my-internal-error-path', - method: 'POST' - }, function (err, res) { + client.request({ pathname: '/my-internal-error-path', method: 'POST' }, (err, res) => { expect(err instanceof Error).to.be.true; expect(err.message).to.be.equal(''); expect(res).to.be.undefined; @@ -81,21 +67,15 @@ describe('Client', function () { }); }); - describe('when the server is not reachable', function() { + describe('when the server is not reachable', () => { - beforeEach(function() { - client = new Client({ - hostname: 'localhost', - port: 99999999 - }); + beforeEach(() => { + client = new Client({ hostname: 'localhost', port: 8080 }); }); - it('gives a usefull error message', function(done) { - client.request({ - pathname: '/my-path', - method: 'POST' - }, function(err) { - var msg = 'Cannot connect to OpenSearchServer at http://localhost:99999999/my-path'; + it('gives a usefull error message', done => { + client.request({ pathname: '/my-path', method: 'POST' }, err => { + const msg = 'Cannot connect to OpenSearchServer at http://localhost:8080/my-path'; expect(err.message).to.equals(msg); done(); }); @@ -103,79 +83,50 @@ describe('Client', function () { }); }); - describe('with credentials', function () { - var client; + describe('with credentials', () => { + let client; - beforeEach(function () { - client = new Client({ - login: 'mylogin', - key: 'mykey' - }); + beforeEach(() => { + client = new Client({ login: 'mylogin', key: 'mykey' }); nock('http://localhost:9090') .post('/my-path?login=mylogin&key=mykey') - .reply(200, { - foo: 'bar' - }); + .reply(200, { foo: 'bar' }); }); - it('should be possible to make a request', function (done) { - client.request({ - pathname: '/my-path', - method: 'POST' - }, function (err, res) { + it('should be possible to make a request', done => { + client.request({ pathname: '/my-path', method: 'POST' }, (err, res) => { if (err) return done(err); - - expect(res).to.deep.equal({ - foo: 'bar' - }); - + expect(res).to.deep.equal({ foo: 'bar' }); done(); }); }); }); }); - describe('instances', function () { + describe('instances', () => { - beforeEach(function () { + beforeEach(() => { nock('http://host1:9090') .get('/x') - .reply(200, { - host: 1 - }); + .reply(200, { host: 1 }); nock('http://host2:9090') .get('/x') - .reply(200, { - host: 2 - }); + .reply(200, { host: 2 }); }); - it('must be independent', function () { - var client1 = new Client({ - hostname: 'host1' - }); - - var client2 = new Client({ - hostname: 'host2' - }); + it('must be independent', () => { + const client1 = new Client({ hostname: 'host1' }); + const client2 = new Client({ hostname: 'host2' }); - client1.indexes.request({ - pathname: 'x' - }, function (err, res) { - expect(res).to.deep.equal({ - host: 1 - }); + client1.indexes.request({ pathname: 'x' }, (err, res) => { + expect(res).to.deep.equal({ host: 1 }); }); - client2.indexes.request({ - pathname: 'x' - }, function (err, res) { - expect(res).to.deep.equal({ - host: 2 - }); + client2.indexes.request({ pathname: 'x' }, function (err, res) { + expect(res).to.deep.equal({ host: 2 }); }); }); }); -}); \ No newline at end of file +}); diff --git a/test/documents.js b/test/documents.js index 87448b5..d22857f 100644 --- a/test/documents.js +++ b/test/documents.js @@ -1,27 +1,27 @@ /* globals describe, it, beforeEach */ -var chai = require('chai').use(require('sinon-chai')), - expect = chai.expect, - sinon = require('sinon'), - oss = require('../'); +const chai = require('chai').use(require('sinon-chai')); +const expect = chai.expect; +const sinon = require('sinon'); +const oss = require('../'); -describe('Documents', function () { +describe('Documents', () => { - var client, rq; + let client, rq; - beforeEach(function () { + beforeEach(() => { client = oss.createClient(); rq = sinon.stub(client.documents, 'request'); }); - describe('#createOrUpdate', function () { + describe('#createOrUpdate', () => { - it('should be possible to create a single document', function () { + it('should be possible to create a single document', () => { client.documents.createOrUpdate('my_index', { fields: [ - {name: 'id', value: 1}, - {name: 'text', value: 'my value'} + { name: 'id', value: 1 }, + { name: 'text', value: 'my value' } ] }); @@ -31,27 +31,27 @@ describe('Documents', function () { json: [ { fields: [ - {name: 'id', value: 1}, - {name: 'text', value: 'my value'} + { name: 'id', value: 1 }, + { name: 'text', value: 'my value' } ] } ] }); }); - it('should be possible to create multiple documents', function () { + it('should be possible to create multiple documents', () => { client.documents.createOrUpdate('my_index', [ { fields: [ - {name: 'id', value: 1}, - {name: 'text', value: 'my value'} + { name: 'id', value: 1 }, + { name: 'text', value: 'my value' } ] }, { fields: [ - {name: 'id', value: 2}, - {name: 'text', value: 'my second value'} + { name: 'id', value: 2 }, + { name: 'text', value: 'my second value' } ] } ]); @@ -62,26 +62,26 @@ describe('Documents', function () { json: [ { fields: [ - {name: 'id', value: 1}, - {name: 'text', value: 'my value'} + { name: 'id', value: 1 }, + { name: 'text', value: 'my value' } ] }, { fields: [ - {name: 'id', value: 2}, - {name: 'text', value: 'my second value'} + { name: 'id', value: 2 }, + { name: 'text', value: 'my second value' } ] } ] }); }); - it('should be possible to update a single document', function () { + it('should be possible to update a single document', () => { client.documents.createOrUpdate('my_index', { fields: [ - {name: 'id', value: 1}, - {name: 'text', value: 'my new value'} + { name: 'id', value: 1 }, + { name: 'text', value: 'my new value' } ] }); @@ -91,8 +91,8 @@ describe('Documents', function () { json: [ { fields: [ - {name: 'id', value: 1}, - {name: 'text', value: 'my new value'} + { name: 'id', value: 1 }, + { name: 'text', value: 'my new value' } ] } ] @@ -100,14 +100,11 @@ describe('Documents', function () { }); }); - describe('#destroy', function () { + describe('#destroy', () => { - it('should be possible to destroy an index', function () { + it('should be possible to destroy an index', () => { - client.documents.destroy('my_index', { - field: 'id', - values: 1 - }); + client.documents.destroy('my_index', { field: 'id', values: 1 }); expect(rq).to.be.calledWith({ method: 'DELETE', @@ -116,4 +113,4 @@ describe('Documents', function () { }); }); }); -}); \ No newline at end of file +}); diff --git a/test/fields.js b/test/fields.js index 7ba1c08..62ba8a2 100644 --- a/test/fields.js +++ b/test/fields.js @@ -1,59 +1,47 @@ /* globals describe, it, beforeEach */ -var chai = require('chai').use(require('sinon-chai')), - expect = chai.expect, - sinon = require('sinon'), - oss = require('../'); +const chai = require('chai').use(require('sinon-chai')); +const expect = chai.expect; +const sinon = require('sinon'); +const oss = require('../'); -describe('Fields', function () { +describe('Fields', () => { - var client, rq; + let client, rq; - beforeEach(function () { + beforeEach(() => { client = oss.createClient(); rq = sinon.stub(client.fields, 'request'); }); - describe('#createOrUpdate', function () { + describe('#createOrUpdate', () => { - it('should be possible to create a field', function () { + it('should be possible to create a field', () => { - client.fields.createOrUpdate('my_index', { - name: 'my_field', - stored: true - }); + client.fields.createOrUpdate('my_index', { name: 'my_field', stored: true }); expect(rq).to.be.calledWith({ method: 'PUT', pathname: '/services/rest/index/my_index/field/my_field', - json: { - name: 'my_field', - stored: 'YES' - } + json: { name: 'my_field', stored: 'YES' } }); }); - it('should be possible to update a field', function () { + it('should be possible to update a field', () => { - client.fields.createOrUpdate('my_index', { - name: 'my_field', - stored: true - }); + client.fields.createOrUpdate('my_index', { name: 'my_field', stored: true }); expect(rq).to.be.calledWith({ method: 'PUT', pathname: '/services/rest/index/my_index/field/my_field', - json: { - name: 'my_field', - stored: 'YES' - } + json: { name: 'my_field', stored: 'YES' } }); }); }); - describe('#destroy', function () { + describe('#destroy', () => { - it('should be possible to destroy an index', function () { + it('should be possible to destroy an index', () => { client.fields.destroy('my_index', 'my_field'); @@ -64,29 +52,23 @@ describe('Fields', function () { }); }); - describe('#setUniqueDefault', function () { + describe('#setUniqueDefault', () => { - it('should be possible to define unique and default field', function () { + it('should be possible to define unique and default field', () => { - client.fields.setUniqueDefault('my_index', { - default: 'my_default_field', - unique: 'my_unique_field' - }); + client.fields.setUniqueDefault('my_index', { default: 'my_default_field', unique: 'my_unique_field' }); expect(rq).to.be.calledWith({ method: 'POST', pathname: '/services/rest/index/my_index/field', - qs: { - default: 'my_default_field', - unique: 'my_unique_field' - } + qs: { default: 'my_default_field', unique: 'my_unique_field' } }); }); }); - describe('#list', function () { + describe('#list', () => { - it('should be possible to list the fileds of an index', function () { + it('should be possible to list the fileds of an index', () => { client.fields.list('my_index'); @@ -96,4 +78,4 @@ describe('Fields', function () { }); }); }); -}); \ No newline at end of file +}); diff --git a/test/indexes.js b/test/indexes.js index 423606b..b29d0b0 100644 --- a/test/indexes.js +++ b/test/indexes.js @@ -1,22 +1,22 @@ /* globals describe, it, beforeEach */ -var chai = require('chai').use(require('sinon-chai')), - expect = chai.expect, - sinon = require('sinon'), - oss = require('../'); +const chai = require('chai').use(require('sinon-chai')); +const expect = chai.expect; +const sinon = require('sinon'); +const oss = require('../'); -describe('Indexes', function () { +describe('Indexes', () => { - var client, rq; + let client, rq; - beforeEach(function () { + beforeEach(() => { client = oss.createClient(); rq = sinon.stub(client.indexes, 'request'); }); - describe('#create', function () { + describe('#create', () => { - it('should be possible to create an index', function () { + it('should be possible to create an index', () => { client.indexes.create('my_index'); @@ -26,11 +26,9 @@ describe('Indexes', function () { }); }); - it('should be possible to create an index with a template', function () { + it('should be possible to create an index with a template', () => { - client.indexes.create('my_index', { - template: 'my_template' - }); + client.indexes.create('my_index', { template: 'my_template' }); expect(rq).to.be.calledWith({ method: 'POST', @@ -39,9 +37,9 @@ describe('Indexes', function () { }); }); - describe('#exists', function () { + describe('#exists', () => { - it('should return if an index exists', function () { + it('should return if an index exists', () => { client.indexes.exists('my_index'); @@ -52,9 +50,9 @@ describe('Indexes', function () { }); }); - describe('#destroy', function () { + describe('#destroy', () => { - it('should be possible to destroy an index', function () { + it('should be possible to destroy an index', () => { client.indexes.destroy('my_index'); @@ -64,4 +62,4 @@ describe('Indexes', function () { }); }); }); -}); \ No newline at end of file +}); diff --git a/test/more-like-this.js b/test/more-like-this.js index 7c4bb54..c3a8cba 100644 --- a/test/more-like-this.js +++ b/test/more-like-this.js @@ -1,26 +1,22 @@ -'use strict'; - /* globals describe, it, beforeEach */ -var oss = require('../'); -var chai = require('chai').use(require('sinon-chai')); -var sinon = require('sinon'); -var expect = chai.expect; +const oss = require('../'); +const chai = require('chai').use(require('sinon-chai')); +const sinon = require('sinon'); +const expect = chai.expect; -describe('More like this', function () { +describe('More like this', () => { - var client, rq; + let client, rq; - beforeEach(function () { + beforeEach(() => { client = oss.createClient(); rq = sinon.stub(client, 'request'); }); - it('should be possible to request more like this', function () { + it('should be possible to request more like this', () => { - client.moreLikeThis('my_index', { - minWordLen: 2 - }); + client.moreLikeThis('my_index', { minWordLen: 2 }); expect(rq).to.be.calledWith({ json: { @@ -40,4 +36,4 @@ describe('More like this', function () { pathname: '/services/rest/index/my_index/morelikethis' }); }); -}); \ No newline at end of file +}); diff --git a/test/replication.js b/test/replication.js index 12905df..45ce2c9 100644 --- a/test/replication.js +++ b/test/replication.js @@ -1,26 +1,23 @@ /* globals describe, it, beforeEach */ -var chai = require('chai').use(require('sinon-chai')), - expect = chai.expect, - sinon = require('sinon'), - oss = require('../'); +const chai = require('chai').use(require('sinon-chai')); +const expect = chai.expect; +const sinon = require('sinon'); +const oss = require('../'); -describe('Replication', function () { +describe('Replication', () => { - var client, request, searcher; + let client, request, searcher; - beforeEach(function () { + beforeEach(() => { client = oss.createClient(); request = sinon.stub(client, 'request'); - searcher = { - hostname: 'searcher-oss.com', - port: 8000 - }; + searcher = { hostname: 'searcher-oss.com', port: 8000 }; }); - describe('#createReplicationIndex', function () { + describe('#createReplicationIndex', () => { - it('should request the API to create a replication index', function () { + it('should request the API to create a replication index', () => { client.createReplicationIndex('my_index', searcher); @@ -36,7 +33,7 @@ describe('Replication', function () { }); }); - it('should request the API to start a replication on an index', function () { + it('should request the API to start a replication on an index', () => { client.replicate('my_index', searcher); expect(request).to.be.calledWithMatch({ diff --git a/test/search.js b/test/search.js index ecf5096..4d7c8ac 100644 --- a/test/search.js +++ b/test/search.js @@ -1,31 +1,27 @@ /* globals describe, it, beforeEach */ -var chai = require('chai').use(require('sinon-chai')), - expect = chai.expect, - sinon = require('sinon'), - oss = require('../'); +const chai = require('chai').use(require('sinon-chai')); +const expect = chai.expect; +const sinon = require('sinon'); +const oss = require('../'); -describe('Search', function () { +describe('Search', () => { - var client, rq; + let client, rq; beforeEach(function () { client = oss.createClient(); rq = sinon.stub(client, 'request'); }); - it('should be possible to make a search', function () { + it('should be possible to make a search', () => { - client.search('my_index', { - query: 'My query' - }); + client.search('my_index', { query: 'My query' }); expect(rq).to.be.calledWith({ - json: { - query: 'My query' - }, + json: { query: 'My query' }, method: 'POST', pathname: '/services/rest/index/my_index/search/field' }); }); -}); \ No newline at end of file +}); diff --git a/test/templates.js b/test/templates.js index 29c0e1f..da53f55 100644 --- a/test/templates.js +++ b/test/templates.js @@ -1,21 +1,21 @@ /* globals describe, it, beforeEach */ -var chai = require('chai').use(require('sinon-chai')), - expect = chai.expect, - sinon = require('sinon'), - oss = require('../'); +const chai = require('chai').use(require('sinon-chai')); +const expect = chai.expect; +const sinon = require('sinon'); +const oss = require('../'); -describe('Templates', function () { +describe('Templates', () => { - var client, rq; + let client, rq; - beforeEach(function () { + beforeEach(() => { client = oss.createClient(); rq = sinon.stub(client.templates, 'request'); }); - describe('#createOrUpdate', function () { - it('should be possible to create a field', function () { + describe('#createOrUpdate', () => { + it('should be possible to create a field', () => { client.templates.createOrUpdate('my_index', 'my_template', { returnedFields: ['my_field'] @@ -24,15 +24,13 @@ describe('Templates', function () { expect(rq).to.be.calledWith({ method: 'PUT', pathname: '/services/rest/index/my_index/search/field/my_template', - json: { - returnedFields: ['my_field'] - } + json: { returnedFields: ['my_field'] } }); }); }); - describe('#destroy', function () { - it('should be possible to destroy an index', function () { + describe('#destroy', () => { + it('should be possible to destroy an index', () => { client.templates.destroy('my_index', 'my_template'); @@ -43,8 +41,8 @@ describe('Templates', function () { }); }); - describe('#list', function () { - it('should be possible to list templates', function () { + describe('#list', () => { + it('should be possible to list templates', () => { client.templates.list('my_index'); @@ -55,8 +53,8 @@ describe('Templates', function () { }); }); - describe('#get', function () { - it('should be possible to get a template', function () { + describe('#get', () => { + it('should be possible to get a template', () => { client.templates.get('my_index', 'my_template'); @@ -66,4 +64,4 @@ describe('Templates', function () { }); }); }); -}); \ No newline at end of file +}); diff --git a/test/util.js b/test/util.js index 18e10f2..7cfd443 100644 --- a/test/util.js +++ b/test/util.js @@ -1,24 +1,24 @@ /* globals describe, it */ -var expect = require('chai').expect, - util = require('../lib/util'); +const expect = require('chai').expect; +const util = require('../lib/util'); -describe('Util', function () { +describe('Util', () => { - describe('#convertParam', function () { + describe('#convertParam', () => { - it('should transform true and false to "YES" and "NO"', function () { + it('should transform true and false to "YES" and "NO"', () => { expect(util.convertParam(true)).to.equal('YES'); expect(util.convertParam(false)).to.equal('NO'); }); - it('should uppercase string', function () { + it('should uppercase string', () => { expect(util.convertParam('my_string')).to.equal('MY_STRING'); }); - it('should do nothing on other parameters', function () { - var object = {kung: 'foo'}; + it('should do nothing on other parameters', () => { + const object = { kung: 'foo' }; expect(util.convertParam(object)).to.equal(object); }); }); -}); \ No newline at end of file +});