From 74a3977d4295601abe84798c4d447eb68cfa02b0 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 30 Dec 2014 18:50:10 -0500 Subject: [PATCH] decrObjectField, incrObjectFieldBy tests --- tests/database/hash.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/database/hash.js b/tests/database/hash.js index 48012396d9..34f6179428 100644 --- a/tests/database/hash.js +++ b/tests/database/hash.js @@ -254,6 +254,48 @@ describe('Hash methods', function() { }); }); + describe('decrObjectField()', function() { + it('should set an objects field to -1 if object does not exist', function(done) { + db.decrObjectField('testObject4', 'field1', function(err, newValue) { + assert.equal(err, null); + assert.equal(arguments.length, 2); + assert.equal(newValue, -1); + done(); + }); + }); + + it('should decrement an object fields by 1 and return it', function(done) { + db.decrObjectField('testObject1', 'age', function(err, newValue) { + assert.equal(err, null); + assert.equal(arguments.length, 2); + assert.equal(newValue, 99); + done(); + }); + }); + }); + + describe('incrObjectFieldBy()', function() { + it('should set an objects field to 5 if object does not exist', function(done) { + db.incrObjectFieldBy('testObject5', 'field1', 5, function(err, newValue) { + assert.equal(err, null); + assert.equal(arguments.length, 2); + assert.equal(newValue, 5); + done(); + }); + }); + + it('should increment an object fields by passed in value and return it', function(done) { + db.decrObjectField('testObject1', 'age', 11, function(err, newValue) { + assert.equal(err, null); + assert.equal(arguments.length, 2); + assert.equal(newValue, 110); + done(); + }); + }); + }); + + + after(function() { db.flushdb();