"use strict";

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

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

var _chai = require("chai");

var _serializeEvent = _interopRequireDefault(require("../serializeEvent"));

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

var _minimalStore = _interopRequireDefault(require("../../../../tests/util/minimalStore"));

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

var _taking = require("../../actions/taking");

describe('serializeEvent', function () {
  // testrail test_id: C2954596, C2954597
  var activeQuizSessionId = '3';
  var fakeState = {
    taking: {
      browserSessionId: 'session_id_guid'
    },
    quizSessions: (0, _defineProperty2.default)({
      activeQuizSessionId: activeQuizSessionId
    }, activeQuizSessionId, {
      accountUuid: 'accountUuid',
      eventCreationToken: 'jwt_token',
      id: activeQuizSessionId
    })
  };
  before(function () {
    (0, _reduxStore.setFakeStore)((0, _minimalStore.default)(fakeState).getState());
  });
  after(function () {
    (0, _reduxStore.unsetFakeStore)();
  });
  context(_constants.RESPONSE, function () {
    context('edit response', function () {
      it('returns a well formed object', function () {
        var sessionItem = {
          position: 1,
          getItem: function getItem() {
            return {
              id: '1'
            };
          }
        };
        var action = (0, _taking.editResponse)(sessionItem, 'bar');
        var eventData = Object.assign({}, action.payload, {
          browserSessionId: 'session_id_guid',
          clientTimestamp: 'timestamp'
        });
        var serializedEvent = (0, _serializeEvent.default)(action);
        var expectedEvent = {
          accountUuid: 'accountUuid',
          eventCreationToken: 'jwt_token',
          eventData: eventData,
          eventType: _constants.RESPONSE,
          quizSessionId: '3'
        };
        (0, _chai.expect)(serializedEvent).to.have.all.keys(Object.keys(expectedEvent));
        (0, _chai.expect)(serializedEvent).to.have.property('accountUuid').that.equals(expectedEvent.accountUuid);
        (0, _chai.expect)(serializedEvent).to.have.property('eventCreationToken').that.is.an('string');
        (0, _chai.expect)(serializedEvent).to.have.property('eventType').that.equals(expectedEvent.eventType);
        (0, _chai.expect)(serializedEvent).to.have.property('quizSessionId').that.equals(expectedEvent.quizSessionId);
        (0, _chai.expect)(serializedEvent).to.have.property('eventData').that.is.an('object');
        (0, _chai.expect)(serializedEvent.eventData).to.have.property('browserSessionId').that.equals(eventData.browserSessionId);
        (0, _chai.expect)(serializedEvent.eventData).to.have.property('clientTimestamp').that.is.a('date');
        (0, _chai.expect)(serializedEvent.eventData).to.have.property('userResponse').that.equals(eventData.userResponse);
        (0, _chai.expect)(serializedEvent.eventData).to.have.property('itemId').that.equals(eventData.itemId);
        (0, _chai.expect)(serializedEvent.eventData).to.have.property('position').that.equals(eventData.position);
      });
    });
  });
  context(_constants.SESSION_STARTED_OR_RESUMED_EVENT, function () {
    context('start a new taking session (or resume)', function () {
      it('returns a well formed object', function () {
        var userAgent = 'userAgent';
        var action = (0, _taking.sessionStartOrResumeEvent)(userAgent);
        var serializedEvent = (0, _serializeEvent.default)(action);
        var expectedEvent = {
          accountUuid: 'accountUuid',
          eventCreationToken: 'jwt_token',
          eventData: {
            browserSessionId: 'session_id_guid',
            userAgent: userAgent
          },
          eventType: _constants.SESSION_STARTED_OR_RESUMED_EVENT,
          quizSessionId: '3'
        };
        (0, _chai.expect)(serializedEvent).to.have.all.keys(Object.keys(expectedEvent));
        (0, _chai.expect)(serializedEvent).to.have.property('accountUuid').that.equals(expectedEvent.accountUuid);
        (0, _chai.expect)(serializedEvent).to.have.property('eventCreationToken').that.is.an('string');
        (0, _chai.expect)(serializedEvent).to.have.property('eventType').that.equals(expectedEvent.eventType);
        (0, _chai.expect)(serializedEvent).to.have.property('quizSessionId').that.equals(expectedEvent.quizSessionId);
        (0, _chai.expect)(serializedEvent).to.have.property('eventData').that.is.an('object').with.property('userAgent').that.equals(userAgent);
        (0, _chai.expect)(serializedEvent.eventData).to.have.property('browserSessionId').that.equals('session_id_guid');
        (0, _chai.expect)(serializedEvent.eventData).to.have.property('clientTimestamp').that.is.a('date');
      });
    });
  });
});