Merge pull request #2676 from strongloop/add-remoting-for-kv-model-ttl
Add remoting for kv model ttl
This commit is contained in:
commit
69f7f0941f
|
@ -16,6 +16,11 @@ module.exports = function(KeyValueModel) {
|
|||
throwNotAttached(this.modelName, 'expire');
|
||||
};
|
||||
|
||||
// TODO add api docs
|
||||
KeyValueModel.ttl = function(key, options, callback) {
|
||||
throwNotAttached(this.modelName, 'ttl');
|
||||
};
|
||||
|
||||
// TODO add api docs
|
||||
KeyValueModel.keys = function(filter, options, callback) {
|
||||
throwNotAttached(this.modelName, 'keys');
|
||||
|
@ -62,6 +67,15 @@ module.exports = function(KeyValueModel) {
|
|||
http: { path: '/:key/expire', verb: 'put' },
|
||||
});
|
||||
|
||||
this.remoteMethod('ttl', {
|
||||
accepts: {
|
||||
arg: 'key', type: 'string', required: true,
|
||||
http: { source: 'path' },
|
||||
},
|
||||
returns: { arg: 'value', type: 'any', root: true },
|
||||
http: { path: '/:key/ttl', verb: 'get' },
|
||||
});
|
||||
|
||||
this.remoteMethod('keys', {
|
||||
accepts: {
|
||||
arg: 'filter', type: 'object', required: false,
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
"mBaaS"
|
||||
],
|
||||
"scripts": {
|
||||
"lint": "grunt eslint",
|
||||
"test": "grunt mocha-and-karma"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
|
@ -81,6 +81,47 @@ describe('KeyValueModel', function() {
|
|||
.expect(404, done);
|
||||
});
|
||||
|
||||
it('provides "ttl(key)" at "GET /key/ttl"', function(done) {
|
||||
request.put('/CacheItems/ttl-key?ttl=2000')
|
||||
.end(function(err, res) {
|
||||
if (err) return done(err);
|
||||
request.get('/CacheItems/ttl-key/ttl')
|
||||
.end(function(err, res) {
|
||||
if (err) return done(err);
|
||||
expect(res.body).to.be.number;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('returns 204 when getting TTL for a key that does not have TTL set',
|
||||
function(done) {
|
||||
request.put('/CacheItems/ttl-key')
|
||||
.end(function(err, res) {
|
||||
if (err) return done(err);
|
||||
request.get('/CacheItems/ttl-key/ttl')
|
||||
.expect(204, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns 404 when getting TTL for a key when TTL has expired',
|
||||
function(done) {
|
||||
request.put('/CacheItems/ttl-key?ttl=10')
|
||||
.end(function(err, res) {
|
||||
setTimeout(function() {
|
||||
if (err) return done(err);
|
||||
request.get('/CacheItems/ttl-key/ttl')
|
||||
.expect(404, done);
|
||||
}, 20);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns 404 when getting TTL for a key that does not exist',
|
||||
function(done) {
|
||||
request.get('/CacheItems/key-does-not-exist/ttl')
|
||||
.expect(404, done);
|
||||
});
|
||||
|
||||
it('provides "keys(filter)" at "GET /keys"', function(done) {
|
||||
CacheItem.set('list-key', AN_OBJECT_VALUE, function(err) {
|
||||
if (err) return done(err);
|
||||
|
|
Loading…
Reference in New Issue