"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 _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));

var _addRecordActionCreatorCheck = _interopRequireDefault(require("../../../../tests/util/addRecordActionCreatorCheck"));

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

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

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

var _constants = require("@instructure/quiz-common/lib/constants");

var _quizSessions = require("../quizSessions");

describe('adding a QuizSession action creators', function () {
  (0, _addRecordActionCreatorCheck.default)('QuizSession', _quizSessions.addQuizSessions, _constants.ADD_QUIZ_SESSIONS);
});
it('returns a well-formed activeQuizSessionId change action', function () {
  var newActiveQuizSessionAction = (0, _quizSessions.newActiveQuizSession)('21');
  expect(newActiveQuizSessionAction).to.deep.equal({
    type: _constants.ACTIVE_QUIZ_SESSION_CHANGE,
    payload: '21'
  });
});
describe('action calls for quizSession', function () {
  var dispatchStub = sinon.stub();
  var getStateStub = sinon.stub();
  var fetchStub = sinon.stub();
  useFakeFetching({
    dispatchStub: dispatchStub,
    getStateStub: getStateStub,
    fetchStub: fetchStub
  });

  var actsAsAction = function actsAsAction(action, params) {
    it('calls the given api action', function () {
      var apiActionStub = sinon.stub();
      action.apply(void 0, (0, _toConsumableArray2.default)(params).concat([apiActionStub]))();
      expect(apiActionStub.called).to.be.true();
    });
    it('dispatches the action',
    /*#__PURE__*/
    (0, _asyncToGenerator2.default)(
    /*#__PURE__*/
    _regenerator.default.mark(function _callee() {
      return _regenerator.default.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              _Fetcher.default.fakeFetch = (0, _fakeFetch.default)((0, _jsonify.jsoniblePromise)([]));
              _context.next = 3;
              return action.apply(void 0, (0, _toConsumableArray2.default)(params))(dispatchStub, getStateStub);

            case 3:
              expect(dispatchStub.called).to.be.true();

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

  describe('getSessionItems', function () {
    actsAsAction(_quizSessions.getSessionItems, [1]);
  });
  describe('getSessionItemResults', function () {
    actsAsAction(_quizSessions.getSessionItemResults, [1, 2]);
  });
  describe('getQuizSessionResult', function () {
    actsAsAction(_quizSessions.getQuizSessionResult, [1, 2]);
  });
  describe('getResultInfo', function () {
    actsAsAction(_quizSessions.getResultInfo, [1]);
  });
});