"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
let assert = require('assert');
const elasticMock_1 = require("../mocks/elasticMock");
const mockObjects_1 = require("../mockObjects");
let config = {
    statusCheckInterval: 1,
    autoConnect: true
};
describe('test elastic', function () {
    it('create destroy', function (done) {
        class SpecialCase extends elasticMock_1.default {
            close() {
                done();
            }
        }
        let elastic = mockObjects_1.default.makeElastic(config, SpecialCase);
        elastic.destroy();
    });
    it('status change', function (done) {
        let getStatus = function () {
            return "default";
        };
        let destroy = function () { };
        class SpecialCase extends elasticMock_1.default {
            constructor() {
                super(...arguments);
                this.i = 0;
            }
            close() {
                done();
            }
            ping(params, callback) {
                this.i += 1;
                if (getStatus() == "default")
                    this.i = 1; //Start to increment just after chenge getStatus function
                switch (this.i) {
                    case 1:
                        //We cant know if is first or secand call
                        if (callback != null)
                            callback(null, null, null);
                        break;
                    case 2:
                        assert.equal(getStatus(), "connected");
                        if (callback != null)
                            callback(new Error(), null, null);
                        break;
                    case 3:
                        assert.equal(getStatus(), "error");
                        destroy();
                        break;
                }
                return super.ping(params);
            }
        }
        let elastic = mockObjects_1.default.makeElastic(config, SpecialCase);
        getStatus = function () { return elastic.getStatus(); };
        destroy = function () { elastic.destroy(); };
    });
});
//# sourceMappingURL=test-elastic.js.map