"use strict";

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

var _chai = require("chai");

var _immutable = require("immutable");

var _recordTests = require("../../../../tests/util/recordTests");

var _QuizSessionResult = _interopRequireDefault(require("../QuizSessionResult"));

var _reduxStore = require("../../../reduxStore");

describe('QuizSessionResult Record', function () {
  describe('#constructor', function () {
    var defaultsToCheck = {
      id: '0'
    };
    (0, _recordTests.defaultChecks)(_QuizSessionResult.default, defaultsToCheck);
  });
  describe('#isLoaded', function () {
    it('is loaded when there is a nonzero id', function () {
      var result = new _QuizSessionResult.default({
        id: '2'
      });
      (0, _chai.expect)(result.isLoaded()).to.be.true();
    });
    it('is not loaded by default', function () {
      var result = new _QuizSessionResult.default();
      (0, _chai.expect)(result.isLoaded()).to.be.false();
    });
    it('is not loaded with id = 0', function () {
      var result = new _QuizSessionResult.default({
        id: '0'
      });
      (0, _chai.expect)(result.isLoaded()).to.be.false();
    });
  });
  describe('#isGraded', function () {
    it('is graded when status is set to "graded"', function () {
      var result = new _QuizSessionResult.default({
        status: 'graded'
      });
      (0, _chai.expect)(result.isGraded()).to.be.true();
    });
    it('is not graded by default', function () {
      var result = new _QuizSessionResult.default();
      (0, _chai.expect)(result.isGraded()).to.be.false();
    });
    it('is not graded when status is not "graded"', function () {
      var result = new _QuizSessionResult.default({
        status: 'somethingelse'
      });
      (0, _chai.expect)(result.isGraded()).to.be.false();
    });
  });
  describe('#getSessionItemResults', function () {
    it('gets the relation list', function () {
      var result = new _QuizSessionResult.default();
      var results = [];
      result.getRelationList = sinon.stub().returns(results);
      (0, _chai.expect)(result.getSessionItemResults()).to.equal(results);
      (0, _chai.expect)(result.getRelationList.calledWith('sessionItemResults', 'findSessionItemResult')).to.be.true();
    });
  });
  describe('#getWorkingInstance', function () {
    after(function () {
      (0, _reduxStore.unsetFakeStore)();
    });
    it('merges the right modifications into itself', function () {
      var modifiedFudgePoints = 5;
      (0, _reduxStore.setFakeStore)((0, _immutable.fromJS)({
        modifications: {
          quizSessionResults: {
            22: {
              id: '22',
              fudgePoints: modifiedFudgePoints
            }
          }
        }
      }));
      var quizSessionResult = new _QuizSessionResult.default({
        id: '22'
      });
      (0, _chai.expect)(quizSessionResult.getWorkingInstance().fudgePoints).to.be.equal(modifiedFudgePoints);
    });
  });
  describe('#hasModifications', function () {
    it('returns false if it has no modifications', function () {
      var result = new _QuizSessionResult.default();
      var unmodifiedResult = result.merge({});
      sinon.stub(result, 'getWorkingInstance').returns(unmodifiedResult);
      (0, _chai.expect)(result.hasModifications()).to.be.false();
    });
    it('returns true if modifications exist', function () {
      var result = new _QuizSessionResult.default();
      var modifiedResult = result.merge({
        fudgePoints: 99
      });
      sinon.stub(result, 'getWorkingInstance').returns(modifiedResult);
      (0, _chai.expect)(result.hasModifications()).to.be.true();
    });
  });
});