"use strict";

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

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

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

var _common = require("../../../../common");

var _ocr = require("../../ocr");

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); }); }; }

describe("Testing service and resource name getters", function () {
  test("resource name getter", function () {
    var serviceName = _ocr.OCR.resourceName;
    expect(serviceName).toBe("ocr");
  });
  test("service name getter", function () {
    var serviceName = _ocr.OCR.serviceName;
    expect(serviceName).toBe("labs");
  });
});
describe("Testing methods", function () {
  test("Should throw error if server return error during getting pre-signed url", /*#__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(_common.APIServer.prototype, "get").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", {
                        error: {
                          message: "Error"
                        }
                      });

                    case 1:
                    case "end":
                      return _context.stop();
                  }
                }
              }, _callee);
            })));
            _context2.prev = 2;
            _context2.next = 5;
            return _ocr.OCR.getPreSingedUrl("");

          case 5:
            _context2.next = 11;
            break;

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

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

          case 12:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2, null, [[2, 7]]);
  })));
  test("Should throw error if server return error during getting request status", /*#__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(_common.APIServer.prototype, "get").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", {
                        error: {
                          message: "Error"
                        }
                      });

                    case 1:
                    case "end":
                      return _context3.stop();
                  }
                }
              }, _callee3);
            })));
            _context4.prev = 2;
            _context4.next = 5;
            return _ocr.OCR.getRequestStatus("");

          case 5:
            _context4.next = 11;
            break;

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

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

          case 12:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4, null, [[2, 7]]);
  })));
  test("Should throw error if server return error during post", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
    var errorHappened;
    return regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            errorHappened = jest.fn();
            jest.spyOn(_common.APIServer.prototype, "post").mockImplementation( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
              return regeneratorRuntime.wrap(function _callee5$(_context5) {
                while (1) {
                  switch (_context5.prev = _context5.next) {
                    case 0:
                      return _context5.abrupt("return", {
                        error: {
                          message: "Error"
                        }
                      });

                    case 1:
                    case "end":
                      return _context5.stop();
                  }
                }
              }, _callee5);
            })));
            _context6.prev = 2;
            _context6.next = 5;
            return _ocr.OCR.upload("", "");

          case 5:
            _context6.next = 11;
            break;

          case 7:
            _context6.prev = 7;
            _context6.t0 = _context6["catch"](2);
            errorHappened();
            expect(_context6.t0).toBeInstanceOf(_common.APIResponseError);

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

          case 12:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6, null, [[2, 7]]);
  })));
});
//# sourceMappingURL=data:application/json;charset=utf-8;base64, 