100 percent coverage on create_index helper

This commit is contained in:
2016-06-27 14:23:49 -07:00
parent eae6942ec2
commit 866f5948af

View File

@@ -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);
@@ -56,3 +66,35 @@ describe('Create Index', function () {
});
});
});
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);
});
});
});
});