"use strict";

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

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

var _withCachedArguments = _interopRequireDefault(require("../withCachedArguments"));

describe('withCachedArguments', function () {
  var stub = sinon.stub();
  var testObject;
  beforeEach(function () {
    var _obj;

    testObject = (_obj = {
      myMethod: function myMethod(arg1, arg2) {
        stub.call();
        return arg1.value + arg2.value;
      }
    }, ((0, _applyDecoratedDescriptor2.default)(_obj, "myMethod", [_withCachedArguments.default], Object.getOwnPropertyDescriptor(_obj, "myMethod"), _obj)), _obj);
  });
  afterEach(function () {
    stub.resetHistory();
  });
  it('calls through to the original method', function () {
    var obj1 = {
      value: 1
    };
    var obj2 = {
      value: 2
    };
    expect(testObject.myMethod(obj1, obj2)).to.eq(3);
  });
  it('caches results of previously seen arguments', function () {
    var obj1 = {
      value: 1
    };
    var obj2 = {
      value: 2
    };
    testObject.myMethod(obj1, obj2);
    expect(testObject.myMethod(obj1, obj2)).to.eq(3);
    expect(stub.callCount).to.eq(1);
  });
  it('calls the original method more times for cache misses', function () {
    var obj1 = {
      value: 1
    };
    var obj2 = {
      value: 2
    };
    testObject.myMethod(obj1, obj2);
    expect(testObject.myMethod(obj2, obj1)).to.eq(3);
    expect(stub.callCount).to.eq(2);
  });
  it('blows up if too many or too few arguments were provided', function () {
    var obj1 = {
      value: 1
    };
    var obj2 = {
      value: 2
    };
    var obj3 = {
      value: 3
    };
    expect(function () {
      return testObject.myMethod(obj1);
    }).to.throw();
    expect(function () {
      return testObject.myMethod(obj1, obj2, obj3);
    }).to.throw();
  });
});