hash tests

v1.18.x
barisusakli 10 years ago
parent 1e6f5d822d
commit a6c75eea88

@ -13,102 +13,7 @@ describe('Test database', function() {
require('./database/keys');
require('./database/list');
require('./database/sets');
it('should not throw err', function(done) {
var objectKey = 'testObj';
function setObject(callback) {
db.setObject(objectKey, {name:'baris', 'lastname':'usakli', age:3}, function(err, result) {
callback(err, {'setObject':result});
});
}
function getObject(callback) {
db.getObject(objectKey, function(err, data) {
callback(err, {'getObject':data});
});
}
function getObjects(callback) {
db.getObjects(['testing1', objectKey, 'doesntexist', 'user:1'], function(err, data) {
callback(err, {'getObjects':data});
});
}
function setObjectField(callback) {
db.setObjectField(objectKey, 'reputation', 5, function(err, result) {
callback(err, {'setObjectField': result});
});
}
function getObjectField(callback) {
db.getObjectField(objectKey, 'age', function(err, age) {
callback(err, {'getObjectField' : age});
});
}
function getObjectFields(callback) {
db.getObjectFields(objectKey, ['name', 'lastname'], function(err, data) {
callback(err, {'getObjectFields':data});
});
}
function getObjectValues(callback) {
db.getObjectValues(objectKey, function(err, data) {
callback(err, {'getObjectValues':data});
});
}
function isObjectField(callback) {
db.isObjectField(objectKey, 'age', function(err, data) {
callback(err, {'isObjectField':data});
});
}
function deleteObjectField(callback) {
db.deleteObjectField(objectKey, 'reputation', function(err, data) {
callback(err, {'deleteObjectField':data});
});
}
function incrObjectFieldBy(callback) {
db.incrObjectFieldBy(objectKey, 'age', 3, function(err, data) {
callback(err, {'incrObjectFieldBy':data});
});
}
function getObjectKeys(callback) {
db.getObjectKeys(objectKey, function(err, data) {
callback(err, {'getObjectKeys':data});
});
}
var objectTasks = [
setObject,
getObject,
deleteObjectField,
getObject,
setObjectField,
getObject,
deleteObjectField,
getObject,
getObjectField,
getObjectFields,
getObjectValues,
isObjectField,
incrObjectFieldBy,
getObject,
getObjects,
getObjectKeys
];
async.series(objectTasks, function(err, results) {
assert.equal(err, null, 'error in object methods');
assert.ok(results);
done();
});
});
require('./database/hash');
it('should not throw err', function(done) {

@ -0,0 +1,81 @@
'use strict';
var async = require('async'),
assert = require('assert'),
db = require('../mocks/databasemock');
describe('Hash methods', function() {
var testData = {
name: 'baris',
age: 99
};
describe('setObject()', function() {
it('should create a object', function(done) {
db.setObject('testObject1', testData, function(err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
done();
});
});
});
describe('setObjectField()', function() {
it('should add a new field to an object', function(done) {
db.setObjectField('testObject1', 'lastname', 'usakli', function(err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
done();
});
});
it('should create a new object with field', function(done) {
db.setObjectField('testObject2', 'name', 'ginger', function(err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
done();
});
});
});
describe('getObject()', function() {
it('should return falsy if object does not exist', function(done) {
db.getObject('doesnotexist', function(err, data) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(!!data, false);
done();
});
});
it('should retrieve an object', function(done) {
db.getObject('testObject1', function(err, data) {
assert.equal(err, null);
assert.equal(data.name, testData.name);
assert.equal(data.age, testData.age);
assert.equal(data.lastname, 'usakli');
done();
});
});
});
describe('getObjects()', function() {
it('should return 3 objects with correct data', function(done) {
db.getObjects(['testObject1' 'testObject2', 'doesnotexist'], function(err, objects) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(Array.isArray(objects) && objects.length === 3, true);
assert.equal(objects[0].name, 'baris');
assert.equal(objects[1].name, 'ginger');
assert.equal(!!objects[2], false);
done();
});
});
});
after(function() {
db.flushdb();
});
});
Loading…
Cancel
Save