"use strict";

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

var _immutable = require("immutable");

var _chai = require("chai");

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

var _quizSessionEvents = require("../quizSessionEvents");

var _quizSessionEvents2 = require("../../../common/actions/quizSessionEvents");

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

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

describe('getQuizSessionEvents', function () {
  var dispatchStub = sinon.stub();
  var getStateStub = sinon.stub().returns((0, _immutable.fromJS)({
    quizSessionEvents: {}
  }));
  var fetchStub = sinon.stub();
  useFakeFetching({
    dispatchStub: dispatchStub,
    getStateStub: getStateStub,
    fetchStub: fetchStub
  });
  var quizSessionId = '123';

  var stubbedGetQuizSessionEventsCall = function stubbedGetQuizSessionEventsCall() {
    _Fetcher.default.fakeFetch = fetchStub;
    var getQuizSessionEventsThunk = (0, _quizSessionEvents.getQuizSessionEvents)(quizSessionId);
    getQuizSessionEventsThunk(dispatchStub, getStateStub);
  };

  it('should hit the right endpoint', function () {
    stubbedGetQuizSessionEventsCall();
    (0, _chai.expect)(fetchStub.calledWith("/api/quiz_sessions/".concat(quizSessionId, "/quiz_session_events?"))).to.be.true();
  });
  it('should persist quiz session event data', function (done) {
    var quizSessionEventsRes = (0, _jsonify.jsoniblePromise)([{
      created_at: 'someValue'
    }]);
    var fakeFetch = (0, _fakeFetch.default)(quizSessionEventsRes);
    _Fetcher.default.fakeFetch = fakeFetch;
    var getQuizSessionEventsThunk = (0, _quizSessionEvents.getQuizSessionEvents)(quizSessionId);
    var fetchPromise = getQuizSessionEventsThunk(dispatchStub, getStateStub);
    var expectedAction = (0, _quizSessionEvents2.addQuizSessionEvents)([{
      createdAt: 'someValue'
    }]);
    fetchPromise.then(function () {
      checkActionDispatched(dispatchStub, expectedAction);
      done();
    });
  });
});