"use strict";

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

var _immutable = require("immutable");

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

var _Item = _interopRequireDefault(require("../Item"));

var _SessionItemResult = _interopRequireDefault(require("../SessionItemResult"));

var _SessionItem = _interopRequireDefault(require("../SessionItem"));

describe('SessionItemResult Record', function () {
  describe('relationships', function () {
    var itemData = {
      id: '2'
    };
    var exampleState = {
      sessionItems: {
        '1_1': {
          item: itemData
        }
      }
    };
    describe('#getItem', function () {
      var options = {
        RelationRecordType: _Item.default,
        relationAttrs: itemData,
        recordAttributes: {
          itemId: itemData.id,
          id: '1_1'
        },
        necessaryState: (0, _immutable.fromJS)(exampleState)
      };
      (0, _recordTests.singleRelationCheck)(_SessionItemResult.default, 'getItem', options);
    });
  });
  describe('#defaultResult', function () {
    it('builds a SessionItemResult with the proper attributes', function () {
      var si = new _SessionItem.default((0, _immutable.fromJS)({
        item: {
          id: '2'
        },
        id: '1_1',
        position: 1
      }));
      var expectedDefaultSir = new _SessionItemResult.default({
        attempt: 1,
        itemId: '2',
        id: si.id,
        position: si.position
      }).toJS();
      var sir = new _SessionItemResult.default();
      var defaultResult = sir.defaultResult(si).toJS();
      expect(defaultResult).to.be.deep.equal(expectedDefaultSir);
    });
  });
  describe('#isLoaded', function () {
    it('returns false if itemId is null', function () {
      var sir = new _SessionItemResult.default({
        itemId: null
      });
      expect(sir.isLoaded()).to.be.false();
    });
    it('returns true if itemId is not null', function () {
      var sir = new _SessionItemResult.default({
        itemId: '1'
      });
      expect(sir.isLoaded()).to.be.true();
    });
  });
  describe('#isGraded', function () {
    it('returns false if itemId is null', function () {
      var sir = new _SessionItemResult.default({
        gradedAt: null
      });
      expect(sir.isGraded()).to.be.false();
    });
    it('returns true if itemId is not null', function () {
      var sir = new _SessionItemResult.default({
        gradedAt: '11/12/44'
      });
      expect(sir.isGraded()).to.be.true();
    });
  });
  describe('#hasModifications', function () {
    it('returns false if it has no modifications', function () {
      var result = new _SessionItemResult.default();
      var unmodifiedResult = result.merge({});
      sinon.stub(result, 'getWorkingInstance').returns(unmodifiedResult);
      expect(result.hasModifications()).to.be.false();
    });
    it('returns true if modifications exist', function () {
      var result = new _SessionItemResult.default();
      var modifiedResult = result.merge({
        score: 99
      });
      sinon.stub(result, 'getWorkingInstance').returns(modifiedResult);
      expect(result.hasModifications()).to.be.true();
    });
  });
});