"use strict";

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

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

var _StreamQueue = _interopRequireDefault(require("../StreamQueue"));

var _kinesisTests = require("./kinesisTests");

describe('StreamQueue', function () {
  var config = (0, _kinesisTests.fakeStreamConfigCreator)();
  var kinesis = (0, _kinesisTests.fakeKinesisClientCreator)();
  var subject = null;
  beforeEach(function () {
    subject = new _StreamQueue.default({
      config: config,
      kinesis: kinesis
    });
  });
  it('accepts new events', function () {
    expect(subject.push('EVENT', {})).to.be.true();
  });
  it('sends to kinesis when a page is full', function () {
    kinesis.putRecords = sinon.spy();
    expect(kinesis.putRecords).to.not.have.been.called();
    subject.push('EVENT', {});
    subject.push('EVENT', {});
    subject.push('EVENT', {});
    subject.push('EVENT', {});
    expect(kinesis.putRecords).to.not.have.been.called();
    subject.push('EVENT', {}); // Page limit here is 5, don't expect an event until it is hit

    expect(kinesis.putRecords).to.have.been.called();
  });
  it('requires a known type of event', function () {
    // eslint-disable-next-line no-unused-expressions
    expect(function () {
      return subject.push('NOT_A_KNOWN_EVENT_TYPE', {});
    }).to.throw();
  });
  context('page size of 1', function () {
    beforeEach(function () {
      subject.config = (0, _objectSpread2.default)({}, config, {
        maxPageSize: 1
      });
    });
    it('sends events to kinesis immediately', function () {
      kinesis.putRecords = sinon.spy();
      subject.push('EVENT', {});
      subject.push('EVENT', {});
      expect(kinesis.putRecords).to.have.been.calledTwice();
    });
  });
});