'use strict';

var _regenerator = require('babel-runtime/regenerator');

var _regenerator2 = _interopRequireDefault(_regenerator);

var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');

var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);

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

var _mocha = require('mocha');

var _assert = require('assert');

var _assert2 = _interopRequireDefault(_assert);

var _Executor = require('../../src/agent/Executor');

var _ExecutorPing = require('../../src/executors/ExecutorPing');

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

(0, _mocha.describe)('ExecutorPing', function () {
    var executorPing = void 0;
    var eventData = void 0;

    (0, _mocha.beforeEach)(function () {
        process.env.GTM_SQS_RESULTS_QUEUE = 'gtmResultsQueue';
        process.env.GTM_SNS_RESULTS_TOPIC = 'gtmResultsSNSTopic';
        process.env.GTM_AWS_REGION = 'ap-southeast-2a';
        eventData = {
            executor: 'Ping',
            context: 'diagnostic',
            options: {
                count: 1
            },
            repository: {
                name: 'pingTest',
                owner: {
                    login: 'shell_cli'
                }
            },
            pull_request: {
                head: {
                    sha: 'cee03d54dc35650b903b0cdc38ebd49208b1efa4'
                }
            }
        };
        executorPing = new _ExecutorPing.ExecutorPing(eventData, console);
    });

    (0, _mocha.describe)('constructor', function () {
        (0, _mocha.it)('should instantiate as Executor', function () {
            _assert2.default.equal(executorPing instanceof _Executor.Executor, true);
        });
    });

    (0, _mocha.describe)('executeTask', function () {
        (0, _mocha.it)('should call ExecutorPing.executeTask with 1 event', (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
            return _regenerator2.default.wrap(function _callee$(_context) {
                while (1) {
                    switch (_context.prev = _context.next) {
                        case 0:
                            _context.prev = 0;
                            _context.next = 3;
                            return executorPing.executeTask(eventData).then(function (data) {
                                return data;
                            });

                        case 3:
                            _context.next = 8;
                            break;

                        case 5:
                            _context.prev = 5;
                            _context.t0 = _context['catch'](0);
                            return _context.abrupt('return', _assert2.default.equal(_context.t0.message, 'Missing region in config'));

                        case 8:
                        case 'end':
                            return _context.stop();
                    }
                }
            }, _callee, undefined, [[0, 5]]);
        })));
    });
});