"use strict";

require("regenerator-runtime/runtime.js");

require("core-js/modules/es.object.to-string.js");

require("core-js/modules/es.promise.js");

var _uploader = require("../../uploader");

var _axios = _interopRequireDefault(require("axios"));

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

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

var mockFile = new File([], "test");
describe("Testing s3 functions", function () {
  test("Should invoke callback if error happens during file upload", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
    var errorHappened;
    return regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            errorHappened = jest.fn();
            jest.spyOn(_axios["default"], "post").mockImplementation( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
              return regeneratorRuntime.wrap(function _callee$(_context) {
                while (1) {
                  switch (_context.prev = _context.next) {
                    case 0:
                      return _context.abrupt("return", Promise.reject());

                    case 1:
                    case "end":
                      return _context.stop();
                  }
                }
              }, _callee);
            })));
            _context2.prev = 2;
            _context2.next = 5;
            return _uploader.Uploader.postUploadFile(mockFile, "test-url", {
              key: "123"
            }, jest.fn);

          case 5:
            _context2.next = 10;
            break;

          case 7:
            _context2.prev = 7;
            _context2.t0 = _context2["catch"](2);
            errorHappened();

          case 10:
            expect(errorHappened).toBeCalledTimes(1);

          case 11:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2, null, [[2, 7]]);
  })));
  test("Should invoke callback if error happens during put file upload", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
    var errorHappened;
    return regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            errorHappened = jest.fn();
            jest.spyOn(_axios["default"], "put").mockImplementation( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
              return regeneratorRuntime.wrap(function _callee3$(_context3) {
                while (1) {
                  switch (_context3.prev = _context3.next) {
                    case 0:
                      return _context3.abrupt("return", Promise.reject());

                    case 1:
                    case "end":
                      return _context3.stop();
                  }
                }
              }, _callee3);
            })));
            _context4.prev = 2;
            _context4.next = 5;
            return _uploader.Uploader.putUploadFile(mockFile, "test-url", jest.fn);

          case 5:
            _context4.next = 10;
            break;

          case 7:
            _context4.prev = 7;
            _context4.t0 = _context4["catch"](2);
            errorHappened();

          case 10:
            expect(errorHappened).toBeCalledTimes(1);

          case 11:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4, null, [[2, 7]]);
  })));
});
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3NyYy9jb21tb24vdXBsb2FkZXIvdGVzdHMvX190ZXN0c19fL3VwbG9hZGVyLnRzIl0sIm5hbWVzIjpbIm1vY2tGaWxlIiwiRmlsZSIsImRlc2NyaWJlIiwidGVzdCIsImVycm9ySGFwcGVuZWQiLCJqZXN0IiwiZm4iLCJzcHlPbiIsImF4aW9zIiwibW9ja0ltcGxlbWVudGF0aW9uIiwiUHJvbWlzZSIsInJlamVjdCIsIlVwbG9hZGVyIiwicG9zdFVwbG9hZEZpbGUiLCJrZXkiLCJleHBlY3QiLCJ0b0JlQ2FsbGVkVGltZXMiLCJwdXRVcGxvYWRGaWxlIl0sIm1hcHBpbmdzIjoiOzs7Ozs7OztBQUFBOztBQUNBOzs7Ozs7OztBQUVBLElBQU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