fixed tests

v1.18.x
Baris Soner Usakli 11 years ago
parent 7135e9424c
commit 4986c8ed3a

@ -55,7 +55,8 @@
nconf.set(dbType, testDbConfig);
db = require('../src/database');
var db = require('../src/database'),
meta = require('../src/meta');
before(function(done) {
db.init(function(err) {
@ -66,12 +67,19 @@
throw new Error(err);
} else {
winston.info('test_database flushed');
done();
}
//TODO: data seeding, if needed at all
meta.configs.init(function () {
var webserver = require('../src/webserver'),
sockets = require('../src/socket.io');
sockets.init(webserver.server);
done();
});
}
});
});
});

@ -166,15 +166,8 @@
module.flushdb = function(callback) {
db.dropDatabase(function(err, result) {
if (err) {
winston.error(err.message);
if (typeof callback === 'function') {
return callback(err);
}
}
if (typeof callback === 'function') {
callback();
callback(err);
}
});
};

@ -117,11 +117,9 @@
module.flushdb = function(callback) {
redisClient.send_command('flushdb', [], function(err) {
if (err) {
winston.error(err.message);
return callback(err);
}
if (typeof callback === 'function') {
callback();
}
});
};

@ -87,6 +87,9 @@ var fs = require('fs'),
Meta.themes = {
get: function (callback) {
var themePath = nconf.get('themes_path');
if (typeof themePath !== 'string') {
return callback(null, []);
}
fs.readdir(themePath, function (err, files) {
async.filter(files, function (file, next) {
fs.stat(path.join(themePath, file), function (err, fileStat) {

@ -1,31 +1,39 @@
var winston = require('winston');
process.on('uncaughtException', function (err) {
winston.error('Encountered error while running test suite: ' + err.message);
});
'use strict';
var assert = require('assert'),
db = require('../mocks/databasemock');
db = require('../mocks/databasemock'),
topics = require('../src/topics'),
categories = require('../src/categories');
describe('Topic\'s', function() {
var topic,
categoryObj;
var Topics = require('../src/topics');
before(function(done) {
describe('Topic\'s', function() {
var topic;
categories.create({
name: 'Test Category',
description: 'Test category created by testing script',
icon: 'fa-check',
blockclass: 'category-blue',
order: '5'
}, function(err, category) {
categoryObj = category;
beforeEach(function(){
topic = {
userId: 1,
categoryId: 1,
categoryId: categoryObj.cid,
title: 'Test Topic Title',
content: 'The content of test topic'
};
done();
});
});
describe('.post', function() {
it('should create a new topic with proper parameters', function(done) {
Topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) {
topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) {
assert.equal(err, null, 'was created with error');
assert.ok(result);
@ -34,9 +42,7 @@ describe('Topic\'s', function() {
});
it('should fail to create new topic with wrong parameters', function(done) {
topic.userId = null;
Topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) {
topics.post({uid: null, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) {
assert.equal(err.message, 'invalid-user');
done();
});
@ -48,7 +54,7 @@ describe('Topic\'s', function() {
var newPost;
beforeEach(function(done) {
Topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) {
topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) {
newTopic = result.topicData;
newPost = result.postData;
done();
@ -57,13 +63,13 @@ describe('Topic\'s', function() {
describe('.getTopicData', function() {
it('should not receive errors', function(done) {
Topics.getTopicData(newTopic.tid, done);
topics.getTopicData(newTopic.tid, done);
});
});
describe('.getTopicDataWithUser', function() {
it('should not receive errors', function(done) {
Topics.getTopicDataWithUser(newTopic.tid, done);
topics.getTopicDataWithUser(newTopic.tid, done);
});
});
});

@ -16,7 +16,7 @@ describe('User', function() {
beforeEach(function(){
userData = {
name: 'John Smith',
username: 'John Smith',
password: 'swordfish',
email: 'john@example.com',
callback: undefined
@ -26,7 +26,7 @@ describe('User', function() {
describe('when created', function() {
it('should be created properly', function(done) {
User.create({usename: userData.name, password: userData.password, email: userData.email}, function(error,userId){
User.create({username: userData.username, password: userData.password, email: userData.email}, function(error,userId){
assert.equal(error, null, 'was created with error');
assert.ok(userId);
done();
@ -35,7 +35,7 @@ describe('User', function() {
it('should have a valid email, if using an email', function() {
assert.throws(
User.create({username: userData.name, password: userData.password, email: 'fakeMail'},function(){}),
User.create({username: userData.username, password: userData.password, email: 'fakeMail'},function(){}),
Error,
'does not validate email'
);

Loading…
Cancel
Save