100 percent coverage on create_index helper
This commit is contained in:
@@ -5,6 +5,8 @@ import elasticsearchMock from '../../fixtures/elasticsearch';
|
||||
import { defaultSettings } from '../../../lib/helpers/constants';
|
||||
|
||||
describe('Create Index', function () {
|
||||
|
||||
describe('Does not exist', function () {
|
||||
let client;
|
||||
let createSpy;
|
||||
|
||||
@@ -13,6 +15,14 @@ describe('Create Index', function () {
|
||||
createSpy = sinon.spy(client.indices, 'create');
|
||||
});
|
||||
|
||||
it('should return true', function () {
|
||||
const indexName = 'test-index';
|
||||
const result = createIndex(client, indexName);
|
||||
|
||||
return result
|
||||
.then((exists) => expect(exists).to.be(true));
|
||||
});
|
||||
|
||||
it('should create the index', function () {
|
||||
const indexName = 'test-index';
|
||||
const result = createIndex(client, indexName);
|
||||
@@ -55,4 +65,36 @@ describe('Create Index', function () {
|
||||
expect(payload.body.mappings[docType]).to.have.property('properties');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Does exist', function () {
|
||||
let client;
|
||||
let existsStub;
|
||||
let createSpy;
|
||||
|
||||
beforeEach(function () {
|
||||
client = new elasticsearchMock.Client();
|
||||
existsStub = sinon.stub(client.indices, 'exists', () => Promise.resolve(true));
|
||||
createSpy = sinon.spy(client.indices, 'create');
|
||||
});
|
||||
|
||||
it('should return true', function () {
|
||||
const indexName = 'test-index';
|
||||
const result = createIndex(client, indexName);
|
||||
|
||||
return result
|
||||
.then((exists) => expect(exists).to.be(true));
|
||||
});
|
||||
|
||||
it('should not create the index', function () {
|
||||
const indexName = 'test-index';
|
||||
const result = createIndex(client, indexName);
|
||||
|
||||
return result
|
||||
.then(function () {
|
||||
sinon.assert.callCount(createSpy, 0);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user