Comparing version 3.4.0 to 3.4.1
@@ -232,5 +232,9 @@ // Load modules | ||
var hasExpiresIn = options.hasOwnProperty('expiresIn'); | ||
Hoek.assert(!hasExpiresIn || !options.expiresAt, 'Rule cannot include both expiresIn and expiresAt', options); // XOR | ||
Hoek.assert(!options.expiresAt || !options.staleIn || options.staleIn < 86400000, 'staleIn must be less than 86400000 milliseconds (one day) when using expiresAt'); | ||
var hasExpiresIn = options.expiresIn !== undefined && options.expiresIn !== null; | ||
var hasExpiresAt = options.expiresAt !== undefined && options.expiresAt !== null; | ||
Hoek.assert(!hasExpiresAt || typeof options.expiresAt === 'string', 'expiresAt must be a string', options); | ||
Hoek.assert(!hasExpiresIn || Hoek.isInteger(options.expiresIn), 'expiresIn must be an integer', options); | ||
Hoek.assert(!hasExpiresIn || !hasExpiresAt, 'Rule cannot include both expiresIn and expiresAt', options); // XOR | ||
Hoek.assert(!hasExpiresAt || !options.staleIn || options.staleIn < 86400000, 'staleIn must be less than 86400000 milliseconds (one day) when using expiresAt'); | ||
Hoek.assert(!hasExpiresIn || !options.staleIn || options.staleIn < options.expiresIn, 'staleIn must be less than expiresIn'); | ||
@@ -246,3 +250,3 @@ Hoek.assert(!options.staleIn || serverSide, 'Cannot use stale options without server-side caching'); | ||
if (options.expiresAt) { | ||
if (hasExpiresAt) { | ||
@@ -249,0 +253,0 @@ // expiresAt |
{ | ||
"name": "catbox", | ||
"description": "Multi-strategy object caching service", | ||
"version": "3.4.0", | ||
"version": "3.4.1", | ||
"author": "Eran Hammer <eran@hammer.io> (http://hueniverse.com)", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -1003,4 +1003,4 @@ // Load modules | ||
var config = { | ||
expiresAt: 50, | ||
expiresIn: '02:00' | ||
expiresAt: '02:00', | ||
expiresIn: 50 | ||
}; | ||
@@ -1012,3 +1012,3 @@ var fn = function () { | ||
expect(fn).to.throw(Error); | ||
expect(fn).to.throw('Rule cannot include both expiresIn and expiresAt {"expiresAt":"02:00","expiresIn":50}'); | ||
@@ -1018,10 +1018,13 @@ done(); | ||
it('allows a rule with neither expiresAt or expiresIn', function (done) { | ||
it('throws an error when expiresAt is invalid type', function (done) { | ||
var config = { | ||
expiresAt: 0 | ||
}; | ||
var fn = function () { | ||
Catbox.policy.compile({ a: 1 }, true); | ||
Catbox.policy.compile(config, false); | ||
}; | ||
expect(fn).to.not.throw(); | ||
expect(fn).to.throw('expiresAt must be a string {"expiresAt":0}'); | ||
@@ -1031,6 +1034,6 @@ done(); | ||
it('throws an error when parsing a bad expiresAt value', function (done) { | ||
it('throws an error when expiresAt is invalid string', function (done) { | ||
var config = { | ||
expiresAt: function () { } | ||
expiresAt: '4' | ||
}; | ||
@@ -1042,3 +1045,3 @@ var fn = function () { | ||
expect(fn).to.throw(Error); | ||
expect(fn).to.throw('Invalid time string for expiresAt: 4'); | ||
@@ -1048,2 +1051,57 @@ done(); | ||
it('throws an error when expiresIn is invalid', function (done) { | ||
var config = { | ||
expiresIn: '50' | ||
}; | ||
var fn = function () { | ||
Catbox.policy.compile(config, false); | ||
}; | ||
expect(fn).to.throw('expiresIn must be an integer {"expiresIn":"50"}'); | ||
done(); | ||
}); | ||
it('throws an error when parsing a rule with both expiresAt and expiresIn (0)', function (done) { | ||
var config = { | ||
expiresAt: '02:00', | ||
expiresIn: 0 | ||
}; | ||
var fn = function () { | ||
Catbox.policy.compile(config, false); | ||
}; | ||
expect(fn).to.throw('Rule cannot include both expiresIn and expiresAt {"expiresAt":"02:00","expiresIn":0}'); | ||
done(); | ||
}); | ||
it('allows a rule with neither expiresAt or expiresIn', function (done) { | ||
var fn = function () { | ||
Catbox.policy.compile({ a: 1 }, true); | ||
}; | ||
expect(fn).to.not.throw(); | ||
done(); | ||
}); | ||
it('allows a rule with expiresAt and undefined expiresIn', function (done) { | ||
var fn = function () { | ||
Catbox.policy.compile({ expiresIn: undefined, expiresAt: '09:00' }, true); | ||
}; | ||
expect(fn).to.not.throw(); | ||
done(); | ||
}); | ||
it('throws an error when staleIn is used without staleTimeout', function (done) { | ||
@@ -1211,3 +1269,3 @@ | ||
it('doesn\'t throw an error if has both staleTimeout and staleIn', function (done) { | ||
it('does not throw an error if has both staleTimeout and staleIn', function (done) { | ||
@@ -1351,3 +1409,3 @@ var config = { | ||
var config = { | ||
expiresIn: '100' | ||
expiresIn: 100 | ||
}; | ||
@@ -1354,0 +1412,0 @@ var created = Date.now() + 1000; |
152613
2282