"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
let assert = require('assert');
const mysqlMock_1 = require("../mocks/mysqlMock");
const mockObjects_1 = require("../mockObjects");
let config = {
    statusCheckInterval: 1,
    keys: {
        rediskey_connections: "test:"
    }
};
describe('test mysql', function () {
    it('create destroy', function (done) {
        class SpecialCase extends mysqlMock_1.default {
            destroy() {
                done();
                return super.destroy();
            }
        }
        let redis = mockObjects_1.default.makeMysql(config, SpecialCase);
        redis.destroy();
    });
    it('status change', function (done) {
        let getStatus = function () {
            return "default";
        };
        let destroy = function () { };
        class SpecialCase extends mysqlMock_1.default {
            constructor() {
                super(...arguments);
                this.i = 0;
            }
            destroy() {
                done();
                return super.destroy();
            }
            ping(options, callback) {
                let status = getStatus();
                this.i += 1;
                if (status == "default")
                    this.i = 1; //Start to increment just after change getStatus function
                switch (this.i) {
                    case 1:
                        //We cant know if is first or secand call
                        if (typeof callback === "function")
                            callback(null);
                        break;
                    case 2:
                        assert.equal(getStatus(), "Connected");
                        assert.equal(mysql.isFunctional(), true);
                        if (typeof callback === "function")
                            callback(new Error());
                        break;
                    case 3:
                        assert.equal(getStatus(), "Error");
                        assert.equal(mysql.isFunctional(), false);
                        destroy();
                        break;
                }
            }
        }
        let mysql = mockObjects_1.default.makeMysql(config, SpecialCase);
        getStatus = function () { return mysql.getStatus(); };
        destroy = function () { mysql.destroy(); };
    });
});
//# sourceMappingURL=test-mysql.js.map