"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

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

var eventTypes = _interopRequireWildcard(require("../eventTypes"));

var RESPONSE = eventTypes.RESPONSE,
    otherEvents = (0, _objectWithoutProperties2.default)(eventTypes, ["RESPONSE"]);
var fakeData = {
  accountUuid: 'uuid',
  eventCreationToken: 'jwt_token',
  quizSessionId: '1'
};
var fakeResponseData = Object.assign({}, fakeData, {
  eventData: {
    itemId: 'item_1',
    position: 'position_1',
    userResponse: 'response_1'
  }
});

function testGenericEvent(type, data) {
  it('has the correct root-level keys', function () {
    expect(data).to.have.keys(['Data', 'PartitionKey']);
    expect(data.PartitionKey).to.eq("".concat(fakeData.quizSessionId, "|").concat(fakeData.accountUuid));
  });
  it('has the correct payload', function () {
    expect(JSON.parse(data.Data)).to.contain.all.keys(['created_at', 'event_creation_token']);
  });
}

describe('eventTypes', function () {
  Object.keys(otherEvents).forEach(function (type) {
    var data = otherEvents[type](fakeData);
    describe(type, function () {
      testGenericEvent(type, data);
    });
  });
  describe(RESPONSE.name, function () {
    var data = RESPONSE(fakeResponseData);
    testGenericEvent(RESPONSE, data);
    it('modifies the payload correctly', function () {
      expect(JSON.parse(data.Data)).to.contain.all.keys(['event_data', 'item_id', 'position', 'user_response']);
    });
  });
});