"use strict";

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

var _immutable = require("immutable");

var _chai = require("chai");

var _keyBy = _interopRequireDefault(require("lodash/keyBy"));

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

var _quizSessionResults = _interopRequireDefault(require("../quizSessionResults"));

var _fakeSessionItemResults = require("../../../../tests/util/fakeSessionItemResults");

describe('quiz session result', function () {
  describe('#addQuizSessionResult', function () {
    it('adds a quizSessionResult to the store with ADD_QUIZ_SESSION_RESULT', function () {
      var mockAction = {
        type: _constants.ADD_QUIZ_SESSION_RESULTS,
        payload: _fakeSessionItemResults.fakeSessionItemResults
      };
      var quizSessionResultsHash = (0, _keyBy.default)(mockAction.payload, 'id');
      var newState = (0, _quizSessionResults.default)(void 0, mockAction);
      (0, _chai.expect)(newState).to.deep.equal((0, _immutable.fromJS)(quizSessionResultsHash));
    });
    it('adds a result to the list when stored', function () {
      var mockAction = {
        type: _constants.ADD_QUIZ_SESSION_RESULTS,
        payload: _fakeSessionItemResults.fakeSessionItemResults
      };
      var mockAction2 = {
        type: _constants.ADD_QUIZ_SESSION_RESULTS,
        payload: _fakeSessionItemResults.fakeSessionItemResults2
      };
      var newState = (0, _quizSessionResults.default)((0, _immutable.fromJS)({}), mockAction);
      var newState2 = (0, _quizSessionResults.default)(newState, mockAction2);

      var expectResult = _fakeSessionItemResults.fakeSessionItemResults.concat(_fakeSessionItemResults.fakeSessionItemResults2);

      (0, _chai.expect)(newState2).to.deep.equal((0, _immutable.fromJS)((0, _keyBy.default)(expectResult, 'id')));
    });
    it('deeply merges new quiz session results', function () {
      var completeResult = {
        id: '1',
        sessionItemResults: ['1', '2']
      };
      var incompleteResult = {
        id: '1'
      };
      var completeInfoAction = {
        type: _constants.ADD_QUIZ_SESSION_RESULTS,
        payload: [completeResult]
      };
      var incompleteInfoAction = {
        type: _constants.ADD_QUIZ_SESSION_RESULTS,
        payload: [incompleteResult]
      };
      var stateOne = (0, _quizSessionResults.default)((0, _immutable.fromJS)({}), completeInfoAction);
      var stateTwo = (0, _quizSessionResults.default)(stateOne, incompleteInfoAction);
      (0, _chai.expect)(stateTwo.getIn(['1', 'sessionItemResults'])).to.deep.equal((0, _immutable.fromJS)(['1', '2']));
    });
  });
});