cache-storage
Version:
[ABANDONED] Advanced cache storage for node js
113 lines (103 loc) • 3.32 kB
JavaScript
// Generated by CoffeeScript 1.6.3
(function() {
var Cache, Storage, cache, expect, fs, moment, storage;
expect = require('chai').expect;
Cache = require('../../../../../lib/Cache');
Storage = require('../../../../../lib/Storage/Sync/Storage');
moment = require('moment');
cache = null;
storage = null;
fs = null;
describe('SyncStorage', function() {
beforeEach(function() {
storage = new Storage;
cache = new Cache(storage);
return fs = Cache.mockFs({
'file': ''
});
});
afterEach(function() {
return Cache.restoreFs();
});
describe('#verify()', function() {
it('should just return true', function() {
return expect(storage.verify('random variable')).to.be["true"];
});
it('should return false if meta expired', function() {
return expect(storage.verify({
expire: (new Date).getTime() - 200
})).to.be["false"];
});
it('should return false if dependent meta expired', function() {
storage.findMeta = function() {
return {
expire: (new Date).getTime() - 200
};
};
return expect(storage.verify({
items: ['test']
})).to.be["false"];
});
return it('should return false if file was changed', function(done) {
var meta;
meta = {
files: {
'/file': fs.statSync('/file').mtime.getTime()
}
};
return setTimeout(function() {
expect(storage.verify(meta)).to.be["true"];
fs.writeFileSync('/file', '');
expect(storage.verify(meta)).to.be["false"];
return done();
}, 100);
});
});
return describe('#parseDependencies()', function() {
it('should return empty object for unknown type of dependencies', function() {
return expect(storage.parseDependencies('random variable')).to.be.eql({});
});
it('should add priority into dependencies', function() {
return expect(storage.parseDependencies({
priority: 100
})).to.be.eql({
priority: 100
});
});
it('should add tags into dependencies', function() {
return expect(storage.parseDependencies({
tags: ['comment', 'article']
})).to.be.eql({
tags: ['comment', 'article']
});
});
it('should add dependent item into dependencies', function() {
return expect(storage.parseDependencies({
items: ['first', 'second']
})).to.be.eql({
items: [cache.generateKey('first'), cache.generateKey('second')]
});
});
it('should add date from string into dependencies', function() {
var time;
time = '2014-01-14 20:10';
return expect(storage.parseDependencies({
expire: time
})).to.be.eql({
expire: moment(time, Cache.TIME_FORMAT).valueOf()
});
});
return it('should add file into dependencies', function() {
var time;
time = fs.statSync('/file').mtime.getTime();
return expect(storage.parseDependencies({
files: ['/file']
})).to.be.eql({
files: {
'/file': time
}
});
});
});
});
}).call(this);