proper list tests, added before hooks

v1.18.x
barisusakli 10 years ago
parent 5bc078d9df
commit 6b5b0b9eec

@ -9,9 +9,9 @@ describe('List methods', function() {
describe('listAppend()', function() { describe('listAppend()', function() {
it('should append to a list', function(done) { it('should append to a list', function(done) {
db.listAppend('testList', 5, function(err) { db.listAppend('testList1', 5, function(err) {
assert.equal(err, null, 'db.listAppend error'); assert.equal(err, null);
assert.equal(arguments.length, 1, 'arguments.length error'); assert.equal(arguments.length, 1);
done(); done();
}); });
}); });
@ -20,8 +20,8 @@ describe('List methods', function() {
describe('listPrepend()', function() { describe('listPrepend()', function() {
it('should prepend to a list', function(done) { it('should prepend to a list', function(done) {
db.listPrepend('testList2', 3, function(err) { db.listPrepend('testList2', 3, function(err) {
assert.equal(err, null, 'db.listPrepend error'); assert.equal(err, null);
assert.equal(arguments.length, 1, 'arguments.length error'); assert.equal(arguments.length, 1);
done(); done();
}); });
}); });
@ -35,64 +35,99 @@ describe('List methods', function() {
db.listPrepend('testList2', 1, next); db.listPrepend('testList2', 1, next);
} }
], function(err) { ], function(err) {
assert.equal(err, null, 'db.listPrepend error'); assert.equal(err, null);
done(); done();
}); });
}); });
}); });
describe('getListRange()', function() { describe('getListRange()', function() {
before(function(done) {
async.series([
function(next) {
db.listAppend('testList3', 7, next);
},
function(next) {
db.listPrepend('testList3', 3, next);
},
function(next) {
db.listAppend('testList4', 5, next);
}
], done);
});
it('should return an empty list', function(done) { it('should return an empty list', function(done) {
db.getListRange('doesnotexist', 0, -1, function(err, list) { db.getListRange('doesnotexist', 0, -1, function(err, list) {
assert.equal(err, null, 'db.getListRange error'); assert.equal(err, null);
assert.equal(arguments.length, 2, 'arguments.length error'); assert.equal(arguments.length, 2);
assert.equal(Array.isArray(list), true, 'list is not an array'); assert.equal(Array.isArray(list), true);
assert.equal(list.length, 0, 'list not empty'); assert.equal(list.length, 0);
done(); done();
}); });
}); });
it('should return a list with one element', function(done) { it('should return a list with one element', function(done) {
db.getListRange('testList', 0, 0, function(err, list) { db.getListRange('testList4', 0, 0, function(err, list) {
assert.equal(err, null, 'db.getListRange error'); assert.equal(err, null);
assert.equal(Array.isArray(list), true, 'list is not an array'); assert.equal(Array.isArray(list), true,);
assert.equal(list[0], 5, 'list does not have value'); assert.equal(list[0], 5);
done(); done();
}); });
}); });
it('should return a list with 3 elements 1,2,3', function(done) { it('should return a list with 2 elements 3, 7', function(done) {
db.getListRange('testList2', 0, -1, function(err, list) { db.getListRange('testList2', 0, -1, function(err, list) {
assert.equal(err, null, 'db.getListRange error'); assert.equal(err, null);
assert.equal(Array.isArray(list), true, 'list is not an array'); assert.equal(Array.isArray(list), true);
assert.equal(list.length, 3, 'list length is not 3'); assert.equal(list.length, 2);
assert.deepEqual(list, ['1', '2', '3'], 'lists not equal'); assert.deepEqual(list, ['3', '7']);
done(); done();
}); });
}); });
}); });
describe('listRemoveLast()', function() { describe('listRemoveLast()', function() {
it('should remove the last element of list', function(done) { before(function(done) {
async.series([
function(next) {
db.listAppend('testList4', 12, next);
},
function(next) {
db.listPrepend('testList4', 9, next);
}
], done);
});
it('should remove the last element of list and return it', function(done) {
db.listRemoveLast('testList2', function(err, lastElement) { db.listRemoveLast('testList2', function(err, lastElement) {
assert.equal(err, null, 'db.listRemoveLast error'); assert.equal(err, null);
assert.equal(arguments.length, 2, 'arguments.length error'); assert.equal(arguments.length, 2);
assert.equal(lastElement, '3', 'last element not correct'); assert.equal(lastElement, '12');
done(); done();
}); });
}); });
}); });
describe('listRemoveAll()', function() { describe('listRemoveAll()', function() {
before(function(done) {
async.series([
async.apply(db.listAppend, 'testList5', 1),
async.apply(db.listAppend, 'testList5', 1),
async.apply(db.listAppend, 'testList5', 1),
async.apply(db.listAppend, 'testList5', 2),
async.apply(db.listAppend, 'testList5', 5)
], done);
});
it('should remove all the matching elements of list', function(done) { it('should remove all the matching elements of list', function(done) {
db.listRemoveAll('testList2', '1', function(err) { db.listRemoveAll('testList2', '1', function(err) {
assert.equal(err, null, 'db.listRemoveAll error'); assert.equal(err, null);
assert.equal(arguments.length, 1, 'arguments.length error'); assert.equal(arguments.length, 1);
db.getListRange('testList2', 0, -1, function(err, list) { db.getListRange('testList2', 0, -1, function(err, list) {
assert.equal(Array.isArray(list), true, 'list is not an array'); assert.equal(Array.isArray(list), true);
assert.equal(list.length, 1, 'element not removed'); assert.equal(list.length, 2);
assert.equal(list.indexOf('1'), -1, 'element not removed'); assert.equal(list.indexOf('1'), -1);
done(); done();
}); });
}); });
@ -103,7 +138,7 @@ describe('List methods', function() {
it('should trim list to a certain range', function(done) { it('should trim list to a certain range', function(done) {
var list = ['1', '2', '3', '4', '5']; var list = ['1', '2', '3', '4', '5'];
async.eachSeries(list, function(value, next) { async.eachSeries(list, function(value, next) {
db.listAppend('testList3', value, next); db.listAppend('testList6', value, next);
}, function(err) { }, function(err) {
if (err) { if (err) {
return done(err); return done(err);

Loading…
Cancel
Save