
checkKey = ()->
  Cache = require '../../src/lib/cache/basic';
  cache = new Cache;
  cache.has('some_key').should.not.be.ok
  cache.set 'some_key','some_val'
  cache.has('some_key').should.be.ok

retriveValid = ()->
  Cache = require '../../src/lib/cache/basic';
  cache = new Cache;
  cache.set('some_key','some_val')
  cache.get('some_key').should.eql('some_val')

retriveInValid = ()->
  Cache = require '../../src/lib/cache/basic';
  cache = new Cache;
  (typeof cache.get('some_key')).should.eql('undefined')

initPersistant = (done)->
  Cache = require '../../src/lib/cache/basic';

  persistantMedium = 
    getItems: (callback)->
      callback some_key: 'some_val'

  cache = new Cache(persistantMedium);
  cache.init ->
    cache.has('some_key').should.be.ok
    cache.get('some_key').should.eql('some_val')
    done();

indicatePersistance = ()->
  Cache = require '../../src/lib/cache/basic';

  persistantMedium = mock(['getItems','save'])
  persistantMedium.modify 'getItems', returns: {}
  persistantMedium.modify 'save', takes: (args)->
    args[0].some_key.should.eql('some_val');


  cache = new Cache(persistantMedium);
  cache.set('some_key', 'some_val')
  persistantMedium.isCalled('save').should.be.ok

describe 'Cache', ->
  it 'should indicate weather a key is present in cache', checkKey;
  it 'should get cached value for a set key', retriveValid;
  it 'should get null for a unset key', retriveInValid;
  it 'should initialize store from persistant medium', initPersistant;
  it 'should save to persistant medium frequently', indicatePersistance;