"use strict";

var _chai = require("chai");

var _sessionStore = require("../sessionStore");

describe('SessionStore', function () {
  context('with a storage that raises on set', function () {
    var errorOnSetStorage = {
      set: function set() {
        throw new Error('no!');
      }
    };
    it('is not enabled', function () {
      var sessionStore = new _sessionStore.SessionStore(errorOnSetStorage);
      (0, _chai.expect)(sessionStore.enabled).to.be.false();
    });
  });
  context('with a storage that can be set', function () {
    var setValue;
    var removeStub = sinon.stub();
    var setableStorage = {
      setItem: function setItem(key, value) {
        setValue = value;
      },
      getItem: function getItem() {
        return setValue;
      },
      removeItem: removeStub
    };
    var sessionStore = new _sessionStore.SessionStore(setableStorage);
    it('is enabled', function () {
      (0, _chai.expect)(sessionStore.enabled).to.be.true();
    });
    context('value is empty', function () {
      it('removes the stored value', function () {
        var key = 'key';
        removeStub.resetHistory();
        sessionStore.set(key);
        (0, _chai.expect)(removeStub.calledWith(key)).to.be.true();
      });
    });
  });
});