'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 _ExecutorHttp = require('../../src/executors/ExecutorHttp');

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

(0, _mocha.describe)('ExecutorHttp', function () {
    var executorHttp = void 0;
    var eventData = void 0;

    (0, _mocha.beforeEach)(function () {
        eventData = {
            executor: 'Http',
            context: 'avtest',
            options: {
                har: {
                    url: 'https://httpbin.org/headers',
                    method: 'GET',
                    headers: [{
                        name: 'accept',
                        value: 'application/json'
                    }]
                },
                validator: {
                    type: 'bodyJson',
                    objectCheckRef: 'headers.Host',
                    objectCheckVal: 'httpbin.org'
                }
            }
        };

        executorHttp = new _ExecutorHttp.ExecutorHttp(eventData, console);
    });

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

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

                        case 3:
                            result = _context.sent;

                            _assert2.default.equal(result.results.passed, true);

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

    (0, _mocha.describe)('validate', function () {
        (0, _mocha.it)('should validate for bodyJson', function () {
            var actual = executorHttp.validate(eventData, { body: '{"headers": {"Host": "httpbin.org"}}' });
            var expected = true;
            _assert2.default.equal(actual, expected);
        });
    });
});