change test structure, create elasticsearch fixture

This commit is contained in:
2016-04-15 16:51:38 -07:00
parent 600f2eb529
commit 822019f12a
4 changed files with 15 additions and 7 deletions

View File

@@ -0,0 +1,25 @@
import expect from 'expect.js';
import proxyquire from 'proxyquire';
import * as elasticsearchMock from '../../fixtures/elasticsearch';
const createClient = proxyquire.noPreserveCache()('../../../lib/helpers/create_client', {
elasticsearch: elasticsearchMock
});
describe('Create client helper', function () {
it('should have a client', function () {
const options = {
host: 'http://localhost:9200'
};
const client = createClient(options);
expect(client).to.be.a(elasticsearchMock.Client);
});
it('should use passed in instance', function () {
const clientInstance = new elasticsearchMock.Client();
const client = createClient(clientInstance);
expect(client).to.equal(clientInstance);
});
});

32
test/src/index.js Normal file
View File

@@ -0,0 +1,32 @@
import Elastique from '../../lib/index';
import expect from 'expect.js';
describe('Elastique class', function () {
describe('Option validation', function () {
it('should throw without an index', function () {
const init = () => new Elastique();
expect(init).to.throwException(/must.+specify.+index/i);
});
it('should throw with an invalid host', function () {
const init = () => new Elastique('elastique', {
client: { host: 'nope://nope' }
});
expect(init).to.throwException(/invalid.+protocol/i);
});
it('should throw with invalid hosts', function () {
const init = () => new Elastique('elastique', {
client: { hosts: [{ host: 'localhost', protocol: 'nope' }] }
});
expect(init).to.throwException(/invalid.+protocol/i);
});
});
describe('Job Creation', function () {
});
});