'use strict';

var _promise = require('babel-runtime/core-js/promise');

var _promise2 = _interopRequireDefault(_promise);

require('source-map-support/register');

var _mocha = require('mocha');

var _assert = require('assert');

var _assert2 = _interopRequireDefault(_assert);

var _Agent = require('../../src/agent/Agent');

var _AgentMetrics = require('../../src/agent/AgentMetrics');

var _sqsConsumer = require('sqs-consumer');

var _sqsConsumer2 = _interopRequireDefault(_sqsConsumer);

var _sinon = require('sinon');

var _sinon2 = _interopRequireDefault(_sinon);

var _AgentUtils = require('../../src/agent/AgentUtils');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

(0, _mocha.describe)('Agent', function () {
    var AGENT_GROUP = void 0;

    var systemConfig = {};
    var agentObj = void 0;

    (0, _mocha.beforeEach)(function () {
        agentObj = new _Agent.Agent();
    });

    (0, _mocha.before)(function () {
        AGENT_GROUP = process.env.GTM_AGENT_GROUP || 'default';
        systemConfig.agentGroup = AGENT_GROUP;
    });

    (0, _mocha.describe)('systemConfig', function () {
        (0, _mocha.it)('should return systemConfig values', function () {
            var actual = _Agent.Agent.systemConfig;
            for (var i = 1; i < 5; i++) {
                _assert2.default.equal(actual[i], systemConfig[i]);
            }
        });
    });

    (0, _mocha.describe)('start', function () {
        var stubCall = void 0;
        var stubUtils = void 0;
        var stubListen = void 0;
        var stubMetrics = void 0;
        var customResult = { on: function on() {} };
        (0, _mocha.before)(function () {
            process.env.GTM_CRYPT_AGENT_AWS_ACCESS_KEY_ID = 'aws_key_id';
            process.env.GTM_CRYPT_AGENT_AWS_SECRET_ACCESS_KEY = 'aws_key_secret';
            process.env.GTM_CRYPT_GITHUB_WEBHOOK_SECRET = 'webhook_secret';

            customResult = {};
            stubCall = _sinon2.default.stub(_sqsConsumer2.default, 'create').returns(_promise2.default.resolve(customResult));
            stubUtils = _sinon2.default.stub(_AgentUtils.AgentUtils, 'getQueueUrl').returns(_promise2.default.resolve(customResult));
            stubListen = _sinon2.default.stub(_Agent.Agent.prototype, 'listen').returns(function () {});
            stubMetrics = _sinon2.default.stub(_AgentMetrics.AgentMetrics, 'configureRoutes').returns(_promise2.default.resolve(customResult));
        });

        (0, _mocha.it)('should start the agent', function () {
            agentObj.start();
        });

        (0, _mocha.after)(function () {
            stubCall.restore();
            stubUtils.restore();
            stubListen.restore();
            stubMetrics.restore();
        });
    });
}); //import { default as fs } from 'fs';