more tests

This commit is contained in:
Barış Soner Uşaklı
2017-05-19 20:24:54 -04:00
parent 77894915eb
commit fd0043f36a
5 changed files with 201 additions and 103 deletions

View File

@@ -2,6 +2,7 @@
var assert = require('assert');
var nconf = require('nconf');
var db = require('./mocks/databasemock');
@@ -12,14 +13,46 @@ describe('Test database', function () {
});
});
it('should return info about database', function (done) {
db.info(db.client, function (err, info) {
assert.ifError(err);
assert(info);
done();
describe('info', function () {
it('should return info about database', function (done) {
db.info(db.client, function (err, info) {
assert.ifError(err);
assert(info);
done();
});
});
it('should not error and return null if client is falsy', function (done) {
db.info(null, function (err, info) {
assert.ifError(err);
assert.equal(info, null);
done();
});
});
});
describe('checkCompatibility', function () {
it('should not throw', function (done) {
db.checkCompatibility(done);
});
it('should return error with a too low version', function (done) {
var dbName = nconf.get('database');
if (dbName === 'redis') {
db.checkCompatibilityVersion('2.4.0', function (err) {
assert.equal(err.message, 'Your Redis version is not new enough to support NodeBB, please upgrade Redis to v2.8.9 or higher.');
done();
});
} else if (dbName === 'mongo') {
db.checkCompatibilityVersion('1.8.0', function (err) {
assert.equal(err.message, 'The `mongodb` package is out-of-date, please run `./nodebb setup` again.');
done();
});
}
});
});
require('./database/keys');
require('./database/list');
require('./database/sets');

View File

@@ -9,11 +9,18 @@ describe('List methods', function () {
describe('listAppend()', function () {
it('should append to a list', function (done) {
db.listAppend('testList1', 5, function (err) {
assert.equal(err, null);
assert.ifError(err);
assert.equal(arguments.length, 1);
done();
});
});
it('should not add anyhing if key is falsy', function (done) {
db.listAppend(null, 3, function (err) {
assert.ifError(err);
done();
});
});
});
describe('listPrepend()', function () {
@@ -38,6 +45,13 @@ describe('List methods', function () {
done();
});
});
it('should not add anyhing if key is falsy', function (done) {
db.listPrepend(null, 3, function (err) {
assert.ifError(err);
done();
});
});
});
describe('getListRange()', function () {
@@ -83,6 +97,14 @@ describe('List methods', function () {
done();
});
});
it('should not get anyhing if key is falsy', function (done) {
db.getListRange(null, 0, -1, function (err, data) {
assert.ifError(err);
assert.equal(data, undefined);
done();
});
});
});
describe('listRemoveLast()', function () {
@@ -105,6 +127,13 @@ describe('List methods', function () {
done();
});
});
it('should not remove anyhing if key is falsy', function (done) {
db.listRemoveLast(null, function (err) {
assert.ifError(err);
done();
});
});
});
describe('listRemoveAll()', function () {
@@ -132,6 +161,13 @@ describe('List methods', function () {
});
});
});
it('should not remove anyhing if key is falsy', function (done) {
db.listRemoveAll(null, 3, function (err) {
assert.ifError(err);
done();
});
});
});
describe('listTrim()', function () {
@@ -156,6 +192,13 @@ describe('List methods', function () {
});
});
});
it('should not add anyhing if key is falsy', function (done) {
db.listTrim(null, 0, 3, function (err) {
assert.ifError(err);
done();
});
});
});

View File

@@ -81,6 +81,10 @@
var db = require('../../src/database');
after(function (done) {
db.close(done);
});
before(function (done) {
this.timeout(30000);
var meta;
@@ -91,6 +95,9 @@
function (next) {
db.emptydb(next);
},
function (next) {
db.createIndices(next);
},
function (next) {
winston.info('test_database flushed');
meta = require('../../src/meta');