use contants for defaults, use a common doctype

add tests, update readme
This commit is contained in:
2016-05-12 11:47:05 -07:00
parent fa784393e5
commit 0020050f3f
6 changed files with 48 additions and 20 deletions

View File

@@ -2,6 +2,7 @@ import expect from 'expect.js';
import sinon from 'sinon';
import createIndex from '../../../lib/helpers/create_index';
import elasticsearchMock from '../../fixtures/elasticsearch';
import { defaultSettings } from '../../../lib/helpers/constants';
describe('Create Index', function () {
let client;
@@ -23,8 +24,9 @@ describe('Create Index', function () {
});
});
it('should create the default mappings', function () {
it('should create the type mappings', function () {
const indexName = 'test-index';
const docType = defaultSettings.DEFAULT_SETTING_DOCTYPE;
const result = createIndex(client, indexName);
return result
@@ -33,8 +35,24 @@ describe('Create Index', function () {
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('_default_');
expect(payload.body.mappings._default_).to.have.property('properties');
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');
});
});
});