"use strict";

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

var _immutable = require("immutable");

var _chai = require("chai");

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

var _sessionItems = require("../../actions/sessionItems");

var _quizSessions2 = require("../../actions/quizSessions");

describe('quizSession reducer', function () {
  describe('addSessionItems', function () {
    it('adds session items to quiz sessions', function () {
      var initialState = (0, _immutable.fromJS)({
        33: {
          sessionItems: ['33_1']
        },
        44: {
          sessionItems: ['44_1', '44_2']
        }
      });
      var action = (0, _sessionItems.addSessionItems)([{
        id: '44_3',
        quizSessionId: '44'
      }, {
        id: '33_2',
        quizSessionId: '33'
      }]);
      (0, _chai.expect)((0, _quizSessions.default)(initialState, action).toJS()).to.eql({
        33: {
          sessionItems: ['33_1', '33_2']
        },
        44: {
          sessionItems: ['44_1', '44_2', '44_3']
        }
      });
    });
    it('works on sessions with no prior session items', function () {
      var initialState = (0, _immutable.fromJS)({
        33: {}
      });
      var action = (0, _sessionItems.addSessionItems)([{
        id: '33_1',
        quizSessionId: '33'
      }, {
        id: '33_2',
        quizSessionId: '33'
      }]);
      (0, _chai.expect)((0, _quizSessions.default)(initialState, action).toJS()).to.eql({
        33: {
          sessionItems: ['33_1', '33_2']
        }
      });
    });
    it('removes duplicates', function () {
      var initialState = (0, _immutable.fromJS)({
        33: {
          sessionItems: ['33_1', '33_2']
        }
      });
      var action = (0, _sessionItems.addSessionItems)([{
        id: '33_1',
        quizSessionId: '33'
      }, {
        id: '33_2',
        quizSessionId: '33'
      }, {
        id: '33_3',
        quizSessionId: '33'
      }]);
      (0, _chai.expect)((0, _quizSessions.default)(initialState, action).toJS()).to.eql({
        33: {
          sessionItems: ['33_1', '33_2', '33_3']
        }
      });
    });
  });
  describe('addQuizSession', function () {
    it('should add quizSession with ADD_QUIZ_SESSIONS action', function () {
      var initialState = (0, _immutable.fromJS)({});
      var newQuizSession = {
        id: '1',
        quiz: '2',
        title: 'fin 283 pop quiz'
      };
      var action = (0, _quizSessions2.addQuizSessions)(newQuizSession);
      var nextState = (0, _quizSessions.default)(initialState, action);
      var nextTitle = nextState.getIn(['1', 'title']);
      (0, _chai.expect)(nextTitle).to.equal('fin 283 pop quiz');
    });
    it('should replace quizSessions with ADD_QUIZ_SESSIONS action', function () {
      var initialState = (0, _immutable.fromJS)({
        2: {
          quiz: '2',
          state: 'some intial title'
        }
      });
      var newQuizSession = {
        id: '2',
        quiz: '2',
        status: 'some new status'
      };
      var action = (0, _quizSessions2.addQuizSessions)(newQuizSession);
      var nextState = (0, _quizSessions.default)(initialState, action);
      var nextTitle = nextState.getIn(['2', 'status']);
      (0, _chai.expect)(nextTitle).to.equal('some new status');
    });
    it('should not replace lists with null if the new session has no value', function () {
      var initialState = (0, _immutable.fromJS)({
        2: {
          sessionItems: ['1', '2']
        }
      });
      var newQuizSession = {
        id: '2',
        quiz: '2'
      };
      var action = (0, _quizSessions2.addQuizSessions)(newQuizSession);
      var nextState = (0, _quizSessions.default)(initialState, action);
      var nextSessionItems = nextState.getIn(['2', 'sessionItems']).toJS();
      (0, _chai.expect)(nextSessionItems).to.eql(['1', '2']);
    });
  });
});