'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 _fs = require('fs');

var _fs2 = _interopRequireDefault(_fs);

var _mocha = require('mocha');

var _assert = require('assert');

var _assert2 = _interopRequireDefault(_assert);

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

var _ExecutorTravis = require('../../src/executors/ExecutorTravis');

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

(0, _mocha.describe)('ExecutorTravis', function () {
    var _this = this;

    var executorTravis = void 0;
    var eventData = void 0;

    (0, _mocha.beforeEach)(function () {
        eventData = JSON.parse(_fs2.default.readFileSync(__dirname + '/../fixtures/executorJenkinsTaskPayload.json', 'utf-8'));
        executorTravis = new _ExecutorTravis.ExecutorTravis(eventData, console);
    });

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

    (0, _mocha.describe)('executeTask', function () {
        eventData = JSON.parse(_fs2.default.readFileSync(__dirname + '/../fixtures/executorJenkinsTaskPayload.json', 'utf-8'));
        var expectedObject = { passed: true, url: 'https://travis-ci.org' };
        (0, _mocha.it)('executeTask to return result object', (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
            var result, i;
            return _regenerator2.default.wrap(function _callee$(_context) {
                while (1) {
                    switch (_context.prev = _context.next) {
                        case 0:
                            _context.next = 2;
                            return executorTravis.executeTask(eventData.ghTaskConfig.tasks);

                        case 2:
                            result = _context.sent;

                            for (i = 0; i < 2; i++) {
                                _assert2.default.equal(result[i], expectedObject[i]);
                            }

                        case 4:
                        case 'end':
                            return _context.stop();
                    }
                }
            }, _callee, _this);
        })));
    });
});