"use strict";

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

var _immutable = require("immutable");

var _QuizSessionEvent = _interopRequireDefault(require("../QuizSessionEvent"));

describe('QuizSessionEvent record', function () {
  // testrail test_id:  C2954598, C2954599, C2954603 , C2954602
  describe('#isLoaded', function () {
    it('returns true if createdAt exists', function () {
      var eventRecord = new _QuizSessionEvent.default({
        createdAt: '2016-09-28T18:45:29.929Z|462090529'
      });
      expect(eventRecord.isLoaded()).to.be.true();
    });
    it('returns false if createdAt is undefined', function () {
      var eventRecord = new _QuizSessionEvent.default({});
      expect(eventRecord.isLoaded()).to.be.false();
    });
  });
  describe('#createdDate', function () {
    it('returns a Date object with correctly parsed data', function () {
      var eventRecord = new _QuizSessionEvent.default({
        createdAt: '2016-09-28T18:45:29.929Z|462090529'
      });
      var expectedDate = new Date('2016-09-28T18:45:29.929Z');
      expect(eventRecord.createdDate().getTime()).to.be.equal(expectedDate.getTime());
    });
  });
  describe('#getSessionItem', function () {
    it('uses the position to fetch the correct session item', function () {
      var eventRecord = new _QuizSessionEvent.default({
        quizSessionId: 'foo',
        eventData: (0, _immutable.Map)({
          position: 2
        })
      });
      var fakeSessionItem = {};
      var findSessionItem = sinon.stub().returns(fakeSessionItem);

      eventRecord.stateHelper = function () {
        return {
          findSessionItem: findSessionItem
        };
      };

      expect(eventRecord.getSessionItem()).to.equal(fakeSessionItem);
      expect(findSessionItem.calledWith('foo_2')).to.be.true();
    });
  });
  describe('#getItem', function () {
    it('proxies a call to getItem from the SessionItem', function () {
      var eventRecord = new _QuizSessionEvent.default();
      var fakeItem = {};
      var getItem = sinon.stub().returns(fakeItem);

      eventRecord.getSessionItem = function () {
        return {
          getItem: getItem
        };
      };

      expect(eventRecord.getItem()).to.equal(fakeItem);
      expect(getItem).to.have.been.called();
    });
  });
});