From 64945556ff0d9a668df9586ddd70fb6b1c6fe966 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Fri, 22 Apr 2016 16:49:38 -0700 Subject: [PATCH] rename create client, fix client instance test --- src/helpers/{create_client.js => es_client.js} | 7 ++++++- test/src/helpers/{create_client.js => es_client.js} | 9 +++++---- 2 files changed, 11 insertions(+), 5 deletions(-) rename src/helpers/{create_client.js => es_client.js} (56%) rename test/src/helpers/{create_client.js => es_client.js} (76%) diff --git a/src/helpers/create_client.js b/src/helpers/es_client.js similarity index 56% rename from src/helpers/create_client.js rename to src/helpers/es_client.js index c63fced..da2eeeb 100644 --- a/src/helpers/create_client.js +++ b/src/helpers/es_client.js @@ -3,7 +3,8 @@ import elasticsearch from 'elasticsearch'; export default function createClient(options) { let client; - if (options instanceof elasticsearch.Client) { + // if there's a transport property, assume it's a client instance + if (isClient(options)) { client = options; } else { client = new elasticsearch.Client(options); @@ -11,3 +12,7 @@ export default function createClient(options) { return client; }; + +export function isClient(client) { + return !!client.transport; +} diff --git a/test/src/helpers/create_client.js b/test/src/helpers/es_client.js similarity index 76% rename from test/src/helpers/create_client.js rename to test/src/helpers/es_client.js index fc0b7a1..303863f 100644 --- a/test/src/helpers/create_client.js +++ b/test/src/helpers/es_client.js @@ -2,24 +2,25 @@ import expect from 'expect.js'; import proxyquire from 'proxyquire'; import * as elasticsearchMock from '../../fixtures/elasticsearch'; -const createClient = proxyquire.noPreserveCache()('../../../lib/helpers/create_client', { +const module = proxyquire.noPreserveCache()('../../../lib/helpers/es_client', { elasticsearch: elasticsearchMock }); +const createClient = module.default; +const { isClient } = module; + 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); + expect(isClient(client)).to.be.ok(); }); it('should use passed in instance', function () { const clientInstance = new elasticsearchMock.Client(); const client = createClient(clientInstance); - expect(client).to.equal(clientInstance); }); });