­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ const sinon = require('sinon'); const should = require('should'); const sandbox = sinon.createSandbox(); const {Client} = require('@elastic/elasticsearch'); const ElasticSearch = require('../index'); const testClientConfig = { node: 'http://test-elastic-client', auth: { username: 'user', password: 'pass' } }; describe('ElasticSearch', function () { afterEach(function () { sandbox.restore(); }); it('Processes client configuration', function () { const es = new ElasticSearch(testClientConfig); should.exist(es.client); should.exist(es.client.index); }); it('Processes index configuration', function () { sandbox.stub(Client.prototype, 'index').callsFake((data) => { should.exist(data.body); should.deepEqual(data.body, testBody); should.exist(data.index); should.equal(data.index, indexConfig.index); should.exist(data.pipeline); should.equal(data.pipeline, indexConfig.pipeline); }); const indexConfig = { index: 'test-index', pipeline: 'test-pipeline' }; const testBody = { message: 'Test data!' }; const es = new ElasticSearch(testClientConfig, indexConfig); es.write(testBody); Client.prototype.index.called.should.eql(true); }); });