"use strict";

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

var _chai = require("chai");

var _immutable = require("immutable");

var _eventLoggerMiddleware = _interopRequireDefault(require("../eventLoggerMiddleware"));

var fakeLoggerFetch = sinon.stub().returns({
  then: function then() {}
});

var createFakeStore = function createFakeStore(fakeData) {
  return {
    getState: function getState() {
      return (0, _immutable.fromJS)(fakeData);
    }
  };
};

var fakeSerializer = sinon.stub();
var fakeAction = {
  type: 'STRING'
};

var fakeDispatchWithDefaults = function fakeDispatchWithDefaults() {
  var storeData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var action = arguments.length > 1 ? arguments[1] : undefined;
  var serializer = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : fakeSerializer;
  var dispatched = null;
  var eventLoggerMiddleware = (0, _eventLoggerMiddleware.default)(fakeLoggerFetch, serializer);

  var fakeActionTrigger = function fakeActionTrigger(actionAttempt) {
    dispatched = actionAttempt;
    return actionAttempt;
  };

  var dispatch = eventLoggerMiddleware(createFakeStore(storeData))(fakeActionTrigger);
  dispatch(action);
  return dispatched;
};

describe('eventLoggerMiddleware', function () {
  it('calls for the kinesis client when serializer returns data', function () {
    fakeSerializer.returns({});
    fakeDispatchWithDefaults({}, fakeAction, fakeSerializer);
    (0, _chai.expect)(fakeLoggerFetch.called).to.be.true();
    fakeLoggerFetch.resetHistory();
  });
  it('does not call for kinesis client when serializer returns no data', function () {
    fakeSerializer.returns(null);
    fakeDispatchWithDefaults({}, fakeAction, fakeSerializer);
    (0, _chai.expect)(fakeLoggerFetch.called).to.not.be.true();
    fakeLoggerFetch.resetHistory();
  });
});