100 percent coverage on create_index helper
This commit is contained in:
@@ -5,54 +5,96 @@ import elasticsearchMock from '../../fixtures/elasticsearch';
|
|||||||
import { defaultSettings } from '../../../lib/helpers/constants';
|
import { defaultSettings } from '../../../lib/helpers/constants';
|
||||||
|
|
||||||
describe('Create Index', function () {
|
describe('Create Index', function () {
|
||||||
let client;
|
|
||||||
let createSpy;
|
|
||||||
|
|
||||||
beforeEach(function () {
|
describe('Does not exist', function () {
|
||||||
client = new elasticsearchMock.Client();
|
let client;
|
||||||
createSpy = sinon.spy(client.indices, 'create');
|
let createSpy;
|
||||||
});
|
|
||||||
|
|
||||||
it('should create the index', function () {
|
beforeEach(function () {
|
||||||
const indexName = 'test-index';
|
client = new elasticsearchMock.Client();
|
||||||
const result = createIndex(client, indexName);
|
createSpy = sinon.spy(client.indices, 'create');
|
||||||
|
});
|
||||||
|
|
||||||
return result
|
it('should return true', function () {
|
||||||
.then(function () {
|
const indexName = 'test-index';
|
||||||
sinon.assert.callCount(createSpy, 1);
|
const result = createIndex(client, indexName);
|
||||||
expect(createSpy.getCall(0).args[0]).to.have.property('index', 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);
|
||||||
|
|
||||||
|
return result
|
||||||
|
.then(function () {
|
||||||
|
sinon.assert.callCount(createSpy, 1);
|
||||||
|
expect(createSpy.getCall(0).args[0]).to.have.property('index', indexName);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create the type mappings', function () {
|
||||||
|
const indexName = 'test-index';
|
||||||
|
const docType = defaultSettings.DEFAULT_SETTING_DOCTYPE;
|
||||||
|
const result = createIndex(client, indexName);
|
||||||
|
|
||||||
|
return result
|
||||||
|
.then(function () {
|
||||||
|
const payload = createSpy.getCall(0).args[0];
|
||||||
|
sinon.assert.callCount(createSpy, 1);
|
||||||
|
expect(payload).to.have.property('body');
|
||||||
|
expect(payload.body).to.have.property('mappings');
|
||||||
|
expect(payload.body.mappings).to.have.property(docType);
|
||||||
|
expect(payload.body.mappings[docType]).to.have.property('properties');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should accept a custom doctype', function () {
|
||||||
|
const indexName = 'test-index';
|
||||||
|
const docType = 'my_type';
|
||||||
|
const result = createIndex(client, indexName, docType);
|
||||||
|
|
||||||
|
return result
|
||||||
|
.then(function () {
|
||||||
|
const payload = createSpy.getCall(0).args[0];
|
||||||
|
sinon.assert.callCount(createSpy, 1);
|
||||||
|
expect(payload).to.have.property('body');
|
||||||
|
expect(payload.body).to.have.property('mappings');
|
||||||
|
expect(payload.body.mappings).to.have.property(docType);
|
||||||
|
expect(payload.body.mappings[docType]).to.have.property('properties');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create the type mappings', function () {
|
describe('Does exist', function () {
|
||||||
const indexName = 'test-index';
|
let client;
|
||||||
const docType = defaultSettings.DEFAULT_SETTING_DOCTYPE;
|
let existsStub;
|
||||||
const result = createIndex(client, indexName);
|
let createSpy;
|
||||||
|
|
||||||
return result
|
beforeEach(function () {
|
||||||
.then(function () {
|
client = new elasticsearchMock.Client();
|
||||||
const payload = createSpy.getCall(0).args[0];
|
existsStub = sinon.stub(client.indices, 'exists', () => Promise.resolve(true));
|
||||||
sinon.assert.callCount(createSpy, 1);
|
createSpy = sinon.spy(client.indices, 'create');
|
||||||
expect(payload).to.have.property('body');
|
|
||||||
expect(payload.body).to.have.property('mappings');
|
|
||||||
expect(payload.body.mappings).to.have.property(docType);
|
|
||||||
expect(payload.body.mappings[docType]).to.have.property('properties');
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('should accept a custom doctype', function () {
|
it('should return true', function () {
|
||||||
const indexName = 'test-index';
|
const indexName = 'test-index';
|
||||||
const docType = 'my_type';
|
const result = createIndex(client, indexName);
|
||||||
const result = createIndex(client, indexName, docType);
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
.then(function () {
|
.then((exists) => expect(exists).to.be(true));
|
||||||
const payload = createSpy.getCall(0).args[0];
|
|
||||||
sinon.assert.callCount(createSpy, 1);
|
|
||||||
expect(payload).to.have.property('body');
|
|
||||||
expect(payload.body).to.have.property('mappings');
|
|
||||||
expect(payload.body.mappings).to.have.property(docType);
|
|
||||||
expect(payload.body.mappings[docType]).to.have.property('properties');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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