"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.mockBasicFilterAGGFetchRequests = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _client = _interopRequireDefault(require("fetch-mock/cjs/client"));
var _mocks = require("./mocks");
var mockBasicFilterAGGFetchRequests = exports.mockBasicFilterAGGFetchRequests = function mockBasicFilterAGGFetchRequests() {
  var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
    withJiraFilterHydration: true
  };
  _client.default.post(new RegExp("/graphql"), /*#__PURE__*/function () {
    var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_url, details) {
      return _regenerator.default.wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", new Promise(function (resolve) {
              var _mockBasicFilterData$;
              var requestBody = JSON.parse(details.body);

              // CLOL basic filter - edited/created by
              if (requestBody.operationName === 'userQuery') {
                return resolve(_mocks.successfulUserQueryResponse);
              }
              if (requestBody.operationName === 'userHydration') {
                return resolve(_mocks.successfuluserHydrationResponse);
              }

              // JLOL basic filter hydration for VR testing
              if (requestBody.operationName === 'hydrate' && opts.withJiraFilterHydration) {
                return resolve(_mocks.hydrateJqlStandardResponseForVRTesting);
              }
              var filterType = requestBody.variables.jqlTerm;
              var searchString = requestBody.variables.searchString;
              var pageCursor = requestBody.variables.after;
              var mockBasicFilterData = {
                project: _mocks.fieldValuesResponseForProjects,
                assignee: _mocks.fieldValuesResponseForAssignees,
                type: _mocks.fieldValuesResponseForTypes,
                status: _mocks.fieldValuesResponseForStatuses
              };
              var resolveData = {
                data: ((_mockBasicFilterData$ = mockBasicFilterData[filterType]) === null || _mockBasicFilterData$ === void 0 ? void 0 : _mockBasicFilterData$.data) || []
              };

              // playwright test specifically requesting more projects data
              if (pageCursor) {
                resolve(_mocks.fieldValuesResponseForProjectsMoreData);
              }

              // slowing down specifically for vr testing
              if (searchString === 'loading-message') {
                setTimeout(function () {
                  resolve(resolveData);
                }, 5000);
              } // returning empty response for vr testing
              else if (searchString === 'empty-message') {
                resolve(_mocks.fieldValuesEmptyResponse);
              } // returning error response for vr testing
              else if (searchString === 'error-message') {
                resolve(_mocks.fieldValuesErrorResponse);
              } else {
                resolve(resolveData);
              }
            }));
          case 1:
          case "end":
            return _context.stop();
        }
      }, _callee);
    }));
    return function (_x, _x2) {
      return _ref.apply(this, arguments);
    };
  }());
};