"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));

var _Fetcher = _interopRequireDefault(require("../../../common/util/Fetcher"));

var _fakeFetch = _interopRequireDefault(require("../../../../tests/util/fakeFetch"));

var _jsonify = require("../../../common/util/jsonify");

var _callHandlers = require("../../../common/api/callHandlers");

var _quizAnalyses = require("../quizAnalyses");

describe('reporting api actions', function () {
  var quizId = '456';
  var quizAnalysisData = [{
    quiz_id: quizId,
    quiz_analysis: {}
  }];
  var fetchStub = sinon.stub();
  var dispatchStub = sinon.stub();
  var dispatchStubIgnore = sinon.stub();
  var getStateStub = sinon.stub();
  useFakeFetching({
    dispatchStub: dispatchStub,
    getStateStub: getStateStub,
    fetchStub: fetchStub
  });
  describe('getQuizAnalysis', function () {
    var stubbedGetQuizAnalysisCall = function stubbedGetQuizAnalysisCall() {
      var response = (0, _jsonify.jsoniblePromise)([quizAnalysisData]);
      _Fetcher.default.fakeFetch = (0, _fakeFetch.default)(response);
      return (0, _quizAnalyses.getQuizAnalysis)(quizId)(dispatchStub, getStateStub);
    };

    it('should hit the right endpoint', function () {
      _Fetcher.default.fakeFetch = fetchStub;
      (0, _quizAnalyses.getQuizAnalysis)(quizId)(dispatchStubIgnore, getStateStub);
      expect(fetchStub.calledWith("/api/quizzes/".concat(quizId, "/stats/quiz_analysis"))).to.be.true();
    });
    it('should trigger additional actions',
    /*#__PURE__*/
    (0, _asyncToGenerator2.default)(
    /*#__PURE__*/
    _regenerator.default.mark(function _callee() {
      var expectedResponse;
      return _regenerator.default.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              _context.next = 2;
              return stubbedGetQuizAnalysisCall();

            case 2:
              expectedResponse = (0, _callHandlers.handleQuizAnalysisResponse)([quizAnalysisData]);
              checkActionDispatched(dispatchStub, expectedResponse[0]);

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